Skip to content

Commit 31de55c

Browse files
feat(ux): add expandFolder to auto expand folders on nested folder creation (#2562)
Co-authored-by: Cursor Agent <[email protected]>
1 parent eaca490 commit 31de55c

File tree

2 files changed

+25
-12
lines changed

2 files changed

+25
-12
lines changed

apps/sim/app/workspace/[workspaceId]/w/components/sidebar/components/workflow-list/components/folder-item/folder-item.tsx

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,16 @@ export function FolderItem({ folder, level, hoverHandlers }: FolderItemProps) {
7575
getFolderIds: () => folder.id,
7676
})
7777

78+
// Folder expand hook - must be declared before callbacks that use expandFolder
79+
const {
80+
isExpanded,
81+
handleToggleExpanded,
82+
expandFolder,
83+
handleKeyDown: handleExpandKeyDown,
84+
} = useFolderExpand({
85+
folderId: folder.id,
86+
})
87+
7888
/**
7989
* Handle create workflow in folder using React Query mutation.
8090
* Generates name and color upfront for optimistic UI updates.
@@ -95,6 +105,8 @@ export function FolderItem({ folder, level, hoverHandlers }: FolderItemProps) {
95105

96106
if (result.id) {
97107
router.push(`/workspace/${workspaceId}/w/${result.id}`)
108+
// Expand the parent folder so the new workflow is visible
109+
expandFolder()
98110
// Scroll to the newly created workflow
99111
window.dispatchEvent(
100112
new CustomEvent(SIDEBAR_SCROLL_EVENT, { detail: { itemId: result.id } })
@@ -104,7 +116,7 @@ export function FolderItem({ folder, level, hoverHandlers }: FolderItemProps) {
104116
// Error already handled by mutation's onError callback
105117
logger.error('Failed to create workflow in folder:', error)
106118
}
107-
}, [createWorkflowMutation, workspaceId, folder.id, router])
119+
}, [createWorkflowMutation, workspaceId, folder.id, router, expandFolder])
108120

109121
/**
110122
* Handle create sub-folder using React Query mutation.
@@ -118,6 +130,8 @@ export function FolderItem({ folder, level, hoverHandlers }: FolderItemProps) {
118130
parentId: folder.id,
119131
})
120132
if (result.id) {
133+
// Expand the parent folder so the new folder is visible
134+
expandFolder()
121135
// Scroll to the newly created folder
122136
window.dispatchEvent(
123137
new CustomEvent(SIDEBAR_SCROLL_EVENT, { detail: { itemId: result.id } })
@@ -126,16 +140,7 @@ export function FolderItem({ folder, level, hoverHandlers }: FolderItemProps) {
126140
} catch (error) {
127141
logger.error('Failed to create folder:', error)
128142
}
129-
}, [createFolderMutation, workspaceId, folder.id])
130-
131-
// Folder expand hook
132-
const {
133-
isExpanded,
134-
handleToggleExpanded,
135-
handleKeyDown: handleExpandKeyDown,
136-
} = useFolderExpand({
137-
folderId: folder.id,
138-
})
143+
}, [createFolderMutation, workspaceId, folder.id, expandFolder])
139144

140145
/**
141146
* Drag start handler - sets folder data for drag operation

apps/sim/app/workspace/[workspaceId]/w/components/sidebar/hooks/use-folder-expand.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ interface UseFolderExpandProps {
1313
* @returns Expansion state and event handlers
1414
*/
1515
export function useFolderExpand({ folderId }: UseFolderExpandProps) {
16-
const { expandedFolders, toggleExpanded } = useFolderStore()
16+
const { expandedFolders, toggleExpanded, setExpanded } = useFolderStore()
1717
const isExpanded = expandedFolders.has(folderId)
1818

1919
/**
@@ -23,6 +23,13 @@ export function useFolderExpand({ folderId }: UseFolderExpandProps) {
2323
toggleExpanded(folderId)
2424
}, [folderId, toggleExpanded])
2525

26+
/**
27+
* Expand the folder (useful when creating items inside)
28+
*/
29+
const expandFolder = useCallback(() => {
30+
setExpanded(folderId, true)
31+
}, [folderId, setExpanded])
32+
2633
/**
2734
* Handle keyboard navigation (Enter/Space)
2835
*/
@@ -39,6 +46,7 @@ export function useFolderExpand({ folderId }: UseFolderExpandProps) {
3946
return {
4047
isExpanded,
4148
handleToggleExpanded,
49+
expandFolder,
4250
handleKeyDown,
4351
}
4452
}

0 commit comments

Comments
 (0)