Skip to content

Commit acec909

Browse files
feat(tables): enable saved views in the embedded mothership table
1 parent e1a294a commit acec909

4 files changed

Lines changed: 38 additions & 3 deletions

File tree

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ interface ResourceContentProps {
8282
isAgentResponding?: boolean
8383
genericResourceData?: GenericResourceData
8484
previewContextKey?: string
85+
/** Resolved server-side by the home page — the embedded table can't read
86+
* AppConfig itself, so the flag is threaded down rather than looked up. */
87+
tableViewsEnabled?: boolean
8588
onNotFound?: (resourceId: string) => void
8689
}
8790

@@ -144,6 +147,7 @@ export const ResourceContent = memo(function ResourceContent({
144147
isAgentResponding,
145148
genericResourceData,
146149
previewContextKey,
150+
tableViewsEnabled,
147151
onNotFound,
148152
}: ResourceContentProps) {
149153
const streamFileName = previewSession?.fileName || 'file.md'
@@ -213,7 +217,15 @@ export const ResourceContent = memo(function ResourceContent({
213217

214218
switch (resource.type) {
215219
case 'table':
216-
return <Table key={resource.id} workspaceId={workspaceId} tableId={resource.id} embedded />
220+
return (
221+
<Table
222+
key={resource.id}
223+
workspaceId={workspaceId}
224+
tableId={resource.id}
225+
embedded
226+
viewsEnabled={tableViewsEnabled}
227+
/>
228+
)
217229

218230
case 'file':
219231
return (

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ interface MothershipViewProps {
5454
previewSession?: FilePreviewSession | null
5555
isAgentResponding?: boolean
5656
genericResourceData?: GenericResourceData
57+
/** Resolved server-side by the home page; forwarded to the embedded table. */
58+
tableViewsEnabled?: boolean
5759
}
5860

5961
export const MothershipView = memo(
@@ -68,6 +70,7 @@ export const MothershipView = memo(
6870
previewSession,
6971
isAgentResponding,
7072
genericResourceData,
73+
tableViewsEnabled,
7174
}: MothershipViewProps,
7275
ref
7376
) {
@@ -141,6 +144,7 @@ export const MothershipView = memo(
141144
isAgentResponding={isAgentResponding}
142145
genericResourceData={active.type === 'generic' ? genericResourceData : undefined}
143146
previewContextKey={chatId}
147+
tableViewsEnabled={tableViewsEnabled}
144148
onNotFound={(resourceId) => removeResource('log', resourceId)}
145149
/>
146150
) : (

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,11 @@ interface HomeProps {
7676
chatId?: string
7777
userName?: string
7878
userId?: string
79+
/** Resolved server-side by the page — the embedded table can't reach AppConfig. */
80+
tableViewsEnabled?: boolean
7981
}
8082

81-
export function Home({ chatId, userName, userId }: HomeProps) {
83+
export function Home({ chatId, userName, userId, tableViewsEnabled }: HomeProps) {
8284
useOAuthReturnRouter()
8385
const { workspaceId } = useParams<{ workspaceId: string }>()
8486
const router = useRouter()
@@ -539,6 +541,7 @@ export function Home({ chatId, userName, userId }: HomeProps) {
539541
previewSession={previewSession}
540542
isAgentResponding={isSending}
541543
genericResourceData={genericResourceData ?? undefined}
544+
tableViewsEnabled={tableViewsEnabled}
542545
className={skipResourceTransition ? '!transition-none' : undefined}
543546
/>
544547
</Suspense>

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ 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'
57
import { getQueryClient } from '@/app/_shell/providers/get-query-client'
68
import { prefetchHomeLists } from '@/app/workspace/[workspaceId]/home/prefetch'
79
import { Home } from './home'
@@ -18,12 +20,26 @@ export default async function HomePage({ params }: { params: Promise<{ workspace
1820
const listsPrefetch = prefetchHomeLists(queryClient, workspaceId)
1921

2022
const session = await getSession()
23+
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+
})
2133
await listsPrefetch
2234

2335
return (
2436
<HydrationBoundary state={dehydrate(queryClient)}>
2537
<Suspense fallback={<HomeFallback />}>
26-
<Home userName={session?.user?.name} userId={session?.user?.id} />
38+
<Home
39+
userName={session?.user?.name}
40+
userId={userId}
41+
tableViewsEnabled={tableViewsEnabled}
42+
/>
2743
</Suspense>
2844
</HydrationBoundary>
2945
)

0 commit comments

Comments
 (0)