The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
Update styling for project usage charts
Joshen Lim490d7fa9dd26
diff --git a/studio/components/interfaces/Home/ChartData.types.ts b/studio/components/interfaces/Home/ChartData.types.tsindex 856c275ff43..52e728baccc 100644--- a/studio/components/interfaces/Home/ChartData.types.ts+++ b/studio/components/interfaces/Home/ChartData.types.ts@@ -4,14 +4,13 @@ export interface StatusCodesDatum {count: number}export interface PathsDatum {- timestamp: number- path: string- query_params: string- count: number- method: string- avg_origin_time: number- }-+ timestamp: number+ path: string+ query_params: string+ count: number+ method: string+ avg_origin_time: number+}export interface EndpointResponse<T> {result: Array<T>diff --git a/studio/components/interfaces/Home/ProjectUsage.tsx b/studio/components/interfaces/Home/ProjectUsage.tsxindex 7fbda487d88..9df61bb3200 100644--- a/studio/components/interfaces/Home/ProjectUsage.tsx+++ b/studio/components/interfaces/Home/ProjectUsage.tsx@@ -18,11 +18,12 @@ import Panel from 'components/to-be-cleaned/Panel'import ChartHandler from 'components/to-be-cleaned/Charts/ChartHandler'import { ProjectUsageMinimal } from 'components/to-be-cleaned/Usage'+import { useFlag } from 'hooks'import { get } from 'lib/common/fetch'import { API_URL, METRICS, DATE_FORMAT } from 'lib/constants'-import { useFlag } from 'hooks'-import StackedAreaChart from 'components/ui/charts/StackedAreaChart'import Table from 'components/to-be-cleaned/Table'+import StackedAreaChart from 'components/ui/ChartComponents/StackedAreaChart'+import { USAGE_COLORS } from 'components/ui/ChartComponents/Charts.constants'import { EndpointResponse, PathsDatum, StatusCodesDatum } from './ChartData.types'const CHART_INTERVALS = [@@ -47,10 +48,12 @@ const ProjectUsage: FC<Props> = ({ project }) => {`${API_URL}/projects/${ref}/analytics/endpoints/usage.api-codes?interval=${interval}`,get)+const { data: pathsData, error: _pathsFetchError }: any = useSWR<EndpointResponse<PathsDatum>>(`${API_URL}/projects/${ref}/analytics/endpoints/usage.api-paths?interval=${interval}`,get)+const selectedInterval = logsUsageChartIntervals? CHART_INTERVALS.find((i) => i.key === interval) || CHART_INTERVALS[1]: CHART_INTERVALS[2]@@ -101,174 +104,186 @@ const ProjectUsage: FC<Props> = ({ project }) => {</div><div className="">{startDate && endDate && (- <div className="grid lg:grid-cols-4 lg:gap-8">- <Panel key="database-chart">- <Panel.Content className="space-y-4">- <PanelHeader- icon={<IconDatabase size="small" />}- title="Database"- href={`/project/${ref}/editor`}- />- <ChartHandler- startDate={startDate}- endDate={endDate}- attribute={'total_rest_requests'}- label={METRICS.find((x: any) => x.key == 'total_rest_requests')?.label ?? ''}- provider="log-stats"- interval="1d"- hideChartType- customDateFormat={datetimeFormat}- data={charts}- isLoading={!charts && !error ? true : false}- onBarClick={(v) => handleBarClick(v, '/rest')}- />- <ProjectUsageMinimal- projectRef={project.ref}- subscription_id={project.subscription_id}- filter="Database"- />- </Panel.Content>- </Panel>- <Panel key="auth-chart">- <Panel.Content className="space-y-4">- <PanelHeader- icon={<IconKey size="small" />}- title="Auth"- href={`/project/${ref}/auth/users`}- />- <ChartHandler- startDate={startDate}- endDate={endDate}- attribute={'total_auth_requests'}- label={METRICS.find((x) => x.key == 'total_auth_requests')?.label ?? ''}- provider="log-stats"- interval="1d"- hideChartType- customDateFormat={datetimeFormat}- data={charts}- isLoading={!charts && !error ? true : false}- onBarClick={(v) => handleBarClick(v, '/auth')}- />- <ProjectUsageMinimal- projectRef={project.ref}- subscription_id={project.subscription_id}- filter="Auth"- />- </Panel.Content>- </Panel>- <Panel key="storage-chart">- <Panel.Content className="space-y-4">- <PanelHeader- icon={<IconArchive size="small" />}- title="Storage"- href={`/project/${ref}/storage/buckets`}- />- <ChartHandler- startDate={startDate}- endDate={endDate}- attribute={'total_storage_requests'}- label={METRICS.find((x) => x.key == 'total_storage_requests')?.label ?? ''}- provider="log-stats"- interval="1d"- hideChartType- customDateFormat={datetimeFormat}- data={charts}- isLoading={!charts && !error ? true : false}- onBarClick={(v) => handleBarClick(v, '/storage')}- />- <ProjectUsageMinimal- projectRef={project.ref}- subscription_id={project.subscription_id}- filter="File storage"- />- </Panel.Content>- </Panel>- <Panel key="realtime-chart">- <Panel.Content className="space-y-4">- <PanelHeader icon={<IconZap size="small" />} title="Realtime" />- <ChartHandler- startDate={startDate}- endDate={endDate}- attribute={'total_realtime_requests'}- label={METRICS.find((x: any) => x.key == 'total_realtime_requests')?.label ?? ''}- provider="log-stats"- interval="1h"- hideChartType- customDateFormat={datetimeFormat}- data={charts}- isLoading={!charts && !error ? true : false}- onBarClick={(v) => handleBarClick(v, '/realtime')}- />- {/* Empty space just so the cards are of the same height */}- <div className="py-[26px]" />- {/* <ProjectUsageMinimal+ <>+ <div className="grid lg:grid-cols-4 lg:gap-8">+ <Panel key="database-chart">+ <Panel.Content className="space-y-4">+ <PanelHeader+ icon={<IconDatabase size="small" />}+ title="Database"+ href={`/project/${ref}/editor`}+ />+ <ChartHandler+ startDate={startDate}+ endDate={endDate}+ attribute={'total_rest_requests'}+ label={METRICS.find((x: any) => x.key == 'total_rest_requests')?.label ?? ''}+ provider="log-stats"+ interval="1d"+ hideChartType+ customDateFormat={datetimeFormat}+ data={charts}+ isLoading={!charts && !error ? true : false}+ onBarClick={(v) => handleBarClick(v, '/rest')}+ />+ <ProjectUsageMinimal+ projectRef={project.ref}+ subscription_id={project.subscription_id}+ filter="Database"+ />+ </Panel.Content>+ </Panel>+ <Panel key="auth-chart">+ <Panel.Content className="space-y-4">+ <PanelHeader+ icon={<IconKey size="small" />}+ title="Auth"+ href={`/project/${ref}/auth/users`}+ />+ <ChartHandler+ startDate={startDate}+ endDate={endDate}+ attribute={'total_auth_requests'}+ label={METRICS.find((x) => x.key == 'total_auth_requests')?.label ?? ''}+ provider="log-stats"+ interval="1d"+ hideChartType+ customDateFormat={datetimeFormat}+ data={charts}+ isLoading={!charts && !error ? true : false}+ onBarClick={(v) => handleBarClick(v, '/auth')}+ />+ <ProjectUsageMinimal+ projectRef={project.ref}+ subscription_id={project.subscription_id}+ filter="Auth"+ />+ </Panel.Content>+ </Panel>+ <Panel key="storage-chart">+ <Panel.Content className="space-y-4">+ <PanelHeader+ icon={<IconArchive size="small" />}+ title="Storage"+ href={`/project/${ref}/storage/buckets`}+ />+ <ChartHandler+ startDate={startDate}+ endDate={endDate}+ attribute={'total_storage_requests'}+ label={METRICS.find((x) => x.key == 'total_storage_requests')?.label ?? ''}+ provider="log-stats"+ interval="1d"+ hideChartType+ customDateFormat={datetimeFormat}+ data={charts}+ isLoading={!charts && !error ? true : false}+ onBarClick={(v) => handleBarClick(v, '/storage')}+ />+ <ProjectUsageMinimal+ projectRef={project.ref}+ subscription_id={project.subscription_id}+ filter="File storage"+ />+ </Panel.Content>+ </Panel>+ <Panel key="realtime-chart">+ <Panel.Content className="space-y-4">+ <PanelHeader icon={<IconZap size="small" />} title="Realtime" />+ <ChartHandler+ startDate={startDate}+ endDate={endDate}+ attribute={'total_realtime_requests'}+ label={+ METRICS.find((x: any) => x.key == 'total_realtime_requests')?.label ?? ''+ }+ provider="log-stats"+ interval="1h"+ hideChartType+ customDateFormat={datetimeFormat}+ data={charts}+ isLoading={!charts && !error ? true : false}+ onBarClick={(v) => handleBarClick(v, '/realtime')}+ />+ {/* Empty space just so the cards are of the same height */}+ <div className="py-[26px]" />+ {/* <ProjectUsageMinimalprojectRef={project.ref}subscription_id={project.subscription_id}filter="Connection requests"/> */}- </Panel.Content>- </Panel>- <Panel className="col-start-1 col-span-2" wrapWithLoading={false}>- <Panel.Content className="space-y-4">- <PanelHeader title="API Status Codes" />- <StackedAreaChart- dateFormat={datetimeFormat}- data={codesData?.result}- stackKey="status_code"- xAxisKey="timestamp"- yAxisKey="count"- isLoading={!codesData && !codesFetchError ? true : false}- xAxisFormatAsDate- size="large"- styleMap={{- 200: { stroke: '#08cc49', fill: '#0bee56' },- 201: { stroke: '#0ad83a', fill: '#0ce43e' },- 400: { stroke: '#d2b40a', fill: '#e2c10a' },- 401: { stroke: '#cc940e ', fill: '#dfa210 ' },- 404: { stroke: '#d0a40a', fill: '#dfb00b' },- 500: { stroke: '#d56d0c', fill: '#e0740e' },- }}- />- </Panel.Content>- </Panel>-- <Panel- className="col-start-3 col-span-2 pb-0"- bodyClassName="h-full"- wrapWithLoading={false}- >- <Panel.Content className="space-y-4">- <PanelHeader title="Top Routes" />- <Table- head={- <>- <Table.th>Path</Table.th>- <Table.th>Count</Table.th>- <Table.th>Avg. Latency (ms)</Table.th>- </>- }- body={- <>- {(pathsData?.result || []).map((row: PathsDatum) => (- <Table.tr>- <Table.td>- <span- className={`bg-gray-500 text-gray-200 rounded p-1 mr-2 text-xs font-mono`}- >- {row.method}- </span>- {row.path}- </Table.td>- <Table.td>{row.count}</Table.td>- <Table.td>{Number(row.avg_origin_time).toFixed(2)}</Table.td>- </Table.tr>- ))}- </>- }- />- </Panel.Content>- </Panel>- </div>+ </Panel.Content>+ </Panel>+ </div>+ <div className="grid lg:grid-cols-4 lg:gap-8">+ <Panel+ key="api-status-codes"+ className="col-start-1 col-span-2"+ wrapWithLoading={false}+ >+ <Panel.Content className="space-y-4">+ <PanelHeader title="API Status Codes" />+ <StackedAreaChart+ dateFormat={datetimeFormat}+ data={codesData?.result}+ stackKey="status_code"+ xAxisKey="timestamp"+ yAxisKey="count"+ isLoading={!codesData && !codesFetchError ? true : false}+ xAxisFormatAsDate+ size="large"+ styleMap={{+ 200: { stroke: USAGE_COLORS['200'], fill: USAGE_COLORS['200'] },+ 201: { stroke: USAGE_COLORS['201'], fill: USAGE_COLORS['201'] },+ 400: { stroke: USAGE_COLORS['400'], fill: USAGE_COLORS['400'] },+ 401: { stroke: USAGE_COLORS['401'], fill: USAGE_COLORS['401'] },+ 404: { stroke: USAGE_COLORS['404'], fill: USAGE_COLORS['404'] },+ 500: { stroke: USAGE_COLORS['500'], fill: USAGE_COLORS['500'] },+ }}+ />+ </Panel.Content>+ </Panel>+ <Panel+ key="top-routes"+ className="col-start-3 col-span-2 pb-0"+ bodyClassName="h-full"+ wrapWithLoading={false}+ >+ <Panel.Content className="space-y-4">+ <PanelHeader title="Top Routes" />+ <Table+ head={+ <>+ <Table.th>Path</Table.th>+ <Table.th>Count</Table.th>+ <Table.th>Avg. Latency (ms)</Table.th>+ </>+ }+ body={+ <>+ {(pathsData?.result ?? []).map((row: PathsDatum) => (+ <Table.tr>+ <Table.td className="flex items-center">+ <div className="w-[60px]">+ <Typography.Text code small>+ {row.method}+ </Typography.Text>+ </div>+ <Typography.Text className="font-mono" small>+ {row.path}+ </Typography.Text>+ </Table.td>+ <Table.td>{row.count}</Table.td>+ <Table.td>{Number(row.avg_origin_time).toFixed(2)}</Table.td>+ </Table.tr>+ ))}+ </>+ }+ />+ </Panel.Content>+ </Panel>+ </div>+ </>)}</div></div>diff --git a/studio/components/to-be-cleaned/Charts/ChartRenderer.tsx b/studio/components/to-be-cleaned/Charts/ChartRenderer.tsxindex d9554ef159c..d4e66618c3c 100644--- a/studio/components/to-be-cleaned/Charts/ChartRenderer.tsx+++ b/studio/components/to-be-cleaned/Charts/ChartRenderer.tsx@@ -10,7 +10,6 @@ import {Tooltip,Cell,ResponsiveContainer,- TooltipProps,} from 'recharts'import dayjs from 'dayjs'@@ -18,7 +17,7 @@ import customParseFormat from 'dayjs/plugin/customParseFormat'import timezone from 'dayjs/plugin/timezone'import utc from 'dayjs/plugin/utc'import { formatBytes } from 'lib/helpers'-import { TooltipType } from 'recharts/types/util/types'+import { CHART_COLORS } from 'components/ui/ChartComponents/Charts.constants'dayjs.extend(customParseFormat)dayjs.extend(timezone)@@ -45,7 +44,7 @@ const Header = ({customDateFormat,label,minimalHeader = false,- displayDateInUtc= false+ displayDateInUtc = false,}: any) => {let FOCUS_FORMAT = customDateFormat? customDateFormat@@ -88,7 +87,6 @@ const Header = ({}const day = (value: number | string) => (displayDateInUtc ? dayjs(value).utc() : dayjs(value))-const chartTitle = (<Typography.Text small={minimalHeader ? true : false} className="mb-0" type="secondary">{label ?? attribute}@@ -110,8 +108,6 @@ const Header = ({</Typography.Text>)--if (minimalHeader) {return (<div className="flex flex-row gap-x-4 items-center" style={{ minHeight: '1.8rem' }}>@@ -133,7 +129,7 @@ const Header = ({)}-export const NoData = () => (+const NoData = () => (<divclassName="h-full w-full@@ -148,21 +144,6 @@ export const NoData = () => (</div>)-const total = (data: any, format: any, attribute: any) => {- let total = 0- data?.map((item: any) => {- total = total + Number(item[attribute])- })- if (format === '%') {- return Number(total).toFixed(2)- }- return numberWithCommas(total)-}--function numberWithCommas(x: any) {- return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',')-}-export function BarChart({data,attribute,@@ -239,9 +220,9 @@ export function BarChart({interval={data ? data.length - 2 : 0}angle={0}// stroke="#4B5563"- tick={{ fontSize: '0px', color: '#6B7280' }}- axisLine={{ stroke: '#444444' }}- tickLine={{ stroke: '#444444' }}+ tick={{ fontSize: '0px', color: CHART_COLORS.TICK }}+ axisLine={{ stroke: CHART_COLORS.AXIS }}+ tickLine={{ stroke: CHART_COLORS.AXIS }}/><Tooltip content={<CustomTooltip />} />{/* <YAxis dataKey={attribute} /> */}@@ -249,7 +230,7 @@ export function BarChart({{yAxisLimit && <YAxis type="number" domain={[0, yAxisLimit]} hide />}<BardataKey={attribute}- fill="#3ecf8e"+ fill={CHART_COLORS.GREEN_1}// barSize={2}animationDuration={300}>@@ -260,7 +241,9 @@ export function BarChart({onBarClick ? 'cursor-pointer' : ''}`}fill={- focusBar === index || mouseLeave ? '#3ecf8e' : 'rgba(62, 207, 142, 0.2)'+ focusBar === index || mouseLeave+ ? CHART_COLORS.GREEN_1+ : CHART_COLORS.GREEN_2}enableBackground={12}// for this, we make the hovered colour #2B5CE7, else its opacity decreases to 20%@@ -356,8 +339,8 @@ export function AreaChart({><defs><linearGradient id="colorUv" x1="0" y1="0" x2="0" y2="1">- <stop offset="5%" stopColor="#3ecf8e" stopOpacity={0.8} />- <stop offset="95%" stopColor="#3ecf8e" stopOpacity={0} />+ <stop offset="5%" stopColor={CHART_COLORS.GREEN_1} stopOpacity={0.8} />+ <stop offset="95%" stopColor={CHART_COLORS.GREEN_1} stopOpacity={0} /></linearGradient></defs><XAxis@@ -368,13 +351,13 @@ export function AreaChart({// stroke="#4B5563"tick={{fontSize: '0px',- color: '#6B7280',+ color: CHART_COLORS.TICK,}}axisLine={{- stroke: '#444444',+ stroke: CHART_COLORS.AXIS,}}tickLine={{- stroke: '#444444',+ stroke: CHART_COLORS.AXIS,}}/>{yAxisLimit && <YAxis type="number" domain={[0, yAxisLimit]} hide />}@@ -382,7 +365,7 @@ export function AreaChart({<Areatype="monotone"dataKey={attribute}- stroke="#3ecf8e"+ stroke={CHART_COLORS.GREEN_1}fillOpacity={1}fill="url(#colorUv)"/>diff --git a/studio/components/ui/ChartComponents/Charts.constants.ts b/studio/components/ui/ChartComponents/Charts.constants.tsnew file mode 100644index 00000000000..d440cc658c7--- /dev/null+++ b/studio/components/ui/ChartComponents/Charts.constants.ts@@ -0,0 +1,19 @@+// Just extracting the color configuration to a single file so that it's easier to observe+// Needs better naming to be honest, but just to get things going++// For ChartHandler+export const CHART_COLORS = {+ TICK: '#6B7280',+ AXIS: '#444444',+ GREEN_1: 'rgba(62, 207, 142, 1.0)', // #3ECF8E+ GREEN_2: 'rgba(62, 207, 142, 0.2)',+}++export const USAGE_COLORS = {+ 200: '#3ECF8E',+ 201: '#2EBDE5',+ 400: '#889096',+ 401: '#FFB224',+ 404: '#F76808',+ 500: '#EF4444',+}diff --git a/studio/components/ui/ChartComponents/EmptyState.tsx b/studio/components/ui/ChartComponents/EmptyState.tsxnew file mode 100644index 00000000000..e329be770f7--- /dev/null+++ b/studio/components/ui/ChartComponents/EmptyState.tsx@@ -0,0 +1,21 @@+import { FC } from 'react'+import { Typography, IconBarChart2 } from '@supabase/ui'++interface Props {}++const EmptyState: FC<Props> = () => (+ <div+ className="+ h-full w-full py-4+ border border-dashed dark:border-dark+ flex flex-col items-center justify-center+ "+ >+ <Typography.Text className="mb-2">+ <IconBarChart2 />+ </Typography.Text>+ <Typography.Text>No data to show</Typography.Text>+ </div>+)++export default EmptyStatediff --git a/studio/components/ui/charts/StackedAreaChart.tsx b/studio/components/ui/ChartComponents/StackedAreaChart.tsxsimilarity index 95%rename from studio/components/ui/charts/StackedAreaChart.tsxrename to studio/components/ui/ChartComponents/StackedAreaChart.tsxindex f835b3bdbfe..fb995c9ae88 100644--- a/studio/components/ui/charts/StackedAreaChart.tsx+++ b/studio/components/ui/ChartComponents/StackedAreaChart.tsx@@ -1,5 +1,3 @@-import { TooltipContent } from '@radix-ui/react-tooltip'-import { NoData } from 'components/to-be-cleaned/Charts/ChartRenderer'import dayjs from 'dayjs'import { useMemo } from 'react'import {@@ -12,6 +10,7 @@ import {CartesianGrid,AreaProps,} from 'recharts'+import EmptyState from './EmptyState'type Datum = {[key: string]: any@@ -43,7 +42,7 @@ const StackedAreaChart: React.FC<Props> = ({styleMap = {},xAxisFormatAsDate = false,}) => {- if (!isLoading && (data === undefined || data === null)) return <NoData />+ if (!isLoading && (data === undefined || data === null)) return <EmptyState />const transformed = useMemo(() => {if (!data) return []const mapping = data.reduce((acc, datum) => {