-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add component sidebar manage tab
- Loading branch information
Showing
12 changed files
with
366 additions
and
189 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
src/library-authoring/component-info/ComponentManagement.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { getConfig } from '@edx/frontend-platform'; | ||
import { useIntl } from '@edx/frontend-platform/i18n'; | ||
import { Collapsible, Icon, Stack } from '@openedx/paragon'; | ||
import { Tag } from '@openedx/paragon/icons'; | ||
|
||
import { useLibraryBlockMetadata } from '../data/apiHooks'; | ||
import StatusWidget from '../generic/status-widget'; | ||
import messages from './messages'; | ||
|
||
interface ComponentManagementProps { | ||
usageKey: string; | ||
} | ||
const ComponentManagement = ({ usageKey }: ComponentManagementProps) => { | ||
const intl = useIntl(); | ||
const { data: componentMetadata } = useLibraryBlockMetadata(usageKey); | ||
|
||
if (!componentMetadata) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<Stack gap={3}> | ||
<StatusWidget | ||
{...componentMetadata} | ||
/> | ||
{[true, 'true'].includes(getConfig().ENABLE_TAGGING_TAXONOMY_PAGES) | ||
&& ( | ||
<Collapsible | ||
defaultOpen | ||
title={( | ||
<Stack gap={1} direction="horizontal"> | ||
<Icon src={Tag} /> | ||
{intl.formatMessage(messages.manageTabTagsTitle)} | ||
</Stack> | ||
)} | ||
className="border-0" | ||
> | ||
Tags placeholder | ||
</Collapsible> | ||
)} | ||
<Collapsible | ||
defaultOpen | ||
title={( | ||
<Stack gap={1} direction="horizontal"> | ||
<Icon src={Tag} /> | ||
{intl.formatMessage(messages.manageTabCollectionsTitle)} | ||
</Stack> | ||
)} | ||
className="border-0" | ||
> | ||
Collections placeholder | ||
</Collapsible> | ||
</Stack> | ||
); | ||
}; | ||
|
||
export default ComponentManagement; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
@import "./status-widget/StatusWidget"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,191 @@ | ||
import { | ||
FormattedDate, | ||
FormattedMessage, | ||
FormattedTime, | ||
useIntl, | ||
} from '@edx/frontend-platform/i18n'; | ||
import { Button, Container, Stack } from '@openedx/paragon'; | ||
import classNames from 'classnames'; | ||
|
||
import messages from './messages'; | ||
|
||
const CustomFormattedDate = ({ date }: { date: string }) => ( | ||
<b> | ||
<FormattedDate | ||
value={date} | ||
year="numeric" | ||
month="long" | ||
day="2-digit" | ||
/> | ||
</b> | ||
); | ||
|
||
const CustomFormattedTime = ({ date }: { date: string }) => ( | ||
<b> | ||
<FormattedTime | ||
value={date} | ||
hour12={false} | ||
/> | ||
</b> | ||
); | ||
|
||
type DraftBodyMessageProps = { | ||
lastDraftCreatedBy?: string | null; | ||
lastDraftCreated?: string | null; | ||
created?: string | null; | ||
}; | ||
const DraftBodyMessage = ({ lastDraftCreatedBy, lastDraftCreated, created }: DraftBodyMessageProps) => { | ||
if (lastDraftCreatedBy && lastDraftCreated) { | ||
return ( | ||
<FormattedMessage | ||
{...messages.lastDraftMsg} | ||
values={{ | ||
date: <CustomFormattedDate date={lastDraftCreated} />, | ||
time: <CustomFormattedTime date={lastDraftCreated} />, | ||
user: <b>{lastDraftCreatedBy}</b>, | ||
}} | ||
/> | ||
); | ||
} | ||
|
||
if (lastDraftCreated) { | ||
return ( | ||
<FormattedMessage | ||
{...messages.lastDraftMsgWithoutUser} | ||
values={{ | ||
date: <CustomFormattedDate date={lastDraftCreated} />, | ||
time: <CustomFormattedTime date={lastDraftCreated} />, | ||
}} | ||
/> | ||
); | ||
} | ||
|
||
if (created) { | ||
return ( | ||
<FormattedMessage | ||
{...messages.lastDraftMsgWithoutUser} | ||
values={{ | ||
date: <CustomFormattedDate date={created} />, | ||
time: <CustomFormattedTime date={created} />, | ||
}} | ||
/> | ||
); | ||
} | ||
|
||
return null; | ||
}; | ||
|
||
type StatusWidgedProps = { | ||
lastPublished?: string | null; | ||
hasUnpublishedChanges: boolean; | ||
hasUnpublishedDeletes?: boolean; | ||
lastDraftCreatedBy?: string | null; | ||
lastDraftCreated?: string | null; | ||
created?: string | null; | ||
publishedBy?: string | null; | ||
numBlocks?: number; | ||
onCommit?: () => void; | ||
onRevert?: () => void; | ||
}; | ||
|
||
const StatusWidget = ({ | ||
lastPublished, | ||
hasUnpublishedChanges, | ||
hasUnpublishedDeletes, | ||
lastDraftCreatedBy, | ||
lastDraftCreated, | ||
created, | ||
publishedBy, | ||
numBlocks, | ||
onCommit, | ||
onRevert, | ||
}: StatusWidgedProps) => { | ||
const intl = useIntl(); | ||
|
||
let isNew: boolean | undefined; | ||
let isPublished: boolean; | ||
let statusMessage: string; | ||
let extraStatusMessage: string | undefined; | ||
let bodyMessage: React.ReactNode | undefined; | ||
|
||
if (!lastPublished) { | ||
// Entity is never published (new) | ||
isNew = numBlocks != null && numBlocks === 0; // allow discarding if components are added | ||
isPublished = false; | ||
statusMessage = intl.formatMessage(messages.draftStatusLabel); | ||
extraStatusMessage = intl.formatMessage(messages.neverPublishedLabel); | ||
bodyMessage = (<DraftBodyMessage {...{ lastDraftCreatedBy, lastDraftCreated, created }} />); | ||
} else if (hasUnpublishedChanges || hasUnpublishedDeletes) { | ||
// Entity is on Draft state | ||
isPublished = false; | ||
statusMessage = intl.formatMessage(messages.draftStatusLabel); | ||
extraStatusMessage = intl.formatMessage(messages.unpublishedStatusLabel); | ||
bodyMessage = (<DraftBodyMessage {...{ lastDraftCreatedBy, lastDraftCreated, created }} />); | ||
} else { | ||
// Entity is published | ||
isPublished = true; | ||
statusMessage = intl.formatMessage(messages.publishedStatusLabel); | ||
if (publishedBy) { | ||
bodyMessage = ( | ||
<FormattedMessage | ||
{...messages.lastPublishedMsg} | ||
values={{ | ||
date: <CustomFormattedDate date={lastPublished} />, | ||
time: <CustomFormattedTime date={lastPublished} />, | ||
user: <b>{publishedBy}</b>, | ||
}} | ||
/> | ||
); | ||
} else { | ||
bodyMessage = ( | ||
<FormattedMessage | ||
{...messages.lastPublishedMsgWithoutUser} | ||
values={{ | ||
date: <CustomFormattedDate date={lastPublished} />, | ||
time: <CustomFormattedTime date={lastPublished} />, | ||
}} | ||
/> | ||
); | ||
} | ||
} | ||
|
||
return ( | ||
<Stack> | ||
<Container className={classNames('status-widget', { | ||
'draft-status': !isPublished, | ||
'published-status': isPublished, | ||
})} | ||
> | ||
<span className="font-weight-bold"> | ||
{statusMessage} | ||
</span> | ||
{ extraStatusMessage && ( | ||
<span className="ml-1"> | ||
{extraStatusMessage} | ||
</span> | ||
)} | ||
</Container> | ||
<Container className="mt-3"> | ||
<Stack gap={3}> | ||
<span> | ||
{bodyMessage} | ||
</span> | ||
{onCommit && ( | ||
<Button disabled={isPublished} onClick={onCommit}> | ||
{intl.formatMessage(messages.publishButtonLabel)} | ||
</Button> | ||
)} | ||
{onRevert && ( | ||
<div className="d-flex justify-content-end"> | ||
<Button disabled={isPublished || isNew} variant="link" onClick={onRevert}> | ||
{intl.formatMessage(messages.discardChangesButtonLabel)} | ||
</Button> | ||
</div> | ||
)} | ||
</Stack> | ||
</Container> | ||
</Stack> | ||
); | ||
}; | ||
|
||
export default StatusWidget; |
Oops, something went wrong.