mirror of
https://github.com/supabase/supabase.git
synced 2026-12-03 23:18:57 +00:00
Add a User tab that resolves the signed-in user from the selected log or a related request step. It shows the shared Auth profile, offers filtering from the User ID row, and explains anonymous, external, or deleted users. When unified logs are enabled, the Auth user's Logs tab shows the user's 10 most recent logs in `EmbeddedLogsTable`, with the Logs page's columns and row styling. A row opens that log on the Logs page, filtered to the user, and View more in Logs opens the rest. Other configurations retain the existing Logs view. Shared user presentation is isolated in #50841; this PR contains the log/Auth integration and resolves missing-user queries to null. The list uses the #50953 helpers instead of its own: `createUnifiedLogsSearch` builds the query search, `buildUnifiedLogsUrl` builds the links (it now takes a `logId` to open a log), and the query asks for only the 10 rows it shows via `pageSize`. At the panel's default width the table is wider than the panel, so Event message needs a horizontal scroll; the empty state renders outside the table so it stays in view. Issue: [DEBUG-222](https://linear.app/supabase/issue/DEBUG-222/build-correlated-log-and-user-connections-in-studio) ### How to test 1. With the Unified Logs preview and `otelUnifiedLogs` enabled, open a signed-in user's log and select User. Check the profile, copy the User ID, and use Add filter to filter logs to that user. 2. Use Open in Authentication, then open the user's Logs tab. Select a row and confirm it opens the matching log; check that View more in Logs preserves the user filter. 3. Open an anonymous request and confirm the explanatory state. For correlated, external, and deleted-user cases, run the fixtures: `pnpm --filter studio exec vitest run components/interfaces/UnifiedLogs/components/LogUser.platform.test.tsx`. 4. In the log's User tab, focus User ID and press Enter, Arrow Down, Enter. Confirm it copies the ID without changing the selected log. Arrow Down should navigate logs again after the menu closes. ### Validation - Latest head: `8e4a9993b0db52ec5e611e55233b5ed77f67e358`, based on `master`, with conflicts resolved and independent review complete. - Local baseline and shuffled verification passed 324 tests across 26 files with retries disabled (shuffle seed `5083710`). An independent affected-suite run passed 29 tests with retries disabled and shuffle seed `5083730`. - Live QA found and reproduced a keyboard collision: field-menu Arrow Down also selected the next log. The shared menu now keeps keyboard events inside the menu. The regression fails when the guard is removed and passes after restoration. - On the verified latest-head preview, keyboard User ID copy, mouse copy, Add filter, Escape, navigation after closing the menu, and adjacent Auth email copying passed. No browser console errors were observed; browser network telemetry was unavailable. - Full signed-in activity, matching log/profile, Authentication navigation, View more filtering, anonymous state and deleted-user handling passed on `311206f9ef`. The subsequent change only affects menu keyboard propagation, which was revalidated on the latest head. - The disposable staging user was deleted and absence verified. Temporary key files were removed and the clipboard cleared. - Current CI: all E2E suites, unit tests, formatting, lint, Docker and deployments passed; typecheck is still running. Local full typecheck exhausted Node's heap, so no local full pass is claimed. ### Stack All prerequisite log-decoupling and request-correlation PRs, including #50841, are merged into `master`. This is the final code PR in the stack. --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Jordi Enric <jordi.err@gmail.com>
131 lines
4.7 KiB
TypeScript
131 lines
4.7 KiB
TypeScript
import { XIcon } from 'lucide-react'
|
|
import { parseAsString, useQueryState } from 'nuqs'
|
|
import { useState } from 'react'
|
|
import {
|
|
Button,
|
|
cn,
|
|
ResizableHandle,
|
|
ResizablePanel,
|
|
Tabs,
|
|
TabsContent,
|
|
TabsIndicator,
|
|
TabsList,
|
|
TabsTrigger,
|
|
} from 'ui'
|
|
import { GenericSkeletonLoader } from 'ui-patterns/ShimmeringLoader'
|
|
|
|
import { UserCard } from './UserCard'
|
|
import { UserLogs } from './UserLogs'
|
|
import { UserOverview } from './UserOverview'
|
|
import { useUnifiedLogsPreview } from '@/components/interfaces/App/FeaturePreview/FeaturePreviewContext'
|
|
import { UserRecentLogs } from '@/components/interfaces/UnifiedLogs/components/UserRecentLogs'
|
|
import { RawJsonView } from '@/components/ui/RawJsonView'
|
|
import { useUserQuery } from '@/data/auth/user-query'
|
|
import { useUnifiedLogsBackend } from '@/data/logs/unified-logs-infinite-query'
|
|
import { useIsFeatureEnabled } from '@/hooks/misc/useIsFeatureEnabled'
|
|
import { useSelectedProjectQuery } from '@/hooks/misc/useSelectedProject'
|
|
|
|
type UserPanelView = 'overview' | 'raw' | 'logs'
|
|
|
|
export const UserPanel = () => {
|
|
const { data: project } = useSelectedProjectQuery()
|
|
const showLogs = useIsFeatureEnabled('logs:all')
|
|
const isOtelUnifiedLogs = useUnifiedLogsBackend()
|
|
const { isEnabled: isUnifiedLogsEnabled } = useUnifiedLogsPreview()
|
|
const showRecentLogs = showLogs && isOtelUnifiedLogs && isUnifiedLogsEnabled
|
|
|
|
const [selectedId, setSelectedId] = useQueryState(
|
|
'show',
|
|
parseAsString.withOptions({ history: 'push', clearOnDefault: true })
|
|
)
|
|
|
|
const [view, setView] = useState<UserPanelView>('overview')
|
|
|
|
const { data: selectedUser, isPending } = useUserQuery({
|
|
projectRef: project?.ref,
|
|
connectionString: project?.connectionString,
|
|
userId: selectedId,
|
|
})
|
|
|
|
return (
|
|
<>
|
|
<ResizableHandle withHandle />
|
|
<ResizablePanel defaultSize="35" maxSize="45" minSize="35" className="bg-studio border-t">
|
|
{!selectedUser && (
|
|
<Button
|
|
variant="text"
|
|
className="absolute top-3 right-3 z-10 px-1"
|
|
icon={<XIcon />}
|
|
aria-label="Close panel"
|
|
onClick={() => setSelectedId(null)}
|
|
/>
|
|
)}
|
|
<Tabs
|
|
value={view}
|
|
className="flex flex-col h-full"
|
|
onValueChange={(value) => {
|
|
if (value === 'overview' || value === 'raw' || value === 'logs') setView(value)
|
|
}}
|
|
>
|
|
{isPending ? (
|
|
<div>
|
|
<div className="min-h-[46px] border-b" />
|
|
<div className="p-4">
|
|
<GenericSkeletonLoader />
|
|
</div>
|
|
</div>
|
|
) : !!selectedUser ? (
|
|
<>
|
|
<UserCard
|
|
user={selectedUser}
|
|
className="pb-3"
|
|
actions={
|
|
<Button
|
|
variant="text"
|
|
className="px-1"
|
|
icon={<XIcon />}
|
|
aria-label="Close panel"
|
|
onClick={() => setSelectedId(null)}
|
|
/>
|
|
}
|
|
/>
|
|
<TabsList className="shrink-0 gap-x-4 px-4">
|
|
<TabsTrigger value="overview">Overview</TabsTrigger>
|
|
{showLogs && !showRecentLogs && <TabsTrigger value="logs">Logs</TabsTrigger>}
|
|
<TabsTrigger value="raw">Raw JSON</TabsTrigger>
|
|
{showRecentLogs && <TabsTrigger value="logs">Logs</TabsTrigger>}
|
|
<TabsIndicator />
|
|
</TabsList>
|
|
|
|
<TabsContent value="overview" className={cn('mt-0 grow min-h-0 overflow-y-auto')}>
|
|
{selectedUser && (
|
|
<UserOverview user={selectedUser} onDeleteSuccess={() => setSelectedId(null)} />
|
|
)}
|
|
</TabsContent>
|
|
{showLogs && (
|
|
<TabsContent value="logs" className={cn('mt-0 grow min-h-0 overflow-y-auto')}>
|
|
{showRecentLogs && selectedUser.id ? (
|
|
<UserRecentLogs userId={selectedUser.id} />
|
|
) : (
|
|
<UserLogs user={selectedUser} />
|
|
)}
|
|
</TabsContent>
|
|
)}
|
|
<TabsContent value="raw" className="mt-0 grow min-h-0 overflow-y-auto">
|
|
<RawJsonView data={selectedUser} copyLabel="Copy user as JSON" />
|
|
</TabsContent>
|
|
</>
|
|
) : (
|
|
<div className="flex items-center justify-center w-full h-full flex-col gap-y-2">
|
|
<p className="text-foreground-light text-sm">
|
|
Unable to find user with the following ID in project
|
|
</p>
|
|
<p className="text-foreground-lighter text-xs">ID: {selectedId}</p>
|
|
</div>
|
|
)}
|
|
</Tabs>
|
|
</ResizablePanel>
|
|
</>
|
|
)
|
|
}
|