-
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 [FC-0062] (#1275)
- Loading branch information
Showing
17 changed files
with
512 additions
and
196 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
1 change: 0 additions & 1 deletion
1
src/library-authoring/component-info/ComponentInfoHeader.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
70 changes: 70 additions & 0 deletions
70
src/library-authoring/component-info/ComponentManagement.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,70 @@ | ||
import { setConfig, getConfig } from '@edx/frontend-platform'; | ||
|
||
import { | ||
initializeMocks, | ||
render, | ||
screen, | ||
} from '../../testUtils'; | ||
import { mockLibraryBlockMetadata } from '../data/api.mocks'; | ||
import ComponentManagement from './ComponentManagement'; | ||
|
||
/* | ||
* FIXME: Summarize the reason here | ||
* https://stackoverflow.com/questions/47902335/innertext-is-undefined-in-jest-test | ||
*/ | ||
const getInnerText = (element: Element) => element?.textContent | ||
?.split('\n') | ||
.filter((text) => text && !text.match(/^\s+$/)) | ||
.map((text) => text.trim()) | ||
.join(' '); | ||
|
||
const matchInnerText = (nodeName: string, textToMatch: string) => (_: string, element: Element) => ( | ||
element.nodeName === nodeName && getInnerText(element) === textToMatch | ||
); | ||
|
||
describe('<ComponentManagement />', () => { | ||
it('should render draft status', async () => { | ||
initializeMocks(); | ||
mockLibraryBlockMetadata.applyMock(); | ||
render(<ComponentManagement usageKey={mockLibraryBlockMetadata.usageKeyNeverPublished} />); | ||
expect(await screen.findByText('Draft')).toBeInTheDocument(); | ||
expect(await screen.findByText('(Never Published)')).toBeInTheDocument(); | ||
expect(screen.getByText(matchInnerText('SPAN', 'Draft saved on June 20, 2024 at 13:54 UTC.'))).toBeInTheDocument(); | ||
}); | ||
|
||
it('should render published status', async () => { | ||
initializeMocks(); | ||
mockLibraryBlockMetadata.applyMock(); | ||
render(<ComponentManagement usageKey={mockLibraryBlockMetadata.usageKeyPublished} />); | ||
expect(await screen.findByText('Published')).toBeInTheDocument(); | ||
expect(screen.getByText('Published')).toBeInTheDocument(); | ||
expect( | ||
screen.getByText(matchInnerText('SPAN', 'Last published on June 21, 2024 at 24:00 UTC by Luke.')), | ||
).toBeInTheDocument(); | ||
}); | ||
|
||
it('should render the tagging info', async () => { | ||
setConfig({ | ||
...getConfig(), | ||
ENABLE_TAGGING_TAXONOMY_PAGES: 'true', | ||
}); | ||
initializeMocks(); | ||
mockLibraryBlockMetadata.applyMock(); | ||
render(<ComponentManagement usageKey={mockLibraryBlockMetadata.usageKeyNeverPublished} />); | ||
expect(await screen.findByText('Tags')).toBeInTheDocument(); | ||
// TODO: replace with actual data when implement tag list | ||
expect(screen.queryByText('Tags placeholder')).toBeInTheDocument(); | ||
}); | ||
|
||
it('should not render draft status', async () => { | ||
setConfig({ | ||
...getConfig(), | ||
ENABLE_TAGGING_TAXONOMY_PAGES: 'false', | ||
}); | ||
initializeMocks(); | ||
mockLibraryBlockMetadata.applyMock(); | ||
render(<ComponentManagement usageKey={mockLibraryBlockMetadata.usageKeyNeverPublished} />); | ||
expect(await screen.findByText('Draft')).toBeInTheDocument(); | ||
expect(screen.queryByText('Tags')).not.toBeInTheDocument(); | ||
}); | ||
}); |
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
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
Oops, something went wrong.