mirror of
https://github.com/IRBorisov/ConceptPortal.git
synced 2025-06-26 04:50:36 +03:00
B: Add timeout for cache invalidation after schema delete
This commit is contained in:
parent
515f398fda
commit
0ad1e4f872
|
@ -53,8 +53,11 @@ export function axiosGet<ResponseData>({ endpoint, options }: IAxiosGetRequest)
|
|||
.get<ResponseData>(endpoint, options)
|
||||
.then(response => response.data)
|
||||
.catch((error: Error | AxiosError) => {
|
||||
toast.error(extractErrorMessage(error));
|
||||
console.error(error);
|
||||
if (error.name !== 'CanceledError') {
|
||||
// Note: Ignore cancellation errors
|
||||
toast.error(extractErrorMessage(error));
|
||||
console.error(error);
|
||||
}
|
||||
throw error;
|
||||
});
|
||||
}
|
||||
|
|
|
@ -2,7 +2,8 @@ import { useMutation, useQueryClient } from '@tanstack/react-query';
|
|||
|
||||
import { ossApi } from '@/backend/oss/api';
|
||||
import { rsformsApi } from '@/backend/rsform/api';
|
||||
import { ILibraryItem, LibraryItemID } from '@/models/library';
|
||||
import { LibraryItemID } from '@/models/library';
|
||||
import { PARAMETER } from '@/utils/constants';
|
||||
|
||||
import { libraryApi } from './api';
|
||||
|
||||
|
@ -12,13 +13,16 @@ export const useDeleteItem = () => {
|
|||
mutationKey: [libraryApi.baseKey, 'delete-item'],
|
||||
mutationFn: libraryApi.deleteItem,
|
||||
onSuccess: (_, variables) => {
|
||||
client.setQueryData(libraryApi.libraryListKey, (prev: ILibraryItem[] | undefined) =>
|
||||
prev?.filter(item => item.id !== variables)
|
||||
client.invalidateQueries({ queryKey: libraryApi.libraryListKey }).catch(console.error);
|
||||
setTimeout(
|
||||
() =>
|
||||
void Promise.allSettled([
|
||||
client.invalidateQueries({ queryKey: [ossApi.baseKey] }),
|
||||
client.resetQueries({ queryKey: rsformsApi.getRSFormQueryOptions({ itemID: variables }).queryKey }),
|
||||
client.resetQueries({ queryKey: ossApi.getOssQueryOptions({ itemID: variables }).queryKey })
|
||||
]).catch(console.error),
|
||||
PARAMETER.navigationDuration
|
||||
);
|
||||
return Promise.allSettled([
|
||||
client.invalidateQueries({ queryKey: [ossApi.baseKey] }),
|
||||
client.invalidateQueries({ queryKey: rsformsApi.getRSFormQueryOptions({ itemID: variables }).queryKey })
|
||||
]);
|
||||
}
|
||||
});
|
||||
return {
|
||||
|
|
|
@ -19,6 +19,7 @@ import { IOperationPosition, IOperationSchema, OperationID, OperationType } from
|
|||
import { UserRole } from '@/models/user';
|
||||
import { RSTabID } from '@/pages/RSFormPage/RSEditContext';
|
||||
import { useDialogsStore } from '@/stores/dialogs';
|
||||
import { useLibrarySearchStore } from '@/stores/librarySearch';
|
||||
import { usePreferencesStore } from '@/stores/preferences';
|
||||
import { useRoleStore } from '@/stores/role';
|
||||
import { PARAMETER } from '@/utils/constants';
|
||||
|
@ -81,6 +82,8 @@ export const OssEditState = ({ itemID, children }: React.PropsWithChildren<OssEd
|
|||
|
||||
const role = useRoleStore(state => state.role);
|
||||
const adjustRole = useRoleStore(state => state.adjustRole);
|
||||
const setSearchLocation = useLibrarySearchStore(state => state.setLocation);
|
||||
const searchLocation = useLibrarySearchStore(state => state.location);
|
||||
|
||||
const { user } = useAuthSuspense();
|
||||
const { schema } = useOssSuspense({ itemID: itemID });
|
||||
|
@ -139,7 +142,12 @@ export const OssEditState = ({ itemID, children }: React.PropsWithChildren<OssEd
|
|||
if (!window.confirm(prompts.deleteOSS)) {
|
||||
return;
|
||||
}
|
||||
deleteItem(schema.id, () => router.push(urls.library));
|
||||
deleteItem(schema.id, () => {
|
||||
if (searchLocation === schema.location) {
|
||||
setSearchLocation('');
|
||||
}
|
||||
router.push(urls.library);
|
||||
});
|
||||
}
|
||||
|
||||
function promptCreateOperation({ defaultX, defaultY, inputs, positions, callback }: ICreateOperationPrompt) {
|
||||
|
|
|
@ -16,6 +16,7 @@ import { ConstituentaID, CstType, IConstituenta, IRSForm } from '@/models/rsform
|
|||
import { generateAlias } from '@/models/rsformAPI';
|
||||
import { UserRole } from '@/models/user';
|
||||
import { useDialogsStore } from '@/stores/dialogs';
|
||||
import { useLibrarySearchStore } from '@/stores/librarySearch';
|
||||
import { useModificationStore } from '@/stores/modification';
|
||||
import { usePreferencesStore } from '@/stores/preferences';
|
||||
import { useRoleStore } from '@/stores/role';
|
||||
|
@ -91,6 +92,8 @@ export const RSEditState = ({
|
|||
const adminMode = usePreferencesStore(state => state.adminMode);
|
||||
const role = useRoleStore(state => state.role);
|
||||
const adjustRole = useRoleStore(state => state.adjustRole);
|
||||
const setSearchLocation = useLibrarySearchStore(state => state.setLocation);
|
||||
const searchLocation = useLibrarySearchStore(state => state.location);
|
||||
|
||||
const { user } = useAuthSuspense();
|
||||
const { schema } = useRSFormSuspense({ itemID: itemID, version: activeVersion });
|
||||
|
@ -175,6 +178,9 @@ export const RSEditState = ({
|
|||
if (ossID) {
|
||||
router.push(urls.oss(ossID, OssTabID.GRAPH));
|
||||
} else {
|
||||
if (searchLocation === schema.location) {
|
||||
setSearchLocation('');
|
||||
}
|
||||
router.push(urls.library);
|
||||
}
|
||||
});
|
||||
|
|
|
@ -11,6 +11,7 @@ export const PARAMETER = {
|
|||
refreshTimeout: 100, // milliseconds delay for post-refresh actions
|
||||
minimalTimeout: 10, // milliseconds delay for fast updates
|
||||
zoomDuration: 500, // milliseconds animation duration
|
||||
navigationDuration: 300, // milliseconds navigation duration
|
||||
|
||||
ossImageWidth: 1280, // pixels - size of OSS image
|
||||
ossImageHeight: 960, // pixels - size of OSS image
|
||||
|
|
Loading…
Reference in New Issue
Block a user