Skip to content

Commit 901ace8

Browse files
committed
refactor(tables): TableView is a canonical resource view
Step 7. The table implementation moves out of the route tree and into `components/resources/table-view/`, joining the layout the unit already had: `table-view.tsx`, `index.ts`, `components/<child>/`, `hooks/`, `utils/`, `types.ts`. What stays behind is four route files — `page.tsx`, `loading.tsx`, `error.tsx`, and the ~50-line client shell that resolves the axes. `Table` becomes `TableView` and takes `source: ResourceSource<'table'>` instead of `workspaceId` + `tableId`. Both are banned prop names, and registering the view in `CANONICAL_UNITS` turns R4a/R4b on to say so — the gate found them immediately. The subtree below still takes plain ids, so the source is narrowed once at the top through `tableWorkspaceId`/`tableResourceId`, which is the helper deleted earlier for having no caller, restored now that it has one. The four preceding steps are what made this a move rather than a rewrite: with the router, the params and the permission context already severed, R6 was already 0 before a single file changed directory. 61 files, ~160 lines of non-import churn. One edge stays and is annotated: the workflow-column sidebar renders the editor's read-only canvas, which reads `useParams` and pulls in the editor's node and edge components. Safe for the same reason the log view's frozen canvas is — `ResourceSeedMap['table']` is `never`, so no anonymous surface can mount this unit — and `CROSS_TREE_ALLOWLIST` now names two files pointing at one component, which is the signal that `Preview` itself wants to move to `components/`. That is a separate change. Every rule back at baseline with the view registered: R2 0, R3c 0, R4a 0, R4b 0, R6 0.
1 parent c7ad09d commit 901ace8

61 files changed

