mirror of
https://github.com/supabase/supabase.git
synced 2026-09-10 03:51:51 +08:00
Follow-up to #48344: collapses the two resolution paths for the Admonition module into one. `src/admonition.tsx` was a back-compat shim re-exporting `src/Admonition/`. Two ways to resolve one module is exactly what produced the macOS self-import bug fixed in #48344, and the local typecheck errors that #48374 worked around. This removes the shim and standardizes on the PascalCase subpath, matching every other export in the package. **Changed:** - Codemodded all 246 `ui-patterns/admonition` imports to `ui-patterns/Admonition` (240 `.tsx`, 5 `.mdx`, 1 `.ts` across studio, docs, www, design-system, and lite-studio) - Pointed the 5 internal `'../admonition'` imports back at the `'../Admonition'` directory **Removed:** - `packages/ui-patterns/src/admonition.tsx`, and its `./admonition` entry in the exports map (regenerated with `pnpm gen:exports`) ## To test - `grep -r "ui-patterns/admonition" --include='*.ts*'` → no hits - `pnpm test:case-hazards` → passes - `pnpm typecheck` → all 15 tasks green - `pnpm --filter studio run lint:ratchet` → passes - `pnpm --filter ui-patterns vitest run src/Admonition` → 11 tests pass <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Standardized Admonition component imports across the application and documentation. * Improved compatibility with case-sensitive environments by using the canonical component path. * Removed the legacy Admonition import entry point. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: Alaister Young <10985857+alaister@users.noreply.github.com>
196 lines
7.2 KiB
TypeScript
196 lines
7.2 KiB
TypeScript
import { useParams } from 'common'
|
|
import { ExternalLink, RefreshCw } from 'lucide-react'
|
|
import Link from 'next/link'
|
|
import { useQueryState } from 'nuqs'
|
|
import { useEffect } from 'react'
|
|
import { Button, cn, CriticalIcon, Separator } from 'ui'
|
|
import { Admonition } from 'ui-patterns/Admonition'
|
|
import { GenericSkeletonLoader } from 'ui-patterns/ShimmeringLoader'
|
|
import { TimestampInfo } from 'ui-patterns/TimestampInfo'
|
|
|
|
import { UserHeader } from './UserHeader'
|
|
import { PANEL_PADDING } from './Users.constants'
|
|
import { LOGS_TABLES } from '@/components/interfaces/Settings/Logs/Logs.constants'
|
|
import { ButtonTooltip } from '@/components/ui/ButtonTooltip'
|
|
import { User } from '@/data/auth/users-infinite-query'
|
|
import useLogsPreview from '@/hooks/analytics/useLogsPreview'
|
|
import { useLogsUrlState } from '@/hooks/analytics/useLogsUrlState'
|
|
|
|
interface UserLogsProps {
|
|
user: User
|
|
}
|
|
|
|
const API_LOGS_QUERY = (userId: string) =>
|
|
`select\n cast(timestamp as datetime) as timestamp,\n event_message, metadata \nfrom edge_logs \nWHERE (\n metadata[SAFE_OFFSET(0)].request[SAFE_OFFSET(0)].sb[SAFE_OFFSET(0)].auth_user\n = '${userId}'\n)\nlimit 100`
|
|
|
|
export const UserLogs = ({ user }: UserLogsProps) => {
|
|
const { ref } = useParams()
|
|
const { filters, setFilters } = useLogsUrlState()
|
|
const [, setFiltersValue] = useQueryState('f')
|
|
|
|
const {
|
|
logData: authLogs,
|
|
isSuccess: isSuccessAuthLogs,
|
|
isLoading: isLoadingAuthLogs,
|
|
refresh,
|
|
} = useLogsPreview({
|
|
projectRef: ref as string,
|
|
table: LOGS_TABLES.auth,
|
|
filterOverride: { search_query: user.id },
|
|
limit: 5,
|
|
})
|
|
|
|
useEffect(() => {
|
|
if (user.id) setFilters({ ...filters, search_query: user.id })
|
|
|
|
return () => {
|
|
setFiltersValue(null)
|
|
}
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
}, [user.id])
|
|
|
|
return (
|
|
<div>
|
|
<UserHeader user={user} />
|
|
|
|
<Separator />
|
|
|
|
<div className={cn('flex flex-col gap-y-3', PANEL_PADDING)}>
|
|
<div>
|
|
<p>API logs</p>
|
|
<p className="text-sm text-foreground-light">
|
|
View edge logs for requests made by this user
|
|
</p>
|
|
</div>
|
|
|
|
<Button asChild variant="default" className="w-min">
|
|
<Link
|
|
href={`/project/${ref}/logs/explorer?q=${encodeURIComponent(API_LOGS_QUERY(user.id ?? ''))}`}
|
|
>
|
|
Open in Log Explorer
|
|
</Link>
|
|
</Button>
|
|
</div>
|
|
|
|
<Separator />
|
|
|
|
<div className={cn('flex flex-col gap-y-3', PANEL_PADDING)}>
|
|
<div>
|
|
<p>Authentication logs</p>
|
|
<p className="text-sm text-foreground-light">
|
|
Latest logs from authentication for this user in the past hour
|
|
</p>
|
|
</div>
|
|
|
|
{/* [Joshen] This whole thing here i reckon we can shift to a component, if in the future we wanna add more user logs */}
|
|
<div className="flex items-center justify-between">
|
|
<div className="flex items-center">
|
|
<Button
|
|
variant={'status_code' in filters ? 'default' : 'secondary'}
|
|
className="rounded-r-none border-r-0"
|
|
disabled={isLoadingAuthLogs}
|
|
onClick={() => setFilters({ search_query: user.id })}
|
|
>
|
|
Show all
|
|
</Button>
|
|
<div className="border-button border border-l-0 py-3" />
|
|
<Button
|
|
variant={'status_code' in filters ? 'secondary' : 'default'}
|
|
className="rounded-l-none border-l-0"
|
|
disabled={isLoadingAuthLogs}
|
|
onClick={() =>
|
|
setFilters({
|
|
search_query: user.id,
|
|
status_code: { client_error: true, server_error: true },
|
|
})
|
|
}
|
|
>
|
|
Error only
|
|
</Button>
|
|
</div>
|
|
<Button
|
|
variant="default"
|
|
loading={isLoadingAuthLogs}
|
|
disabled={isLoadingAuthLogs}
|
|
icon={<RefreshCw />}
|
|
onClick={() => refresh()}
|
|
>
|
|
Refresh
|
|
</Button>
|
|
</div>
|
|
|
|
{isLoadingAuthLogs && !isSuccessAuthLogs ? (
|
|
<GenericSkeletonLoader />
|
|
) : authLogs.length === 0 ? (
|
|
<Admonition
|
|
type="note"
|
|
title="No authentication logs available for this user"
|
|
description="Auth events such as logging in will be shown here"
|
|
/>
|
|
) : (
|
|
<div>
|
|
<div className="border border-b-0 rounded-t-md divide-y overflow-hidden">
|
|
{authLogs.map((log) => {
|
|
const status = ((log.status ?? '-') as any).toString()
|
|
const is400 = status.startsWith('4')
|
|
const is500 = status.startsWith('5')
|
|
|
|
return (
|
|
<div
|
|
key={log.id}
|
|
className="flex items-center transition font-mono px-2 py-1.5 bg-surface-100 divide-x"
|
|
>
|
|
<p className="text-xs text-foreground-light min-w-[125px] w-[125px] px-1">
|
|
<TimestampInfo utcTimestamp={log.timestamp / 1000} />
|
|
</p>
|
|
<div className="flex items-center text-xs text-foreground-light h-[22px] min-w-[70px] w-[70px] px-2">
|
|
<div
|
|
className={cn(
|
|
'flex items-center justify-center gap-x-1',
|
|
!!log.status && 'border px-1 py-0.5 rounded-sm',
|
|
is400
|
|
? 'text-warning border-warning bg-warning-300'
|
|
: is500
|
|
? 'text-destructive border-destructive bg-destructive-300'
|
|
: ''
|
|
)}
|
|
>
|
|
{(is400 || is500) && (
|
|
<CriticalIcon hideBackground className={cn(is400 && 'text-warning')} />
|
|
)}
|
|
{status}
|
|
</div>
|
|
</div>
|
|
<p className="group relative flex items-center py-1.5 text-xs text-foreground-light px-2 truncate w-full">
|
|
{`${log.path} | ${log.msg}`}
|
|
|
|
<ButtonTooltip
|
|
variant="outline"
|
|
asChild
|
|
tooltip={{ content: { text: 'Open in logs' } }}
|
|
className="px-1.5 absolute right-0 top-0 opacity-0 group-hover:opacity-100 transition bg-background focus-visible:opacity-100"
|
|
>
|
|
<Link href={`/project/${ref}/logs/auth-logs?log=${log.id}`}>
|
|
<ExternalLink size="12" className="text-foreground-light" />
|
|
</Link>
|
|
</ButtonTooltip>
|
|
</p>
|
|
</div>
|
|
)
|
|
})}
|
|
</div>
|
|
<Button
|
|
block
|
|
asChild
|
|
variant="outline"
|
|
className="transition rounded-t-none text-foreground-light hover:text-foreground"
|
|
>
|
|
<Link href={`/project/${ref}/logs/auth-logs?s=${user.id}`}>See more logs</Link>
|
|
</Button>
|
|
</div>
|
|
)}
|
|
</div>
|
|
</div>
|
|
)
|
|
}
|