Skip to content
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

feat: assign taxonomy to organizations [FC-0036] #760

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
0c60c37
feat: add import taxonomy feature
rpenido Nov 9, 2023
c273af1
test: add api.test.js
rpenido Nov 9, 2023
047530d
test: add import button click test
rpenido Nov 9, 2023
303e7ba
test: add action.test.js
rpenido Nov 9, 2023
3955e91
test: add more tests to action.tests.js
rpenido Nov 9, 2023
8176973
test: add more tests to action.tests.js 2
rpenido Nov 9, 2023
4f31714
Merge branch 'openedx:master' into rpenido/fal-3532-import-taxonomy
rpenido Nov 10, 2023
df441fb
fix: import
rpenido Nov 10, 2023
a0e92f0
test: simplify import test
rpenido Nov 10, 2023
dc8ed9e
fix: remove undefined var
rpenido Nov 10, 2023
120154e
refactor: rename actions.js -> utils.js
rpenido Nov 10, 2023
318bbb7
revert: change in the jest.config
rpenido Nov 10, 2023
a8c2fd5
Merge branch 'master' into rpenido/fal-3532-import-taxonomy
pomegranited Nov 16, 2023
70ac2a7
Merge branch 'openedx:master' into rpenido/fal-3532-import-taxonomy
rpenido Nov 20, 2023
adacf23
chore: trigger CD/CI
rpenido Nov 20, 2023
5983953
Merge branch 'master' into rpenido/fal-3532-import-taxonomy
rpenido Nov 20, 2023
7756c7f
feat: import tags to existing taxonomy
rpenido Nov 24, 2023
4202c27
Merge branch 'master' into rpenido/fal-3532-import-taxonomy
rpenido Nov 24, 2023
6bcd924
refactor: merges TaxonomyCardMenu and TaxonomyDetailMenu (#13)
rpenido Nov 30, 2023
f318dfc
refactor: improve menu organization
rpenido Dec 4, 2023
204b2b9
fix: types
rpenido Dec 9, 2023
5e0f599
Merge branch 'master' into rpenido/fal-3532-import-taxonomy
rpenido Dec 12, 2023
f888ecf
refactor: merging conflicts
rpenido Dec 12, 2023
3c8da66
refactor: change export syntax
rpenido Dec 12, 2023
40479c1
fix: eslint
rpenido Dec 12, 2023
46e5d1b
fix: export TaxonomyDetail
rpenido Dec 12, 2023
db8ba58
fix: eslint
rpenido Dec 12, 2023
a8b82cf
feat: add manage-orgs modal
rpenido Dec 13, 2023
6484bdc
fix: menu layout and input clear
rpenido Dec 13, 2023
8fe8c07
Merge branch 'openedx:master' into rpenido/fal-3532-import-taxonomy
rpenido Dec 14, 2023
1440215
fix: TaxonomyContext types
rpenido Dec 15, 2023
cd971cf
feat: add api
rpenido Dec 15, 2023
7093304
refactor: move useTaxonomyDetail hooks to avoid circular dependency
rpenido Dec 18, 2023
eb670ff
fix: undo css change
rpenido Dec 18, 2023
e5b8e58
Merge branch 'master' into rpenido/fal-3532-import-taxonomy
rpenido Dec 19, 2023
fafcb9b
chore: rebasing
rpenido Dec 19, 2023
e80194f
fix: types
rpenido Dec 19, 2023
1e0dde3
fix: remove typo
rpenido Dec 19, 2023
ef7cdaa
fix: add confirm modal
rpenido Dec 19, 2023
5da46b2
test: add manage org menu test
rpenido Dec 19, 2023
7cae57b
test: cleaning test removing useMutation mock
rpenido Dec 19, 2023
7eb728a
Merge branch 'rpenido/fal-3532-import-taxonomy' into rpenido/fal-3543…
rpenido Dec 19, 2023
5aed312
fix: merge conflicts
rpenido Dec 19, 2023
1002fc6
style: cleaning code and fix lint
rpenido Dec 19, 2023
30890b5
Merge branch 'rpenido/fal-3532-import-taxonomy' into rpenido/fal-3543…
rpenido Dec 19, 2023
1e00d27
fix: disable element if is allOrg
rpenido Dec 19, 2023
f962b29
test: add tests
rpenido Dec 19, 2023
9fbe76e
style: add comment about modal style to allow dropdown overflow
rpenido Dec 20, 2023
aca5ce5
fix: add spacing
rpenido Dec 20, 2023
2bf4c53
fix: dont pass null children
rpenido Dec 20, 2023
6054020
fix: cleaning code
rpenido Dec 20, 2023
44d2428
test: add tests
rpenido Dec 20, 2023
ca38b43
test: add more tests
rpenido Dec 20, 2023
5d2b314
fix: typo
rpenido Dec 20, 2023
25fb779
Merge branch 'master' into rpenido/fal-3543-assign-taxonomy-to-organi…
rpenido Jan 8, 2024
56e6c1e
test: fix test
rpenido Jan 8, 2024
bc966b4
fix: console warnings and disable dialog overlay
rpenido Jan 10, 2024
3cf5758
fix: changes from review
rpenido Jan 11, 2024
aa1031e
test: update tests from review
rpenido Jan 11, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/taxonomy/TaxonomyListPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
Check,
} from '@edx/paragon/icons';
import { useIntl } from '@edx/frontend-platform/i18n';

import { Helmet } from 'react-helmet';

