Skip to content

Commit

Permalink
2329: invalidate annotations cache on update
Browse files Browse the repository at this point in the history
  • Loading branch information
ThieryMichel committed Feb 3, 2025
1 parent 0341555 commit 0f31155
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
3 changes: 3 additions & 0 deletions cypress/e2e/phase_4/annotation.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,9 @@ describe('Annotation', () => {

cy.findByText('Annotations').click();

cy.wait(1000);
cy.findByRole('progressbar').should('not.exist');

cy.findAllByRole('cell').then((cells) => {
const firstUri = cells[0].textContent;
const secondUri = cells[14].textContent;
Expand Down
13 changes: 9 additions & 4 deletions src/app/js/admin/annotations/useUpdateAnnotation.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useCallback, useMemo } from 'react';
import { useMutation } from '@tanstack/react-query';
import { useMutation, useQueryClient } from '@tanstack/react-query';
import { useTranslate } from '../../i18n/I18NContext';
import { getUserSessionStorageInfo } from '../api/tools';
import { getRequest } from '../../user';
Expand All @@ -10,6 +10,7 @@ import fetch from '../../lib/fetch';
export function useUpdateAnnotation() {
const { translate } = useTranslate();
const history = useHistory();
const queryClient = useQueryClient();

const mutation = useMutation({
mutationFn: async ({ id, annotation }) => {
Expand All @@ -35,13 +36,17 @@ export function useUpdateAnnotation() {

return response.data;
},
onSuccess: () => {
toast(translate('annotation_create_success'), {
onSuccess: (data) => {
queryClient.setQueryData(['get-annotation', data._id], data);
queryClient.invalidateQueries({
predicate: (query) => query.queryKey[0] === 'get-annotations',
});
toast(translate('annotation_update_success'), {
type: toast.TYPE.SUCCESS,
});
},
onError: () => {
toast(translate('annotation_create_error'), {
toast(translate('annotation_update_error'), {
type: toast.TYPE.ERROR,
});
},
Expand Down

0 comments on commit 0f31155

Please sign in to comment.