Skip to content

Commit 2a379fa

Browse files
j15zclaude
andcommitted
fix(tables): make the first saved view the default
Creating the first view left isDefault false, so the legacy All fallback stayed in the menu instead of handing off to the new view. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent 39c9bc8 commit 2a379fa

2 files changed

Lines changed: 25 additions & 1 deletion

File tree

apps/sim/lib/table/views/service.test.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,28 @@ describe('table-view mutations signal collaborators', () => {
157157
expect(mockSignalTableViewsChanged).toHaveBeenCalledWith('table-1')
158158
})
159159

160+
it.each([
161+
{ existingTotal: 0, isDefault: true },
162+
{ existingTotal: 1, isDefault: false },
163+
])(
164+
'creates a view with isDefault=$isDefault when $existingTotal views already exist',
165+
async ({ existingTotal, isDefault }) => {
166+
queueTableRows(tableViews, [{ total: existingTotal }])
167+
dbChainMockFns.returning.mockResolvedValueOnce([{ ...viewRow, isDefault }])
168+
169+
await createTableView({
170+
tableId: 'table-1',
171+
workspaceId: 'ws-1',
172+
name: 'My View',
173+
config: {},
174+
userId: 'user-1',
175+
columns,
176+
})
177+
178+
expect(dbChainMockFns.values).toHaveBeenCalledWith(expect.objectContaining({ isDefault }))
179+
}
180+
)
181+
160182
it('updateTableView signals when the target view exists', async () => {
161183
queueTableRows(tableViews, [{ id: 'view-1' }]) // the in-transaction existence pre-check
162184
dbChainMockFns.returning.mockResolvedValueOnce([viewRow]) // the update returning

apps/sim/lib/table/views/service.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,8 @@ export async function createTableView(data: CreateTableViewData): Promise<TableV
464464
and(eq(tableViews.tableId, data.tableId), eq(tableViews.workspaceId, data.workspaceId))
465465
)
466466

467-
if (Number(existing?.total ?? 0) >= TABLE_LIMITS.MAX_VIEWS_PER_TABLE) {
467+
const existingTotal = Number(existing?.total ?? 0)
468+
if (existingTotal >= TABLE_LIMITS.MAX_VIEWS_PER_TABLE) {
468469
throw new TableViewValidationError(
469470
`A table cannot have more than ${TABLE_LIMITS.MAX_VIEWS_PER_TABLE} saved views`
470471
)
@@ -478,6 +479,7 @@ export async function createTableView(data: CreateTableViewData): Promise<TableV
478479
workspaceId: data.workspaceId,
479480
name,
480481
config,
482+
isDefault: existingTotal === 0,
481483
createdBy: data.userId,
482484
})
483485
.returning()

0 commit comments

Comments
 (0)