mirror of
https://github.com/supabase/supabase.git
synced 2026-10-06 01:45:10 +03:00
## Problem Primary colour serves readable text and selected controls, but those uses need different shades. Light mode needs darker text, while dark mode needs a deeper button fill. Fixed brand green on interactive chrome also prevents a custom primary hue from carrying through the interface. Some slider tracks and selected text are hard to read. ## Solution - Keep `--primary` for accessible text and small selected indicators. Use `--primary-solid` for button fills, which need a deeper shade in dark mode. - Add `--primary-bright` for focus rings, selected control chrome, chart accents, and other interactive highlights. It follows `--primary-hue`; `brand-*` stays fixed for Supabase identity. - Make slider troughs clearer and text selection translucent with theme foreground text. - Document the split in the design-system colour guide. | Before | After | | --- | --- | | <img width="980" height="244" alt="Before: light mode primary controls" src="https://github.com/user-attachments/assets/dfae325d-0dfe-4231-8bcd-3f89c4b9d793" /> | <img width="982" height="204" alt="After: light mode primary controls" src="https://github.com/user-attachments/assets/5fdcb531-a6e3-4549-8a13-9d9a5ebe6e20" /> | | <img width="610" height="120" alt="Before: slider track" src="https://github.com/user-attachments/assets/04f768e0-51e8-4d06-9b97-c52f4a34f122" /> | <img width="622" height="126" alt="After: slider track" src="https://github.com/user-attachments/assets/95127f4e-13dc-4f0f-b63c-cf5d70a28b42" /> | | <img width="652" height="512" alt="Before: dark mode controls" src="https://github.com/user-attachments/assets/3f88de66-90cc-40ee-8cf1-b5f4eb87b09a" /> | <img width="658" height="498" alt="After: dark mode controls" src="https://github.com/user-attachments/assets/906bec30-6ca1-4614-9fb3-6cf5e5feec22" /> | ## Review instructions 1. Compare light and dark mode in the [colour usage guide](https://design-system-git-dnywh-fix-bright-brand-chrome-supabase.vercel.app/design-system/docs/color-usage#primary-and-brand-colors). Check primary ink, primary-solid, primary-bright, and fixed brand swatches. 2. In Studio, open the ‘new table’ sheet in [Table Editor](https://studio-staging-git-dnywh-fix-bright-brand-chrome-supabase.vercel.app/dashboard/project/_/editor). Tab through the new table sheet's fields and toggles. Check the focus rings, selected controls, and the sheet's edges in both themes. You do not need to save a table. 3. Select text in Studio in both themes, including a link or primary-coloured label. The selection and text should remain legible. 4. Check the [Field](https://design-system-git-dnywh-fix-bright-brand-chrome-supabase.vercel.app/design-system/docs/components/field) Price Range slider: the unused track should remain visible in both themes. The selected field card border should follow primary-bright. 5. Check the [Button](https://design-system-git-dnywh-fix-bright-brand-chrome-supabase.vercel.app/design-system/docs/components/button) and [Radio Group](https://design-system-git-dnywh-fix-bright-brand-chrome-supabase.vercel.app/design-system/docs/components/radio-group) previews. In dark mode, `primary` button fill should be deeper than primary [text](https://design-system-git-dnywh-fix-bright-brand-chrome-supabase.vercel.app/design-system/docs/color-usage#text); selected radios should remain readable.
328 lines
10 KiB
TypeScript
328 lines
10 KiB
TypeScript
import { useParams } from 'common'
|
|
import dayjs from 'dayjs'
|
|
import { Activity, BarChart2, Database } from 'lucide-react'
|
|
import { useMemo } from 'react'
|
|
import type { ChartConfig } from 'ui'
|
|
import { cn } from 'ui'
|
|
import {
|
|
Chart,
|
|
ChartCard,
|
|
ChartContent,
|
|
ChartEmptyState,
|
|
ChartHeader,
|
|
ChartLine,
|
|
ChartLoadingState,
|
|
ChartMetric,
|
|
} from 'ui-patterns/Chart'
|
|
|
|
import {
|
|
buildUsageChartData,
|
|
formatUsagePercent,
|
|
getComputeUsageSummary,
|
|
getDiskUsageSummary,
|
|
getUsageMetricStatus,
|
|
type UsageMetricStatus,
|
|
} from './ComputeAndDiskUsageCharts.utils'
|
|
import { hasBurstableIO } from './DiskManagement.utils'
|
|
import type { InfraMonitoringAttribute } from '@/data/analytics/infra-monitoring-query'
|
|
import {
|
|
getInfraMonitoringAttributes,
|
|
useInfraMonitoringAttributesQuery,
|
|
} from '@/data/analytics/infra-monitoring-query'
|
|
import { useSelectedProjectQuery } from '@/hooks/misc/useSelectedProject'
|
|
import { formatBytes } from '@/lib/helpers'
|
|
|
|
const USAGE_ATTRIBUTES = [
|
|
'max_cpu_usage',
|
|
'ram_usage',
|
|
'disk_io_consumption',
|
|
'disk_fs_used_system',
|
|
'disk_fs_used_wal',
|
|
'pg_database_size',
|
|
'disk_fs_size',
|
|
] satisfies InfraMonitoringAttribute[]
|
|
|
|
const ROLLING_WINDOW_DAYS = 7
|
|
|
|
const getRollingWindow = () => {
|
|
const now = dayjs()
|
|
|
|
return {
|
|
startDate: now.subtract(ROLLING_WINDOW_DAYS, 'day').toISOString(),
|
|
endDate: now.toISOString(),
|
|
}
|
|
}
|
|
|
|
const COMPUTE_CHART_CONFIG = {
|
|
maxCpuUsage: {
|
|
label: 'CPU',
|
|
color: 'var(--primary-bright)',
|
|
},
|
|
ramUsage: {
|
|
label: 'Memory',
|
|
color: 'hsl(var(--warning-default))',
|
|
},
|
|
diskIoConsumption: {
|
|
label: 'Disk IO',
|
|
color: 'hsl(var(--destructive-500))',
|
|
},
|
|
} satisfies ChartConfig
|
|
|
|
const DISK_CHART_CONFIG = {
|
|
databaseUsagePercent: {
|
|
label: 'Database',
|
|
color: 'var(--primary-bright)',
|
|
},
|
|
walUsagePercent: {
|
|
label: 'WAL',
|
|
color: 'hsl(var(--warning-default))',
|
|
},
|
|
systemUsagePercent: {
|
|
label: 'System',
|
|
color: 'hsl(var(--destructive-500))',
|
|
},
|
|
} satisfies ChartConfig
|
|
|
|
const PERCENTAGE_Y_AXIS_PROPS = {
|
|
domain: [0, 100] as [number, number],
|
|
allowDataOverflow: true,
|
|
ticks: [0, 25, 50, 75, 100],
|
|
tickFormatter: (value: number) => `${Math.round(Number(value))}%`,
|
|
width: 64,
|
|
}
|
|
|
|
const getUsageCardClassName = (status: UsageMetricStatus) =>
|
|
cn(
|
|
'h-full flex flex-col transition-colors',
|
|
status === 'warning' && 'border-warning-400 bg-warning-200/30',
|
|
status === 'negative' && 'border-destructive-400 bg-destructive-200/30'
|
|
)
|
|
|
|
export const ComputeAndDiskUsageCharts = ({ className }: { className?: string }) => {
|
|
const { ref: projectRef } = useParams()
|
|
const { data: project } = useSelectedProjectQuery()
|
|
const supportsBurstableIO = hasBurstableIO(project?.infra_compute_size)
|
|
|
|
// Anchor query key dates to mount time; fetch uses a rolling 7-day window on each refetch.
|
|
const { startDate, endDate } = useMemo(getRollingWindow, [])
|
|
|
|
const {
|
|
data: usageData,
|
|
isLoading,
|
|
isError,
|
|
} = useInfraMonitoringAttributesQuery(
|
|
{
|
|
projectRef,
|
|
attributes: USAGE_ATTRIBUTES,
|
|
startDate,
|
|
endDate,
|
|
interval: '1d',
|
|
},
|
|
{
|
|
queryFn: ({ signal }) =>
|
|
getInfraMonitoringAttributes(
|
|
{
|
|
projectRef,
|
|
attributes: USAGE_ATTRIBUTES,
|
|
...getRollingWindow(),
|
|
interval: '1d',
|
|
},
|
|
signal
|
|
),
|
|
}
|
|
)
|
|
|
|
const { computeChartData, diskChartData } = useMemo(
|
|
() => buildUsageChartData(usageData),
|
|
[usageData]
|
|
)
|
|
|
|
const {
|
|
peakCpuUsage,
|
|
peakMemoryUsage,
|
|
peakDiskIoUsage,
|
|
peakComputeUsage,
|
|
status: computeUsageStatus,
|
|
} = useMemo(
|
|
() => getComputeUsageSummary(computeChartData, supportsBurstableIO),
|
|
[computeChartData, supportsBurstableIO]
|
|
)
|
|
|
|
const {
|
|
latestDataPoint: latestDiskDataPoint,
|
|
usagePercent: latestDiskUsage,
|
|
status: diskUsageStatus,
|
|
} = useMemo(() => getDiskUsageSummary(diskChartData), [diskChartData])
|
|
|
|
const isComputeEmpty = computeChartData.length === 0
|
|
const isDiskEmpty = diskChartData.length === 0
|
|
|
|
return (
|
|
<div
|
|
className={cn(
|
|
'grid grid-cols-1 gap-4 @[680px]:grid-cols-2 @[680px]:items-stretch',
|
|
className
|
|
)}
|
|
>
|
|
<div id="cpu" className="scroll-mt-24 h-full min-h-0">
|
|
<span id="ram" className="block h-0 scroll-mt-24" aria-hidden />
|
|
<span id="disk_io" className="block h-0 scroll-mt-24" aria-hidden />
|
|
<Chart isLoading={isLoading} isErrored={isError} className="h-full">
|
|
<ChartCard className={getUsageCardClassName(computeUsageStatus)}>
|
|
<ChartHeader align="start" className="min-h-[5.5rem]">
|
|
<ChartMetric
|
|
label="Compute"
|
|
tooltip={
|
|
supportsBurstableIO
|
|
? 'Peak CPU, memory, and disk IO usage over the last 7 days. Sustained high usage may require a larger compute size.'
|
|
: 'Peak CPU and memory usage over the last 7 days. Sustained high usage may require a larger compute size.'
|
|
}
|
|
value={formatUsagePercent(peakComputeUsage)}
|
|
status={computeUsageStatus}
|
|
/>
|
|
<div className="flex flex-wrap items-center gap-6">
|
|
<ChartMetric
|
|
label="CPU"
|
|
value={formatUsagePercent(peakCpuUsage)}
|
|
status={getUsageMetricStatus(peakCpuUsage)}
|
|
align="end"
|
|
/>
|
|
<ChartMetric
|
|
label="Memory"
|
|
value={formatUsagePercent(peakMemoryUsage)}
|
|
status={getUsageMetricStatus(peakMemoryUsage)}
|
|
align="end"
|
|
/>
|
|
{supportsBurstableIO && (
|
|
<ChartMetric
|
|
label="Disk IO"
|
|
value={formatUsagePercent(peakDiskIoUsage)}
|
|
status={getUsageMetricStatus(peakDiskIoUsage)}
|
|
align="end"
|
|
/>
|
|
)}
|
|
</div>
|
|
</ChartHeader>
|
|
<ChartContent
|
|
className="p-0"
|
|
isEmpty={isComputeEmpty}
|
|
loadingState={<ChartLoadingState className="h-48 border-x-0 border-b-0" />}
|
|
errorState={
|
|
<ChartEmptyState
|
|
className="h-48 border-x-0 border-b-0"
|
|
icon={<Activity size={16} />}
|
|
title="Failed to load usage data"
|
|
/>
|
|
}
|
|
emptyState={
|
|
<ChartEmptyState
|
|
className="h-48 border-x-0 border-b-0"
|
|
icon={<Activity size={16} />}
|
|
title="No compute data"
|
|
description="Usage data may take a few minutes to appear."
|
|
/>
|
|
}
|
|
>
|
|
<div className="h-48 px-card pb-4 pt-2">
|
|
<ChartLine
|
|
data={computeChartData}
|
|
dataKey="maxCpuUsage"
|
|
dataKeys={
|
|
supportsBurstableIO
|
|
? ['maxCpuUsage', 'ramUsage', 'diskIoConsumption']
|
|
: ['maxCpuUsage', 'ramUsage']
|
|
}
|
|
DateTimeFormat="MMM D"
|
|
isFullHeight
|
|
showGrid
|
|
showYAxis
|
|
config={COMPUTE_CHART_CONFIG}
|
|
YAxisProps={PERCENTAGE_Y_AXIS_PROPS}
|
|
/>
|
|
</div>
|
|
</ChartContent>
|
|
</ChartCard>
|
|
</Chart>
|
|
</div>
|
|
|
|
<div id="disk" className="scroll-mt-24 h-full min-h-0">
|
|
<Chart isLoading={isLoading} isErrored={isError} className="h-full">
|
|
<ChartCard className={getUsageCardClassName(diskUsageStatus)}>
|
|
<ChartHeader align="start" className="min-h-[5.5rem]">
|
|
<ChartMetric
|
|
label="Disk"
|
|
tooltip="Provisioned disk and used disk split by database, WAL, and system usage over the last 7 days."
|
|
value={formatUsagePercent(latestDiskUsage)}
|
|
status={diskUsageStatus}
|
|
/>
|
|
<div className="flex flex-wrap items-center gap-6">
|
|
<ChartMetric
|
|
label="Database"
|
|
value={
|
|
latestDiskDataPoint === undefined
|
|
? '—'
|
|
: formatBytes(latestDiskDataPoint.databaseBytes, 1)
|
|
}
|
|
align="end"
|
|
/>
|
|
<ChartMetric
|
|
label="WAL"
|
|
value={
|
|
latestDiskDataPoint === undefined
|
|
? '—'
|
|
: formatBytes(latestDiskDataPoint.walBytes, 1)
|
|
}
|
|
align="end"
|
|
/>
|
|
<ChartMetric
|
|
label="System"
|
|
value={
|
|
latestDiskDataPoint === undefined
|
|
? '—'
|
|
: formatBytes(latestDiskDataPoint.systemBytes, 1)
|
|
}
|
|
align="end"
|
|
/>
|
|
</div>
|
|
</ChartHeader>
|
|
<ChartContent
|
|
className="p-0"
|
|
isEmpty={isDiskEmpty}
|
|
loadingState={<ChartLoadingState className="h-48 border-x-0 border-b-0" />}
|
|
errorState={
|
|
<ChartEmptyState
|
|
className="h-48 border-x-0 border-b-0"
|
|
icon={<BarChart2 size={16} />}
|
|
title="Failed to load usage data"
|
|
/>
|
|
}
|
|
emptyState={
|
|
<ChartEmptyState
|
|
className="h-48 border-x-0 border-b-0"
|
|
icon={<Database size={16} />}
|
|
title="No disk data"
|
|
description="Disk metrics may take a few minutes to appear."
|
|
/>
|
|
}
|
|
>
|
|
<div className="h-48 px-card pb-4 pt-2">
|
|
<ChartLine
|
|
data={diskChartData}
|
|
dataKey="databaseUsagePercent"
|
|
dataKeys={['databaseUsagePercent', 'walUsagePercent', 'systemUsagePercent']}
|
|
DateTimeFormat="MMM D"
|
|
isFullHeight
|
|
showGrid
|
|
showYAxis
|
|
config={DISK_CHART_CONFIG}
|
|
YAxisProps={PERCENTAGE_Y_AXIS_PROPS}
|
|
/>
|
|
</div>
|
|
</ChartContent>
|
|
</ChartCard>
|
|
</Chart>
|
|
</div>
|
|
</div>
|
|
)
|
|
}
|