Skip to content

Commit

Permalink
feat: Library history section of info sidebar added
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisChV committed Jul 3, 2024
1 parent 1fb8421 commit 473fc27
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 9 deletions.
2 changes: 2 additions & 0 deletions src/library-authoring/data/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ export interface ContentLibrary {
hasUnpublishedDeletes: boolean;
canEditLibrary: boolean;
license: string;
created: Date;
updated: Date;
}

export interface CreateBlockDataRequest {
Expand Down
43 changes: 36 additions & 7 deletions src/library-authoring/library-info/LibraryInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,52 @@ import { Stack } from "@openedx/paragon";
import { useIntl } from '@edx/frontend-platform/i18n';
import React from "react";

Check failure on line 3 in src/library-authoring/library-info/LibraryInfo.tsx

View workflow job for this annotation

GitHub Actions / tests

Strings must use singlequote
import messages from "./messages";

Check failure on line 4 in src/library-authoring/library-info/LibraryInfo.tsx

View workflow job for this annotation

GitHub Actions / tests

Strings must use singlequote
import { convertToStringFromDateAndFormat } from "../../utils";

Check failure on line 5 in src/library-authoring/library-info/LibraryInfo.tsx

View workflow job for this annotation

GitHub Actions / tests

Strings must use singlequote
import { COMMA_SEPARATED_DATE_FORMAT } from "../../constants";

Check failure on line 6 in src/library-authoring/library-info/LibraryInfo.tsx

View workflow job for this annotation

GitHub Actions / tests

Strings must use singlequote

const LibraryInfo = () => {
type LibraryInfoProps = {
orgName: string,
createdAt: Date,
updatedAt: Date,
};

const LibraryInfo = ({ orgName, createdAt, updatedAt } : LibraryInfoProps) => {
const intl = useIntl();

return (
<Stack direction='vertical'>
<Stack direction='vertical' gap={2.5}>

Check failure on line 18 in src/library-authoring/library-info/LibraryInfo.tsx

View workflow job for this annotation

GitHub Actions / tests

Unexpected usage of singlequote
<div>
Published section
</div>
<div>
<Stack direction='vertical'>
<span className="font-weight-bold">
{intl.formatMessage(messages.organizationSectionTitle)}
</span>
</div>
<div>
Library History Section
</div>
<span>
{orgName}
</span>
</Stack>
<Stack>
<span className="font-weight-bold">
{intl.formatMessage(messages.libraryHistorySectionTitle)}
</span>
<Stack>
<span className="small text-gray-500">
{intl.formatMessage(messages.lastModifiedLabel)}
</span>
<span className="small">
{convertToStringFromDateAndFormat(updatedAt, COMMA_SEPARATED_DATE_FORMAT)}
</span>
</Stack>
<Stack>
<span className="small text-gray-500">
{intl.formatMessage(messages.createdLabel)}
</span>
<span className="small">
{convertToStringFromDateAndFormat(createdAt, COMMA_SEPARATED_DATE_FORMAT)}
</span>
</Stack>
</Stack>
</Stack>
);
};
Expand Down
15 changes: 15 additions & 0 deletions src/library-authoring/library-info/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,21 @@ const messages = defineMessages({
defaultMessage: 'Organization',
description: 'Title for Organization section in Library info sidebar.'
},
libraryHistorySectionTitle: {
id: 'course-authoring.library-authoring.sidebar.info.history.title',
defaultMessage: 'Library History',
description: 'Title for Library History section in Library info sidebar.'
},
lastModifiedLabel: {
id: 'course-authoring.library-authoring.sidebar.info.history.last-modified',
defaultMessage: 'Last Modified',
description: 'Last Modified label used in Library History section.'
},
createdLabel: {
id: 'course-authoring.library-authoring.sidebar.info.history.created',
defaultMessage: 'Created',
description: 'Created label used in Library History section.'
},
});

export default messages;
8 changes: 6 additions & 2 deletions src/library-authoring/library-sidebar/LibrarySidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ const LibrarySidebar = ({library}: LibrarySidebarProps) => {

const bodyComponentMap = {
'add-content': <AddContentContainer />,
'info': <LibraryInfo />,
'info': <LibraryInfo
orgName={library.org}
createdAt={library.created}
updatedAt={library.updated}
/>,
unknown: null,
};

Expand All @@ -45,7 +49,7 @@ const LibrarySidebar = ({library}: LibrarySidebarProps) => {
const buildHeader = (): React.ReactNode | null => headerComponentMap[sidebarBodyComponent || 'unknown'];

return (
<div className="p-2 vh-100">
<div className="p-2 vh-100 text-primary-700">
<Stack direction="horizontal" className="d-flex justify-content-between">
{buildHeader()}
<IconButton
Expand Down
15 changes: 15 additions & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,21 @@ export const convertToStringFromDate = (date) => {
return moment(date).format(DATE_TIME_FORMAT);
};

export const convertToStringFromDateAndFormat = (date, format) => {
/**
* Convert local time to UTC string from react-datepicker in a format
* Note: react-datepicker has a bug where it only interacts with local time
* @param {Date} date - date in local time
* @param {string} format - format of the date
* @return {string} date converted in string in the desired format
*/
if (!date) {
return '';
}

return moment(date).format(format);
};

export const isValidDate = (date) => {
const formattedValue = convertToStringFromDate(date).split('T')[0];

Expand Down

0 comments on commit 473fc27

Please sign in to comment.