Files
supabase/apps/design-system/registry/default/block/chart-composed-states.tsx
Ivan Vasilov 92e79e67d9 feat: Add error state to charts (#46991)
This PR adds an error state to the usage charts on the Project home
page.

<img width="1708" height="471" alt="Screenshot 2026-06-16 at 18 10 20"
src="https://github.com/user-attachments/assets/cba87dad-5e23-4cd1-b787-0ea699445d7f"
/>

I also added an error state to the charts in the [design
system](https://design-system-git-feat-chart-error-state-supabase.vercel.app/design-system/docs/ui-patterns/charts#chart-states).


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

* **New Features**
* Charts now display error states when data retrieval or processing
fails, providing users with clear feedback about issues.
* Improved error visibility and handling across analytics and charting
components for better transparency.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-06-16 16:18:17 +00:00

122 lines
3.3 KiB
TypeScript

'use client'
import { BarChart2, ExternalLink } from 'lucide-react'
import { Badge, CriticalIcon } from 'ui'
import {
Chart,
ChartActions,
ChartCard,
ChartContent,
ChartDisabledState,
ChartEmptyState,
ChartHeader,
ChartLoadingState,
ChartTitle,
} from 'ui-patterns/Chart'
export default function ChartComposedStates() {
const actions = [
{
label: 'Open in Logs Explorer',
onClick: () => {
alert('Ta da! You clicked me! 🎉')
},
icon: <ExternalLink size={12} />,
},
]
const disabledActions = [
{
label: 'Upgrade to Pro',
href: '#',
},
]
return (
<div className="flex flex-col gap-6 w-8/12">
<Chart isLoading={true}>
<ChartCard>
<ChartHeader>
<ChartTitle tooltip="This is a tooltip">Response Errors</ChartTitle>
<ChartActions actions={actions} />
</ChartHeader>
<ChartContent loadingState={<ChartLoadingState />}>My chart here...</ChartContent>
</ChartCard>
</Chart>
<Chart isErrored={true}>
<ChartCard>
<ChartHeader>
<ChartTitle tooltip="This is a tooltip">Response Errors</ChartTitle>
<ChartActions actions={actions} />
</ChartHeader>
<ChartContent
isEmpty={true}
errorState={
<ChartEmptyState
icon={<CriticalIcon />}
title="Some error happened"
description="Error happened why trying to fetch data. Please try again later."
/>
}
emptyState={
<ChartEmptyState
icon={<BarChart2 size={20} />}
title="No data to show"
description="It may take up to 24 hours for data to refresh"
/>
}
loadingState={<ChartLoadingState />}
>
My chart here...
</ChartContent>
</ChartCard>
</Chart>
<Chart>
<ChartCard>
<ChartHeader>
<ChartTitle tooltip="This is a tooltip">Response Errors</ChartTitle>
<ChartActions actions={actions} />
</ChartHeader>
<ChartContent
isEmpty={true}
emptyState={
<ChartEmptyState
icon={<BarChart2 size={20} />}
title="No data to show"
description="It may take up to 24 hours for data to refresh"
/>
}
loadingState={<ChartLoadingState />}
>
My chart here...
</ChartContent>
</ChartCard>
</Chart>
<Chart isDisabled={true}>
<ChartCard>
<ChartHeader>
<ChartTitle tooltip="This is a tooltip">Response Errors</ChartTitle>
<ChartActions actions={actions} />
</ChartHeader>
<ChartContent
loadingState={<ChartLoadingState />}
disabledState={
<ChartDisabledState
icon={<Badge variant="success">Pro</Badge>}
label="API Processing Time"
description="This chart is available on the Pro plan and above"
actions={disabledActions}
/>
}
>
My chart here...
</ChartContent>
</ChartCard>
</Chart>
</div>
)
}