mirror of
https://github.com/suitenumerique/docs.git
synced 2026-09-22 01:25:07 +02:00
🐛(frontend) avoid full doc-tree reload on drag-and-drop move
Moving a doc via drag-and-drop already applies the move locally through `treeData.handleMove`, but `useMoveDoc`'s `onSuccess` also invalidated the `KEY_DOC_TREE` query, which `useDocTree` reacts to by nulling `treeContext.root` and forcing the whole tree to refetch and remount. Add a `skipTreeInvalidation` option so the drag-and-drop handler can skip that invalidation and rely on its own local update, while other callers (e.g. the move modal) keep reloading the tree as before.
This commit is contained in:
@@ -15,6 +15,7 @@ export type MoveDocParam = {
|
||||
sourceDocumentId: string;
|
||||
targetDocumentId: string;
|
||||
position: TreeViewMoveModeEnum;
|
||||
skipTreeInvalidation?: boolean;
|
||||
};
|
||||
|
||||
export const moveDoc = async ({
|
||||
@@ -48,7 +49,9 @@ export function useMoveDoc(options?: UseMoveDocOptions) {
|
||||
onSuccess(data, variables, onMutateResult, context) {
|
||||
void queryClient.invalidateQueries({ queryKey: [KEY_LIST_DOC] });
|
||||
void queryClient.invalidateQueries({ queryKey: [KEY_DOC] });
|
||||
void queryClient.invalidateQueries({ queryKey: [KEY_DOC_TREE] });
|
||||
if (!variables.skipTreeInvalidation) {
|
||||
void queryClient.invalidateQueries({ queryKey: [KEY_DOC_TREE] });
|
||||
}
|
||||
|
||||
if (options?.onSuccess) {
|
||||
void options.onSuccess(data, variables, onMutateResult, context);
|
||||
|
||||
@@ -58,6 +58,7 @@ export const DocTreeSubpages = memo(function DocTreeSubpages({
|
||||
sourceDocumentId: result.sourceId,
|
||||
targetDocumentId: result.targetModeId,
|
||||
position: result.mode,
|
||||
skipTreeInvalidation: true,
|
||||
});
|
||||
|
||||
treeContext?.treeData.handleMove(result);
|
||||
|
||||
Reference in New Issue
Block a user