Files
supabase/apps/studio/components/ui/HighQueryCost.tsx
Alaister Young ca2b50a0a7 chore(ui-patterns): collapse the admonition shim into ui-patterns/Admonition (#48377)
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>
2026-07-29 00:48:56 +08:00

184 lines
5.9 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import {
Button,
Dialog,
DialogClose,
DialogContent,
DialogDescription,
DialogFooter,
DialogHeader,
DialogSection,
DialogSectionSeparator,
DialogTitle,
DialogTrigger,
Tooltip,
TooltipContent,
TooltipTrigger,
} from 'ui'
import { Admonition } from 'ui-patterns/Admonition'
import { DocsButton } from './DocsButton'
import { InlineLinkClassName } from './InlineLink'
import { DOCS_URL } from '@/lib/constants'
import { ResponseError } from '@/types'
interface HighQueryCostErrorProps {
error: ResponseError
suggestions?: string[]
onSelectLoadData?: () => void
}
export const HighCostError = ({
error,
suggestions,
onSelectLoadData,
}: HighQueryCostErrorProps) => {
return (
<Admonition
type="default"
title="Data not loaded to protect database performance"
description="The query to retrieve the data was not run as it could place heavy load on the database and impact performance"
>
<div className="mt-2 flex items-center gap-x-2 items-center">
{!!onSelectLoadData && (
<LoadDataWarningDialog error={error} onSelectLoadData={onSelectLoadData} />
)}
<HighQueryCostDialog error={error} suggestions={suggestions} />
</div>
</Admonition>
)
}
const HighQueryCostDialog = ({ error, suggestions = [] }: HighQueryCostErrorProps) => {
const metadata = error.metadata
return (
<Dialog>
<DialogTrigger asChild>
<Button variant="outline">Learn more</Button>
</DialogTrigger>
<DialogContent onOpenAutoFocus={(event) => event.preventDefault()}>
<DialogHeader>
<DialogTitle>Estimated query cost exceeds safety thresholds</DialogTitle>
<DialogDescription>
Preventive measure to mitigate impacting the database
</DialogDescription>
</DialogHeader>
<DialogSectionSeparator />
<DialogSection className="flex flex-col gap-y-2 text-sm">
<p>
The dashboard runs optimized SQL queries on your projects database to load data for
this interface.
</p>
<p>
However, the query was skipped as its{' '}
<Tooltip>
<TooltipTrigger className={InlineLinkClassName}>estimated cost</TooltipTrigger>
<TooltipContent side="bottom" className="flex flex-col gap-y-1">
<p>Estimated cost: {metadata?.cost.toLocaleString()}</p>
<p className="text-foreground-light">
Determined via the <code className="text-code-inline">EXPLAIN</code> command
</p>
</TooltipContent>
</Tooltip>{' '}
is high and could place significant load on the database with high disk I/O or CPU
usage.
</p>
</DialogSection>
{suggestions.length > 0 && (
<>
<DialogSectionSeparator />
<DialogSection className="flex flex-col gap-y-4 text-sm">
<p className="font-mono text-foreground-lighter uppercase tracking-tight text-sm">
Suggested steps
</p>
{suggestions.length > 0 && (
<div className="flex flex-col gap-y-1">
<p>You may check the following to lower the cost of the query</p>
<ul className="list-disc pl-6">
{suggestions.map((x) => (
<li key={x}>{x}</li>
))}
</ul>
</div>
)}
</DialogSection>
</>
)}
<DialogFooter>
<DocsButton
href={`${DOCS_URL}/guides/troubleshooting/understanding-postgresql-explain-output-Un9dqX`}
/>
<DialogClose asChild>
<Button variant="default" className="opacity-100">
Understood
</Button>
</DialogClose>
</DialogFooter>
</DialogContent>
</Dialog>
)
}
const LoadDataWarningDialog = ({
error,
onSelectLoadData,
}: {
error: ResponseError
onSelectLoadData: () => void
}) => {
const metadata = error.metadata
return (
<Dialog>
<DialogTrigger asChild>
<Button variant="default">Load data</Button>
</DialogTrigger>
<DialogContent onOpenAutoFocus={(event) => event.preventDefault()}>
<DialogHeader>
<DialogTitle>Confirm to proceed loading data</DialogTitle>
<DialogDescription>
Preventive measure to mitigate impacting the database
</DialogDescription>
</DialogHeader>
<DialogSectionSeparator />
<DialogSection className="flex flex-col gap-y-2 text-sm">
<p>
The query to load your table's data was initially skipped as its{' '}
<Tooltip>
<TooltipTrigger className={InlineLinkClassName}>estimated cost</TooltipTrigger>
<TooltipContent side="bottom" className="flex flex-col gap-y-1">
<p>Estimated cost: {metadata?.cost.toLocaleString()}</p>
<p className="text-foreground-light">
Determined via the <code className="text-code-inline">EXPLAIN</code> command
</p>
</TooltipContent>
</Tooltip>{' '}
is high and could place significant load on the database with high disk I/O or CPU
usage.
</p>
<p>
You may proceed to run the query, and we'll suppress this warning for this table for the
rest of this browser session.
</p>
</DialogSection>
<DialogFooter>
<DialogClose asChild>
<Button variant="default" className="opacity-100">
Cancel
</Button>
</DialogClose>
<DialogClose asChild>
<Button variant="warning" onClick={() => onSelectLoadData()}>
I understand, proceed
</Button>
</DialogClose>
</DialogFooter>
</DialogContent>
</Dialog>
)
}