The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
chore: more cleanup, add ChartNoData
TzeYiing7b48b1b1da95
diff --git a/studio/components/ui/Charts/AreaChart.stories.tsx b/studio/components/ui/Charts/AreaChart.stories.tsxindex 2d6914fe9a1..665bfb852c2 100644--- a/studio/components/ui/Charts/AreaChart.stories.tsx+++ b/studio/components/ui/Charts/AreaChart.stories.tsx@@ -2,7 +2,6 @@ import React from 'react'import { ComponentMeta } from '@storybook/react'import Chart from './AreaChart'import dayjs from 'dayjs'-import Divider from '../Divider'export default {title: 'Charts',@@ -14,12 +13,15 @@ const DATA = [290, 430, 649, 422, 321, 893, 111].map((value, index) => ({}))export const AreaChart = () => (- <div className="flex flex-col gap-4">- <ExampleName>Normal</ExampleName>- <Chart title="Memory usage" xAxisKey="timestamp" yAxisKey="ram_usage" data={DATA} />- <Divider light={false} />- <ExampleName>No title prop</ExampleName>- <Chart xAxisKey="timestamp" yAxisKey="ram_usage" data={DATA} />+ <div className="flex flex-row gap-4 flex-wrap">+ <div className="w-72">+ <ExampleName>Normal</ExampleName>+ <Chart title="Memory usage" xAxisKey="timestamp" yAxisKey="ram_usage" data={DATA} />+ </div>+ <div className="w-72">+ <ExampleName>No title prop</ExampleName>+ <Chart xAxisKey="timestamp" yAxisKey="ram_usage" data={DATA} />+ </div></div>)diff --git a/studio/components/ui/Charts/AreaChart.tsx b/studio/components/ui/Charts/AreaChart.tsxindex 3586b9341fe..1b9575f938d 100644--- a/studio/components/ui/Charts/AreaChart.tsx+++ b/studio/components/ui/Charts/AreaChart.tsx@@ -1,73 +1,23 @@-import { IconBarChart2, Loading } from '@supabase/ui'import { useState } from 'react'import {- BarChart as RechartBarChart,AreaChart as RechartAreaChart,Area,- Bar,XAxis,YAxis,Tooltip,- ReferenceLine,- Cell,ResponsiveContainer,} from 'recharts'-import dayjs from 'dayjs'-import { formatBytes } from 'lib/helpers'import { CHART_COLORS, DateTimeFormats } from 'components/ui/Charts/Charts.constants'import ChartHeader from './ChartHeader'+import { Datum } from './Charts.types'-function dataCheck(data: any, attribute: any) {- const hasData = data && data.find((record: any) => record[attribute])- return hasData ? true : false-}--const CustomTooltip = () => {- return null-}--const DATE_FORMAT__WITH_TIME = 'MMM D, YYYY, hh:mma'-const DATE_FORMAT__DATE_ONLY = 'MMM D, YYYY'--const NoData = ({ title = 'No data to show', message = 'May take 24 hours for data to show' }) => (- <div- className="- border-scale-600 flex- h-full w-full flex-col- items-center justify-center space-y-2 border- border-dashed text-center- "- >- <IconBarChart2 className="text-scale-800" />- <div>- <p className="text-scale-1100 text-xs">{title}</p>- <p className="text-scale-900 text-xs">{message}</p>- </div>- </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, ',')-}--interface Props {- data: any[]+interface Props<D = Datum> {+ data: D[]yAxisLimit?: anyyAxisKey: stringxAxisKey: stringformat?: string- timeseries?: booleancustomDateFormat?: stringtitle?: stringhighlightedValue?: string | number@@ -76,7 +26,6 @@ interface Props {const AreaChart: React.FC<Props> = ({data,- attribute,yAxisLimit,yAxisKey,xAxisKey,@@ -103,95 +52,66 @@ const AreaChart: React.FC<Props> = ({highlightedValue || (focusDataIndex !== null ? data[focusDataIndex]?.[yAxisKey] : null)return (- <Loading active={!data}>- {data && (- <>- <ChartHeader- title={title}- format={format}- customDateFormat={customDateFormat}- highlightedValue={resolvedHighlightedValue}- highlightedLabel={highlightedLabel}+ <>+ <ChartHeader+ title={title}+ format={format}+ customDateFormat={customDateFormat}+ highlightedValue={resolvedHighlightedValue}+ highlightedLabel={highlightedLabel}+ />+ <ResponsiveContainer width="100%" height={chartHeight}>+ <RechartAreaChart+ data={data}+ margin={{+ top: 0,+ right: 0,+ left: 0,+ bottom: 0,+ }}+ className="overflow-visible"+ // mouse hover focusing logic+ onMouseMove={(e: any) => {+ if (e.activeTooltipIndex !== focusDataIndex) {+ setFocusDataIndex(e.activeTooltipIndex)+ }+ }}+ onMouseLeave={() => setFocusDataIndex(null)}+ >+ <defs>+ <linearGradient id="colorUv" x1="0" y1="0" x2="0" y2="1">+ <stop offset="5%" stopColor={CHART_COLORS.GREEN_1} stopOpacity={0.8} />+ <stop offset="95%" stopColor={CHART_COLORS.GREEN_1} stopOpacity={0} />+ </linearGradient>+ </defs>+ <XAxis+ dataKey={xAxisKey}+ interval={data.length - 2}+ angle={0}+ // hide the tick+ tick={{ fontSize: '0px' }}+ // color the axis+ axisLine={{ stroke: CHART_COLORS.AXIS }}+ tickLine={{ stroke: CHART_COLORS.AXIS }}+ />+ {yAxisLimit && <YAxis type="number" domain={[0, yAxisLimit]} hide />}+ <Tooltip content={() => null} />+ <Area+ type="monotone"+ dataKey={yAxisKey}+ stroke={CHART_COLORS.GREEN_1}+ fillOpacity={1}+ fill="url(#colorUv)"/>- <div- style={{- width: '100%',- height: `${chartHeight}px`,- }}- >- <>- <ResponsiveContainer width="100%" height={chartHeight}>- <RechartAreaChart- data={data}- margin={{- top: 0,- right: 0,- left: 0,- bottom: 0,- }}- className="overflow-visible"- // mouse hover focusing logic- onMouseMove={(e: any) => {- if (e.activeTooltipIndex !== focusDataIndex) {- setFocusDataIndex(e.activeTooltipIndex)- }- }}- onMouseLeave={() => setFocusDataIndex(null)}- >- <defs>- <linearGradient id="colorUv" x1="0" y1="0" x2="0" y2="1">- <stop offset="5%" stopColor={CHART_COLORS.GREEN_1} stopOpacity={0.8} />- <stop offset="95%" stopColor={CHART_COLORS.GREEN_1} stopOpacity={0} />- </linearGradient>- </defs>- <XAxis- dataKey={xAxisKey}- //interval={size === 'small' ? 5 : 1}- // interval={data ? data.length - 2 : 0}- interval={data.length - 2}- angle={0}- tickCount={2}- tickFormatter={(value) =>- dayjs(data[0][xAxisKey]).format(- customDateFormat ? customDateFormat : DATE_FORMAT__WITH_TIME- )- }- // hide the tick- tick={{ fontSize: '0px' }}- // color the axis- axisLine={{ stroke: CHART_COLORS.AXIS }}- tickLine={{ stroke: CHART_COLORS.AXIS }}- />- {yAxisLimit && <YAxis type="number" domain={[0, yAxisLimit]} hide />}- <Tooltip content={<CustomTooltip />} />- <Area- type="monotone"- dataKey={yAxisKey}- stroke={CHART_COLORS.GREEN_1}- fillOpacity={1}- fill="url(#colorUv)"- />- </RechartAreaChart>- </ResponsiveContainer>- {data && (- <div className="text-scale-900 -mt-5 flex items-center justify-between text-xs">- <span>- {dayjs(data[0][xAxisKey]).format(- customDateFormat ? customDateFormat : DATE_FORMAT__WITH_TIME- )}- </span>- <span>- {dayjs(data[data?.length - 1]?.[xAxisKey]).format(- customDateFormat ? customDateFormat : DATE_FORMAT__WITH_TIME- )}- </span>- </div>- )}- </>- </div>- </>+ </RechartAreaChart>+ </ResponsiveContainer>+ {data && (+ <div className="text-scale-900 -mt-5 flex items-center justify-between text-xs">+ <span>{dayjs(data[0][xAxisKey]).format(customDateFormat)}</span>+ <span>{dayjs(data[data?.length - 1]?.[xAxisKey]).format(customDateFormat)}</span>+ </div>)}- </Loading>+ </>)}export default AreaChartdiff --git a/studio/components/ui/Charts/Chart.utils.ts b/studio/components/ui/Charts/Chart.utils.tsdeleted file mode 100644index e69de29bb2d..00000000000diff --git a/studio/components/ui/Charts/ChartHeader.tsx b/studio/components/ui/Charts/ChartHeader.tsxindex c9a18062ff3..8ccf18ccc09 100644--- a/studio/components/ui/Charts/ChartHeader.tsx+++ b/studio/components/ui/Charts/ChartHeader.tsx@@ -1,46 +1,25 @@-import dayjs from 'dayjs'import { DateTimeFormats } from './Charts.constants'-const DATE_FORMAT__WITH_TIME = 'MMM D, YYYY, hh:mma'-const DATE_FORMAT__DATE_ONLY = 'MMM D, YYYY'export interface ChartHeaderProps {title?: stringformat?: string- highlightedValue: number | stringcustomDateFormat?: stringminimalHeader?: booleandisplayDateInUtc?: boolean- highlightedLabel?: string+ highlightedLabel?: number | string | null+ highlightedValue?: number | string | null}const ChartHeader: React.FC<ChartHeaderProps> = ({format,highlightedValue,highlightedLabel,- customDateFormat,title,minimalHeader = false,- displayDateInUtc = false,}) => {- let FOCUS_FORMAT = customDateFormat- ? customDateFormat- : format == '%'- ? DateTimeFormats.FULL- : DateTimeFormats.DATE_ONLY-const chartTitle = (<h3 className={'text-scale-900 ' + (minimalHeader ? 'text-xs' : 'text-sm')}>{title}</h3>)- // let highlightedLabel = ''-- // if (focus) {- // if (data) {- // highlightedLabel = data[focus]?.[attribute]?.toLocaleString()- // } else if (highlightedValue) {- // highlightedLabel = highlightedValue?.toLocaleString()- // }- // }-const highlighted = (<h5className={`text-scale-1200 text-xl font-normal ${minimalHeader ? 'text-base' : 'text-2xl'}`}@@ -49,12 +28,7 @@ const ChartHeader: React.FC<ChartHeaderProps> = ({<span className="text-lg">{format}</span></h5>)- const date = (- <h5 className="text-scale-900 text-xs">- {highlightedLabel}- {/* {focus && data && data[focus] && day(data[focus].period_start).format(FOCUS_FORMAT)} */}- </h5>- )+ const label = <h5 className="text-scale-900 text-xs">{highlightedLabel}</h5>if (minimalHeader) {return (@@ -62,7 +36,7 @@ const ChartHeader: React.FC<ChartHeaderProps> = ({{chartTitle}<div className="flex flex-row items-baseline gap-x-2">{highlighted}- {date}+ {label}</div></div>)@@ -72,7 +46,7 @@ const ChartHeader: React.FC<ChartHeaderProps> = ({<div className="h-16">{chartTitle}{highlighted}- {date}+ {label}</div>)}diff --git a/studio/components/ui/Charts/ChartNoData.tsx b/studio/components/ui/Charts/ChartNoData.tsxnew file mode 100644index 00000000000..1a89e8647c2--- /dev/null+++ b/studio/components/ui/Charts/ChartNoData.tsx@@ -0,0 +1,22 @@+import { IconBarChart2 } from '@supabase/ui'++const ChartNoData = ({+ title = 'No data to show',+ message = 'May take 24 hours for data to show',+}) => (+ <div+ className="+ border-scale-600 flex+ h-full w-full flex-col+ items-center justify-center space-y-2 border+ border-dashed text-center+ "+ >+ <IconBarChart2 className="text-scale-800" />+ <div>+ <p className="text-scale-1100 text-xs">{title}</p>+ <p className="text-scale-900 text-xs">{message}</p>+ </div>+ </div>+)+export default ChartNoDatadiff --git a/studio/components/ui/Charts/Chart.types.tsx b/studio/components/ui/Charts/Charts.types.tsxsimilarity index 86%rename from studio/components/ui/Charts/Chart.types.tsxrename to studio/components/ui/Charts/Charts.types.tsxindex f7bcf93138d..1b0fd7820a5 100644--- a/studio/components/ui/Charts/Chart.types.tsx+++ b/studio/components/ui/Charts/Charts.types.tsx@@ -1,9 +1,9 @@-export type HeaderType<Datum> = {+export type HeaderType<D> = {attribute: stringfocus: number | nullformat?: stringhighlightedValue?: number- data?: Datum[]+ data?: D[]customDateFormat?: stringlabel: stringminimalHeader?: boolean