-
Notifications
You must be signed in to change notification settings - Fork 80
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 Details sidebar [FC-0062] (#1303)
* feat: add ComponentDetails component --------- Co-authored-by: Jillian <[email protected]>
- Loading branch information
1 parent
c13ab00
commit ff67c9a
Showing
14 changed files
with
203 additions
and
8 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
src/library-authoring/component-info/ComponentDetails.test.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,42 @@ | ||
import { | ||
initializeMocks, | ||
render, | ||
screen, | ||
} from '../../testUtils'; | ||
import { mockLibraryBlockMetadata } from '../data/api.mocks'; | ||
import ComponentDetails from './ComponentDetails'; | ||
|
||
describe('<ComponentDetails />', () => { | ||
it('should render the component details loading', async () => { | ||
initializeMocks(); | ||
mockLibraryBlockMetadata.applyMock(); | ||
render(<ComponentDetails usageKey={mockLibraryBlockMetadata.usageKeyThatNeverLoads} />); | ||
expect(await screen.findByText('Loading...')).toBeInTheDocument(); | ||
}); | ||
|
||
it('should render the component details error', async () => { | ||
initializeMocks(); | ||
mockLibraryBlockMetadata.applyMock(); | ||
render(<ComponentDetails usageKey={mockLibraryBlockMetadata.usageKeyError404} />); | ||
expect(await screen.findByText(/Mocked request failed with status code 404/)).toBeInTheDocument(); | ||
}); | ||
|
||
it('should render the component usage', async () => { | ||
initializeMocks(); | ||
mockLibraryBlockMetadata.applyMock(); | ||
render(<ComponentDetails usageKey={mockLibraryBlockMetadata.usageKeyNeverPublished} />); | ||
expect(await screen.findByText('Component Usage')).toBeInTheDocument(); | ||
// TODO: replace with actual data when implement tag list | ||
expect(screen.queryByText('This will show the courses that use this component.')).toBeInTheDocument(); | ||
}); | ||
|
||
it('should render the component history', async () => { | ||
initializeMocks(); | ||
mockLibraryBlockMetadata.applyMock(); | ||
render(<ComponentDetails usageKey={mockLibraryBlockMetadata.usageKeyNeverPublished} />); | ||
// Show created date | ||
expect(await screen.findByText('June 20, 2024')).toBeInTheDocument(); | ||
// Show modified date | ||
expect(await screen.findByText('June 21, 2024')).toBeInTheDocument(); | ||
}); | ||
}); |
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 { useIntl } from '@edx/frontend-platform/i18n'; | ||
import { Stack } from '@openedx/paragon'; | ||
|
||
import AlertError from '../../generic/alert-error'; | ||
import Loading from '../../generic/Loading'; | ||
import { useLibraryBlockMetadata } from '../data/apiHooks'; | ||
import HistoryWidget from '../generic/history-widget'; | ||
import { ComponentDeveloperInfo } from './ComponentDeveloperInfo'; | ||
import messages from './messages'; | ||
|
||
interface ComponentDetailsProps { | ||
usageKey: string; | ||
} | ||
|
||
const ComponentDetails = ({ usageKey }: ComponentDetailsProps) => { | ||
const intl = useIntl(); | ||
const { | ||
data: componentMetadata, | ||
isError, | ||
error, | ||
isLoading, | ||
} = useLibraryBlockMetadata(usageKey); | ||
|
||
if (isError) { | ||
return <AlertError error={error} />; | ||
} | ||
|
||
if (isLoading) { | ||
return <Loading />; | ||
} | ||
|
||
return ( | ||
<Stack gap={3}> | ||
<div> | ||
<h3 className="h5"> | ||
{intl.formatMessage(messages.detailsTabUsageTitle)} | ||
</h3> | ||
<small>This will show the courses that use this component.</small> | ||
</div> | ||
<hr className="w-100" /> | ||
<div> | ||
<h3 className="h5"> | ||
{intl.formatMessage(messages.detailsTabHistoryTitle)} | ||
</h3> | ||
<HistoryWidget | ||
{...componentMetadata} | ||
/> | ||
</div> | ||
{ | ||
// istanbul ignore next: this is only shown in development | ||
(process.env.NODE_ENV === 'development' ? <ComponentDeveloperInfo usageKey={usageKey} /> : null) | ||
} | ||
</Stack> | ||
); | ||
}; | ||
|
||
export default ComponentDetails; |
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
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
6 changes: 6 additions & 0 deletions
6
src/library-authoring/generic/history-widget/HistoryWidget.scss
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,6 @@ | ||
.history-widget-bar { | ||
border-left: 8px solid $info-300; | ||
border-radius: 4px; | ||
padding-left: 1rem; | ||
} | ||
|
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,52 @@ | ||
import { FormattedMessage, FormattedDate } from '@edx/frontend-platform/i18n'; | ||
import { Stack } from '@openedx/paragon'; | ||
|
||
import messages from './messages'; | ||
|
||
const CustomFormattedDate = ({ date }: { date: string }) => ( | ||
<FormattedDate | ||
value={date} | ||
year="numeric" | ||
month="long" | ||
day="2-digit" | ||
/> | ||
); | ||
|
||
type HistoryWidgedProps = { | ||
modified: string | null; | ||
created: string | null; | ||
}; | ||
|
||
/** | ||
* This component displays the history of an entity (Last Modified and Created dates) | ||
* | ||
* This component doesn't handle fetching the data or any other side effects. It only displays the dates. | ||
* | ||
* @example | ||
* ```tsx | ||
* const { data: componentMetadata } = useLibraryBlockMetadata(usageKey); | ||
* | ||
* return <HistoryWidget {...componentMetadata} />; | ||
* ``` | ||
*/ | ||
const HistoryWidget = ({ | ||
modified, | ||
created, | ||
}: HistoryWidgedProps) => ( | ||
<Stack className="history-widget-bar small" gap={3}> | ||
{modified && ( | ||
<div> | ||
<div className="text-muted"><FormattedMessage {...messages.lastModifiedTitle} /> </div> | ||
<CustomFormattedDate date={modified} /> | ||
</div> | ||
)} | ||
{created && ( | ||
<div> | ||
<div className="text-muted"><FormattedMessage {...messages.createdTitle} /> </div> | ||
<CustomFormattedDate date={created} /> | ||
</div> | ||
)} | ||
</Stack> | ||
); | ||
|
||
export default HistoryWidget; |
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,16 @@ | ||
import { defineMessages } from '@edx/frontend-platform/i18n'; | ||
|
||
const messages = defineMessages({ | ||
lastModifiedTitle: { | ||
id: 'course-authoring.library-authoring.generic.history-widget.last-modified', | ||
defaultMessage: 'Last Modified', | ||
description: 'Title of the last modified section in the library authoring sidebar.', | ||
}, | ||
createdTitle: { | ||
id: 'course-authoring.library-authoring.generic.history-widget.created', | ||
defaultMessage: 'Created', | ||
description: 'Title of the created section in the library authoring sidebar.', | ||
}, | ||
}); | ||
|
||
export default messages; |
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 |
---|---|---|
@@ -1 +1,2 @@ | ||
@import "./status-widget/StatusWidget"; | ||
@import "./history-widget/HistoryWidget"; |