fix: remove refetch

This commit is contained in:
hexastack 2024-10-29 14:54:14 +01:00
parent 3cef49d4de
commit 9ab93f1bcf

View File

@ -37,10 +37,12 @@ import {
useRef, useRef,
useState, useState,
} from "react"; } from "react";
import { useQueryClient } from "react-query";
import { DeleteDialog } from "@/app-components/dialogs"; import { DeleteDialog } from "@/app-components/dialogs";
import { MoveDialog } from "@/app-components/dialogs/MoveDialog"; import { MoveDialog } from "@/app-components/dialogs/MoveDialog";
import { CategoryDialog } from "@/components/categories/CategoryDialog"; import { CategoryDialog } from "@/components/categories/CategoryDialog";
import { isSameEntity } from "@/hooks/crud/helpers";
import { useDelete, useDeleteFromCache } from "@/hooks/crud/useDelete"; import { useDelete, useDeleteFromCache } from "@/hooks/crud/useDelete";
import { useFind } from "@/hooks/crud/useFind"; import { useFind } from "@/hooks/crud/useFind";
import { useGetFromCache } from "@/hooks/crud/useGet"; import { useGetFromCache } from "@/hooks/crud/useGet";
@ -49,7 +51,7 @@ import useDebouncedUpdate from "@/hooks/useDebouncedUpdate";
import { getDisplayDialogs, useDialog } from "@/hooks/useDialog"; import { getDisplayDialogs, useDialog } from "@/hooks/useDialog";
import { useSearch } from "@/hooks/useSearch"; import { useSearch } from "@/hooks/useSearch";
import { useTranslate } from "@/hooks/useTranslate"; import { useTranslate } from "@/hooks/useTranslate";
import { EntityType, Format } from "@/services/types"; import { EntityType, Format, QueryType } from "@/services/types";
import { IBlock } from "@/types/block.types"; import { IBlock } from "@/types/block.types";
import { ICategory } from "@/types/category.types"; import { ICategory } from "@/types/category.types";
import { BlockPorts } from "@/types/visual-editor.types"; import { BlockPorts } from "@/types/visual-editor.types";
@ -70,12 +72,6 @@ const Diagrams = () => {
const [selectedBlockId, setSelectedBlockId] = useState<string | undefined>(); const [selectedBlockId, setSelectedBlockId] = useState<string | undefined>();
const deleteDialogCtl = useDialog<string>(false); const deleteDialogCtl = useDialog<string>(false);
const moveDialogCtl = useDialog<string[] | string>(false); const moveDialogCtl = useDialog<string[] | string>(false);
const { refetch: refetchBlocks } = useFind(
{ entity: EntityType.BLOCK, format: Format.FULL },
{
hasCount: false,
},
);
const addCategoryDialogCtl = useDialog<ICategory>(false); const addCategoryDialogCtl = useDialog<ICategory>(false);
const { const {
buildDiagram, buildDiagram,
@ -153,6 +149,7 @@ const Diagrams = () => {
}, },
[selectedCategoryId, debouncedUpdateCategory], [selectedCategoryId, debouncedUpdateCategory],
); );
const queryClient = useQueryClient();
const getBlockFromCache = useGetFromCache(EntityType.BLOCK); const getBlockFromCache = useGetFromCache(EntityType.BLOCK);
const updateCachedBlock = useUpdateCache(EntityType.BLOCK); const updateCachedBlock = useUpdateCache(EntityType.BLOCK);
const deleteCachedBlock = useDeleteFromCache(EntityType.BLOCK); const deleteCachedBlock = useDeleteFromCache(EntityType.BLOCK);
@ -183,13 +180,10 @@ const Diagrams = () => {
}, []); }, []);
useEffect(() => { useEffect(() => {
const filteredBlocks = blocks.filter(
(block) => block.category === selectedCategoryId,
);
const { canvas, model, engine } = buildDiagram({ const { canvas, model, engine } = buildDiagram({
zoom: currentCategory?.zoom || 100, zoom: currentCategory?.zoom || 100,
offset: currentCategory?.offset || [0, 0], offset: currentCategory?.offset || [0, 0],
data: filteredBlocks, data: blocks,
setter: setSelectedBlockId, setter: setSelectedBlockId,
updateFn: updateBlock, updateFn: updateBlock,
onRemoveNode: (ids, next) => { onRemoveNode: (ids, next) => {
@ -303,15 +297,12 @@ const Diagrams = () => {
zoomUpdated: debouncedZoomEvent, zoomUpdated: debouncedZoomEvent,
offsetUpdated: debouncedOffsetEvent, offsetUpdated: debouncedOffsetEvent,
}); });
refetchBlocks();
}, [ }, [
selectedCategoryId, selectedCategoryId,
JSON.stringify( JSON.stringify(
blocks blocks.map((b) => {
.filter((b) => b.category === selectedCategoryId) return { ...b, position: undefined, updatedAt: undefined };
.map((b) => { }),
return { ...b, position: undefined, updatedAt: undefined };
}),
), ),
]); ]);
@ -485,7 +476,18 @@ const Diagrams = () => {
}, },
); );
} }
refetchBlocks();
queryClient.removeQueries({
predicate: ({ queryKey }) => {
const [qType, qEntity] = queryKey;
return (
(qType === QueryType.collection &&
isSameEntity(qEntity, EntityType.BLOCK)) ||
isSameEntity(qEntity, EntityType.CATEGORY)
);
},
});
setSelectedCategoryId(newCategoryId); setSelectedCategoryId(newCategoryId);
setSelectedBlockId(undefined); setSelectedBlockId(undefined);