Skip to content

Commit af98191

Browse files
fix(design-system): chart rendering (supabase#40306)
* chore: exploring possible breaking charts * chore: still exploring why chart container content wont load * chore: clean up and pin recharts to catalog * chore: remove comments from comment preview file * chore: remove react override * Remove React 19.2 as a dependency. --------- Co-authored-by: Ivan Vasilov <[email protected]>
1 parent 534c300 commit af98191

File tree

12 files changed

+48
-105
lines changed

12 files changed

+48
-105
lines changed

apps/design-system/components/component-preview.tsx

Lines changed: 1 addition & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,6 @@ import {
1111
cn,
1212
} from 'ui'
1313
import { useConfig } from '@/hooks/use-config'
14-
import {
15-
// CopyButton,
16-
CopyWithClassNames,
17-
} from '@/components/copy-button'
18-
// import { Icons } from '@/components/icons'
19-
// import { StyleSwitcher } from '@/components/style-switcher'
20-
// import { ThemeWrapper } from '@/components/theme-wrapper'
21-
import {
22-
Tabs_Shadcn_ as Tabs,
23-
TabsContent_Shadcn_ as TabsContent,
24-
TabsList_Shadcn_ as TabsList,
25-
TabsTrigger_Shadcn_ as TabsTrigger,
26-
} from 'ui'
27-
28-
// import { LoaderCircle } from 'lucide-react'
29-
3014
import { styles } from '@/registry/styles'
3115
import { ChevronRight, Expand } from 'lucide-react'
3216

@@ -63,12 +47,7 @@ export function ComponentPreview({
6347
const [expand, setExpandState] = React.useState(false)
6448

6549
const Preview = React.useMemo(() => {
66-
// console.log('Index', Index)
67-
// console.log('name', name)
68-
// console.log('config.style', config.style)
69-
7050
const Component = Index[config.style][name]?.component
71-
// const Component = Index[name]?.component
7251

7352
if (!Component) {
7453
return (
@@ -85,17 +64,9 @@ export function ComponentPreview({
8564
return <Component />
8665
}, [name, config.style])
8766

88-
const codeString = React.useMemo(() => {
89-
if (typeof Code?.props['data-rehype-pretty-code-fragment'] !== 'undefined') {
90-
const [, Button] = React.Children.toArray(Code.props.children) as React.ReactElement[]
91-
return Button?.props?.value || Button?.props?.__rawString__ || null
92-
}
93-
}, [Code])
94-
9567
const ComponentPreview = React.useMemo(() => {
9668
return (
9769
<>
98-
{/* <ThemeWrapper defaultTheme="zinc"> */}
9970
<div
10071
className={cn('preview flex min-h-[350px] w-full justify-center p-10', {
10172
'items-center': align === 'center',
@@ -105,17 +76,12 @@ export function ComponentPreview({
10576
>
10677
<React.Suspense
10778
fallback={
108-
<div className="flex items-center text-sm text-muted-foreground">
109-
{/* <Icons.spinner className="mr-2 h-4 w-4 animate-spin" /> */}
110-
{/* <LoaderCircle className="mr-2 h-4 w-4 animate-spin" /> */}
111-
Loading...
112-
</div>
79+
<div className="flex items-center text-sm text-muted-foreground">Loading...</div>
11380
}
11481
>
11582
{Preview}
11683
</React.Suspense>
11784
</div>
118-
{/* </ThemeWrapper> */}
11985
</>
12086
)
12187
}, [Preview, align])
@@ -179,7 +145,6 @@ export function ComponentPreview({
179145
<div className="z-0 pointer-events-none absolute h-full w-full bg-[radial-gradient(hsla(var(--foreground-default)/0.02)_1px,transparent_1px)] [background-size:16px_16px] [mask-image:radial-gradient(ellipse_50%_50%_at_50%_50%,#000_70%,transparent_100%)]"></div>
180146
)}
181147
<div className="z-10 relative">{ComponentPreview}</div>
182-
{/* <div className="preview-grid-background"></div> */}
183148
</div>
184149
<Collapsible_Shadcn_>
185150
<CollapsibleTrigger_Shadcn_
@@ -219,40 +184,4 @@ export function ComponentPreview({
219184
</Collapsible_Shadcn_>
220185
</div>
221186
)
222-
223-
return (
224-
<div
225-
className={cn('group relative my-4 flex flex-col gap-2', wideClasses, className)}
226-
{...props}
227-
>
228-
<Tabs defaultValue="preview" className="relative mr-auto w-full">
229-
<div className="flex items-center justify-between pb-3">
230-
<TabsList className="w-full justify-start rounded-none border-b bg-transparent p-0">
231-
<TabsTrigger
232-
value="preview"
233-
className="relative h-9 rounded-none border-b-2 border-b-transparent bg-transparent px-4 pb-3 pt-2 font-semibold text-muted-foreground shadow-none transition-none data-[state=active]:border-b-primary data-[state=active]:text-foreground data-[state=active]:shadow-none"
234-
>
235-
Preview
236-
</TabsTrigger>
237-
<TabsTrigger
238-
value="code"
239-
className="relative h-9 rounded-none border-b-2 border-b-transparent bg-transparent px-4 pb-3 pt-2 font-semibold text-muted-foreground shadow-none transition-none data-[state=active]:border-b-primary data-[state=active]:text-foreground data-[state=active]:shadow-none"
240-
>
241-
Code
242-
</TabsTrigger>
243-
</TabsList>
244-
</div>
245-
<TabsContent value="preview" className="relative rounded-md border bg-studio">
246-
{ComponentPreview}
247-
</TabsContent>
248-
<TabsContent value="code">
249-
<div className="flex flex-col space-y-4">
250-
<div className="w-full rounded-md [&_pre]:my-0 [&_pre]:max-h-[350px] [&_pre]:overflow-auto">
251-
{Code}
252-
</div>
253-
</div>
254-
</TabsContent>
255-
</Tabs>
256-
</div>
257-
)
258187
}

apps/design-system/content/docs/fragments/logs-bar-chart.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,6 @@ type LogsBarChartDatum = {
1717
timestamp: string
1818
ok_count: number
1919
error_count: number
20+
warning_count: number
2021
}
2122
```

apps/design-system/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"dependencies": {
2020
"@hookform/resolvers": "^3.1.1",
2121
"contentlayer2": "0.4.6",
22+
"dayjs": "1.11.13",
2223
"date-fns": "^2.30.0",
2324
"eslint-config-supabase": "workspace:*",
2425
"icons": "workspace:*",
@@ -36,7 +37,7 @@
3637
"react-hook-form": "^7.45.0",
3738
"react-inlinesvg": "^4.0.4",
3839
"react-wrap-balancer": "^1.1.0",
39-
"recharts": "^2.12.7",
40+
"recharts": "catalog:",
4041
"rehype-autolink-headings": "^7.1.0",
4142
"rehype-pretty-code": "^0.9.0",
4243
"rehype-slug": "^6.0.0",

apps/design-system/registry/default/example/logs-bar-chart.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use client'
2+
13
import { LogsBarChart } from 'ui-patterns/LogsBarChart'
24

35
export default function LogsBarChartDemo() {

apps/studio/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@
127127
"react-simple-maps": "4.0.0-beta.6",
128128
"react-use": "^17.5.0",
129129
"reactflow": "^11.10.1",
130-
"recharts": "^2.8.0",
130+
"recharts": "catalog:",
131131
"remark-gfm": "^3.0.1",
132132
"shared-data": "workspace:*",
133133
"sonner": "^1.5.0",

apps/ui-library/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
"react-hook-form": "^7.45.0",
7474
"react-markdown": "^10.1.0",
7575
"react-wrap-balancer": "^1.1.0",
76-
"recharts": "^2.8.0",
76+
"recharts": "catalog:",
7777
"rehype-autolink-headings": "^7.1.0",
7878
"rehype-pretty-code": "^0.9.0",
7979
"rehype-slug": "^6.0.0",

apps/www/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
"react-syntax-highlighter": "^15.6.6",
7474
"react-transition-group": "^4.4.1",
7575
"react-use": "^17.4.0",
76-
"recharts": "^2.8.0",
76+
"recharts": "catalog:",
7777
"rehype-slug": "^5.1.0",
7878
"remark": "^15.0.1",
7979
"remark-gfm": "^3.0.1",

packages/ui-patterns/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,7 @@
635635
"react-syntax-highlighter": "^15.6.6",
636636
"react-tooltip": "*",
637637
"react-use": "^17.5.0",
638-
"recharts": "^2.8.0",
638+
"recharts": "catalog:",
639639
"remark": "^15.0.1",
640640
"remark-gfm": "^4.0.0",
641641
"scroll-into-view-if-needed": "^3.1.0",
@@ -671,4 +671,4 @@
671671
"peerDependencies": {
672672
"next": "catalog:"
673673
}
674-
}
674+
}

packages/ui-patterns/src/LogsBarChart/index.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
'use client'
2+
23
import dayjs from 'dayjs'
34
import { ReactNode, useState } from 'react'
45
import { Bar, Cell, BarChart as RechartBarChart, XAxis, YAxis } from 'recharts'
@@ -15,12 +16,14 @@ const CHART_COLORS = {
1516
YELLOW_1: 'hsl(var(--warning-default))',
1617
YELLOW_2: 'hsl(var(--warning-500))',
1718
}
19+
1820
type LogsBarChartDatum = {
1921
timestamp: string
2022
error_count: number
2123
ok_count: number
2224
warning_count: number
2325
}
26+
2427
export const LogsBarChart = ({
2528
data,
2629
onBarClick,
@@ -95,7 +98,7 @@ export const LogsBarChart = ({
9598
content={
9699
<ChartTooltipContent
97100
className="text-foreground-light -mt-5"
98-
labelFormatter={(v) => dayjs(v).format(DateTimeFormat)}
101+
labelFormatter={(v: string) => dayjs(v).format(DateTimeFormat)}
99102
/>
100103
}
101104
/>

packages/ui/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
"react-medium-image-zoom": "^5.2.4",
7474
"react-resizable-panels": "^2.1.4",
7575
"react-syntax-highlighter": "^15.6.6",
76-
"recharts": "^2.12.7",
76+
"recharts": "catalog:",
7777
"sonner": "^1.5.0",
7878
"tailwind-merge": "^1.13.2",
7979
"tailwindcss": "catalog:",

0 commit comments

Comments
 (0)