feat(ux): add expandFolder to auto expand folders on nested folder creation (#2562)

Co-authored-by: Cursor Agent <cursoragent@cursor.com>
This commit is contained in:
Emir Karabeg
2025-12-23 16:27:00 -08:00
committed by GitHub
parent eaca49037d
commit 31de55cbdf
2 changed files with 25 additions and 12 deletions

View File

@@ -75,6 +75,16 @@ export function FolderItem({ folder, level, hoverHandlers }: FolderItemProps) {
getFolderIds: () => folder.id, getFolderIds: () => folder.id,
}) })
// Folder expand hook - must be declared before callbacks that use expandFolder
const {
isExpanded,
handleToggleExpanded,
expandFolder,
handleKeyDown: handleExpandKeyDown,
} = useFolderExpand({
folderId: folder.id,
})
/** /**
* Handle create workflow in folder using React Query mutation. * Handle create workflow in folder using React Query mutation.
* Generates name and color upfront for optimistic UI updates. * Generates name and color upfront for optimistic UI updates.
@@ -95,6 +105,8 @@ export function FolderItem({ folder, level, hoverHandlers }: FolderItemProps) {
if (result.id) { if (result.id) {
router.push(`/workspace/${workspaceId}/w/${result.id}`) router.push(`/workspace/${workspaceId}/w/${result.id}`)
// Expand the parent folder so the new workflow is visible
expandFolder()
// Scroll to the newly created workflow // Scroll to the newly created workflow
window.dispatchEvent( window.dispatchEvent(
new CustomEvent(SIDEBAR_SCROLL_EVENT, { detail: { itemId: result.id } }) new CustomEvent(SIDEBAR_SCROLL_EVENT, { detail: { itemId: result.id } })
@@ -104,7 +116,7 @@ export function FolderItem({ folder, level, hoverHandlers }: FolderItemProps) {
// Error already handled by mutation's onError callback // Error already handled by mutation's onError callback
logger.error('Failed to create workflow in folder:', error) logger.error('Failed to create workflow in folder:', error)
} }
}, [createWorkflowMutation, workspaceId, folder.id, router]) }, [createWorkflowMutation, workspaceId, folder.id, router, expandFolder])
/** /**
* Handle create sub-folder using React Query mutation. * Handle create sub-folder using React Query mutation.
@@ -118,6 +130,8 @@ export function FolderItem({ folder, level, hoverHandlers }: FolderItemProps) {
parentId: folder.id, parentId: folder.id,
}) })
if (result.id) { if (result.id) {
// Expand the parent folder so the new folder is visible
expandFolder()
// Scroll to the newly created folder // Scroll to the newly created folder
window.dispatchEvent( window.dispatchEvent(
new CustomEvent(SIDEBAR_SCROLL_EVENT, { detail: { itemId: result.id } }) new CustomEvent(SIDEBAR_SCROLL_EVENT, { detail: { itemId: result.id } })
@@ -126,16 +140,7 @@ export function FolderItem({ folder, level, hoverHandlers }: FolderItemProps) {
} catch (error) { } catch (error) {
logger.error('Failed to create folder:', error) logger.error('Failed to create folder:', error)
} }
}, [createFolderMutation, workspaceId, folder.id]) }, [createFolderMutation, workspaceId, folder.id, expandFolder])
// Folder expand hook
const {
isExpanded,
handleToggleExpanded,
handleKeyDown: handleExpandKeyDown,
} = useFolderExpand({
folderId: folder.id,
})
/** /**
* Drag start handler - sets folder data for drag operation * Drag start handler - sets folder data for drag operation

View File

@@ -13,7 +13,7 @@ interface UseFolderExpandProps {
* @returns Expansion state and event handlers * @returns Expansion state and event handlers
*/ */
export function useFolderExpand({ folderId }: UseFolderExpandProps) { export function useFolderExpand({ folderId }: UseFolderExpandProps) {
const { expandedFolders, toggleExpanded } = useFolderStore() const { expandedFolders, toggleExpanded, setExpanded } = useFolderStore()
const isExpanded = expandedFolders.has(folderId) const isExpanded = expandedFolders.has(folderId)
/** /**
@@ -23,6 +23,13 @@ export function useFolderExpand({ folderId }: UseFolderExpandProps) {
toggleExpanded(folderId) toggleExpanded(folderId)
}, [folderId, toggleExpanded]) }, [folderId, toggleExpanded])
/**
* Expand the folder (useful when creating items inside)
*/
const expandFolder = useCallback(() => {
setExpanded(folderId, true)
}, [folderId, setExpanded])
/** /**
* Handle keyboard navigation (Enter/Space) * Handle keyboard navigation (Enter/Space)
*/ */
@@ -39,6 +46,7 @@ export function useFolderExpand({ folderId }: UseFolderExpandProps) {
return { return {
isExpanded, isExpanded,
handleToggleExpanded, handleToggleExpanded,
expandFolder,
handleKeyDown, handleKeyDown,
} }
} }