Skip to content

Commit db1b08f

Browse files
committed
refactor(tables): take the table's address as props, not route params
Step 2 of the migration. A canonical unit may not read route context (R6, held at 0 with no annotation escape), and both of these would fail it the moment the tree moves. - `TableGrid` had `workspaceId`/`tableId` as optional props with a `useParams()` fallback. Its only mount already passes both, so the fallback was dead code that nonetheless made the grid unmountable more than once per page. Props are now required and the fallback is gone. - `RowModal` read `params.workspaceId` with no fallback at all — a hard route dependency feeding three mutations. It now takes `workspaceId` as a required prop from its two mount sites in `table.tsx`. No behavior change: every call site already had the values, and the panel was already passing them explicitly. What changes is that the panel's copy no longer silently resolves the *host page's* params when a prop is missing.
1 parent bdf61bb commit db1b08f

3 files changed

Lines changed: 27 additions & 12 deletions

File tree

apps/sim/app/workspace/[workspaceId]/tables/[tableId]/components/row-modal/row-modal.tsx

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import {
1616
} from '@sim/emcn'
1717
import { createLogger } from '@sim/logger'
1818
import { getErrorMessage } from '@sim/utils/errors'
19-
import { useParams } from 'next/navigation'
2019
import {
2120
cleanCellValue,
2221
dateValueToLocalParts,
@@ -35,6 +34,12 @@ const logger = createLogger('RowModal')
3534

3635
export interface RowModalProps {
3736
mode: 'edit' | 'delete'
37+
/**
38+
* The workspace the table lives in. A prop rather than a route-param read:
39+
* this modal is mounted inside a view that also renders in the chat panel,
40+
* where the page's params address a different resource entirely.
41+
*/
42+
workspaceId: string
3843
isOpen: boolean
3944
onClose: () => void
4045
table: TableInfo
@@ -70,9 +75,16 @@ function cleanRowData(
7075
* call-site ever keeps it mounted across target-row changes, it must supply a `key`
7176
* prop (e.g. the row id) so React remounts with the new row's values.
7277
*/
73-
export function RowModal({ mode, isOpen, onClose, table, row, rowIds, onSuccess }: RowModalProps) {
74-
const params = useParams()
75-
const workspaceId = params.workspaceId as string
78+
export function RowModal({
79+
mode,
80+
workspaceId,
81+
isOpen,
82+
onClose,
83+
table,
84+
row,
85+
rowIds,
86+
onSuccess,
87+
}: RowModalProps) {
7688
const tableId = table.id
7789

7890
const schema = table?.schema

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

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import { createLogger } from '@sim/logger'
88
import type { TableCellSelection } from '@sim/realtime-protocol/table-presence'
99
import { getErrorMessage } from '@sim/utils/errors'
1010
import { useVirtualizer } from '@tanstack/react-virtual'
11-
import { useParams } from 'next/navigation'
1211
import { usePostHog } from 'posthog-js/react'
1312
import type { EditingCell, SaveReason } from '@/components/resources/table-view'
1413
import {
@@ -165,8 +164,13 @@ export interface SelectionSnapshot {
165164
}
166165

167166
interface TableGridProps {
168-
workspaceId?: string
169-
tableId?: string
167+
/**
168+
* The table's address, supplied by the view. Required rather than derived: a
169+
* route-param fallback meant this grid could only ever exist once per page,
170+
* and it is mounted in a panel beside the page that owns those params.
171+
*/
172+
workspaceId: string
173+
tableId: string
170174
embedded?: boolean
171175
/** Remote collaborators' cell selections, rendered as presence overlays. */
172176
remoteSelections: RemoteTableSelection[]
@@ -419,8 +423,8 @@ async function chunkBatchUpdates(
419423
}
420424

421425
export function TableGrid({
422-
workspaceId: propWorkspaceId,
423-
tableId: propTableId,
426+
workspaceId,
427+
tableId,
424428
embedded,
425429
remoteSelections,
426430
emitCellSelection,
@@ -456,9 +460,6 @@ export function TableGrid({
456460
confirmDeleteColumnsSinkRef,
457461
pushTableRenameUndoSinkRef,
458462
}: TableGridProps) {
459-
const params = useParams()
460-
const workspaceId = propWorkspaceId || (params.workspaceId as string)
461-
const tableId = propTableId || (params.tableId as string)
462463
const posthog = usePostHog()
463464

464465
useEffect(() => {

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1592,6 +1592,7 @@ export function Table({
15921592
{editingRow && tableData && (
15931593
<RowModal
15941594
mode='edit'
1595+
workspaceId={workspaceId}
15951596
isOpen={true}
15961597
onClose={() => setEditingRow(null)}
15971598
table={tableData}
@@ -1602,6 +1603,7 @@ export function Table({
16021603
{deletingRows.length > 0 && tableData && (
16031604
<RowModal
16041605
mode='delete'
1606+
workspaceId={workspaceId}
16051607
isOpen={true}
16061608
onClose={() => setDeletingRows([])}
16071609
table={tableData}

0 commit comments

Comments
 (0)