Skip to content

Commit

Permalink
fix: Fix typing issues with mutations
Browse files Browse the repository at this point in the history
  • Loading branch information
yusuf-musleh committed Nov 27, 2023
1 parent 313728b commit 9271338
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/content-tags-drawer/data/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const getContentDataApiUrl = (contentId) => new URL(`/xblock/outline/${co

/**
* Get all tags that belong to taxonomy.
* @param {string} taxonomyId The id of the taxonomy to fetch tags for
* @param {number} taxonomyId The id of the taxonomy to fetch tags for
* @param {string} fullPathProvided Optional param that contains the full URL to fetch data
* If provided, we use it instead of generating the URL. This is usually for fetching subTags
* @returns {Promise<Object>}
Expand Down
16 changes: 11 additions & 5 deletions src/content-tags-drawer/data/apiHooks.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,22 @@ export const useContentData = (contentId) => (

/**
* Builds the mutation to update the tags applied to the content object
* @param {string} contentId The id of the content object to update tags for
* @param {number} taxonomyId The id of the taxonomy the tags belong to
*/
export const useContentTaxonomyTagsMutation = (contentId, taxonomyId) => {
const queryClient = useQueryClient();

/**
* @type {
* import("@tanstack/react-query").MutateFunction<any, any, {contentId: string, taxonomyId: number, tags: string[]}>
* }
*/
return useMutation({
/**
* @type {import("@tanstack/react-query").MutateFunction<
* any,
* any,
* {
* tags: string[]
* }
* >}
*/
mutationFn: ({ tags }) => updateContentTaxonomyTags(contentId, taxonomyId, tags),
onSettled: () => {
queryClient.invalidateQueries({ queryKey: ['contentTaxonomyTags', contentId] });
Expand Down
2 changes: 1 addition & 1 deletion src/content-tags-drawer/data/apiHooks.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ describe('useContentTaxonomyTagsMutation', () => {
useMutation.mockReturnValueOnce({ mutate: jest.fn() });

const mutation = useContentTaxonomyTagsMutation();
mutation.mutate();
mutation.mutate({ tags: ['a', 'b', 'c'] });

expect(useMutation).toBeCalled();

Expand Down

0 comments on commit 9271338

Please sign in to comment.