-
Notifications
You must be signed in to change notification settings - Fork 3.2k
feat(workflow-controls): added action bar for picker/hand/undo/redo/zoom workflow controls, added general setting to disabl #2767
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
Open
waleedlatif1
wants to merge
6
commits into
staging
Choose a base branch
from
fix/action-bar
base: staging
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+10,610
−215
Open
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
e59e2fd
feat(workflow-controls): added action bar for picker/hand/undo/redo/z…
waleedlatif1 530e2ac
added util for fit to zoom that accounts for sidebar, terminal, and p…
waleedlatif1 14a691b
ack PR comments
waleedlatif1 75da0c3
remove dead state variable, add logs
waleedlatif1 06782a8
improvement(ui/ux): action bar, panel, tooltip, dragging, invite modal
emir-karabeg 14570e7
added fit to view in canvas context menu
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
Some comments aren't visible on the classic Files Changed page.
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
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
194 changes: 194 additions & 0 deletions
194
apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/action-bar/action-bar.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,194 @@ | ||
| 'use client' | ||
|
|
||
| import { useRef, useState } from 'react' | ||
| import { createLogger } from '@sim/logger' | ||
| import { useReactFlow } from 'reactflow' | ||
| import { | ||
| Button, | ||
| Cursor, | ||
| Expand, | ||
| Hand, | ||
| Popover, | ||
| PopoverAnchor, | ||
| PopoverContent, | ||
| PopoverItem, | ||
| Redo, | ||
| Tooltip, | ||
| Undo, | ||
| ZoomIn, | ||
| ZoomOut, | ||
| } from '@/components/emcn' | ||
| import { useSession } from '@/lib/auth/auth-client' | ||
| import { useUpdateGeneralSetting } from '@/hooks/queries/general-settings' | ||
| import { useCanvasViewport } from '@/hooks/use-canvas-viewport' | ||
| import { useCollaborativeWorkflow } from '@/hooks/use-collaborative-workflow' | ||
| import { useCanvasModeStore } from '@/stores/canvas-mode' | ||
| import { useGeneralStore } from '@/stores/settings/general' | ||
| import { useUndoRedoStore } from '@/stores/undo-redo' | ||
| import { useWorkflowRegistry } from '@/stores/workflows/registry/store' | ||
|
|
||
| const logger = createLogger('ActionBar') | ||
|
|
||
| export function ActionBar() { | ||
| const reactFlowInstance = useReactFlow() | ||
| const { zoomIn, zoomOut } = reactFlowInstance | ||
| const { fitViewToBounds } = useCanvasViewport(reactFlowInstance) | ||
| const { mode, setMode } = useCanvasModeStore() | ||
| const { undo, redo } = useCollaborativeWorkflow() | ||
| const showActionBar = useGeneralStore((s) => s.showActionBar) | ||
| const updateSetting = useUpdateGeneralSetting() | ||
|
|
||
| const { activeWorkflowId } = useWorkflowRegistry() | ||
| const { data: session } = useSession() | ||
| const userId = session?.user?.id || 'unknown' | ||
| const stacks = useUndoRedoStore((s) => s.stacks) | ||
| const key = activeWorkflowId && userId ? `${activeWorkflowId}:${userId}` : '' | ||
| const stack = (key && stacks[key]) || { undo: [], redo: [] } | ||
| const canUndo = stack.undo.length > 0 | ||
| const canRedo = stack.redo.length > 0 | ||
|
|
||
| const [contextMenu, setContextMenu] = useState<{ x: number; y: number } | null>(null) | ||
| const menuRef = useRef<HTMLDivElement>(null) | ||
|
|
||
| const handleContextMenu = (e: React.MouseEvent) => { | ||
| e.preventDefault() | ||
| setContextMenu({ x: e.clientX, y: e.clientY }) | ||
| } | ||
|
|
||
| const handleHide = async () => { | ||
| try { | ||
| await updateSetting.mutateAsync({ key: 'showActionBar', value: false }) | ||
| } catch (error) { | ||
| logger.error('Failed to hide action bar', error) | ||
| } finally { | ||
| setContextMenu(null) | ||
| } | ||
| } | ||
|
|
||
| if (!showActionBar) { | ||
| return null | ||
| } | ||
|
|
||
| return ( | ||
| <> | ||
| <div | ||
| className='fixed bottom-[calc(var(--terminal-height)+16px)] left-[calc(var(--sidebar-width)+16px)] z-10 flex h-[36px] items-center gap-[2px] rounded-[8px] border border-[var(--border)] bg-[var(--surface-1)] p-[4px] shadow-sm transition-[left,bottom] duration-100 ease-out' | ||
| onContextMenu={handleContextMenu} | ||
| > | ||
| <Tooltip.Root> | ||
| <Tooltip.Trigger asChild> | ||
| <Button | ||
| variant={mode === 'hand' ? 'secondary' : 'ghost'} | ||
| className='h-[28px] w-[28px] p-0' | ||
| onClick={() => setMode('hand')} | ||
| > | ||
| <Hand className='h-[16px] w-[16px]' /> | ||
| </Button> | ||
| </Tooltip.Trigger> | ||
| <Tooltip.Content side='top'>Hand tool</Tooltip.Content> | ||
| </Tooltip.Root> | ||
|
|
||
| <Tooltip.Root> | ||
| <Tooltip.Trigger asChild> | ||
| <Button | ||
| variant={mode === 'cursor' ? 'secondary' : 'ghost'} | ||
| className='h-[28px] w-[28px] p-0' | ||
| onClick={() => setMode('cursor')} | ||
| > | ||
| <Cursor className='h-[16px] w-[16px]' /> | ||
| </Button> | ||
| </Tooltip.Trigger> | ||
| <Tooltip.Content side='top'>Move</Tooltip.Content> | ||
waleedlatif1 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| </Tooltip.Root> | ||
|
|
||
| <div className='mx-[4px] h-[20px] w-[1px] bg-[var(--border)]' /> | ||
|
|
||
| <Tooltip.Root> | ||
| <Tooltip.Trigger asChild> | ||
| <Button | ||
| variant='ghost' | ||
| className='h-[28px] w-[28px] p-0' | ||
| onClick={undo} | ||
| disabled={!canUndo} | ||
| > | ||
| <Undo className='h-[16px] w-[16px]' /> | ||
| </Button> | ||
| </Tooltip.Trigger> | ||
| <Tooltip.Content side='top'> | ||
| <Tooltip.Shortcut keys='⌘Z'>Undo</Tooltip.Shortcut> | ||
| </Tooltip.Content> | ||
| </Tooltip.Root> | ||
|
|
||
| <Tooltip.Root> | ||
| <Tooltip.Trigger asChild> | ||
| <Button | ||
| variant='ghost' | ||
| className='h-[28px] w-[28px] p-0' | ||
| onClick={redo} | ||
| disabled={!canRedo} | ||
| > | ||
| <Redo className='h-[16px] w-[16px]' /> | ||
| </Button> | ||
| </Tooltip.Trigger> | ||
| <Tooltip.Content side='top'> | ||
| <Tooltip.Shortcut keys='⌘⇧Z'>Redo</Tooltip.Shortcut> | ||
| </Tooltip.Content> | ||
| </Tooltip.Root> | ||
|
|
||
| <div className='mx-[4px] h-[20px] w-[1px] bg-[var(--border)]' /> | ||
|
|
||
| <Tooltip.Root> | ||
| <Tooltip.Trigger asChild> | ||
| <Button variant='ghost' className='h-[28px] w-[28px] p-0' onClick={() => zoomOut()}> | ||
| <ZoomOut className='h-[16px] w-[16px]' /> | ||
| </Button> | ||
| </Tooltip.Trigger> | ||
| <Tooltip.Content side='top'>Zoom out</Tooltip.Content> | ||
| </Tooltip.Root> | ||
|
|
||
| <Tooltip.Root> | ||
| <Tooltip.Trigger asChild> | ||
| <Button variant='ghost' className='h-[28px] w-[28px] p-0' onClick={() => zoomIn()}> | ||
| <ZoomIn className='h-[16px] w-[16px]' /> | ||
| </Button> | ||
| </Tooltip.Trigger> | ||
| <Tooltip.Content side='top'>Zoom in</Tooltip.Content> | ||
| </Tooltip.Root> | ||
|
|
||
| <Tooltip.Root> | ||
| <Tooltip.Trigger asChild> | ||
| <Button | ||
| variant='ghost' | ||
| className='h-[28px] w-[28px] p-0' | ||
| onClick={() => fitViewToBounds({ padding: 0.1, duration: 300 })} | ||
| > | ||
| <Expand className='h-[16px] w-[16px]' /> | ||
| </Button> | ||
| </Tooltip.Trigger> | ||
| <Tooltip.Content side='top'>Zoom to fit</Tooltip.Content> | ||
| </Tooltip.Root> | ||
| </div> | ||
|
|
||
| <Popover | ||
| open={contextMenu !== null} | ||
| onOpenChange={(open) => !open && setContextMenu(null)} | ||
| variant='secondary' | ||
| size='sm' | ||
| colorScheme='inverted' | ||
| > | ||
| <PopoverAnchor | ||
| style={{ | ||
| position: 'fixed', | ||
| left: `${contextMenu?.x ?? 0}px`, | ||
| top: `${contextMenu?.y ?? 0}px`, | ||
| width: '1px', | ||
| height: '1px', | ||
| }} | ||
| /> | ||
| <PopoverContent ref={menuRef} align='start' side='bottom' sideOffset={4}> | ||
| <PopoverItem onClick={handleHide}>Hide canvas controls</PopoverItem> | ||
| </PopoverContent> | ||
| </Popover> | ||
| </> | ||
| ) | ||
| } | ||
1 change: 1 addition & 0 deletions
1
apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/action-bar/index.ts
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 @@ | ||
| export { ActionBar } from './action-bar' |
1 change: 1 addition & 0 deletions
1
apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/index.ts
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
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
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
51 changes: 0 additions & 51 deletions
51
...aceId]/w/[workflowId]/components/panel/components/workflow-controls/workflow-controls.tsx
This file was deleted.
Oops, something went wrong.
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
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
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.