-
Notifications
You must be signed in to change notification settings - Fork 178
feat: display all child tags in the "bare bones" taxonomy detail page [FAL-3529] [FC-0036] #703
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 all commits
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 |
|---|---|---|
| @@ -1,10 +1,16 @@ | ||
| import { isEmpty } from 'lodash'; | ||
|
|
||
| const getPageHeadTitle = (courseName, pageName) => { | ||
| if (isEmpty(courseName)) { | ||
| /** | ||
| * Generate the string for the page <title> | ||
| * @param {string} courseOrSectionName The name of the course, or the section of the MFE that the user is in currently | ||
| * @param {string} pageName The name of the current page | ||
| * @returns {string} The combined title | ||
| */ | ||
| const getPageHeadTitle = (courseOrSectionName, pageName) => { | ||
| if (isEmpty(courseOrSectionName)) { | ||
| return `${pageName} | ${process.env.SITE_NAME}`; | ||
| } | ||
| return `${pageName} | ${courseName} | ${process.env.SITE_NAME}`; | ||
| return `${pageName} | ${courseOrSectionName} | ${process.env.SITE_NAME}`; | ||
| }; | ||
|
|
||
| export default getPageHeadTitle; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,6 +7,7 @@ const getApiBaseUrl = () => getConfig().STUDIO_BASE_URL; | |
| export const getTaxonomyListApiUrl = (org) => { | ||
| const url = new URL('api/content_tagging/v1/taxonomies/', getApiBaseUrl()); | ||
| url.searchParams.append('enabled', 'true'); | ||
| url.searchParams.append('page_size', '500'); // For the tagging MVP, we don't paginate the taxonomy list | ||
|
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. @ChrisChV FYI - I included a quick fix here for the pagination issue on the taxonomy list page. |
||
| if (org !== undefined) { | ||
| url.searchParams.append('org', org); | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,46 @@ | ||
| // ts-check | ||
| import { useIntl } from '@edx/frontend-platform/i18n'; | ||
| import { | ||
| DataTable, | ||
| } from '@edx/paragon'; | ||
| import { FormattedMessage, useIntl } from '@edx/frontend-platform/i18n'; | ||
| import { DataTable } from '@edx/paragon'; | ||
| import _ from 'lodash'; | ||
| import Proptypes from 'prop-types'; | ||
| import { useState } from 'react'; | ||
|
|
||
| import { LoadingSpinner } from '../../generic/Loading'; | ||
| import messages from './messages'; | ||
| import { useTagListDataResponse, useTagListDataStatus } from './data/apiHooks'; | ||
| import { useSubTags } from './data/api'; | ||
|
|
||
| const SubTagsExpanded = ({ taxonomyId, parentTagValue }) => { | ||
| const subTagsData = useSubTags(taxonomyId, parentTagValue); | ||
|
|
||
| if (subTagsData.isLoading) { | ||
| return <LoadingSpinner />; | ||
| } | ||
| if (subTagsData.isError) { | ||
| return <FormattedMessage {...messages.tagListError} />; | ||
| } | ||
|
|
||
| return ( | ||
| <ul style={{ listStyleType: 'none' }}> | ||
| {subTagsData.data.results.map(tagData => ( | ||
| <li key={tagData.id} style={{ paddingLeft: `${(tagData.depth - 1) * 30}px` }}> | ||
| {tagData.value} <span className="text-light-900">{tagData.childCount > 0 ? `(${tagData.childCount})` : null}</span> | ||
| </li> | ||
| ))} | ||
| </ul> | ||
|
Comment on lines
+24
to
+30
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. If this date is nested, instead of using padding perhaps it can do the following: const TagList = ({subTagData}) => (
<ul style={{ listStyleType: 'none' }}>
{subTagsData.data.results.map(tagData => (
<li key={tagData.id}>
{tagData.value} <span className="text-light-900">{tagData.childCount > 0 ? `(${tagData.childCount})` : null}</span>
{tagData.children && <TagList subTagData={tagData} />}
</li>
))}
</ul>
)I don't know if the data is structured that way or can be accessed that way. It will avoid the need to use padding to denote hierarchy.
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. Yes, I think that's what we'll do eventually. We're basically going to be re-building this whole table in openedx/modular-learning#130 so I didn't bother doing anything too fancy for now. Right now we're just trying to get the basic read-only functionality out the door. The data is currently just in a single array, though the tags are in "tree order" in that array, which is why we can display them this way and why I went with the simplest option. |
||
| ); | ||
| }; | ||
|
|
||
| SubTagsExpanded.propTypes = { | ||
| taxonomyId: Proptypes.number.isRequired, | ||
| parentTagValue: Proptypes.string.isRequired, | ||
| }; | ||
|
|
||
| /** | ||
| * An "Expand" toggle to show/hide subtags, but one which is hidden if the given tag row has no subtags. | ||
| */ | ||
| const OptionalExpandLink = ({ row }) => (row.values.childCount > 0 ? <DataTable.ExpandRow row={row} /> : null); | ||
| OptionalExpandLink.propTypes = DataTable.ExpandRow.propTypes; | ||
|
|
||
| const TagListTable = ({ taxonomyId }) => { | ||
| const intl = useIntl(); | ||
|
|
@@ -34,11 +66,24 @@ const TagListTable = ({ taxonomyId }) => { | |
| itemCount={tagList?.count || 0} | ||
| pageCount={tagList?.numPages || 0} | ||
| initialState={options} | ||
| isExpandable | ||
| // This is a temporary "bare bones" solution for brute-force loading all the child tags. In future we'll match | ||
| // the Figma design and do something more sophisticated. | ||
| renderRowSubComponent={({ row }) => <SubTagsExpanded taxonomyId={taxonomyId} parentTagValue={row.values.value} />} | ||
| columns={[ | ||
| { | ||
| Header: intl.formatMessage(messages.tagListColumnValueHeader), | ||
| accessor: 'value', | ||
| }, | ||
| { | ||
| id: 'expander', | ||
| Header: DataTable.ExpandAll, | ||
| Cell: OptionalExpandLink, | ||
| }, | ||
| { | ||
| Header: intl.formatMessage(messages.tagListColumnChildCountHeader), | ||
| accessor: 'childCount', | ||
| }, | ||
| ]} | ||
| > | ||
| <DataTable.TableControlBar /> | ||
|
|
@@ -50,7 +95,7 @@ const TagListTable = ({ taxonomyId }) => { | |
| }; | ||
|
|
||
| TagListTable.propTypes = { | ||
| taxonomyId: Proptypes.string.isRequired, | ||
| taxonomyId: Proptypes.number.isRequired, | ||
| }; | ||
|
|
||
| export default TagListTable; | ||
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.
Good catch!