Skip to content

Commit 975ad42

Browse files
committed
Merge branch 'wip/fix-consistency' into wip/platform-org-wiring
2 parents 346afdd + b084f11 commit 975ad42

71 files changed

Lines changed: 648 additions & 234 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎apps/sim/app/o/[organizationId]/components/organization-conversation-landing.test.tsx‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ beforeEach(() => {
9494
searchAccess: { memberScoped: true },
9595
mothershipAvailable: true,
9696
canBuild: false,
97-
viewer: { isAdmin: false, canUseSearchMcp: true },
97+
viewer: { userId: 'reader', isAdmin: false, canUseSearchMcp: true },
9898
})
9999
mockUseChat.mockReturnValue({ messages: [], resources: [], sendMessage: vi.fn() })
100100
mocks.composer.mockReturnValue(<div>Question composer</div>)
@@ -110,16 +110,16 @@ afterEach(async () => {
110110
})
111111

112112
describe('an Assistant conversation on a surface with its own landing', () => {
113-
it('holds the surface’s fallback until the session arrives', async () => {
114-
authClientMockFns.mockUseSession.mockReturnValue({ data: null })
113+
it('mounts on the viewer the layout authorized, without a round trip for the client session', async () => {
114+
authClientMockFns.mockUseSession.mockReturnValue({ data: null, isPending: true })
115115
await render(
116116
<PageConversation
117117
requestMode='assistant'
118118
fallback={<div>Dashboard skeleton</div>}
119119
landing={landing}
120120
/>
121121
)
122-
expect(container.textContent).toBe('Dashboard skeleton')
122+
expect(container.textContent).not.toContain('Dashboard skeleton')
123123
})
124124

125125
it('shows no dashboard while a restored chat entry hands itself back to the router', async () => {

‎apps/sim/app/o/[organizationId]/components/organization-conversation-queued-edit.test.tsx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ beforeEach(async () => {
132132
searchAccess: { memberScoped: true },
133133
mothershipAvailable: true,
134134
canBuild: true,
135+
viewer: { userId: 'reader' },
135136
})
136137
mocks.speech.mockReturnValue({
137138
isSupported: false,

‎apps/sim/app/o/[organizationId]/components/organization-conversation.test.tsx‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ beforeEach(() => {
130130
searchAccess: { memberScoped: true },
131131
mothershipAvailable: true,
132132
canBuild: true,
133-
viewer: { isAdmin: false, canUseSearchMcp: true },
133+
viewer: { userId: 'reader', isAdmin: false, canUseSearchMcp: true },
134134
})
135135
mocks.apiKeys.mockReturnValue({ data: { personalKeys: [] } })
136136
mockAuthorizedApps([{ apps: [], nextCursor: null }])
@@ -247,12 +247,16 @@ it('isolates saved drafts by user, organization, and conversation', async () =>
247247
)
248248
expect(draftText()).toBe('Chat A follow-up')
249249
expect(composerProps().files.attachedFiles[0]?.key).toBe('image-key')
250-
mockSession.mockReturnValue({ data: { user: { id: 'other-user' } } })
250+
const reader = toRecord(mockContext())
251+
mockContext.mockReturnValue({
252+
...reader,
253+
viewer: { ...toRecord(reader.viewer), userId: 'other-user' },
254+
})
251255
await act(async () =>
252256
renderHome(<PageConversation chatId='chat-a' requestMode='assistant' fallback={null} />)
253257
)
254258
expect(draftText()).toBe('')
255-
mockSession.mockReturnValue({ data: { user: { id: 'reader' } } })
259+
mockContext.mockReturnValue(reader)
256260
mockContext.mockReturnValue({
257261
...toRecord(mockContext()),
258262
organization: { id: 'other-org', name: 'Other' },

‎apps/sim/app/o/[organizationId]/components/use-organization-conversation.ts‎

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import { createSerializer, useQueryStates } from 'nuqs'
99
import { requestJson } from '@/lib/api/client/request'
1010
import type { WorkspaceSearchFilters } from '@/lib/api/contracts/knowledge'
1111
import { getWorkspaceHostContextContract } from '@/lib/api/contracts/workspaces'
12-
import { useSession } from '@/lib/auth/client'
1312
import { BrowserStorage } from '@/lib/core/utils/browser-storage'
1413
import {
1514
getMothershipAttachmentPreviewUrl,
@@ -125,21 +124,19 @@ interface UseConversationGateOptions {
125124

126125
/** Whether the surface may mount, and for which identity. Its key remounts on any change to one. */
127126
export function useConversationGate({ chatId, requestMode }: UseConversationGateOptions) {
128-
const { organization, searchAccess, canBuild, mothershipAvailable } = useOrganization()
129-
const { data: session } = useSession()
127+
const { organization, viewer, searchAccess, canBuild, mothershipAvailable } = useOrganization()
130128
const isClient = useHydrated()
131129
const isRestoredChatEntry = useRestoredChatEntry({ chatId })
132-
const userId = session?.user?.id
133130
if (
134131
!mothershipAvailable ||
135132
(requestMode === 'assistant' ? !searchAccess.memberScoped : !canBuild)
136133
)
137134
return { status: 'denied' } as const
138135
if (isRestoredChatEntry) return { status: 'restoring' } as const
139-
if (!isClient || !userId) return { status: 'waiting' } as const
136+
if (!isClient) return { status: 'waiting' } as const
140137
return {
141138
status: 'ready',
142-
instanceKey: `${userId}:${organization.id}:${chatId ?? 'new'}`,
139+
instanceKey: `${viewer.userId}:${organization.id}:${chatId ?? 'new'}`,
143140
} as const
144141
}
145142

@@ -165,10 +162,9 @@ export function useOrganizationConversation({
165162
summaryRequest,
166163
onSummaryConsumed,
167164
}: UseOrganizationConversationOptions) {
168-
const { organization, canBuild } = useOrganization()
165+
const { organization, viewer, canBuild } = useOrganization()
169166
const panelSurface = surface.kind === 'panel' ? surface : null
170-
const { data: session } = useSession()
171-
const userId = session?.user?.id
167+
const userId = viewer.userId
172168
const planEnabled = useFeatureFlag('mothership-plan-mode')
173169
const [planning, setPlanning] = useState(false)
174170
const requestMode =
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { HomeDashboardSkeleton } from '@/platform/embedded/app/(shell)/home/_components/home-dashboard/home-dashboard-skeleton'
22

3-
/** A route boundary cannot know the viewer's mode, so it holds the Assistant's, the common one. */
43
export default function OrganizationHomeLoading() {
5-
return <HomeDashboardSkeleton requestMode='assistant' />
4+
return <HomeDashboardSkeleton />
65
}

‎apps/sim/app/o/[organizationId]/home/page.test.tsx‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { ReactNode } from 'react'
12
import { authMockFns } from '@sim/testing'
23
import { createSessionPrincipal } from '@sim/testing/factories/principal.factory'
34
import {
@@ -20,7 +21,16 @@ vi.mock('@/platform/embedded/lib/data/prefetch-member-inventory', () => ({
2021
vi.mock(
2122
'@/platform/embedded/app/(shell)/home/_components/home-dashboard/home-dashboard-skeleton',
2223
() => ({
23-
HomeDashboardSkeleton: ({ requestMode }: { requestMode: string }) => (
24+
HomeDashboardSkeleton: () => <div>Home skeleton</div>,
25+
})
26+
)
27+
vi.mock('@/platform/design-system/components/surface/hydrated', () => ({
28+
Hydrated: ({ children }: { children: ReactNode }) => children,
29+
}))
30+
vi.mock(
31+
'@/platform/embedded/app/(shell)/home/_components/home-conversation/home-conversation',
32+
() => ({
33+
HomeConversation: ({ requestMode }: { requestMode: string }) => (
2434
<div>Home for {requestMode}</div>
2535
),
2636
})

‎apps/sim/app/o/[organizationId]/home/page.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export default async function OrganizationHomePage({
2828

2929
const requestMode = context.canBuild ? 'agent' : 'assistant'
3030
return (
31-
<Suspense fallback={<HomeDashboardSkeleton requestMode={requestMode} />}>
31+
<Suspense fallback={<HomeDashboardSkeleton />}>
3232
<Hydrated state={prefetchHome(context, principal)}>
3333
<HomeConversation requestMode={requestMode} />
3434
</Hydrated>

‎apps/sim/app/o/[organizationId]/integrations/secrets/loading.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { LoadingRows } from '@/platform/design-system/components'
1+
import { LoadingRows } from '@/platform/design-system/components/status/query-boundary'
22
import { PageSurface } from '@/platform/design-system/components/surface/surface'
33
import { IntegrationsPage } from '@/platform/embedded/app/(shell)/integrations/_components/integrations-page/integrations-page'
44

‎apps/sim/app/o/[organizationId]/integrations/secrets/organization-secrets-page.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { readOrganizationSecretSource } from '@/lib/organization-secrets/applica
66
import type { SecretSourceMode } from '@/lib/organization-secrets/validation'
77
import { getOrganizationSurfaceContext } from '@/lib/organizations/surface'
88
import { buildAuthCrossLink } from '@/app/(auth)/auth-redirect'
9-
import { LoadingRows } from '@/platform/design-system/components'
9+
import { LoadingRows } from '@/platform/design-system/components/status/query-boundary'
1010
import { PageSurface } from '@/platform/design-system/components/surface/surface'
1111
import { IntegrationsPage } from '@/platform/embedded/app/(shell)/integrations/_components/integrations-page/integrations-page'
1212
import { SecretsEditor } from '@/platform/embedded/app/(shell)/integrations/_components/secrets-editor/secrets-editor'

‎apps/sim/app/o/[organizationId]/settings/integrations/providers/[connectorType]/loading.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { LoadingRows } from '@/platform/design-system/components'
1+
import { LoadingRows } from '@/platform/design-system/components/status/query-boundary'
22
import { SettingsSubpageHost } from '@/platform/embedded/app/(shell)/settings/_components/settings-subpage-host'
33

44
/** Keeps the section's heading visible while authorization and content load. */

0 commit comments

Comments
 (0)