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 [TEMP] #23

Closed
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
a8b82cf
feat: add manage-orgs modal
rpenido Dec 13, 2023
6484bdc
fix: menu layout and input clear
rpenido Dec 13, 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
ef7cdaa
fix: add confirm modal
rpenido Dec 19, 2023
5da46b2
test: add manage org menu test
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
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
4ffebda
fix(deps): update dependency @edx/frontend-lib-content-components to …
renovate[bot] Dec 21, 2023
2788621
feat: Add filter taxonomies by org (#755)
yusuf-musleh Jan 4, 2024
52b75e0
fix: uploading progress percentage (#763)
KristinAoki Jan 4, 2024
2e070c9
feat: error page on invalid course key (#761)
ArturGaspar Jan 4, 2024
2205506
chore: removed reported_content_email_notifications_flag dependency (…
ayesha-waris Jan 5, 2024
6c0fc09
feat: add import taxonomy feature [FC-0036] (#675)
rpenido Jan 8, 2024
138f1d2
feat: Add v2 lib components content tags support (#771)
yusuf-musleh Jan 8, 2024
25fb779
Merge branch 'master' into rpenido/fal-3543-assign-taxonomy-to-organi…
rpenido Jan 8, 2024
56e6c1e
test: fix test
rpenido Jan 8, 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
15 changes: 15 additions & 0 deletions src/generic/data/apiHooks.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// @ts-check
import { useQuery } from '@tanstack/react-query';
import { getOrganizations } from './api';

/**
* Builds the query to get a list of available organizations
*/
export const useOrganizationListData = () => (
useQuery({
queryKey: ['organizationList'],
queryFn: () => getOrganizations(),
})
);

export default useOrganizationListData;
4 changes: 4 additions & 0 deletions src/taxonomy/TaxonomyListPage.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ describe('<TaxonomyListPage />', async () => {
store = initializeStore();
});

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

it('should render page and page title correctly', () => {
const { getByText } = render(<RootWrapper />);
expect(getByText('Taxonomies')).toBeInTheDocument();
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 @@ -18,10 +18,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 @@ -43,6 +50,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 @@ -61,6 +62,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;
};
38 changes: 38 additions & 0 deletions src/taxonomy/data/apiHooks.test.jsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { useQuery, useMutation } from '@tanstack/react-query';
import { act } from '@testing-library/react';

import {
useTaxonomyListDataResponse,
useIsTaxonomyListDataLoaded,
useDeleteTaxonomy,
useTaxonomyDetailDataStatus,
useTaxonomyDetailDataResponse,
} from './apiHooks';
import { deleteTaxonomy } from './api';

Expand Down Expand Up @@ -75,3 +78,38 @@ describe('useDeleteTaxonomy', () => {
});
});
});

describe('useTaxonomyDetailDataStatus', () => {
it('should return status values', () => {
const status = {
isError: false,
error: undefined,
isFetched: true,
isSuccess: true,
};

useQuery.mockReturnValueOnce(status);

const result = useTaxonomyDetailDataStatus(0);

expect(result).toEqual(status);
});
});

describe('useTaxonomyDetailDataResponse', () => {
it('should return data when status is success', () => {
useQuery.mockReturnValueOnce({ isSuccess: true, data: 'data' });

const result = useTaxonomyDetailDataResponse();

expect(result).toEqual('data');
});

it('should return undefined when status is not success', () => {
useQuery.mockReturnValueOnce({ isSuccess: false });

const result = useTaxonomyDetailDataResponse();

expect(result).toBeUndefined();
});
});
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
Loading