diff --git a/src/taxonomy/tag-list/TagListTable.jsx b/src/taxonomy/tag-list/TagListTable.jsx index a7ae3d950c..0eeb5fe402 100644 --- a/src/taxonomy/tag-list/TagListTable.jsx +++ b/src/taxonomy/tag-list/TagListTable.jsx @@ -1,3 +1,4 @@ +// ts-check import { useIntl } from '@edx/frontend-platform/i18n'; import { DataTable, @@ -42,8 +43,8 @@ const TagListTable = ({ taxonomyId }) => { manualPagination fetchData={fetchData} data={tagList?.results || []} - itemCount={tagList?.count} - pageCount={tagList?.numPages} + itemCount={tagList?.count || 0} + pageCount={tagList?.numPages || 0} initialState={options} columns={[ { diff --git a/src/taxonomy/tag-list/data/api.js b/src/taxonomy/tag-list/data/api.js index f5bff808cc..456cb0020f 100644 --- a/src/taxonomy/tag-list/data/api.js +++ b/src/taxonomy/tag-list/data/api.js @@ -12,15 +12,15 @@ const getTagListApiUrl = (taxonomyId, page) => new URL( // ToDo: fix types /** * @param {number} taxonomyId - * @param {import('../types.mjs').QueryOptions} options - * @returns {import('@tanstack/react-query').UseQueryResult} + * @param {import('./types.mjs').QueryOptions} options + * @returns {import('@tanstack/react-query').UseQueryResult} */ // 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(camelCaseObject) - .then((response) => response.data), + .then((response) => response.data) + .then(camelCaseObject), }); }; diff --git a/src/taxonomy/tag-list/data/selectors.js b/src/taxonomy/tag-list/data/selectors.js index f94bfedbba..7f793f466c 100644 --- a/src/taxonomy/tag-list/data/selectors.js +++ b/src/taxonomy/tag-list/data/selectors.js @@ -6,7 +6,7 @@ import { /* eslint-disable max-len */ /** * @param {number} taxonomyId - * @param {import("../types.mjs").QueryOptions} options + * @param {import("./types.mjs").QueryOptions} options * @returns {Pick} */ /* eslint-enable max-len */ export const useTagListDataStatus = (taxonomyId, options) => { @@ -29,8 +29,8 @@ export const useTagListDataStatus = (taxonomyId, options) => { // ToDo: fix types /** * @param {number} taxonomyId - * @param {import("../types.mjs").QueryOptions} options - * @returns {import("../types.mjs").TaxonomyData | undefined} + * @param {import("./types.mjs").QueryOptions} options + * @returns {import("./types.mjs").TagListData | undefined} */ export const useTagListDataResponse = (taxonomyId, options) => { const { isSuccess, data } = useTagListData(taxonomyId, options); diff --git a/src/taxonomy/tag-list/data/types.mjs b/src/taxonomy/tag-list/data/types.mjs new file mode 100644 index 0000000000..63f6550c29 --- /dev/null +++ b/src/taxonomy/tag-list/data/types.mjs @@ -0,0 +1,28 @@ +// @ts-check + +/** + * @typedef {Object} QueryOptions + * @property {number} pageIndex + */ + +/** + * @typedef {Object} TagListData + * @property {number} childCount + * @property {number} depth + * @property {string} externalId + * @property {number} id + * @property {string | null} parentValue + * @property {string | null} subTagsUrl + * @property {string} value + */ + +/** + * @typedef {Object} TagData + * @property {number} count + * @property {number} currentPage + * @property {string} next + * @property {number} numPages + * @property {string} previous + * @property {TagListData[]} results + * @property {number} start + */ diff --git a/src/taxonomy/tag-list/types.mjs b/src/taxonomy/tag-list/types.mjs deleted file mode 100644 index 3141228c7d..0000000000 --- a/src/taxonomy/tag-list/types.mjs +++ /dev/null @@ -1,6 +0,0 @@ -// @ts-check - -/** - * @typedef {Object} QueryOptions - * @property {number} pageIndex - */ diff --git a/src/taxonomy/taxonomy-detail/data/api.js b/src/taxonomy/taxonomy-detail/data/api.js index 9148310926..81b7929ec9 100644 --- a/src/taxonomy/taxonomy-detail/data/api.js +++ b/src/taxonomy/taxonomy-detail/data/api.js @@ -11,13 +11,13 @@ const getTaxonomyDetailApiUrl = (taxonomyId) => new URL( /** * @param {number} taxonomyId - * @returns {import('@tanstack/react-query').UseQueryResult} + * @returns {import('@tanstack/react-query').UseQueryResult} */ // eslint-disable-next-line import/prefer-default-export export const useTaxonomyDetailData = (taxonomyId) => ( useQuery({ queryKey: ['taxonomyDetail', taxonomyId], queryFn: () => getAuthenticatedHttpClient().get(getTaxonomyDetailApiUrl(taxonomyId)) - .then(camelCaseObject) - .then((response) => response.data), + .then((response) => response.data) + .then(camelCaseObject), }) ); diff --git a/src/taxonomy/taxonomy-detail/data/selectors.js b/src/taxonomy/taxonomy-detail/data/selectors.js index 4805b2c94b..31f3361a97 100644 --- a/src/taxonomy/taxonomy-detail/data/selectors.js +++ b/src/taxonomy/taxonomy-detail/data/selectors.js @@ -24,7 +24,7 @@ export const useTaxonomyDetailDataStatus = (taxonomyId) => { /** * @param {number} taxonomyId - * @returns {import("../types.mjs").TaxonomyData | undefined} + * @returns {import("./types.mjs").TaxonomyData | undefined} */ export const useTaxonomyDetailDataResponse = (taxonomyId) => { const { isSuccess, data } = useTaxonomyDetailData(taxonomyId); diff --git a/src/taxonomy/taxonomy-detail/data/types.mjs b/src/taxonomy/taxonomy-detail/data/types.mjs new file mode 100644 index 0000000000..90b2c07acf --- /dev/null +++ b/src/taxonomy/taxonomy-detail/data/types.mjs @@ -0,0 +1,19 @@ +// @ts-check + +/** + * @typedef {Object} TaxonomyData + * @property {number} id + * @property {string} name + * @property {boolean} enabled + * @property {boolean} allowMultiple + * @property {boolean} allowFreeText + * @property {boolean} systemDefined + * @property {boolean} visibleToAuthors + * @property {string[]} orgs + */ + +/** + * @typedef {Object} UseQueryResult + * @property {Object} data + * @property {string} status + */