mirror of
https://github.com/supabase/supabase.git
synced 2026-12-06 08:29:01 +00:00
Moves the `/logs/*` and `/observability/*` page bodies into their route files and deletes the pages (FE-3106). Part 9 of the stack. **Depends on:** #53217 **Changed:** - `routes/project/$ref/logs/**` – 20 page bodies inlined. `logs/index` keeps its `withAuth` wrapper; `replication-logs` redirects with `<Navigate search hash>`; the Logs Explorer save navigates with `search: { queryId }` (never a query inside `to`) - `routes/project/$ref/observability/**` – 12 page bodies inlined; chart highlight actions navigate with `search` params - `components/interfaces/Observability/DatabaseReport.hooks.ts` – the database report's URL hooks move out of the page (with their test) - `components/ui/Charts/ComposedChartHandler.tsx` – imports `UpdateDateRange` from `ChartHighlightActions` instead of a page **Removed:** - 32 page files Addresses [FE-3106](https://linear.app/supabase/issue/FE-3106/move-page-bodies-into-route-files-and-delete-pages). ## To test - Logs Explorer: run a multi-line query, save it – the URL keeps newlines and the saved query reopens - Each log source (Postgres, Auth, Edge, Storage, Realtime, …) – same layout and title - Observability reports – charts render; highlighting a range links to the right logs page Co-authored-by: Alaister Young <10985857+alaister@users.noreply.github.com>
144 lines
4.8 KiB
TypeScript
144 lines
4.8 KiB
TypeScript
import { createFileRoute } from '@tanstack/react-router'
|
|
import dayjs from 'dayjs'
|
|
import { CirclePauseIcon, CirclePlayIcon } from 'lucide-react'
|
|
import { useEffect, useState } from 'react'
|
|
import { Badge, Button, Tooltip, TooltipContent, TooltipTrigger } from 'ui'
|
|
|
|
import { Activity } from '@/components/interfaces/Observability/DatabaseConnections/Activity'
|
|
import { buildDatabaseConnectionsSummaryPrompt } from '@/components/interfaces/Observability/DatabaseConnections/DatabaseConnections.ai'
|
|
import { Overview } from '@/components/interfaces/Observability/DatabaseConnections/Overview'
|
|
import { ReportPadding } from '@/components/interfaces/Reports/ReportPadding'
|
|
import { SIDEBAR_KEYS } from '@/components/layouts/ProjectLayout/LayoutSidebar/LayoutSidebarProvider'
|
|
import { AiAssistantDropdown } from '@/components/ui/AiAssistantDropdown'
|
|
import { ShortcutTooltip } from '@/components/ui/ShortcutTooltip'
|
|
import { useDatabaseActivityQuery } from '@/data/database/activity-query'
|
|
import { useSelectedProjectQuery } from '@/hooks/misc/useSelectedProject'
|
|
import { useTrack } from '@/lib/telemetry/track'
|
|
import { useAiAssistantStateSnapshot } from '@/state/ai-assistant-state'
|
|
import { SHORTCUT_IDS } from '@/state/shortcuts/registry'
|
|
import { useShortcut } from '@/state/shortcuts/useShortcut'
|
|
import { useSidebarManagerSnapshot } from '@/state/sidebar-manager-state'
|
|
|
|
export const Route = createFileRoute('/project/$ref/observability/connections')({
|
|
component: DatabaseConnections,
|
|
staticData: {
|
|
observabilityLayoutTitle: 'Database Connections',
|
|
},
|
|
})
|
|
|
|
function DatabaseConnections() {
|
|
const track = useTrack()
|
|
const { data: project } = useSelectedProjectQuery()
|
|
const { openSidebar } = useSidebarManagerSnapshot()
|
|
const aiSnap = useAiAssistantStateSnapshot()
|
|
|
|
const [live, setLive] = useState(true)
|
|
const [now, setNow] = useState(() => dayjs.utc())
|
|
|
|
useShortcut(SHORTCUT_IDS.DATA_TABLE_TOGGLE_LIVE, handleToggleLive, {
|
|
registerInCommandMenu: false,
|
|
})
|
|
|
|
const {
|
|
data,
|
|
isPending: isLoadingActivity,
|
|
refetch: refetchActivity,
|
|
} = useDatabaseActivityQuery(
|
|
{
|
|
projectRef: project?.ref,
|
|
connectionString: project?.connectionString,
|
|
},
|
|
{
|
|
refetchOnWindowFocus: live,
|
|
refetchInterval: live ? 3000 : false,
|
|
}
|
|
)
|
|
|
|
function handleToggleLive() {
|
|
const nextLive = !live
|
|
|
|
track('database_connections_live_mode_clicked', {
|
|
newState: nextLive ? 'enabled' : 'disabled',
|
|
})
|
|
|
|
setLive(nextLive)
|
|
if (nextLive) {
|
|
setNow(dayjs.utc())
|
|
refetchActivity()
|
|
}
|
|
}
|
|
|
|
const buildPrompt = () => {
|
|
return buildDatabaseConnectionsSummaryPrompt({
|
|
activities: data ?? [],
|
|
timestamp: now.toISOString(),
|
|
})
|
|
}
|
|
|
|
const handleSummarizeActivity = () => {
|
|
openSidebar(SIDEBAR_KEYS.AI_ASSISTANT)
|
|
const prompt = buildPrompt()
|
|
aiSnap.newChat({
|
|
name: `DB Connections Summary ${dayjs().format('DD/MM/YYYY HH:mm')}`,
|
|
initialMessage: prompt,
|
|
})
|
|
}
|
|
|
|
// [Joshen] Just to trigger a UI re-render for the duration to be "live"
|
|
useEffect(() => {
|
|
if (!live) return
|
|
const interval = setInterval(() => setNow(dayjs.utc()), 1000)
|
|
return () => clearInterval(interval)
|
|
}, [live])
|
|
|
|
return (
|
|
<ReportPadding className="gap-y-12">
|
|
<div className="flex items-center justify-between gap-x-4">
|
|
<div className="flex items-center gap-x-2">
|
|
<h1 className="w-max">Database Connections</h1>
|
|
{live && (
|
|
<Tooltip>
|
|
<TooltipTrigger className="flex items-center">
|
|
<Badge variant="success">
|
|
<span className="h-1.5 w-1.5 bg-brand-default rounded-full animate-pulse" />
|
|
<span>Live</span>
|
|
</Badge>
|
|
</TooltipTrigger>
|
|
<TooltipContent side="bottom">Refreshes data every 3 seconds</TooltipContent>
|
|
</Tooltip>
|
|
)}
|
|
</div>
|
|
|
|
<div className="flex items-center gap-x-2">
|
|
<ShortcutTooltip
|
|
shortcutId={SHORTCUT_IDS.DATA_TABLE_TOGGLE_LIVE}
|
|
label={live ? 'Pause live mode' : 'Refresh data every 3 seconds'}
|
|
side="bottom"
|
|
>
|
|
<Button
|
|
variant={live ? 'default' : 'primary'}
|
|
onClick={handleToggleLive}
|
|
icon={live ? <CirclePauseIcon /> : <CirclePlayIcon />}
|
|
>
|
|
{live ? 'Pause' : 'Live'}
|
|
</Button>
|
|
</ShortcutTooltip>
|
|
<AiAssistantDropdown
|
|
label="Summarize activity"
|
|
buildPrompt={buildPrompt}
|
|
onOpenAssistant={handleSummarizeActivity}
|
|
disabled={isLoadingActivity}
|
|
loading={isLoadingActivity}
|
|
telemetrySource="database_connections"
|
|
size="tiny"
|
|
variant="default"
|
|
/>
|
|
</div>
|
|
</div>
|
|
|
|
<Overview live={live} />
|
|
<Activity live={live} />
|
|
</ReportPadding>
|
|
)
|
|
}
|