Lines changed: 161 additions & 121 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import { useRouter } from 'next/navigation'
2727
import { FileView, type PreviewMode, resolveFileCategory } from '@/components/resources/file-view'
2828
import { LogView } from '@/components/resources/log-view'
2929
import { ResourceEmptyState } from '@/components/resources/resource-empty-state'
30+
import { TableView } from '@/components/resources/table-view'
3031
import { isApiClientError } from '@/lib/api/client/errors'
3132
import { useSession } from '@/lib/auth/auth-client'
3233
import { getWorkspaceUsageLimitAction } from '@/lib/billing/workspace-permissions'
@@ -59,7 +60,6 @@ import {
5960
useUserPermissionsContext,
6061
useWorkspacePermissionsContext,
6162
} from '@/app/workspace/[workspaceId]/providers/workspace-permissions-provider'
62-
import { Table } from '@/app/workspace/[workspaceId]/tables/[tableId]/table'
6363
import { useUsageLimits } from '@/app/workspace/[workspaceId]/w/[workflowId]/components/panel/hooks'
6464
import { useWorkflowExecution } from '@/app/workspace/[workspaceId]/w/[workflowId]/hooks/use-workflow-execution'
6565
import { useFolders } from '@/hooks/queries/folders'
@@ -270,6 +270,11 @@ export const ResourceContent = memo(function ResourceContent({
270270
error: logError,
271271
} = useLogDetail(resource.id, workspaceId, { enabled: isLogResource })
272272

273+
const tableSource = useMemo(
274+
() => workspaceSource({ kind: 'table' as const, workspaceId, resourceId: resource.id }),
275+
[workspaceId, resource.id]
276+
)
277+
273278
const logSource = useMemo(
274279
() => workspaceSource({ kind: 'log' as const, workspaceId, resourceId: resource.id }),
275280
[workspaceId, resource.id]
@@ -311,14 +316,13 @@ export const ResourceContent = memo(function ResourceContent({
311316
switch (resource.type) {
312317
case 'table':
313318
return (
314-
<Table
319+
<TableView
315320
key={resource.id}
316321
host='panel'
317322
grants={grants}
318323
onNavigate={navigate}
319324
showExecutionInternals={!permissionConfig.hideTraceSpans}
320-
workspaceId={workspaceId}
321-
tableId={resource.id}
325+
source={tableSource}
322326
viewsEnabled={tableViewsEnabled}
323327
/>
324328
)

apps/sim/app/workspace/[workspaceId]/tables/[tableId]/table-route.tsx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
import { useCallback, useMemo } from 'react'
44
import { useParams, useRouter } from 'next/navigation'
5+
import { TableView } from '@/components/resources/table-view'
56
import { useUserPermissionsContext } from '@/app/workspace/[workspaceId]/providers/workspace-permissions-provider'
6-
import { Table } from '@/app/workspace/[workspaceId]/tables/[tableId]/table'
77
import { usePermissionConfig } from '@/hooks/use-permission-config'
8-
import { grantsFromPermissions } from '@/resources'
8+
import { grantsFromPermissions, workspaceSource } from '@/resources'
99

1010
interface TableRouteProps {
1111
/** `table-locks` — resolved server-side; AppConfig has no client counterpart. */
@@ -33,17 +33,20 @@ export function TableRoute({ tableLocksEnabled, viewsEnabled }: TableRouteProps)
3333
const router = useRouter()
3434
const { config: permissionConfig } = usePermissionConfig()
3535

36+
const source = useMemo(
37+
() => workspaceSource({ kind: 'table' as const, workspaceId, resourceId: tableId }),
38+
[workspaceId, tableId]
39+
)
3640
const grants = useMemo(() => grantsFromPermissions(permissions), [permissions])
3741
const navigate = useCallback((path: string) => router.push(path), [router])
3842

3943
return (
40-
<Table
44+
<TableView
4145
host='page'
4246
grants={grants}
4347
onNavigate={navigate}
4448
showExecutionInternals={!permissionConfig.hideTraceSpans}
45-
workspaceId={workspaceId}
46-
tableId={tableId}
49+
source={source}
4750
tableLocksEnabled={tableLocksEnabled}
4851
viewsEnabled={viewsEnabled}
4952
/>

apps/sim/app/workspace/[workspaceId]/tables/[tableId]/types.ts

Lines changed: 0 additions & 21 deletions
This file was deleted.

apps/sim/app/workspace/[workspaceId]/tables/[tableId]/components/column-config-sidebar/column-config-sidebar.tsx renamed to apps/sim/components/resources/table-view/components/column-config-sidebar/column-config-sidebar.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@ import { useState } from 'react'
44
import { Button, ChipCombobox, ChipInput, cn, FieldDivider, Label, Switch, toast } from '@sim/emcn'
55
import { X } from '@sim/emcn/icons'
66
import { toError } from '@sim/utils/errors'
7+
import {
8+
FieldError,
9+
RequiredLabel,
10+
} from '@/components/resources/table-view/components/sidebar-fields'
711
import { findValidationIssue, isValidationError } from '@/lib/api/client/errors'
812
import type { ColumnDefinition, SelectOption } from '@/lib/table'
913
import {
1014
DEFAULT_CURRENCY_CODE,
1115
getCurrencyOptions,
1216
resolveCurrencyCode,
1317
} from '@/lib/table/currency'
14-
import {
15-
FieldError,
16-
RequiredLabel,
17-
} from '@/app/workspace/[workspaceId]/tables/[tableId]/components/sidebar-fields'
1818
import { useAddTableColumn, useUpdateColumn } from '@/hooks/queries/tables'
1919
import { SelectOptionsEditor } from '../select-field'
2020
import { PLAIN_COLUMN_TYPE_OPTIONS } from './column-types'

apps/sim/app/workspace/[workspaceId]/tables/[tableId]/components/column-config-sidebar/column-types.ts renamed to apps/sim/components/resources/table-view/components/column-config-sidebar/column-types.ts

File renamed without changes.

apps/sim/app/workspace/[workspaceId]/tables/[tableId]/components/column-config-sidebar/index.ts renamed to apps/sim/components/resources/table-view/components/column-config-sidebar/index.ts

File renamed without changes.

apps/sim/app/workspace/[workspaceId]/tables/[tableId]/components/columns-menu/columns-menu.tsx renamed to apps/sim/components/resources/table-view/components/columns-menu/columns-menu.tsx

File renamed without changes.

apps/sim/app/workspace/[workspaceId]/tables/[tableId]/components/columns-menu/index.ts renamed to apps/sim/components/resources/table-view/components/columns-menu/index.ts

File renamed without changes.

apps/sim/app/workspace/[workspaceId]/tables/[tableId]/components/context-menu/context-menu.tsx renamed to apps/sim/components/resources/table-view/components/context-menu/context-menu.tsx

File renamed without changes.

apps/sim/app/workspace/[workspaceId]/tables/[tableId]/components/context-menu/index.ts renamed to apps/sim/components/resources/table-view/components/context-menu/index.ts

File renamed without changes.

0 commit comments

Comments
 (0)