Files
supabase/apps/studio/components/interfaces/BranchManagement/DatabaseDiffPanel.tsx
T
Andrew Valleteau dcc5703674 feat(branching): add-pg-delta-diff-for-branching (#42952)
Allow to use the `pg-delta` capability for merge requests diffing.
Feature flag it behind an auto opt-in flag.

Must be merged after: https://github.com/supabase/platform/pull/29776
<img width="921" height="623" alt="Screenshot 2026-02-17 at 16 50 38"
src="https://github.com/user-attachments/assets/bfe704e9-4137-45e1-b0b5-1cecce284d6e"
/>


Also updated the loading + final state of the diff view to:

1. Take all the height available

- From: <img width="1894" height="893" alt="Screenshot 2026-02-16 at 20
46 15"
src="https://github.com/user-attachments/assets/22ed8c72-2d9d-4b68-b315-6d40aefc0b3c"
/>


- To: <img width="1629" height="1396" alt="Screenshot 2026-02-16 at 20
57 26"
src="https://github.com/user-attachments/assets/6e83c8e9-607d-4077-977e-046058ce3e44"
/>

2. Show a proper loading state rather than just a plain grey skeleton

- From: <img width="2232" height="1137" alt="Screenshot 2026-02-20 at 15
02 51"
src="https://github.com/user-attachments/assets/0c924b04-d60f-49b5-a5a0-3bf1942bfdef"
/>
- To:
<img width="2231" height="1129" alt="Screenshot 2026-02-20 at 15 05 46"
src="https://github.com/user-attachments/assets/49751001-1818-4842-a0c8-b74683c2e9bc"
/>
2026-02-26 15:28:13 +01:00

123 lines
4.1 KiB
TypeScript

import { CircleAlert, Database, Download, Loader2, Wind } from 'lucide-react'
import Link from 'next/link'
import { toast } from 'sonner'
import { DiffEditor } from '@/components/ui/DiffEditor'
import { Button, Card, CardContent, CardHeader, CardTitle, Skeleton } from 'ui'
interface DatabaseDiffPanelProps {
diffContent?: string
isLoading: boolean
error?: any
showRefreshButton?: boolean
currentBranchRef?: string
}
export const DatabaseDiffPanel = ({
diffContent,
isLoading,
error,
currentBranchRef,
}: DatabaseDiffPanelProps) => {
if (isLoading) {
return (
<div className="flex flex-1 min-h-0 flex-col">
<div className="flex flex-1 min-h-[400px] flex-col rounded-md border border-border bg-surface-100">
<div className="flex shrink-0 items-center gap-2 border-b border-border px-4 py-3">
<Loader2
size={16}
strokeWidth={1.5}
className="animate-spin text-foreground-muted"
aria-hidden
/>
<span className="text-sm text-foreground-light">Loading database diff…</span>
</div>
<div className="min-h-0 flex-1 p-4">
<Skeleton className="h-full w-full rounded" />
</div>
</div>
</div>
)
}
if (error)
return (
<div className="p-6 text-center">
<CircleAlert size={32} strokeWidth={1.5} className="text-foreground-muted mx-auto mb-8" />
<h3 className="mb-1">Error loading branch diff</h3>
<p className="text-sm text-foreground-light">
Please try again in a few minutes and contact support if the problem persists.
</p>
</div>
)
if (!diffContent || diffContent.trim() === '') {
return (
<div className="p-6 text-center">
<Wind size={32} strokeWidth={1.5} className="text-foreground-muted mx-auto mb-8" />
<h3 className="mb-1">No changes detected between branches</h3>
<p className="text-sm text-foreground-light">
Any changes to your database schema will be shown here for review
</p>
</div>
)
}
return (
<Card className="flex flex-1 min-h-0 flex-col">
<CardHeader className="flex shrink-0 flex-row items-center justify-between space-y-0 py-3">
<CardTitle>
<Link
href={`/project/${currentBranchRef}/database/schema`}
className="flex items-center gap-2"
>
<Database strokeWidth={1.5} size={16} className="text-foreground-muted" />
Schema Changes
</Link>
</CardTitle>
<Button
type="default"
size="tiny"
icon={<Download strokeWidth={1.5} size={14} className="text-foreground-light" />}
className="mt-0"
onClick={() => {
if (!diffContent) return
const now = new Date()
const pad = (n: number) => n.toString().padStart(2, '0')
const timestamp =
now.getFullYear().toString() +
pad(now.getMonth() + 1) +
pad(now.getDate()) +
pad(now.getHours()) +
pad(now.getMinutes()) +
pad(now.getSeconds())
const filename = `${timestamp}_migration.sql`
const blob = new Blob([diffContent], { type: 'text/plain;charset=utf-8;' })
const url = window.URL.createObjectURL(blob)
const a = document.createElement('a')
a.href = url
a.setAttribute('download', filename)
document.body.appendChild(a)
a.click()
document.body.removeChild(a)
window.URL.revokeObjectURL(url)
toast.success('Migration file downloaded!')
}}
>
Download as migration
</Button>
</CardHeader>
<CardContent className="flex min-h-0 flex-1 flex-col p-0">
<div className="min-h-0 flex-1">
<DiffEditor
language="sql"
original=""
modified={diffContent}
options={{ readOnly: true }}
/>
</div>
</CardContent>
</Card>
)
}