Skip to content

Commit acfef82

Browse files
Bill LeoutsakosBill Leoutsakos
authored andcommitted
fix(tables): handle stale chat views
1 parent a59c683 commit acfef82

5 files changed

Lines changed: 20 additions & 9 deletions

File tree

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

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,7 @@ describe('EmbeddedViewTable', () => {
6666
root.render(<EmbeddedViewTable workspaceId='workspace_1' resourceId='tbl_1:view_1' />)
6767
})
6868

69-
expect(tableMock).toHaveBeenCalledWith({
70-
workspaceId: 'workspace_1',
71-
tableId: 'tbl_1',
72-
viewId: 'view_1',
73-
embedded: true,
74-
viewsEnabled: false,
75-
})
69+
expect(container.innerHTML).toBe('')
70+
expect(tableMock).not.toHaveBeenCalled()
7671
})
7772
})

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export function EmbeddedViewTable({
1616
viewsEnabled = false,
1717
}: EmbeddedViewTableProps) {
1818
const parsed = parseTableViewResourceId(resourceId)
19-
if (!parsed) return null
19+
if (!parsed || !viewsEnabled) return null
2020
return (
2121
<Table
2222
workspaceId={workspaceId}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,7 @@ export function Table({
562562
// switching resources away and back, not leakage.
563563
const inheritedParams =
564564
embedded &&
565+
!propViewId &&
565566
activeViewId !== null &&
566567
activeViewId !== ALL_VIEW_PARAM &&
567568
!views.some((view) => view.id === activeViewId)

apps/sim/lib/copilot/tools/server/table/user-table.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -900,6 +900,17 @@ describe('userTableServerTool.create_view', () => {
900900
)
901901
})
902902

903+
it('normalizes an empty model-authored filter to no filter', async () => {
904+
await userTableServerTool.execute(
905+
{ operation: 'create_view', args: { tableId: 'tbl_1', filter: {} } },
906+
{ userId: 'user-1', workspaceId: 'workspace-1' }
907+
)
908+
909+
expect(mockCreateTableView).toHaveBeenCalledWith(
910+
expect.objectContaining({ config: { filter: null, sort: null } })
911+
)
912+
})
913+
903914
it('rejects a Table from another workspace without creating a View', async () => {
904915
mockGetTableById.mockResolvedValue(buildTable({ workspaceId: 'other-workspace' }))
905916

apps/sim/lib/copilot/tools/server/table/user-table.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ import { markTableDeleteFailed, runTableDelete } from '@/lib/table/delete-runner
4949
import { runTableImport, type TableImportPayload } from '@/lib/table/import-runner'
5050
import { markTableJobRunning, releaseJobClaim } from '@/lib/table/jobs/service'
5151
import { assertRowDelete, assertRowUpdate, patchColumnIds } from '@/lib/table/mutation-locks'
52+
import { pruneViewFilterForColumns } from '@/lib/table/query-builder/converters'
5253
import {
5354
batchInsertRows,
5455
batchUpdateRows,
@@ -778,7 +779,10 @@ export const userTableServerTool: BaseServerTool<UserTableArgs, UserTableResult>
778779
}
779780

780781
const filter = args.filter
781-
? canonicalViewFilter(args.filter as Filter, table.schema.columns)
782+
? pruneViewFilterForColumns(
783+
canonicalViewFilter(args.filter as Filter, table.schema.columns),
784+
table.schema.columns
785+
)
782786
: null
783787
const sort = args.sort
784788
? canonicalViewSort(args.sort as Record<string, 'asc' | 'desc'>, table.schema.columns)

0 commit comments

Comments
 (0)