Repository navigation
feat: bare bones taxonomy detail page [FC-0036] #655
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
Merged
arbrandes
merged 29 commits into
openedx:master
from
open-craft:rpenido/fal-3529-bare-bones-taxonomy-detail-page
Nov 20, 2023
Merged
Changes from 24 commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
4963124
feat: System-defined tooltip added
ChrisChV 4077397
feat: Taxonomy card menu added. Export menu item added
ChrisChV e87c545
feat: Modal for export taxonomy
ChrisChV 4922420
feat: Connect with export API
ChrisChV 5e12a8f
test: Tests for API and selectors
ChrisChV 09aa8b6
feat: Use windows.location.href to call the export endpoint
ChrisChV 1925fae
test: ExportModal.test added
ChrisChV 0be804c
style: Delete unnecesary code
ChrisChV da0156f
Merge branch 'master' into chris/FAL-3528-taxonomy-export-menu
rpenido 0cc473c
Merge branch 'master' into chris/FAL-3528-taxonomy-export-menu
ChrisChV 5af8d66
docs: README updated with taxonomy feature
ChrisChV a21fac2
style: TaxonomyCard updated to a better code style
ChrisChV 61864d3
style: injectIntl replaced by useIntl on taxonomy pages and components
ChrisChV b09b86a
refactor: Move and rename taxonomy UI components to match 0002 ADR
ChrisChV df8432d
refactor: Move api to data to match with 0002 ADR
ChrisChV 1abf034
test: Refactor ExportModal tests
1d6f9a5
chore: Merge conflicts solved
5c4c87a
chore: Fix validations
ChrisChV 7e514b6
chore: Lint
ChrisChV 080b03e
refactor: Moving hooks to apiHooks
ChrisChV 56dbdd2
feat: add taxonomy detail page
rpenido 9c582ed
Merge branch 'master' into rpenido/fal-3529-bare-bones-taxonomy-detai…
pomegranited 9df1699
fix: address nits in PR review
pomegranited 0fdaa07
refactor: move data/selectors to data/apiHooks
pomegranited 0e19e99
fix: address nits in PR review
pomegranited 3f0dbaa
fix: replace taxonomy menu ModalPopup with Dropdown menu
pomegranited 0872d5d
Merge branch 'master' into rpenido/fal-3529-bare-bones-taxonomy-detai…
pomegranited a15e3a4
fix: change taxonomy URLs
pomegranited 924e28e
chore: update this branch with master
bradenmacdonald File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,14 @@ | ||
| import { StudioFooter } from '@edx/frontend-component-footer'; | ||
| import { Outlet } from 'react-router-dom'; | ||
|
|
||
| import Header from '../header'; | ||
|
|
||
| const TaxonomyLayout = () => ( | ||
| <div className="bg-light-400"> | ||
| <Header isHiddenMainMenu /> | ||
| <Outlet /> | ||
| <StudioFooter /> | ||
| </div> | ||
| ); | ||
|
|
||
| export default TaxonomyLayout; |
This file contains hidden or 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,48 @@ | ||
| import React from 'react'; | ||
| import { IntlProvider } from '@edx/frontend-platform/i18n'; | ||
| import { initializeMockApp } from '@edx/frontend-platform'; | ||
| import { AppProvider } from '@edx/frontend-platform/react'; | ||
| import { render } from '@testing-library/react'; | ||
|
|
||
| import initializeStore from '../store'; | ||
| import TaxonomyLayout from './TaxonomyLayout'; | ||
|
|
||
| let store; | ||
|
|
||
| jest.mock('../header', () => jest.fn(() => <div data-testid="mock-header" />)); | ||
| jest.mock('@edx/frontend-component-footer', () => ({ | ||
| StudioFooter: jest.fn(() => <div data-testid="mock-footer" />), | ||
| })); | ||
| jest.mock('react-router-dom', () => ({ | ||
| ...jest.requireActual('react-router-dom'), | ||
| Outlet: jest.fn(() => <div data-testid="mock-content" />), | ||
| })); | ||
|
|
||
| const RootWrapper = () => ( | ||
| <AppProvider store={store}> | ||
| <IntlProvider locale="en" messages={{}}> | ||
| <TaxonomyLayout /> | ||
| </IntlProvider> | ||
| </AppProvider> | ||
| ); | ||
|
|
||
| describe('<TaxonomyLayout />', async () => { | ||
| beforeEach(async () => { | ||
| initializeMockApp({ | ||
| authenticatedUser: { | ||
| userId: 3, | ||
| username: 'abc123', | ||
| administrator: true, | ||
| roles: [], | ||
| }, | ||
| }); | ||
| store = initializeStore(); | ||
| }); | ||
|
|
||
| it('should render page correctly', async () => { | ||
| const { getByTestId } = render(<RootWrapper />); | ||
| expect(getByTestId('mock-header')).toBeInTheDocument(); | ||
| expect(getByTestId('mock-content')).toBeInTheDocument(); | ||
| expect(getByTestId('mock-footer')).toBeInTheDocument(); | ||
| }); | ||
| }); |
This file contains hidden or 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 hidden or 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,2 +1,3 @@ | ||
| // eslint-disable-next-line import/prefer-default-export | ||
| export { default as TaxonomyListPage } from './TaxonomyListPage'; | ||
| export { default as TaxonomyLayout } from './TaxonomyLayout'; | ||
| export { TaxonomyDetailPage } from './taxonomy-detail'; |
This file contains hidden or 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,68 @@ | ||
| // ts-check | ||
| import { useIntl } from '@edx/frontend-platform/i18n'; | ||
| import { | ||
| DataTable, | ||
| } from '@edx/paragon'; | ||
| import _ from 'lodash'; | ||
| import Proptypes from 'prop-types'; | ||
| import { useState } from 'react'; | ||
|
|
||
| import messages from './messages'; | ||
| import { useTagListDataResponse, useTagListDataStatus } from './data/apiHooks'; | ||
|
|
||
| const TagListTable = ({ taxonomyId }) => { | ||
| const intl = useIntl(); | ||
|
|
||
| const [options, setOptions] = useState({ | ||
| pageIndex: 0, | ||
| }); | ||
|
|
||
| const useTagListData = () => { | ||
| const { isError, isFetched, isLoading } = useTagListDataStatus(taxonomyId, options); | ||
| const tagList = useTagListDataResponse(taxonomyId, options); | ||
| return { | ||
| isError, | ||
| isFetched, | ||
| isLoading, | ||
| tagList, | ||
| }; | ||
| }; | ||
|
|
||
| const { tagList, isLoading } = useTagListData(); | ||
|
|
||
| const fetchData = (args) => { | ||
| if (!_.isEqual(args, options)) { | ||
| setOptions({ ...args }); | ||
| } | ||
| }; | ||
|
|
||
| return ( | ||
| <DataTable | ||
| isLoading={isLoading} | ||
| isPaginated | ||
| manualPagination | ||
| fetchData={fetchData} | ||
| data={tagList?.results || []} | ||
| itemCount={tagList?.count || 0} | ||
| pageCount={tagList?.numPages || 0} | ||
| initialState={options} | ||
| columns={[ | ||
| { | ||
| Header: intl.formatMessage(messages.tagListColumnValueHeader), | ||
| accessor: 'value', | ||
| }, | ||
| ]} | ||
| > | ||
| <DataTable.TableControlBar /> | ||
| <DataTable.Table /> | ||
| <DataTable.EmptyTable content={intl.formatMessage(messages.noResultsFoundMessage)} /> | ||
| <DataTable.TableFooter /> | ||
| </DataTable> | ||
| ); | ||
| }; | ||
|
|
||
| TagListTable.propTypes = { | ||
| taxonomyId: Proptypes.string.isRequired, | ||
| }; | ||
|
|
||
| export default TagListTable; | ||
This file contains hidden or 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,67 @@ | ||
| import React from 'react'; | ||
| import { IntlProvider } from '@edx/frontend-platform/i18n'; | ||
| import { initializeMockApp } from '@edx/frontend-platform'; | ||
| import { AppProvider } from '@edx/frontend-platform/react'; | ||
| import { render } from '@testing-library/react'; | ||
|
|
||
| import { useTagListData } from './data/api'; | ||
| import initializeStore from '../../store'; | ||
| import TagListTable from './TagListTable'; | ||
|
|
||
| let store; | ||
|
|
||
| jest.mock('./data/api', () => ({ | ||
| useTagListData: jest.fn(), | ||
| })); | ||
|
|
||
| const RootWrapper = () => ( | ||
| <AppProvider store={store}> | ||
| <IntlProvider locale="en" messages={{}}> | ||
| <TagListTable taxonomyId="1" /> | ||
| </IntlProvider> | ||
| </AppProvider> | ||
| ); | ||
|
|
||
| describe('<TagListPage />', async () => { | ||
| beforeEach(async () => { | ||
| initializeMockApp({ | ||
| authenticatedUser: { | ||
| userId: 3, | ||
| username: 'abc123', | ||
| administrator: true, | ||
| roles: [], | ||
| }, | ||
| }); | ||
| store = initializeStore(); | ||
| }); | ||
|
|
||
| it('shows the spinner before the query is complete', async () => { | ||
| useTagListData.mockReturnValue({ | ||
| isLoading: true, | ||
| isFetched: false, | ||
| }); | ||
| const { getByRole } = render(<RootWrapper />); | ||
| const spinner = getByRole('status'); | ||
| expect(spinner.textContent).toEqual('loading'); | ||
| }); | ||
|
|
||
| it('should render page correctly', async () => { | ||
| useTagListData.mockReturnValue({ | ||
| isSuccess: true, | ||
| isFetched: true, | ||
| isError: false, | ||
| data: { | ||
| count: 3, | ||
| numPages: 1, | ||
| results: [ | ||
| { value: 'Tag 1' }, | ||
| { value: 'Tag 2' }, | ||
| { value: 'Tag 3' }, | ||
| ], | ||
| }, | ||
| }); | ||
| const { getAllByRole } = render(<RootWrapper />); | ||
| const rows = getAllByRole('row'); | ||
| expect(rows.length).toBe(3 + 1); // 3 items plus header | ||
| }); | ||
| }); |
This file contains hidden or 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,26 @@ | ||||||||||||||||||||
| // @ts-check | ||||||||||||||||||||
| import { useQuery } from '@tanstack/react-query'; | ||||||||||||||||||||
| import { camelCaseObject, getConfig } from '@edx/frontend-platform'; | ||||||||||||||||||||
| import { getAuthenticatedHttpClient } from '@edx/frontend-platform/auth'; | ||||||||||||||||||||
|
|
||||||||||||||||||||
| const getApiBaseUrl = () => getConfig().STUDIO_BASE_URL; | ||||||||||||||||||||
| const getTagListApiUrl = (taxonomyId, page) => new URL( | ||||||||||||||||||||
| `api/content_tagging/v1/taxonomies/${taxonomyId}/tags/?page=${page + 1}`, | ||||||||||||||||||||
| getApiBaseUrl(), | ||||||||||||||||||||
| ).href; | ||||||||||||||||||||
|
|
||||||||||||||||||||
| // ToDo: fix types | ||||||||||||||||||||
| /** | ||||||||||||||||||||
| * @param {number} taxonomyId | ||||||||||||||||||||
| * @param {import('./types.mjs').QueryOptions} options | ||||||||||||||||||||
| * @returns {import('@tanstack/react-query').UseQueryResult<import('./types.mjs').TagListData>} | ||||||||||||||||||||
| */ // eslint-disable-next-line import/prefer-default-export | ||||||||||||||||||||
| export const useTagListData = (taxonomyId, options) => { | ||||||||||||||||||||
| const { pageIndex } = options; | ||||||||||||||||||||
| return useQuery({ | ||||||||||||||||||||
| queryKey: ['tagList', taxonomyId, pageIndex], | ||||||||||||||||||||
| queryFn: () => getAuthenticatedHttpClient().get(getTagListApiUrl(taxonomyId, pageIndex)) | ||||||||||||||||||||
| .then((response) => response.data) | ||||||||||||||||||||
| .then(camelCaseObject), | ||||||||||||||||||||
| }); | ||||||||||||||||||||
|
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. Just realised you can use async/await here:
Suggested change
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. Addressed with 0e19e99 |
||||||||||||||||||||
| }; | ||||||||||||||||||||
This file contains hidden or 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,27 @@ | ||
| import { useQuery } from '@tanstack/react-query'; | ||
| import { | ||
| useTagListData, | ||
| } from './api'; | ||
|
|
||
| const mockHttpClient = { | ||
| get: jest.fn(), | ||
| }; | ||
|
|
||
| jest.mock('@tanstack/react-query', () => ({ | ||
| useQuery: jest.fn(), | ||
| })); | ||
|
|
||
| jest.mock('@edx/frontend-platform/auth', () => ({ | ||
| getAuthenticatedHttpClient: jest.fn(() => mockHttpClient), | ||
| })); | ||
|
|
||
| describe('useTagListData', () => { | ||
| it('should call useQuery with the correct parameters', () => { | ||
| useTagListData('1', { pageIndex: 3 }); | ||
|
|
||
| expect(useQuery).toHaveBeenCalledWith({ | ||
| queryKey: ['tagList', '1', 3], | ||
| queryFn: expect.any(Function), | ||
| }); | ||
| }); | ||
| }); |
This file contains hidden or 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,41 @@ | ||
| // @ts-check | ||
| import { | ||
| useTagListData, | ||
| } from './api'; | ||
|
|
||
| /* eslint-disable max-len */ | ||
| /** | ||
| * @param {number} taxonomyId | ||
| * @param {import("./types.mjs").QueryOptions} options | ||
| * @returns {Pick<import('@tanstack/react-query').UseQueryResult, "error" | "isError" | "isFetched" | "isLoading" | "isSuccess" >} | ||
| */ /* eslint-enable max-len */ | ||
| export const useTagListDataStatus = (taxonomyId, options) => { | ||
| const { | ||
| error, | ||
| isError, | ||
| isFetched, | ||
| isLoading, | ||
| isSuccess, | ||
| } = useTagListData(taxonomyId, options); | ||
| return { | ||
| error, | ||
| isError, | ||
| isFetched, | ||
| isLoading, | ||
| isSuccess, | ||
| }; | ||
| }; | ||
|
|
||
| /** | ||
| * @param {number} taxonomyId | ||
| * @param {import("./types.mjs").QueryOptions} options | ||
| * @returns {import("./types.mjs").TagListData | undefined} | ||
| */ | ||
| export const useTagListDataResponse = (taxonomyId, options) => { | ||
| const { isSuccess, data } = useTagListData(taxonomyId, options); | ||
| if (isSuccess) { | ||
| return data; | ||
| } | ||
|
|
||
| return undefined; | ||
| }; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
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.
Addressed with 0e19e99