Skip to content

Commit 5496dee

Browse files
fix(tables): resolve the views flag on the chat route too
1 parent acec909 commit 5496dee

3 files changed

Lines changed: 34 additions & 13 deletions

File tree

apps/sim/app/workspace/[workspaceId]/chat/[chatId]/page.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import type { Metadata } from 'next'
33
import { getSession } from '@/lib/auth'
44
import { Home } from '@/app/workspace/[workspaceId]/home/home'
55
import { HomeFallback } from '@/app/workspace/[workspaceId]/home/home-fallback'
6+
import { resolveTableViewsEnabled } from '@/app/workspace/[workspaceId]/home/resolve-table-views-flag'
67

78
export const metadata: Metadata = {
89
title: 'Chat',
@@ -16,14 +17,17 @@ interface ChatPageProps {
1617
}
1718

1819
export default async function ChatPage({ params }: ChatPageProps) {
19-
const [{ chatId }, session] = await Promise.all([params, getSession()])
20+
const [{ workspaceId, chatId }, session] = await Promise.all([params, getSession()])
21+
const userId = session?.user?.id
22+
const tableViewsEnabled = await resolveTableViewsEnabled(workspaceId, userId)
2023
return (
2124
<Suspense fallback={<HomeFallback />}>
2225
<Home
2326
key={chatId}
2427
chatId={chatId}
2528
userName={session?.user?.name}
26-
userId={session?.user?.id}
29+
userId={userId}
30+
tableViewsEnabled={tableViewsEnabled}
2731
/>
2832
</Suspense>
2933
)

apps/sim/app/workspace/[workspaceId]/home/page.tsx

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@ import { Suspense } from 'react'
22
import { dehydrate, HydrationBoundary } from '@tanstack/react-query'
33
import type { Metadata } from 'next'
44
import { getSession } from '@/lib/auth'
5-
import { isFeatureEnabled } from '@/lib/core/config/feature-flags'
6-
import { getWorkspaceHostContextForViewer } from '@/lib/workspaces/host-context'
75
import { getQueryClient } from '@/app/_shell/providers/get-query-client'
86
import { prefetchHomeLists } from '@/app/workspace/[workspaceId]/home/prefetch'
7+
import { resolveTableViewsEnabled } from '@/app/workspace/[workspaceId]/home/resolve-table-views-flag'
98
import { Home } from './home'
109
import { HomeFallback } from './home-fallback'
1110

@@ -21,15 +20,7 @@ export default async function HomePage({ params }: { params: Promise<{ workspace
2120

2221
const session = await getSession()
2322
const userId = session?.user?.id
24-
// Resolved here for the same reason the table page does it: the flag's gating
25-
// lives in AppConfig, which has no client counterpart, and the embedded table is
26-
// a client component. Keyed on the workspace's host organization, matching the
27-
// table page so both surfaces gate identically. Both reads are request-memoized.
28-
const host = userId ? await getWorkspaceHostContextForViewer(workspaceId, userId) : null
29-
const tableViewsEnabled = await isFeatureEnabled('table-views', {
30-
userId,
31-
orgId: host?.hostOrganizationId ?? undefined,
32-
})
23+
const tableViewsEnabled = await resolveTableViewsEnabled(workspaceId, userId)
3324
await listsPrefetch
3425

3526
return (
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { isFeatureEnabled } from '@/lib/core/config/feature-flags'
2+
import { getWorkspaceHostContextForViewer } from '@/lib/workspaces/host-context'
3+
4+
/**
5+
* Resolves `table-views` for the mothership panel's embedded table.
6+
*
7+
* Lives here rather than inline because BOTH routes that render `<Home>` need it
8+
* — `home/page.tsx` and `chat/[chatId]/page.tsx` — and the flag can only be read
9+
* server-side (its gating is in AppConfig, which has no client counterpart).
10+
* Resolving it in one place is what keeps the two routes from drifting; the chat
11+
* route missing it is precisely why views didn't appear in the panel.
12+
*
13+
* Keyed on the workspace's HOST organization, matching the table page, so the
14+
* same workspace gates identically wherever its tables are rendered. Both this
15+
* and `getSession` are request-memoized, so callers pay no extra round-trip.
16+
*/
17+
export async function resolveTableViewsEnabled(
18+
workspaceId: string,
19+
userId: string | undefined
20+
): Promise<boolean> {
21+
const host = userId ? await getWorkspaceHostContextForViewer(workspaceId, userId) : null
22+
return isFeatureEnabled('table-views', {
23+
userId,
24+
orgId: host?.hostOrganizationId ?? undefined,
25+
})
26+
}

0 commit comments

Comments
 (0)