Files
supabase/apps/docs/components/RealtimeLimitsEstimator/RealtimeLimitsEstimator.tsx
Anthony Lio 3d326d7644 feat(ui): prose table component (#51794)
## Problem

- docs and kb render markdown tables in different ways
- docs uses its own `Table` component with its own scroll listener
- kb has no scroll container which can lead on phones to overflow
- design system `Table` already scrolls with `ShadowScrollArea` which
was not used within guides

## Solution

- docs and kb article tables use the `ui` `Table`
- (proposal) `Table` gets a `prose` variant
- kb guides map `table` to `<Table prose />`
- `ShadowScrollArea` shows and hides the edge shadows without a fade (no
strong opinion but felt snappier)
- refactor table components to use `ref` vs deprecated `forwardRef`
- fixes #52065 cc @jbergstroem 

<!--
## Preview links

If relevant, include links to changed pages for easy review access.

Copy the preview base URL from the Vercel bot comment on this PR. Use
the following table as an example template.

| Site | Live | Preview | Search for |
| -------------- |
-------------------------------------------------------------------------
|
------------------------------------------------------------------------------------------------------------
| ----------------------------- |
| WWW | [/blog/your-post](https://supabase.com/blog/your-post) |
[/blog/your-post](https://zone-www-dot-com-git-branch-name-supabase.vercel.app/blog/your-post)
| unique phrase from the change |
| Docs |
[/docs/guides/your-page](https://supabase.com/docs/guides/your-page) |
[/docs/guides/your-page](https://docs-git-branch-name-supabase.vercel.app/docs/guides/your-page)
| unique phrase from the change |
| Studio | [/dashboard](https://supabase.com/dashboard) |
[/dashboard](https://studio-git-branch-name-supabase.vercel.app/dashboard)
| unique phrase from the change |
| Design system | [/design-system](https://supabase.com/design-system) |
[/design-system](https://design-system-git-branch-name-supabase.vercel.app/design-system)
| unique phrase from the change |
| UI library | [/library](https://supabase.com/library) |
[/library](https://ui-library-git-branch-name-supabase.vercel.app/library)
| unique phrase from the change |
| Knowledge base |
[/kb/guides/your-page](https://supabase.com/kb/guides/your-page) |
[/kb/guides/your-page](https://kb-git-branch-name-supabase.vercel.app/kb/guides/your-page)
| unique phrase from the change |
-->

<!-- ## Additional context

Optionally add any other context or screenshots.

-->

## Review instructions

1. open `/docs/guides/ai/choosing-compute-addon` on
[prod](https://supabase.com/docs/guides/ai/choosing-compute-addon#hnsw)
and on
[preview](https://docs-3t4ed5odv-supabase.vercel.app/docs/guides/ai/choosing-compute-addon#hnsw)
2. open `/kb/guides/migrate-from-postgres` on
[prod](https://supabase.com/kb/guides/migrate-from-postgres) and on
[preview](https://docs-3t4ed5odv-supabase.vercel.app/kb/guides/migrate-from-postgres).
on live, the table goes out of the article. on preview, the table
scrolls in the article.


## Checklist

Check all before review:

- [x] I have read
[CONTRIBUTING.md](https://github.com/supabase/supabase/blob/master/CONTRIBUTING.md)
- [x] If I wrote a new docs topic or edited an existing topic, I used
the `/write-the-docs` or `/edit-the-docs` skill, which applies the docs
[style
guide](https://github.com/supabase/supabase/tree/master/apps/docs/style-guide)
2026-10-22 13:01:54 +03:00

201 lines
7.1 KiB
TypeScript

import throughputTable from '~/data/realtime/throughput.json'
import { ChevronDown } from 'lucide-react'
import { useState } from 'react'
import {
cn,
Collapsible,
CollapsibleContent,
CollapsibleTrigger,
Label,
Select,
SelectContent,
SelectItem,
SelectTrigger,
SelectValue,
Table,
} from 'ui'
import {
COMPUTE_LABELS,
COMPUTE_OPTIONS,
THROUGHPUT_METRIC_HEADINGS,
THROUGHPUT_TABLE_HEADINGS,
} from './RealtimeLimitsEstimator.constants'
export default function RealtimeLimitsEstimater({}) {
const findTableValue = ({ computeAddOn, rls, concurrency }) => {
return throughputTable.find(
(l) => l.computeAddOn === computeAddOn && l.rls === rls && l.concurrency === concurrency
)
}
const [computeAddOn, setComputeAddOn] = useState('micro')
const [rls, setRLS] = useState(false)
const [concurrency, setConcurrency] = useState(500)
const [limits, setLimits] = useState(findTableValue({ computeAddOn, rls, concurrency }))
const [expandPreview, setExpandPreview] = useState(false)
const handleComputeAddOnSelection = (val) => {
setComputeAddOn(val)
setConcurrency(500)
setLimits(findTableValue({ computeAddOn: val, rls, concurrency: 500 }))
}
const handleRLSSelection = (value) => {
const val = value.toLowerCase() === 'true'
setRLS(val)
setConcurrency(500)
setLimits(findTableValue({ computeAddOn, rls: val, concurrency: 500 }))
}
const handleConcurrencySelection = (value) => {
const val = parseInt(value)
setConcurrency(val)
setLimits(findTableValue({ computeAddOn, rls, concurrency: val }))
}
return (
<div>
<span className="block font-heading font-semibold text-lg mt-9 mb-[18px] text-foreground">
Set your expected parameters
</span>
<div className="grid mb-8 gap-y-8 gap-x-8 grid-cols-2 xl:grid-cols-4">
<div>
<Label htmlFor="computeAddOn">Compute:</Label>
<Select onValueChange={handleComputeAddOnSelection} value={computeAddOn}>
<SelectTrigger id="computeAddOn">
<SelectValue className="font-mono" />
</SelectTrigger>
<SelectContent>
{COMPUTE_OPTIONS.map((option) => (
<SelectItem key={option.value} value={option.value}>
{option.label}
</SelectItem>
))}
</SelectContent>
</Select>
</div>
<div>
<Label htmlFor="rls">RLS:</Label>
<Select onValueChange={handleRLSSelection} value={rls.toString()}>
<SelectTrigger id="rls">
<SelectValue className="font-mono" />
</SelectTrigger>
<SelectContent>
<SelectItem value="false">No</SelectItem>
<SelectItem value="true">Yes</SelectItem>
</SelectContent>
</Select>
</div>
<div>
<Label htmlFor="concurrency">Connected clients:</Label>
<Select onValueChange={handleConcurrencySelection} value={concurrency.toString()}>
<SelectTrigger id="concurrency">
<SelectValue className="font-mono" />
</SelectTrigger>
<SelectContent>
{throughputTable
.filter((l) => l.computeAddOn === computeAddOn && l.rls === rls)
.map((l) => (
<SelectItem key={l.concurrency} value={l.concurrency.toString()}>
{Intl.NumberFormat().format(l.concurrency)}
</SelectItem>
))}
</SelectContent>
</Select>
</div>
</div>
{limits && (
<div className="mt-8">
<span className="block font-heading font-semibold text-lg mt-9 mb-[18px] text-foreground">
Current maximum possible throughput
</span>
<Table prose className="table-auto">
<thead>
<tr>
{THROUGHPUT_METRIC_HEADINGS.map((heading) => (
<th key={heading} className="px-4 py-2">
{heading}
</th>
))}
</tr>
</thead>
<tbody>
<tr>
<td className="border px-4 py-2">{limits.maxDBChanges}</td>
<td className="border px-4 py-2">{limits.maxMessagesPerClient}</td>
<td className="border px-4 py-2">
{Intl.NumberFormat().format(limits.totalMessagesPerSecond)}
</td>
<td className="border px-4 py-2">{limits.p95Latency}ms</td>
</tr>
</tbody>
</Table>
</div>
)}
<Collapsible open={expandPreview} onOpenChange={setExpandPreview}>
<CollapsibleTrigger className="group text-base py-1 flex items-center gap-1 cursor-pointer select-none mb-10 text-foreground-light hover:text-foreground transition-colors">
View raw throughput table
<ChevronDown
size={14}
strokeWidth={2}
aria-hidden
className={cn(
'text-foreground-lighter group-hover:text-foreground transition-colors',
expandPreview && 'rotate-180'
)}
/>
</CollapsibleTrigger>
<CollapsibleContent>
<div>
{throughputTable
.map((l) => l.computeAddOn)
.filter((v, i, a) => a.indexOf(v) === i)
.map((computeAddOn) => (
<div>
<span className="block font-heading font-semibold text-lg mt-9 mb-[18px] text-foreground">
{COMPUTE_LABELS[computeAddOn]}
</span>
<Table prose className="table-auto">
<thead>
<tr>
{THROUGHPUT_TABLE_HEADINGS.map((heading) => (
<th key={heading} className="px-4 py-2">
{heading}
</th>
))}
</tr>
</thead>
<tbody>
{throughputTable
.filter((l) => l.computeAddOn === computeAddOn)
.map((l) => (
<tr>
<td className="border px-4 py-2">{l.rls ? '✅' : '🚫'}</td>
<td className="border px-4 py-2">
{Intl.NumberFormat().format(l.concurrency)}
</td>
<td className="border px-4 py-2">{l.maxDBChanges}</td>
<td className="border px-4 py-2">{l.maxMessagesPerClient}</td>
<td className="border px-4 py-2">
{Intl.NumberFormat().format(l.totalMessagesPerSecond)}
</td>
<td className="border px-4 py-2">{l.p95Latency}ms</td>
</tr>
))}
</tbody>
</Table>
</div>
))}
</div>
</CollapsibleContent>
</Collapsible>
</div>
)
}