Files
Alaister YoungandAlaister Young 96e4543ea9 [FE-3106] (part 9) – refactor(studio): move logs and observability page bodies (#53218)
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>
2026-11-17 16:24:24 +09:00

81 lines
2.5 KiB
TypeScript

import { useEffect } from 'react'
const CHART_LAYOUT_OBSERVATION_DURATION = 10_000
const CHART_LAYOUT_OBSERVATION_CANCEL_EVENTS = [
'keydown',
'pointerdown',
'touchstart',
'wheel',
] as const
const isChartFullyVisible = (target: HTMLElement) => {
const targetBounds = target.getBoundingClientRect()
const scrollContainerBounds = target.closest('main')?.getBoundingClientRect()
const viewportTop = scrollContainerBounds?.top ?? 0
const viewportBottom = scrollContainerBounds?.bottom ?? window.innerHeight
return targetBounds.top >= viewportTop && targetBounds.bottom <= viewportBottom
}
export const useDatabaseChartDeepLink = (chart?: string) => {
useEffect(() => {
if (chart === undefined) return
let chartTargetObserver: MutationObserver | undefined
let resizeObserver: ResizeObserver | undefined
let stopObservingTimer: number | undefined
const stopDeepLink = () => {
if (stopObservingTimer !== undefined) window.clearTimeout(stopObservingTimer)
chartTargetObserver?.disconnect()
resizeObserver?.disconnect()
CHART_LAYOUT_OBSERVATION_CANCEL_EVENTS.forEach((eventName) =>
window.removeEventListener(eventName, stopDeepLink, true)
)
}
CHART_LAYOUT_OBSERVATION_CANCEL_EVENTS.forEach((eventName) =>
window.addEventListener(eventName, stopDeepLink, true)
)
const scrollToChart = () => {
const target = document.getElementById(chart)
if (target === null) return false
chartTargetObserver?.disconnect()
target.scrollIntoView({ behavior: 'smooth', block: 'center' })
const chartList = target.parentElement
if (chartList === null) return true
resizeObserver = new ResizeObserver(() => {
if (!isChartFullyVisible(target)) {
target.scrollIntoView({ behavior: 'auto', block: 'center' })
}
})
resizeObserver.observe(chartList)
stopObservingTimer = window.setTimeout(stopDeepLink, CHART_LAYOUT_OBSERVATION_DURATION)
return true
}
if (!scrollToChart()) {
chartTargetObserver = new MutationObserver(scrollToChart)
chartTargetObserver.observe(document.body, { childList: true, subtree: true })
}
return stopDeepLink
}, [chart])
}
export const useDatabaseSelectionFromUrl = (
db: string | undefined,
setSelectedDatabaseId: (databaseId: string) => void
) => {
useEffect(() => {
if (db === undefined) return
const timeout = window.setTimeout(() => setSelectedDatabaseId(db), 100)
return () => window.clearTimeout(timeout)
}, [db, setSelectedDatabaseId])
}