Skip to content

Commit

Permalink
fix: types
Browse files Browse the repository at this point in the history
  • Loading branch information
rpenido committed Nov 11, 2023
1 parent 76c0169 commit 0e25638
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 19 deletions.
5 changes: 3 additions & 2 deletions src/taxonomy/tag-list/TagListTable.jsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// ts-check
import { useIntl } from '@edx/frontend-platform/i18n';
import {
DataTable,
Expand Down Expand Up @@ -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={[
{
Expand Down
8 changes: 4 additions & 4 deletions src/taxonomy/tag-list/data/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<import('../types.mjs').TaxonomyData>}
* @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(camelCaseObject)
.then((response) => response.data),
.then((response) => response.data)
.then(camelCaseObject),
});
};
6 changes: 3 additions & 3 deletions src/taxonomy/tag-list/data/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<import('@tanstack/react-query').UseQueryResult, "error" | "isError" | "isFetched" | "isLoading" | "isSuccess" >}
*/ /* eslint-enable max-len */
export const useTagListDataStatus = (taxonomyId, options) => {
Expand All @@ -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);
Expand Down
28 changes: 28 additions & 0 deletions src/taxonomy/tag-list/data/types.mjs
Original file line number Diff line number Diff line change
@@ -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
*/
6 changes: 0 additions & 6 deletions src/taxonomy/tag-list/types.mjs

This file was deleted.

6 changes: 3 additions & 3 deletions src/taxonomy/taxonomy-detail/data/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ const getTaxonomyDetailApiUrl = (taxonomyId) => new URL(

/**
* @param {number} taxonomyId
* @returns {import('@tanstack/react-query').UseQueryResult<import('../types.mjs').TaxonomyData>}
* @returns {import('@tanstack/react-query').UseQueryResult<import('./types.mjs').TaxonomyData>}
*/ // 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),
})
);
2 changes: 1 addition & 1 deletion src/taxonomy/taxonomy-detail/data/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
19 changes: 19 additions & 0 deletions src/taxonomy/taxonomy-detail/data/types.mjs
Original file line number Diff line number Diff line change
@@ -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
*/

0 comments on commit 0e25638

Please sign in to comment.