Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

feat: add more props to AreaChart

TzeYiingf832385fc9c3
diff --git a/studio/components/ui/Charts/AreaChart.stories.tsx b/studio/components/ui/Charts/AreaChart.stories.tsx
index 665bfb852c2..0594186a9d5 100644
--- a/studio/components/ui/Charts/AreaChart.stories.tsx
+++ b/studio/components/ui/Charts/AreaChart.stories.tsx
@@ -1,6 +1,6 @@
import React from 'react'
import { ComponentMeta } from '@storybook/react'
-import Chart from './AreaChart'
+import Chart, { AreaChartProps } from './AreaChart'
import dayjs from 'dayjs'
export default {
@@ -12,16 +12,30 @@ const DATA = [290, 430, 649, 422, 321, 893, 111].map((value, index) => ({
timestamp: dayjs().subtract(index, 'day').toISOString(),
}))
+const PROPS: AreaChartProps<typeof DATA[number]> = {
+ title: 'Memory usage',
+ xAxisKey: 'timestamp',
+ yAxisKey: 'ram_usage',
+ data: DATA,
+}
+
export const AreaChart = () => (
<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>
+ {[
+ { title: 'Normal', props: {} },
+ { title: 'No title', props: { title: undefined } },
+ { title: 'Minimal Header', props: { minimalHeader: true } },
+ { title: 'Highlighted Value', props: { highlightedValue: 123 } },
+ { title: 'UTC Dates', props: { displayDateInUtc: true } },
+ { title: 'Custom date format', props: { customDateFormat: "HH:mm" } },
+ ].map(({ title, props }) => (
+ <div className="w-72">
+ <ExampleName>{title}</ExampleName>
+ <div className="w-full mt-4">
+ <Chart {...PROPS} {...props} />
+ </div>
+ </div>
+ ))}
</div>
)
diff --git a/studio/components/ui/Charts/AreaChart.tsx b/studio/components/ui/Charts/AreaChart.tsx
index 1b9575f938d..12f369d15bd 100644
--- a/studio/components/ui/Charts/AreaChart.tsx
+++ b/studio/components/ui/Charts/AreaChart.tsx
@@ -10,21 +10,21 @@ import {
import dayjs from 'dayjs'
import { CHART_COLORS, DateTimeFormats } from 'components/ui/Charts/Charts.constants'
import ChartHeader from './ChartHeader'
-import { Datum } from './Charts.types'
+import { Datum, CommonChartProps } from './Charts.types'
+import utc from 'dayjs/plugin/utc'
+dayjs.extend(utc)
-interface Props<D = Datum> {
+export interface AreaChartProps<D = Datum> extends CommonChartProps {
data: D[]
yAxisLimit?: any
yAxisKey: string
xAxisKey: string
format?: string
customDateFormat?: string
- title?: string
- highlightedValue?: string | number
displayDateInUtc?: boolean
}
-const AreaChart: React.FC<Props> = ({
+const AreaChart: React.FC<AreaChartProps> = ({
data,
yAxisLimit,
yAxisKey,
@@ -34,6 +34,7 @@ const AreaChart: React.FC<Props> = ({
title,
highlightedValue,
displayDateInUtc,
+ minimalHeader,
}) => {
const [focusDataIndex, setFocusDataIndex] = useState<number | null>(null)
@@ -59,6 +60,7 @@ const AreaChart: React.FC<Props> = ({
customDateFormat={customDateFormat}
highlightedValue={resolvedHighlightedValue}
highlightedLabel={highlightedLabel}
+ minimalHeader={minimalHeader}
/>
<ResponsiveContainer width="100%" height={chartHeight}>
<RechartAreaChart
diff --git a/studio/components/ui/Charts/ChartBase.tsx b/studio/components/ui/Charts/ChartBase.tsx
deleted file mode 100644
index 5a1a92921f6..00000000000
--- a/studio/components/ui/Charts/ChartBase.tsx
+++ /dev/null
@@ -1,8 +0,0 @@
-// interface Props {}
-
-// const ChartBase = ({ header }) => {}
-
-// export default ChartBase
-const ChartBase = () => <>ChartBase</>
-
-export default ChartBase
diff --git a/studio/components/ui/Charts/Charts.types.tsx b/studio/components/ui/Charts/Charts.types.tsx
index 1b0fd7820a5..1d9024515e6 100644
--- a/studio/components/ui/Charts/Charts.types.tsx
+++ b/studio/components/ui/Charts/Charts.types.tsx
@@ -1,3 +1,9 @@
+export interface CommonChartProps {
+ title?: string
+ minimalHeader?: boolean
+ highlightedValue?: number
+}
+
export type HeaderType<D> = {
attribute: string
focus: number | null