Skip to content

Commit 2487a0f

Browse files
committed
improvement(sidebar): move useContextMenu to shared hooks
Review flagged the four workspace routes deep-importing `useContextMenu` from the sidebar's hooks barrel as a barrel-convention violation. Fair — the code-splitting exception in sim-imports.md is written for `lazy()` splits, and these are static imports. The hook was in the wrong place to begin with. It is entirely generic — no sidebar-specific references, just right-click state and positioning — and nine consumers across tables, files, knowledge, home, the terminal and the preview editor already reached across features to get it. Moved to `@/hooks`, the repo's shared-hooks location, and every consumer including the sidebar's own now imports it from there. This satisfies the barrel convention rather than making an exception to it, and keeps the graph win: tables, knowledge and files stay off the sidebar barrel's path to `stores/workflow-diff -> serializer -> tools/metadata`, unchanged at 20.19 / 20.89 / 21.37 MB of reachable source.
1 parent d1b0a62 commit 2487a0f

16 files changed

Lines changed: 81 additions & 106 deletions

File tree

apps/sim/app/workspace/[workspaceId]/files/files.tsx

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -128,13 +128,6 @@ import {
128128
} from '@/app/workspace/[workspaceId]/files/untitled-title'
129129
import { useRegisterGlobalCommands } from '@/app/workspace/[workspaceId]/providers/global-commands-provider'
130130
import { useUserPermissionsContext } from '@/app/workspace/[workspaceId]/providers/workspace-permissions-provider'
131-
/**
132-
* Deep-imported rather than taken from the `sidebar/hooks` barrel on purpose. That barrel
133-
* also exports `useWorkflowOperations`, whose graph reaches `stores/workflow-diff` ->
134-
* `serializer` -> `tools/metadata`, pulling the 5 MB generated tool-metadata artifact into
135-
* this route's client bundle for a hook that is a dependency-free leaf.
136-
*/
137-
import { useContextMenu } from '@/app/workspace/[workspaceId]/w/components/sidebar/hooks/use-context-menu'
138131
import { usePinItem, usePinnedIds, useUnpinItem } from '@/hooks/queries/pinned-items'
139132
import { useWorkspaceMembersQuery, type WorkspaceMember } from '@/hooks/queries/workspace'
140133
import {
@@ -153,6 +146,7 @@ import {
153146
useUploadWorkspaceFile,
154147
useWorkspaceFiles,
155148
} from '@/hooks/queries/workspace-files'
149+
import { useContextMenu } from '@/hooks/use-context-menu'
156150
import { useDebouncedSearchSetter } from '@/hooks/use-debounced-search-setter'
157151
import { useInlineRename } from '@/hooks/use-inline-rename'
158152
import { usePermissionConfig } from '@/hooks/use-permission-config'

apps/sim/app/workspace/[workspaceId]/home/components/mothership-view/components/resource-content/components/terminal-session/terminal-session.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import { WebLinksAddon } from '@xterm/addon-web-links'
3434
import { WebglAddon } from '@xterm/addon-webgl'
3535
import { type IBufferRange, Terminal } from '@xterm/xterm'
3636
import { useTheme } from 'next-themes'
37+
import { useContextMenu } from '@/hooks/use-context-menu'
3738
import '@xterm/xterm/css/xterm.css'
3839
import {
3940
describeRunningCommand,
@@ -73,7 +74,6 @@ import { useMothershipResources } from '@/app/workspace/[workspaceId]/home/compo
7374
import { TerminalContextMenu } from '@/app/workspace/[workspaceId]/home/components/mothership-view/components/resource-content/components/terminal-session/terminal-context-menu'
7475
import { TerminalTabIcon } from '@/app/workspace/[workspaceId]/home/components/mothership-view/components/resource-content/components/terminal-session/terminal-tab-icon'
7576
import { ContextMenu } from '@/app/workspace/[workspaceId]/w/components/sidebar/components/workflow-list/components/context-menu/context-menu'
76-
import { useContextMenu } from '@/app/workspace/[workspaceId]/w/components/sidebar/hooks'
7777
import { useDesktopPreferenceMutation } from '@/hooks/use-desktop-preference-mutation'
7878
import { useCopilotTerminalStore } from '@/stores/copilot-terminal/store'
7979
import type { ChatContext, TerminalTextSelection } from '@/stores/panel'

apps/sim/app/workspace/[workspaceId]/knowledge/[id]/[documentId]/document.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ import {
5959
import { ActionBar } from '@/app/workspace/[workspaceId]/knowledge/[id]/components'
6060
import { getDocumentIcon } from '@/app/workspace/[workspaceId]/knowledge/components'
6161
import { useUserPermissionsContext } from '@/app/workspace/[workspaceId]/providers/workspace-permissions-provider'
62-
import { useContextMenu } from '@/app/workspace/[workspaceId]/w/components/sidebar/hooks'
6362
import { CONNECTOR_META_REGISTRY } from '@/connectors/registry'
6463
import { useDocument, useDocumentChunks, useKnowledgeBase } from '@/hooks/kb/use-knowledge'
6564
import {
@@ -69,6 +68,7 @@ import {
6968
useUpdateChunk,
7069
useUpdateDocument,
7170
} from '@/hooks/queries/kb/knowledge'
71+
import { useContextMenu } from '@/hooks/use-context-menu'
7272
import { useDebounce } from '@/hooks/use-debounce'
7373
import { useDebouncedSearchSetter } from '@/hooks/use-debounced-search-setter'
7474
import { useInlineRename } from '@/hooks/use-inline-rename'

apps/sim/app/workspace/[workspaceId]/knowledge/[id]/base.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ import {
9797
import { getDocumentIcon } from '@/app/workspace/[workspaceId]/knowledge/components'
9898
import { useRegisterGlobalCommands } from '@/app/workspace/[workspaceId]/providers/global-commands-provider'
9999
import { useUserPermissionsContext } from '@/app/workspace/[workspaceId]/providers/workspace-permissions-provider'
100-
import { useContextMenu } from '@/app/workspace/[workspaceId]/w/components/sidebar/hooks'
101100
import { BrandIcon } from '@/blocks/brand-icon'
102101
import { CONNECTOR_META_REGISTRY } from '@/connectors/registry'
103102
import {
@@ -119,6 +118,7 @@ import {
119118
useUpdateDocument,
120119
useUpdateKnowledgeBase,
121120
} from '@/hooks/queries/kb/knowledge'
121+
import { useContextMenu } from '@/hooks/use-context-menu'
122122
import { useDebounce } from '@/hooks/use-debounce'
123123
import { useDebouncedSearchSetter } from '@/hooks/use-debounced-search-setter'
124124
import { useInlineRename } from '@/hooks/use-inline-rename'

apps/sim/app/workspace/[workspaceId]/knowledge/knowledge.tsx

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,6 @@ import {
7979
} from '@/app/workspace/[workspaceId]/knowledge/search-params'
8080
import { useRegisterGlobalCommands } from '@/app/workspace/[workspaceId]/providers/global-commands-provider'
8181
import { useUserPermissionsContext } from '@/app/workspace/[workspaceId]/providers/workspace-permissions-provider'
82-
/**
83-
* Deep-imported rather than taken from the `sidebar/hooks` barrel on purpose. That barrel
84-
* also exports `useWorkflowOperations`, whose graph reaches `stores/workflow-diff` ->
85-
* `serializer` -> `tools/metadata`, pulling the 5 MB generated tool-metadata artifact into
86-
* this route's client bundle for a hook that is a dependency-free leaf.
87-
*/
88-
import { useContextMenu } from '@/app/workspace/[workspaceId]/w/components/sidebar/hooks/use-context-menu'
8982
import { BrandIcon } from '@/blocks/brand-icon'
9083
import { CONNECTOR_META_REGISTRY } from '@/connectors/registry'
9184
import { useKnowledgeBasesList } from '@/hooks/kb/use-knowledge'
@@ -98,6 +91,7 @@ import {
9891
} from '@/hooks/queries/kb/knowledge'
9992
import { usePinItem, usePinnedIds, useUnpinItem } from '@/hooks/queries/pinned-items'
10093
import { useWorkspaceMembersQuery, type WorkspaceMember } from '@/hooks/queries/workspace'
94+
import { useContextMenu } from '@/hooks/use-context-menu'
10195
import { useDebouncedSearchSetter } from '@/hooks/use-debounced-search-setter'
10296
import { useInlineRename } from '@/hooks/use-inline-rename'
10397
import { usePermissionConfig } from '@/hooks/use-permission-config'

apps/sim/app/workspace/[workspaceId]/tables/tables.tsx

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,6 @@ import {
7777
tablesSortParams,
7878
tablesUrlKeys,
7979
} from '@/app/workspace/[workspaceId]/tables/search-params'
80-
/**
81-
* Deep-imported rather than taken from the `sidebar/hooks` barrel on purpose. That barrel
82-
* also exports `useWorkflowOperations`, whose graph reaches `stores/workflow-diff` ->
83-
* `serializer` -> `tools/metadata`, pulling the 5 MB generated tool-metadata artifact into
84-
* this route's client bundle for a hook that is a dependency-free leaf.
85-
*/
86-
import { useContextMenu } from '@/app/workspace/[workspaceId]/w/components/sidebar/hooks/use-context-menu'
8780
import { useCreateFolder, useDeleteFolderMutation, useUpdateFolder } from '@/hooks/queries/folders'
8881
import { usePinItem, usePinnedIds, useUnpinItem } from '@/hooks/queries/pinned-items'
8982
import {
@@ -99,6 +92,7 @@ import {
9992
} from '@/hooks/queries/tables'
10093
import { getCanonicalFolderPath } from '@/hooks/queries/utils/folder-tree'
10194
import { useWorkspaceMembersQuery, type WorkspaceMember } from '@/hooks/queries/workspace'
95+
import { useContextMenu } from '@/hooks/use-context-menu'
10296
import { useDebouncedSearchSetter } from '@/hooks/use-debounced-search-setter'
10397
import { useInlineRename } from '@/hooks/use-inline-rename'
10498
import { usePermissionConfig } from '@/hooks/use-permission-config'

apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/terminal/components/output-panel/output-panel.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ import {
3434
StructuredOutput,
3535
} from '@/app/workspace/[workspaceId]/w/[workflowId]/components/terminal/components/output-panel/components'
3636
import { ToggleButton } from '@/app/workspace/[workspaceId]/w/[workflowId]/components/terminal/components/toggle-button'
37-
import { useContextMenu } from '@/app/workspace/[workspaceId]/w/components/sidebar/hooks'
3837
import { useCodeViewerFeatures } from '@/hooks/use-code-viewer'
38+
import { useContextMenu } from '@/hooks/use-context-menu'
3939
import type { ConsoleEntry } from '@/stores/terminal'
4040
import { safeConsoleStringify, useTerminalStore } from '@/stores/terminal'
4141

apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/terminal/terminal.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ import {
4747
TERMINAL_CONFIG,
4848
type VisibleTerminalRow,
4949
} from '@/app/workspace/[workspaceId]/w/[workflowId]/components/terminal/utils'
50-
import { useContextMenu } from '@/app/workspace/[workspaceId]/w/components/sidebar/hooks'
50+
import { useContextMenu } from '@/hooks/use-context-menu'
5151
import { OUTPUT_PANEL_WIDTH, TERMINAL_HEIGHT } from '@/stores/constants'
5252
import type { ConsoleEntry } from '@/stores/terminal'
5353
import {

apps/sim/app/workspace/[workspaceId]/w/components/preview/components/preview-editor/preview-editor.tsx

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,20 +41,14 @@ import { DELETED_WORKFLOW_LABEL } from '@/lib/workflows/workflow-labels'
4141
import { SubBlock } from '@/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components'
4242
import { PreviewContextMenu } from '@/app/workspace/[workspaceId]/w/components/preview/components/preview-context-menu'
4343
import { PreviewWorkflow } from '@/app/workspace/[workspaceId]/w/components/preview/components/preview-workflow'
44-
/**
45-
* Deep-imported rather than taken from the `sidebar/hooks` barrel on purpose. That barrel
46-
* also exports `useWorkflowOperations`, whose graph reaches `stores/workflow-diff` ->
47-
* `serializer` -> `tools/metadata`, pulling the 5 MB generated tool-metadata artifact into
48-
* this route's client bundle for a hook that is a dependency-free leaf.
49-
*/
50-
import { useContextMenu } from '@/app/workspace/[workspaceId]/w/components/sidebar/hooks/use-context-menu'
5144
import { getBlock } from '@/blocks'
5245
import { BlockTile } from '@/blocks/block-tile'
5346
import type { BlockConfig, SubBlockConfig, SubBlockType } from '@/blocks/types'
5447
import { normalizeName } from '@/executor/constants'
5548
import { navigatePath } from '@/executor/variables/resolvers/reference'
5649
import { useWorkflowState } from '@/hooks/queries/workflows'
5750
import { useCodeViewerFeatures } from '@/hooks/use-code-viewer'
51+
import { useContextMenu } from '@/hooks/use-context-menu'
5852
import type { BlockState, Loop, Parallel, WorkflowState } from '@/stores/workflows/workflow/types'
5953

6054
/**

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import { useUserPermissionsContext } from '@/app/workspace/[workspaceId]/provide
1313
import { ContextMenu } from '@/app/workspace/[workspaceId]/w/components/sidebar/components/workflow-list/components/context-menu/context-menu'
1414
import { DeleteModal } from '@/app/workspace/[workspaceId]/w/components/sidebar/components/workflow-list/components/delete-modal/delete-modal'
1515
import {
16-
useContextMenu,
1716
useFolderExpand,
1817
useItemDrag,
1918
useItemRename,
@@ -41,6 +40,7 @@ import {
4140
} from '@/hooks/queries/utils/folder-tree'
4241
import { getWorkflows } from '@/hooks/queries/utils/workflow-cache'
4342
import { useCreateWorkflow } from '@/hooks/queries/workflows'
43+
import { useContextMenu } from '@/hooks/use-context-menu'
4444
import { useFolderStore } from '@/stores/folders/store'
4545
import type { FolderTreeNode } from '@/stores/folders/types'
4646
import { useWorkflowRegistry } from '@/stores/workflows/registry/store'

0 commit comments

Comments
 (0)