mirror of
https://github.com/supabase/supabase.git
synced 2026-12-06 08:29:01 +00:00
## Problem Closes #31221. The applications and shared UI packages still import the former `framer-motion` package instead of Motion's React entry point. ## Solution Replace runtime imports, type imports, and three test mocks with `motion/react` across the consuming workspaces. Replace the seven direct dependency declarations with `motion: ^11.18.2`. Preserve the existing animation engine version and all other dependency resolutions, including the asynchronous `domMax` feature loader. Historical blog examples remain as published; `framer-motion` remains a transitive implementation dependency of Motion. ## Review instructions 1. Run `pnpm install --frozen-lockfile` and check the seven dependency replacements in the lockfile. 2. Open the WWW Auth page and Docs homepage at desktop and mobile widths, with normal and reduced motion preferences. 3. Open the mobile navigation, expand Product on WWW, and close the menu using Escape and the close button. 4. Check the existing animation components, shared form validation, and Studio tests for unchanged behavior. Validation: - Studio: 731 test files, 8,334 passing tests and one expected failure, with `--maxWorkers=4`. - Shared UI, UI patterns, WWW, and UI library: 615 passing tests. - `pnpm run typecheck --concurrency=1`: all 16 repository tasks pass. - All six application source lint scripts and lint ratchets pass; generated Docs example copies are excluded from local lint. - Repository Prettier source check, lockfile formatting, and case hazard check pass. - WWW: 10 existing end-to-end checks across nine pages. - Docs: 5 existing guide link and accessibility checks across Database and Auth. - WWW and Docs mobile navigation pass at desktop/mobile sizes with normal/reduced motion; SQL-to-REST translation tabs exercise the asynchronous feature loader without browser errors. - Frozen-lockfile installation passes; all existing package and snapshot resolutions are unchanged. - Learn and UI library command palettes open, filter results, and close with Escape without browser errors. - Independent code review finds no actionable defects. - `npm run build -- --filter=www --filter=docs --filter=studio --filter=learn --filter=library --concurrency=1 --continue=always`: all five affected applications build successfully (9 tasks including prerequisites); asset uploads disabled for local validation. ## Checklist - [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) (no docs topics changed) --------- Co-authored-by: Danny White <3104761+dnywh@users.noreply.github.com>
238 lines
6.8 KiB
TypeScript
238 lines
6.8 KiB
TypeScript
import { Code, DatabaseIcon, Play } from 'lucide-react'
|
|
import { motion } from 'motion/react'
|
|
import { useEffect, useState } from 'react'
|
|
import { Bar, BarChart, CartesianGrid, XAxis } from 'recharts'
|
|
import { Button, ChartContainer, ChartTooltip, ChartTooltipContent, cn, SQL_ICON } from 'ui'
|
|
|
|
import CodeBlock from '../CodeBlock/CodeBlock'
|
|
|
|
interface SqlSnippetProps {
|
|
id: string
|
|
sql: string
|
|
title?: string
|
|
resultType?: 'chart' | 'table'
|
|
mockData?: any
|
|
}
|
|
|
|
// Example mock data matching the Results component format
|
|
const MOCK_TABLE_DATA = {
|
|
rows: [
|
|
{
|
|
id: 1,
|
|
name: 'John Doe',
|
|
email: 'john@example.com',
|
|
created_at: '2024-01-15T10:00:00Z',
|
|
status: 'active',
|
|
metadata: { role: 'admin', last_login: '2024-01-14' },
|
|
},
|
|
{
|
|
id: 2,
|
|
name: 'Jane Smith',
|
|
email: 'jane@example.com',
|
|
created_at: '2024-01-14T15:30:00Z',
|
|
status: 'pending',
|
|
metadata: null,
|
|
},
|
|
{
|
|
id: 3,
|
|
name: 'Bob Wilson',
|
|
email: 'bob@example.com',
|
|
created_at: '2024-01-13T09:15:00Z',
|
|
status: 'active',
|
|
metadata: { role: 'user', last_login: '2024-01-12' },
|
|
},
|
|
],
|
|
}
|
|
|
|
const MOCK_CHART_DATA = [
|
|
{ name: 'Jan', value: 400 },
|
|
{ name: 'Feb', value: 300 },
|
|
{ name: 'Mar', value: 600 },
|
|
{ name: 'Apr', value: 800 },
|
|
{ name: 'May', value: 700 },
|
|
]
|
|
|
|
export const SqlSnippet = ({
|
|
id,
|
|
sql,
|
|
title = 'SQL Query',
|
|
resultType = 'table',
|
|
mockData,
|
|
}: SqlSnippetProps) => {
|
|
const [showCode, setShowCode] = useState(!mockData)
|
|
const [isExecuting, setIsExecuting] = useState(false)
|
|
const [showResults, setShowResults] = useState(false)
|
|
const [results, setResults] = useState<any>(null)
|
|
|
|
const handleExecute = () => {
|
|
setIsExecuting(true)
|
|
setShowResults(false)
|
|
|
|
// Simulate SQL execution delay
|
|
setTimeout(() => {
|
|
setIsExecuting(false)
|
|
if (mockData) {
|
|
setShowResults(true)
|
|
// Use provided mock data or default mock data
|
|
setResults(
|
|
resultType === 'chart'
|
|
? mockData || MOCK_CHART_DATA
|
|
: mockData?.rows || MOCK_TABLE_DATA.rows
|
|
)
|
|
}
|
|
}, 1000)
|
|
}
|
|
|
|
// Auto-execute on mount
|
|
useEffect(() => {
|
|
handleExecute()
|
|
}, [])
|
|
|
|
const ResultsDisplay = () => {
|
|
if (resultType === 'chart') {
|
|
return (
|
|
<div className="px-0 py-5 border-t border-t-muted">
|
|
<ChartContainer config={{}} className="aspect-auto h-[250px] w-full">
|
|
<BarChart
|
|
data={results}
|
|
margin={{
|
|
left: 12,
|
|
right: 12,
|
|
}}
|
|
>
|
|
<CartesianGrid vertical={false} />
|
|
<XAxis
|
|
dataKey="name"
|
|
tickLine={false}
|
|
axisLine={false}
|
|
tickMargin={8}
|
|
minTickGap={16}
|
|
padding={{ left: 24, right: 24 }}
|
|
/>
|
|
<ChartTooltip
|
|
cursor={false}
|
|
content={<ChartTooltipContent className="w-[150px]" />}
|
|
/>
|
|
<Bar dataKey="value" fill="hsl(var(--brand-default))" />
|
|
</BarChart>
|
|
</ChartContainer>
|
|
</div>
|
|
)
|
|
}
|
|
|
|
return (
|
|
<>
|
|
<div className={cn(showResults ? 'h-auto max-h-64 overflow-auto border-t' : 'h-0')}>
|
|
<table className="w-full m-0 p-0">
|
|
<thead>
|
|
<tr className="bg-surface-100 border-b">
|
|
{results?.length > 0 &&
|
|
Object.keys(results[0]).map((key) => (
|
|
<th key={key} className="p-2 px-5 text-left text-xs font-mono">
|
|
{key}
|
|
</th>
|
|
))}
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
{results?.map((row: any, i: number) => (
|
|
<tr key={i} className="border-b">
|
|
{Object.values(row).map((value: any, j: number) => (
|
|
<td key={j} className="p-2 px-5 text-left text-xs font-mono">
|
|
{value === null
|
|
? 'NULL'
|
|
: typeof value === 'object'
|
|
? JSON.stringify(value)
|
|
: String(value)}
|
|
</td>
|
|
))}
|
|
</tr>
|
|
))}
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
<div className="flex items-center justify-between bg-surface-100 py-2 px-4">
|
|
<p className="text-xs text-foreground-light">
|
|
{results.length} rows
|
|
{results.length >= 100 && ' (Limited to only 100 rows)'}
|
|
</p>
|
|
</div>
|
|
</>
|
|
)
|
|
}
|
|
|
|
return (
|
|
<div className="my-3 mt-2 border rounded-sm bg-surface-100 overflow-hidden">
|
|
<div className="">
|
|
<div className="flex items-center gap-2 px-4 py-1">
|
|
<SQL_ICON
|
|
className={cn(
|
|
'transition-colors',
|
|
'fill-foreground-muted',
|
|
'group-aria-selected:fill-foreground',
|
|
'w-5 h-5 shrink-0',
|
|
'-ml-0.5'
|
|
)}
|
|
size={16}
|
|
strokeWidth={1.5}
|
|
/>
|
|
<h3 className="text-xs font-medium flex-1">{title}</h3>
|
|
<div className="flex">
|
|
<Button
|
|
variant="text"
|
|
size="tiny"
|
|
className="w-7 h-7"
|
|
icon={<Code size={14} />}
|
|
onClick={() => setShowCode(!showCode)}
|
|
/>
|
|
<Button
|
|
variant="text"
|
|
size="tiny"
|
|
className="w-7 h-7"
|
|
icon={<Play size={14} />}
|
|
loading={isExecuting}
|
|
onClick={handleExecute}
|
|
/>
|
|
</div>
|
|
</div>
|
|
|
|
{showCode && (
|
|
<div className="border-t">
|
|
<CodeBlock className="border-0 rounded-none" showLineNumbers lang="sql">
|
|
{sql}
|
|
</CodeBlock>
|
|
</div>
|
|
)}
|
|
|
|
{isExecuting ? (
|
|
<motion.div className="text-foreground-lighter text-sm flex gap-1.5 items-center p-5">
|
|
<span>Executing query</span>
|
|
<div className="flex gap-1">
|
|
<motion.span
|
|
animate={{ opacity: [0, 1, 0] }}
|
|
transition={{ duration: 1.5, repeat: Infinity, delay: 0 }}
|
|
>
|
|
.
|
|
</motion.span>
|
|
<motion.span
|
|
animate={{ opacity: [0, 1, 0] }}
|
|
transition={{ duration: 1.5, repeat: Infinity, delay: 0.3 }}
|
|
>
|
|
.
|
|
</motion.span>
|
|
<motion.span
|
|
animate={{ opacity: [0, 1, 0] }}
|
|
transition={{ duration: 1.5, repeat: Infinity, delay: 0.6 }}
|
|
>
|
|
.
|
|
</motion.span>
|
|
</div>
|
|
</motion.div>
|
|
) : showResults && results ? (
|
|
<ResultsDisplay />
|
|
) : null}
|
|
</div>
|
|
</div>
|
|
)
|
|
}
|