From a0cbf05da8e96a0b7333aeab36f2ba817aec8947 Mon Sep 17 00:00:00 2001 From: EYHN Date: Mon, 29 Jul 2024 09:57:36 +0000 Subject: [PATCH] fix(core): sidebar renaming bug (#7632) --- .../src/modules/explorer/views/nodes/folder/index.tsx | 11 ++++++++++- .../explorer/views/sections/organize/index.tsx | 11 ++++++++++- .../modules/explorer/views/sections/tags/index.tsx | 11 ++++++++++- .../core/src/modules/explorer/views/tree/node.tsx | 8 +++----- 4 files changed, 33 insertions(+), 8 deletions(-) diff --git a/packages/frontend/core/src/modules/explorer/views/nodes/folder/index.tsx b/packages/frontend/core/src/modules/explorer/views/nodes/folder/index.tsx index cba01b834c..ae2d1ad72e 100644 --- a/packages/frontend/core/src/modules/explorer/views/nodes/folder/index.tsx +++ b/packages/frontend/core/src/modules/explorer/views/nodes/folder/index.tsx @@ -679,6 +679,15 @@ export const ExplorerFolderNodeFolder = ({ [handleDeleteChildren, t] ); + const handleCollapsedChange = useCallback((collapsed: boolean) => { + if (collapsed) { + setNewFolderId(null); // reset new folder id to clear the renaming state + setCollapsed(true); + } else { + setCollapsed(false); + } + }, []); + return ( ( @@ -694,7 +703,7 @@ export const ExplorerFolderNodeFolder = ({ renameable reorderable={reorderable} collapsed={collapsed} - setCollapsed={setCollapsed} + setCollapsed={handleCollapsedChange} onRename={handleRename} operations={finalOperations} canDrop={handleCanDrop} diff --git a/packages/frontend/core/src/modules/explorer/views/sections/organize/index.tsx b/packages/frontend/core/src/modules/explorer/views/sections/organize/index.tsx index 43c0151fd0..91be86b4fd 100644 --- a/packages/frontend/core/src/modules/explorer/views/sections/organize/index.tsx +++ b/packages/frontend/core/src/modules/explorer/views/sections/organize/index.tsx @@ -95,12 +95,21 @@ export const ExplorerOrganize = ({ DropTargetOptions['canDrop'] >(() => args => args.source.data.entity?.type === 'folder', []); + const handleCollapsedChange = useCallback((collapsed: boolean) => { + if (collapsed) { + setNewFolderId(null); // reset new folder id to clear the renaming state + setCollapsed(true); + } else { + setCollapsed(false); + } + }, []); + return ( { + if (collapsed) { + setCreatedTag(null); // reset created tag to clear the renaming state + setCollapsed(true); + } else { + setCollapsed(false); + } + }, []); + return ( >; + setCollapsed: (collapsed: boolean) => void; renameable?: boolean; onRename?: (newName: string) => void; disabled?: boolean; @@ -285,9 +283,9 @@ export const ExplorerTreeNode = ({ if (!clickForCollapse) { onClick?.(); } else { - setCollapsed(prev => !prev); + setCollapsed(!collapsed); } - }, [clickForCollapse, onClick, setCollapsed]); + }, [clickForCollapse, collapsed, onClick, setCollapsed]); const content = (