import { useOrganizationListData } from '../generic/data/apiHooks';
Expand Down
14 changes: 10 additions & 4 deletions src/taxonomy/TaxonomyListPage.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,7 @@ const RootWrapper = () => (
<IntlProvider locale="en" messages={{}}>
<QueryClientProvider client={queryClient}>
<TaxonomyContext.Provider value={context}>
<QueryClientProvider client={queryClient}>
<TaxonomyListPage intl={injectIntl} />
</QueryClientProvider>
<TaxonomyListPage intl={injectIntl} />
</TaxonomyContext.Provider>
</QueryClientProvider>
</IntlProvider>
Expand All @@ -71,6 +69,10 @@ describe('<TaxonomyListPage />', () => {
axiosMock.onGet(organizationsListUrl).reply(200, organizations);
});

afterEach(() => {
jest.clearAllMocks();
});

it('should render page and page title correctly', () => {
const { getByText } = render(<RootWrapper />);
expect(getByText('Taxonomies')).toBeInTheDocument();
Expand Down Expand Up @@ -134,7 +136,11 @@ describe('<TaxonomyListPage />', () => {
it('should show all "All taxonomies", "Unassigned" and org names in taxonomy org filter', async () => {
useIsTaxonomyListDataLoaded.mockReturnValue(true);
useTaxonomyListDataResponse.mockReturnValue({
results: taxonomies,
results: [{
id: 1,
name: 'Taxonomy',
description: 'This is a description',
}],
});

const {
Expand Down
16 changes: 16 additions & 0 deletions src/taxonomy/data/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,17 @@ export const getExportTaxonomyApiUrl = (pk, format) => new URL(
`api/content_tagging/v1/taxonomies/${pk}/export/?output_format=${format}&download=1`,
getApiBaseUrl(),
).href;

export const getTaxonomyTemplateApiUrl = (format) => new URL(
`api/content_tagging/v1/taxonomies/import/template.${format}`,
getApiBaseUrl(),
).href;

/**
* Get the URL for a Taxonomy
* @param {number} pk
* @returns {string}
*/
export const getTaxonomyApiUrl = (pk) => new URL(`api/content_tagging/v1/taxonomies/${pk}/`, getApiBaseUrl()).href;

/**
Expand All @@ -47,6 +54,15 @@ export async function deleteTaxonomy(pk) {
await getAuthenticatedHttpClient().delete(getTaxonomyApiUrl(pk));
}

/** Get a Taxonomy
* @param {number} pk
* @returns {Promise<import("./types.mjs").TaxonomyData>}
*/
export async function getTaxonomy(pk) {
const { data } = await getAuthenticatedHttpClient().get(getTaxonomyApiUrl(pk));
return camelCaseObject(data);
}

/**
* Downloads the file of the exported taxonomy
* @param {number} pk
Expand Down
8 changes: 8 additions & 0 deletions src/taxonomy/data/api.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
getTaxonomyListApiUrl,
getTaxonomyListData,
getTaxonomyApiUrl,
getTaxonomy,
deleteTaxonomy,
} from './api';

Expand Down Expand Up @@ -65,6 +66,13 @@ describe('taxonomy api calls', () => {
expect(axiosMock.history.delete[0].url).toEqual(getTaxonomyApiUrl());
});

it('should call get taxonomy', async () => {
axiosMock.onGet(getTaxonomyApiUrl(1)).reply(200);
await getTaxonomy(1);

expect(axiosMock.history.get[0].url).toEqual(getTaxonomyApiUrl(1));
});

it('Export should set window.location.href correctly', () => {
const pk = 1;
const format = 'json';
Expand Down
44 changes: 43 additions & 1 deletion src/taxonomy/data/apiHooks.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* Ex. useTaxonomyListDataResponse & useIsTaxonomyListDataLoaded.
*/
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
import { getTaxonomyListData, deleteTaxonomy } from './api';
import { getTaxonomyListData, deleteTaxonomy, getTaxonomy } from './api';

/**
* Builds the query to get the taxonomy list
Expand Down Expand Up @@ -41,6 +41,16 @@ export const useDeleteTaxonomy = () => {
return mutate;
};

/** Builds the query to get the taxonomy detail
* @param {number} taxonomyId
*/
const useTaxonomyDetailData = (taxonomyId) => (
useQuery({
queryKey: ['taxonomyDetail', taxonomyId],
queryFn: async () => getTaxonomy(taxonomyId),
})
);

/**
* Gets the taxonomy list data
* @param {string} org Optional organization query param
Expand All @@ -62,3 +72,35 @@ export const useTaxonomyListDataResponse = (org) => {
export const useIsTaxonomyListDataLoaded = (org) => (
useTaxonomyListData(org).status === 'success'
);

/**
* @param {number} taxonomyId
* @returns {Pick<import('@tanstack/react-query').UseQueryResult, "error" | "isError" | "isFetched" | "isSuccess">}
*/
export const useTaxonomyDetailDataStatus = (taxonomyId) => {
const {
isError,
error,
isFetched,
isSuccess,
} = useTaxonomyDetailData(taxonomyId);
return {
isError,
error,
isFetched,
isSuccess,
};
};

/**
* @param {number} taxonomyId
* @returns {import("./types.mjs").TaxonomyData | undefined}
*/
export const useTaxonomyDetailDataResponse = (taxonomyId) => {
const { isSuccess, data } = useTaxonomyDetailData(taxonomyId);
if (isSuccess) {
return data;
}

return undefined;
};
1 change: 1 addition & 0 deletions src/taxonomy/data/apiHooks.test.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useQuery, useMutation } from '@tanstack/react-query';
import { act } from '@testing-library/react';

import {
useTaxonomyListDataResponse,
useIsTaxonomyListDataLoaded,
Expand Down
1 change: 1 addition & 0 deletions src/taxonomy/data/types.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
* @property {boolean} visibleToAuthors
* @property {number} tagsCount
* @property {string[]} orgs
* @property {boolean} allOrgs
*/

/**
Expand Down
Loading