Repository navigation
[FC-0036] Tags Sidebar #852
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 13 commits
88b5438
6839859
4bed61a
540c2f7
29ad22a
56af892
f808a84
139e978
14fd7cd
67cfe58
c83c2bc
7a70d81
bc39fe9
1f33ca4
040e55b
94d3f1f
fa1c2d2
c9261e4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| module.exports = { | ||
| 'block-v1:SampleTaxonomyOrg1+STC1+2023_1+type@vertical+block@aaf8b8eb86b54281aeeab12499d2cb0b': 20, | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| module.exports = { | ||
| 'hierarchical taxonomy tag 1': { | ||
| children: { | ||
| 'hierarchical taxonomy tag 1.7': { | ||
| children: { | ||
| 'hierarchical taxonomy tag 1.7.59': { | ||
| children: {}, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| 'hierarchical taxonomy tag 2': { | ||
| children: { | ||
| 'hierarchical taxonomy tag 2.13': { | ||
| children: { | ||
| 'hierarchical taxonomy tag 2.13.46': { | ||
| children: {}, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| 'hierarchical taxonomy tag 3': { | ||
| children: { | ||
| 'hierarchical taxonomy tag 3.4': { | ||
| children: { | ||
| 'hierarchical taxonomy tag 3.4.50': { | ||
| children: {}, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| @import "content-tags-drawer/TagBubble"; | ||
| @import "content-tags-drawer/tags-sidebar-controls/TagsSidebarControls"; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,6 +33,14 @@ const messages = defineMessages({ | |
| id: 'course-authoring.content-tags-drawer.content-tags-collapsible.selectable-box.selection.aria.label', | ||
| defaultMessage: 'taxonomy tags selection', | ||
| }, | ||
| manageTagsButton: { | ||
| id: 'course-authoring.content-tags-drawer.button.manage', | ||
| defaultMessage: 'Manage Tags', | ||
| }, | ||
| tagsSidebarTitle: { | ||
| id: 'course-authoring.course-unit.sidebar.tags.title', | ||
| defaultMessage: 'Unit Tags', | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be awesome if you could add some descriptions to these new messages. We'll be making them a requirement pretty soon. See openedx/frontend-build#517.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done c9261e4 |
||
| }, | ||
| }); | ||
|
|
||
| export default messages; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,110 @@ | ||
| // @ts-check | ||
| import React, { useState, useMemo } from 'react'; | ||
| import { | ||
| Card, Stack, Button, Sheet, Collapsible, Icon, | ||
| } from '@openedx/paragon'; | ||
| import { ArrowDropDown, ArrowDropUp } from '@openedx/paragon/icons'; | ||
| import { useIntl } from '@edx/frontend-platform/i18n'; | ||
| import { useParams } from 'react-router-dom'; | ||
| import { ContentTagsDrawer } from '..'; | ||
|
|
||
| import messages from '../messages'; | ||
| import { useContentTaxonomyTagsData } from '../data/apiHooks'; | ||
| import { LoadingSpinner } from '../../generic/Loading'; | ||
| import TagsTree from './TagsTree'; | ||
|
|
||
| const TagsSidebarBody = () => { | ||
| const intl = useIntl(); | ||
| const [showManageTags, setShowManageTags] = useState(false); | ||
| const contentId = useParams().blockId; | ||
| const onClose = () => setShowManageTags(false); | ||
|
|
||
| const { | ||
| data: contentTaxonomyTagsData, | ||
| isSuccess: isContentTaxonomyTagsLoaded, | ||
| } = useContentTaxonomyTagsData(contentId || ''); | ||
|
|
||
| const buildTagsTree = (contentTags) => { | ||
| const resultTree = {}; | ||
| contentTags.forEach(item => { | ||
| let currentLevel = resultTree; | ||
|
|
||
| item.lineage.forEach((key) => { | ||
| if (!currentLevel[key]) { | ||
| currentLevel[key] = { | ||
| children: {}, | ||
| canChangeObjecttag: item.canChangeObjecttag, | ||
| canDeleteObjecttag: item.canDeleteObjecttag, | ||
| }; | ||
| } | ||
|
|
||
| currentLevel = currentLevel[key].children; | ||
| }); | ||
| }); | ||
|
|
||
| return resultTree; | ||
| }; | ||
|
|
||
| const tree = useMemo(() => { | ||
| const result = []; | ||
| if (isContentTaxonomyTagsLoaded && contentTaxonomyTagsData) { | ||
| contentTaxonomyTagsData.taxonomies.forEach((taxonomy) => { | ||
| result.push({ | ||
| ...taxonomy, | ||
| tags: buildTagsTree(taxonomy.tags), | ||
| }); | ||
| }); | ||
| } | ||
| return result; | ||
| }, [isContentTaxonomyTagsLoaded, contentTaxonomyTagsData]); | ||
|
|
||
| return ( | ||
| <> | ||
| <Card.Body className="course-unit-sidebar-date tags-sidebar-body"> | ||
| <Stack> | ||
| { isContentTaxonomyTagsLoaded | ||
| ? ( | ||
| <Stack> | ||
| {tree.map((taxonomy) => ( | ||
| <div key={taxonomy.name}> | ||
| <Collapsible | ||
| className="tags-sidebar-taxonomy" | ||
| styling="card" | ||
| title={taxonomy.name} | ||
| iconWhenClosed={<Icon src={ArrowDropDown} />} | ||
| iconWhenOpen={<Icon src={ArrowDropUp} />} | ||
| > | ||
| <TagsTree tags={taxonomy.tags} parentKey={taxonomy.name} /> | ||
| </Collapsible> | ||
| </div> | ||
| ))} | ||
| </Stack> | ||
| ) | ||
| : ( | ||
| <div className="d-flex justify-content-center"> | ||
| <LoadingSpinner /> | ||
| </div> | ||
| )} | ||
|
|
||
| <Button className="mt-3 ml-2" variant="outline-primary" size="sm" onClick={() => setShowManageTags(true)}> | ||
| {intl.formatMessage(messages.manageTagsButton)} | ||
| </Button> | ||
| </Stack> | ||
| </Card.Body> | ||
| <Sheet | ||
| position="right" | ||
| show={showManageTags} | ||
| onClose={onClose} | ||
| > | ||
| <ContentTagsDrawer | ||
| id={contentId} | ||
| onClose={onClose} | ||
| /> | ||
| </Sheet> | ||
| </> | ||
| ); | ||
| }; | ||
|
|
||
| TagsSidebarBody.propTypes = {}; | ||
|
|
||
| export default TagsSidebarBody; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| import React from 'react'; | ||
| import { render, screen, fireEvent } from '@testing-library/react'; | ||
| import { IntlProvider } from '@edx/frontend-platform/i18n'; | ||
| import TagsSidebarBody from './TagsSidebarBody'; | ||
| import { useContentTaxonomyTagsData } from '../data/apiHooks'; | ||
| import { contentTaxonomyTagsMock } from '../__mocks__'; | ||
|
|
||
| const contentId = 'block-v1:SampleTaxonomyOrg1+STC1+2023_1+type@vertical+block@aaf8b8eb86b54281aeeab12499d2cb0b'; | ||
|
|
||
| jest.mock('../data/apiHooks', () => ({ | ||
| useContentTaxonomyTagsData: jest.fn(() => ({ | ||
| isSuccess: false, | ||
| data: {}, | ||
| })), | ||
| })); | ||
| jest.mock('../ContentTagsDrawer', () => jest.fn(() => <div>Mocked ContentTagsDrawer</div>)); | ||
|
|
||
| const RootWrapper = () => ( | ||
| <IntlProvider locale="en" messages={{}}> | ||
| <TagsSidebarBody /> | ||
| </IntlProvider> | ||
| ); | ||
|
|
||
| describe('<TagSidebarBody>', () => { | ||
| it('shows spinner before the content data query is complete', () => { | ||
| render(<RootWrapper />); | ||
| expect(screen.getByRole('status')).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('should render data after wuery is complete', () => { | ||
| useContentTaxonomyTagsData.mockReturnValue({ | ||
| isSuccess: true, | ||
| data: contentTaxonomyTagsMock[contentId], | ||
| }); | ||
| render(<RootWrapper />); | ||
| const taxonomyButton = screen.getByRole('button', { name: /hierarchicaltaxonomy/i }); | ||
| expect(taxonomyButton).toBeInTheDocument(); | ||
|
|
||
| /// ContentTagsDrawer must be closed | ||
| expect(screen.queryByText('Mocked ContentTagsDrawer')).not.toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('should open ContentTagsDrawer', () => { | ||
| useContentTaxonomyTagsData.mockReturnValue({ | ||
| isSuccess: true, | ||
| data: contentTaxonomyTagsMock[contentId], | ||
| }); | ||
| render(<RootWrapper />); | ||
|
|
||
| const manageButton = screen.getByRole('button', { name: /manage tags/i }); | ||
| fireEvent.click(manageButton); | ||
|
|
||
| expect(screen.getByText('Mocked ContentTagsDrawer')).toBeInTheDocument(); | ||
| }); | ||
| }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't like this, but I don't know a better way to do it and maintain compatibility with the iframe in the studio. Could you comment on why we use the component props and the query params?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is fine for now, but I agree we should add a comment saying that once the legacy iframe is no longer used, we can remove
useParams()There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added here