-
Notifications
You must be signed in to change notification settings - Fork 3.6k
improvement/folders #493
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
improvement/folders #493
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
43c86bf
added multi-select for folders
waleedlatif1 1971a6b
allow drag into root
waleedlatif1 a183d30
remove extraneous comments
waleedlatif1 48af939
instantly create worfklow on plus
waleedlatif1 dd0437b
styling improvements, fixed flicker
waleedlatif1 f64ca8b
small improvement to dragover container
waleedlatif1 a7416be
ack PR comments
waleedlatif1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
151 changes: 151 additions & 0 deletions
151
apps/sim/app/w/components/sidebar/components/folder-tree/components/folder-item.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,151 @@ | ||
| 'use client' | ||
|
|
||
| import { useCallback, useEffect, useRef } from 'react' | ||
| import clsx from 'clsx' | ||
| import { ChevronDown, ChevronRight, Folder, FolderOpen } from 'lucide-react' | ||
| import { Tooltip, TooltipContent, TooltipTrigger } from '@/components/ui/tooltip' | ||
| import { type FolderTreeNode, useFolderStore } from '@/stores/folders/store' | ||
| import { FolderContextMenu } from '../../folder-context-menu/folder-context-menu' | ||
|
|
||
| interface FolderItemProps { | ||
| folder: FolderTreeNode | ||
| isCollapsed?: boolean | ||
| onCreateWorkflow: (folderId?: string) => void | ||
| dragOver?: boolean | ||
| onDragOver?: (e: React.DragEvent) => void | ||
| onDragLeave?: (e: React.DragEvent) => void | ||
| onDrop?: (e: React.DragEvent) => void | ||
| } | ||
|
|
||
| export function FolderItem({ | ||
| folder, | ||
| isCollapsed, | ||
| onCreateWorkflow, | ||
| dragOver = false, | ||
| onDragOver, | ||
| onDragLeave, | ||
| onDrop, | ||
| }: FolderItemProps) { | ||
| const { expandedFolders, toggleExpanded, updateFolderAPI, deleteFolder } = useFolderStore() | ||
|
|
||
| const isExpanded = expandedFolders.has(folder.id) | ||
| const updateTimeoutRef = useRef<ReturnType<typeof setTimeout> | undefined>(undefined) | ||
| const pendingStateRef = useRef<boolean | null>(null) | ||
|
|
||
| const handleToggleExpanded = useCallback(() => { | ||
| const newExpandedState = !isExpanded | ||
| toggleExpanded(folder.id) | ||
| pendingStateRef.current = newExpandedState | ||
|
|
||
| if (updateTimeoutRef.current) { | ||
| clearTimeout(updateTimeoutRef.current) | ||
| } | ||
|
|
||
| updateTimeoutRef.current = setTimeout(() => { | ||
| if (pendingStateRef.current === newExpandedState) { | ||
| updateFolderAPI(folder.id, { isExpanded: newExpandedState }) | ||
| .catch(console.error) | ||
| .finally(() => { | ||
| pendingStateRef.current = null | ||
| }) | ||
| } | ||
| }, 300) | ||
| }, [folder.id, isExpanded, toggleExpanded, updateFolderAPI]) | ||
|
|
||
| useEffect(() => { | ||
| return () => { | ||
| if (updateTimeoutRef.current) { | ||
| clearTimeout(updateTimeoutRef.current) | ||
| } | ||
| } | ||
| }, []) | ||
|
|
||
| const handleRename = async (folderId: string, newName: string) => { | ||
| try { | ||
| await updateFolderAPI(folderId, { name: newName }) | ||
| } catch (error) { | ||
| console.error('Failed to rename folder:', error) | ||
| } | ||
| } | ||
|
|
||
| const handleDelete = async (folderId: string) => { | ||
| if ( | ||
| confirm( | ||
| `Are you sure you want to delete "${folder.name}"? Child folders and workflows will be moved to the parent folder.` | ||
| ) | ||
| ) { | ||
| try { | ||
| await deleteFolder(folderId) | ||
| } catch (error) { | ||
| console.error('Failed to delete folder:', error) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| if (isCollapsed) { | ||
| return ( | ||
| <Tooltip> | ||
| <TooltipTrigger asChild> | ||
| <div | ||
| className='group mx-auto flex h-8 w-8 cursor-pointer items-center justify-center' | ||
| onDragOver={onDragOver} | ||
| onDragLeave={onDragLeave} | ||
| onDrop={onDrop} | ||
| onClick={handleToggleExpanded} | ||
| > | ||
| <div | ||
| className={clsx( | ||
| 'flex h-4 w-4 items-center justify-center rounded transition-colors hover:bg-accent/50', | ||
| dragOver ? 'ring-2 ring-blue-500' : '' | ||
| )} | ||
| > | ||
| {isExpanded ? ( | ||
| <FolderOpen className='h-3 w-3 text-foreground/70 dark:text-foreground/60' /> | ||
| ) : ( | ||
| <Folder className='h-3 w-3 text-foreground/70 dark:text-foreground/60' /> | ||
| )} | ||
| </div> | ||
| </div> | ||
| </TooltipTrigger> | ||
| <TooltipContent side='right'> | ||
| <p>{folder.name}</p> | ||
| </TooltipContent> | ||
| </Tooltip> | ||
| ) | ||
| } | ||
|
|
||
| return ( | ||
| <div className='group' onDragOver={onDragOver} onDragLeave={onDragLeave} onDrop={onDrop}> | ||
| <div | ||
| className='flex cursor-pointer items-center rounded-md px-2 py-1.5 text-sm hover:bg-accent/50' | ||
| onClick={handleToggleExpanded} | ||
| > | ||
| <div className='mr-1 flex h-4 w-4 items-center justify-center'> | ||
| {isExpanded ? <ChevronDown className='h-3 w-3' /> : <ChevronRight className='h-3 w-3' />} | ||
| </div> | ||
|
|
||
| <div className='mr-2 flex h-4 w-4 flex-shrink-0 items-center justify-center'> | ||
| {isExpanded ? ( | ||
| <FolderOpen className='h-4 w-4 text-foreground/70 dark:text-foreground/60' /> | ||
| ) : ( | ||
| <Folder className='h-4 w-4 text-foreground/70 dark:text-foreground/60' /> | ||
| )} | ||
| </div> | ||
|
|
||
| <span className='flex-1 cursor-default select-none truncate text-muted-foreground'> | ||
| {folder.name} | ||
| </span> | ||
|
|
||
| <div className='flex items-center justify-center' onClick={(e) => e.stopPropagation()}> | ||
| <FolderContextMenu | ||
| folderId={folder.id} | ||
| folderName={folder.name} | ||
| onCreateWorkflow={onCreateWorkflow} | ||
| onRename={handleRename} | ||
| onDelete={handleDelete} | ||
| /> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| ) | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.