mirror of
https://github.com/supabase/supabase.git
synced 2026-10-06 01:45:10 +03:00
## What kind of change does this PR introduce? UI polish / design system: refreshed button styles, related token tweaks, and a shared floating-button plate. Resolves DEPR-652. ## What is the current behavior? Default, primary, and secondary buttons use older fills, borders, and hover treatments. Primary still leans on brand scale utilities. Default fills don’t always read as raised chrome across surfaces, and floating copy / expand / scroll controls can let busy content show through translucent fills. Call sites hand-roll `rounded-* bg-background` wrappers for that. ## What is the new behavior? Refreshes primary, default, and secondary buttons with medium-weight labels, subtle shadows and inset edges, and smoother transitions. Light-mode default buttons use a raised fill with an accent hover state, primary text is brighter, and inline keyboard shortcuts inherit the button’s colour. Adds `FloatingPlate`: an opaque `bg-popover` shell for floating default buttons (and small clusters). Migrates Studio, Docs-related patterns, www, and `ui-patterns` floaters onto it so busy content no longer shows through translucent fills. Positioning, z-index, and hover/focus reveal stay on the plate’s `className`. Use `rounded="full"` for pills. Also: - Moves primary onto semantic `--primary` / `--primary-hover` (with a light-theme override) instead of brand utility fills - Tokenises button shadows as `--button-shadow-drop` / `--button-shadow-raised` / `--button-shadow-default` on the Button base - Aligns hover direction: darken on light mode, lighten on dark mode for both default and primary - Default fill stays opaque `bg-card` in light (occlusion) and translucent `bg-muted` in dark (adapts to the local surface) - Documents fills and `FloatingPlate` on the design-system Button page (with a live example) - Scales shared radius tokens in Studio and www; medium+ Button sizes use a proportionally softer radius - Fixes www nav CTA centering (`lg:inline-flex` instead of `lg:block`) - Query detail Expand/Collapse wires `aria-expanded` / `aria-controls` | Before | After | | --- | --- | | <img width="1074" height="438" alt="CleanShot 2026-09-18 at 15 52 51@2x" src="https://github.com/user-attachments/assets/ef43da21-b053-4b7e-9ac4-ab8b428228ab" /> | <img width="1090" height="464" alt="CleanShot 2026-09-18 at 15 50 59@2x" src="https://github.com/user-attachments/assets/2ddc55fc-4c8d-499c-a280-f3db3d99023c" /> | | <img width="1082" height="446" alt="CleanShot 2026-09-18 at 15 52 35@2x" src="https://github.com/user-attachments/assets/3dd5452d-325a-4e4a-a79d-26c6c6950a31" /> | <img width="1078" height="446" alt="CleanShot 2026-09-18 at 15 51 13@2x" src="https://github.com/user-attachments/assets/93666385-3e6e-42e0-9891-9cd6bb935b67" /> | ## To test ### Design system - [Button page](https://design-system-git-chore-button-styles-supabase.vercel.app/design-system/docs/components/button): default / primary in light and dark; hover should darken on light, lighten on dark - Same page: [Floating over content](https://design-system-git-chore-button-styles-supabase.vercel.app/design-system/docs/components/button#floating-over-content) / [Floating plate](https://design-system-git-chore-button-styles-supabase.vercel.app/design-system/docs/components/button#floating-plate) example; Copy over SQL should stay opaque - Spot-check hover on a code preview Copy control ### Docs [Docs deploy preview](https://docs-git-chore-button-styles-supabase.vercel.app/docs): - [Docs homepage](https://docs-git-chore-button-styles-supabase.vercel.app/docs): top-right **Sign up** / **Dashboard** primary; menu icon beside it (default icon button) - Shrink below `lg` and open the hamburger drawer: bottom **Sign in** (default) + **Start your project** (primary) medium block buttons - Tab once for **Skip to content** (FloatingPlate) - [MCP guide](https://docs-git-chore-button-styles-supabase.vercel.app/docs/guides/ai-tools/mcp): project picker - [Apple login](https://docs-git-chore-button-styles-supabase.vercel.app/docs/guides/auth/social-login/auth-apple): **Generate Secret Key** button in the Apple Secret Generator - Optional opacity check: any guide code block Copy control (e.g. at the bottom of [Import data into Supabase](https://docs-git-chore-button-styles-supabase.vercel.app/docs/guides/database/import-data)) ### Studio [Studio deploy preview](https://studio-staging-git-chore-button-styles-supabase.vercel.app/): - **Observability → Query Performance**: open a query detail → Expand/Collapse pill + SQL Copy chip (dark: no bleed-through) - **Observability → Query Insights**: select a query → Clear query pill - **Table Editor → any table → Definition** → floating **Open in SQL Editor** - **Connect → Framework → Add files**: Copy on the code tabs (FloatingPlate; light hover follow-up is DEPR-694) - Tab once for **Skip to content** ### WWW - [www deploy preview](https://zone-www-dot-com-git-chore-button-styles-supabase.vercel.app/): nav Sign in / Start your project vertical centering; hero medium CTAs radius --------- Co-authored-by: Danny White <3104761+dnywh@users.noreply.github.com>
255 lines
9.4 KiB
TypeScript
255 lines
9.4 KiB
TypeScript
import { ChevronsUpDown, Lightbulb } from 'lucide-react'
|
|
import dynamic from 'next/dynamic'
|
|
import { useEffect, useState } from 'react'
|
|
import { Alert, AlertDescription, AlertTitle, Button, cn, FloatingPlate } from 'ui'
|
|
|
|
import { QueryPanelContainer, QueryPanelSection } from './QueryPanel'
|
|
import { buildQueryExplanationPrompt } from './QueryPerformance.ai'
|
|
import { QUERY_PERFORMANCE_COLUMNS } from './QueryPerformance.constants'
|
|
import { QueryPerformanceRow } from './QueryPerformance.types'
|
|
import { formatDuration } from './QueryPerformance.utils'
|
|
import { SIDEBAR_KEYS } from '@/components/layouts/ProjectLayout/LayoutSidebar/LayoutSidebarProvider'
|
|
import { AiAssistantDropdown } from '@/components/ui/AiAssistantDropdown'
|
|
import { formatSql } from '@/lib/formatSql'
|
|
import { useTrack } from '@/lib/telemetry/track'
|
|
import { useAiAssistantStateSnapshot } from '@/state/ai-assistant-state'
|
|
import { useSidebarManagerSnapshot } from '@/state/sidebar-manager-state'
|
|
|
|
interface QueryDetailProps {
|
|
selectedRow?: QueryPerformanceRow
|
|
onClickViewSuggestion: () => void
|
|
onClose?: () => void
|
|
}
|
|
|
|
// Load SqlMonacoBlock (monaco editor) client-side only (does not behave well server-side)
|
|
const SqlMonacoBlock = dynamic(
|
|
() => import('./SqlMonacoBlock').then(({ SqlMonacoBlock }) => SqlMonacoBlock),
|
|
{
|
|
ssr: false,
|
|
}
|
|
)
|
|
|
|
export const QueryDetail = ({ selectedRow, onClickViewSuggestion, onClose }: QueryDetailProps) => {
|
|
// [Joshen] TODO implement this logic once the linter rules are in
|
|
const isLinterWarning = false
|
|
const report = QUERY_PERFORMANCE_COLUMNS
|
|
const [query, setQuery] = useState(selectedRow?.['query'])
|
|
|
|
const { openSidebar } = useSidebarManagerSnapshot()
|
|
const aiSnap = useAiAssistantStateSnapshot()
|
|
const track = useTrack()
|
|
|
|
useEffect(() => {
|
|
if (selectedRow !== undefined) {
|
|
const formattedQuery = formatSql(selectedRow['query'])
|
|
setQuery(formattedQuery)
|
|
}
|
|
}, [selectedRow])
|
|
|
|
const [isExpanded, setIsExpanded] = useState(false)
|
|
|
|
const handleExplainQuery = () => {
|
|
if (!selectedRow?.query) return
|
|
|
|
const { query, prompt } = buildQueryExplanationPrompt(selectedRow)
|
|
|
|
openSidebar(SIDEBAR_KEYS.AI_ASSISTANT)
|
|
aiSnap.newChat({
|
|
sqlSnippets: [
|
|
{
|
|
label: 'Query',
|
|
content: query,
|
|
},
|
|
],
|
|
initialMessage: prompt,
|
|
})
|
|
|
|
track('query_performance_explain_with_ai_button_clicked')
|
|
|
|
// Close the query detail panel since we need to see the AI assistant panel
|
|
onClose?.()
|
|
}
|
|
|
|
const buildPromptForCopy = () => {
|
|
if (!selectedRow?.query) return ''
|
|
|
|
const { query, prompt } = buildQueryExplanationPrompt(selectedRow)
|
|
return `${prompt}\n\nSQL Query:\n\`\`\`sql\n${query}\n\`\`\``
|
|
}
|
|
|
|
return (
|
|
<QueryPanelContainer>
|
|
<QueryPanelSection className="pt-2 border-b relative">
|
|
<div className="flex items-center justify-between mb-4">
|
|
<h4>Query pattern</h4>
|
|
<AiAssistantDropdown
|
|
label="Explain with AI"
|
|
buildPrompt={buildPromptForCopy}
|
|
onOpenAssistant={handleExplainQuery}
|
|
telemetrySource="query_performance"
|
|
size="tiny"
|
|
variant="default"
|
|
/>
|
|
</div>
|
|
<div
|
|
id="query-detail-sql-panel"
|
|
className={cn(
|
|
'overflow-hidden pb-0 z-0 relative transition-all duration-300',
|
|
isExpanded ? 'h-[348px]' : 'h-[120px]'
|
|
)}
|
|
>
|
|
<SqlMonacoBlock
|
|
value={query}
|
|
wrapperClassName={cn('bg-surface-100', !isExpanded && 'pointer-events-none')}
|
|
/>
|
|
{isLinterWarning && (
|
|
<Alert
|
|
variant="default"
|
|
className="mt-2 border-brand-400 bg-alternative [&>svg]:p-0.5 [&>svg]:bg-transparent [&>svg]:text-primary"
|
|
>
|
|
<Lightbulb />
|
|
<AlertTitle>Suggested optimization: Add an index</AlertTitle>
|
|
<AlertDescription>
|
|
Adding an index will help this query execute faster
|
|
</AlertDescription>
|
|
<AlertDescription>
|
|
<Button variant="primary" className="mt-3" onClick={() => onClickViewSuggestion()}>
|
|
View suggestion
|
|
</Button>
|
|
</AlertDescription>
|
|
</Alert>
|
|
)}
|
|
</div>
|
|
<div
|
|
className={cn(
|
|
'absolute left-0 bottom-0 w-full bg-linear-to-t from-black/30 to-transparent h-24 transition-opacity duration-300',
|
|
isExpanded && 'opacity-0 pointer-events-none'
|
|
)}
|
|
/>
|
|
<div className="absolute bottom-[-13px] left-0 right-0 w-full flex items-center justify-center z-10">
|
|
<FloatingPlate rounded="full">
|
|
<Button
|
|
type="button"
|
|
className="rounded-full"
|
|
icon={<ChevronsUpDown />}
|
|
aria-expanded={isExpanded}
|
|
aria-controls="query-detail-sql-panel"
|
|
onClick={() => setIsExpanded(!isExpanded)}
|
|
>
|
|
{isExpanded ? 'Collapse' : 'Expand'}
|
|
</Button>
|
|
</FloatingPlate>
|
|
</div>
|
|
</QueryPanelSection>
|
|
<QueryPanelSection className="pb-3 pt-6">
|
|
<h4 className="mb-4">Metadata</h4>
|
|
<ul className="flex flex-col gap-y-3 divide-y divide-dashed">
|
|
{report
|
|
.filter((x) => x.id !== 'query')
|
|
.map((x) => {
|
|
const rawValue = selectedRow?.[x.id]
|
|
const isTime = x.name.includes('time')
|
|
|
|
const formattedValue = isTime
|
|
? typeof rawValue === 'number' && !isNaN(rawValue) && isFinite(rawValue)
|
|
? `${Math.round(rawValue).toLocaleString()}ms`
|
|
: 'n/a'
|
|
: rawValue != null
|
|
? String(rawValue)
|
|
: 'n/a'
|
|
|
|
if (x.id === 'prop_total_time') {
|
|
const percentage = selectedRow?.prop_total_time || 0
|
|
const totalTime = selectedRow?.total_time || 0
|
|
|
|
return (
|
|
<li key={x.id} className="flex justify-between pb-3 text-sm">
|
|
<p className="text-foreground-light">{x.name}</p>
|
|
{percentage && totalTime ? (
|
|
<p className="flex items-center gap-x-1.5">
|
|
<span
|
|
className={cn(
|
|
'tabular-nums',
|
|
percentage.toFixed(1) === '0.0' && 'text-foreground-lighter'
|
|
)}
|
|
>
|
|
{percentage.toFixed(1)}%
|
|
</span>{' '}
|
|
<span className="text-muted">/</span>{' '}
|
|
<span
|
|
className={cn(
|
|
'tabular-nums',
|
|
formatDuration(totalTime) === '0.00s' && 'text-foreground-lighter'
|
|
)}
|
|
>
|
|
{formatDuration(totalTime)}
|
|
</span>
|
|
</p>
|
|
) : (
|
|
<p className="text-muted">–</p>
|
|
)}
|
|
</li>
|
|
)
|
|
}
|
|
|
|
if (x.id == 'rows_read') {
|
|
return (
|
|
<li key={x.id} className="flex justify-between pb-3 text-sm">
|
|
<p className="text-foreground-light">{x.name}</p>
|
|
{typeof rawValue === 'number' && !isNaN(rawValue) && isFinite(rawValue) ? (
|
|
<p
|
|
className={cn('tabular-nums', rawValue === 0 && 'text-foreground-lighter')}
|
|
>
|
|
{rawValue.toLocaleString()}
|
|
</p>
|
|
) : (
|
|
<p className="text-muted">–</p>
|
|
)}
|
|
</li>
|
|
)
|
|
}
|
|
|
|
const cacheHitRateToNumber = (value: number | string) => {
|
|
if (typeof value === 'number') return value
|
|
return parseFloat(value.toString().replace('%', '')) || 0
|
|
}
|
|
|
|
if (x.id === 'cache_hit_rate') {
|
|
return (
|
|
<li key={x.id} className="flex justify-between pb-3 text-sm">
|
|
<p className="text-foreground-light">{x.name}</p>
|
|
{typeof rawValue === 'string' || typeof rawValue === 'number' ? (
|
|
<p
|
|
className={cn(
|
|
cacheHitRateToNumber(rawValue).toFixed(2) === '0.00' &&
|
|
'text-foreground-lighter'
|
|
)}
|
|
>
|
|
{cacheHitRateToNumber(rawValue).toLocaleString(undefined, {
|
|
minimumFractionDigits: 2,
|
|
maximumFractionDigits: 2,
|
|
})}
|
|
%
|
|
</p>
|
|
) : (
|
|
<p className="text-muted">–</p>
|
|
)}
|
|
</li>
|
|
)
|
|
}
|
|
|
|
return (
|
|
<li key={x.id} className="flex justify-between pb-3 text-sm">
|
|
<p className="text-foreground-light">{x.name}</p>
|
|
<p className={cn('tabular-nums', x.id === 'rolname' && 'font-mono')}>
|
|
{formattedValue}
|
|
</p>
|
|
</li>
|
|
)
|
|
})}
|
|
</ul>
|
|
</QueryPanelSection>
|
|
</QueryPanelContainer>
|
|
)
|
|
}
|