Files
supabase/apps/studio/components/interfaces/App/FeaturePreview/FeaturePreviewModal.tsx
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

168 lines
6.9 KiB
TypeScript

import { LOCAL_STORAGE_KEYS, useParams } from 'common'
import { useSendEventMutation } from 'data/telemetry/send-event-mutation'
import { useSelectedOrganizationQuery } from 'hooks/misc/useSelectedOrganization'
import { IS_PLATFORM } from 'lib/constants'
import { ExternalLink, Eye, EyeOff, FlaskConical } from 'lucide-react'
import Link from 'next/link'
import { ReactNode } from 'react'
import {
Badge,
Button,
cn,
Dialog,
DialogContent,
DialogDescription,
DialogHeader,
DialogSection,
DialogSectionSeparator,
DialogTitle,
ScrollArea,
} from 'ui'
import { AdvisorRulesPreview } from './AdvisorRulesPreview'
import { APISidePanelPreview } from './APISidePanelPreview'
import { Branching2Preview } from './Branching2Preview'
import { CLSPreview } from './CLSPreview'
import { useFeaturePreviewContext, useFeaturePreviewModal } from './FeaturePreviewContext'
import { PgDeltaDiffPreview } from './PgDeltaDiffPreview'
import { QueueOperationsPreview } from './QueueOperationsPreview'
import { TableFilterBarPreview } from './TableFilterBarPreview'
import { UnifiedLogsPreview } from './UnifiedLogsPreview'
import { useFeaturePreviews } from './useFeaturePreviews'
const FEATURE_PREVIEW_KEY_TO_CONTENT: {
[key: string]: ReactNode
} = {
[LOCAL_STORAGE_KEYS.UI_PREVIEW_BRANCHING_2_0]: <Branching2Preview />,
[LOCAL_STORAGE_KEYS.UI_PREVIEW_PG_DELTA_DIFF]: <PgDeltaDiffPreview />,
[LOCAL_STORAGE_KEYS.UI_PREVIEW_ADVISOR_RULES]: <AdvisorRulesPreview />,
[LOCAL_STORAGE_KEYS.UI_PREVIEW_API_SIDE_PANEL]: <APISidePanelPreview />,
[LOCAL_STORAGE_KEYS.UI_PREVIEW_CLS]: <CLSPreview />,
[LOCAL_STORAGE_KEYS.UI_PREVIEW_UNIFIED_LOGS]: <UnifiedLogsPreview />,
[LOCAL_STORAGE_KEYS.UI_PREVIEW_QUEUE_OPERATIONS]: <QueueOperationsPreview />,
[LOCAL_STORAGE_KEYS.UI_PREVIEW_TABLE_FILTER_BAR]: <TableFilterBarPreview />,
}
export const FeaturePreviewModal = () => {
const { ref } = useParams()
const featurePreviews = useFeaturePreviews()
const {
showFeaturePreviewModal,
selectedFeatureKey,
selectFeaturePreview,
toggleFeaturePreviewModal,
} = useFeaturePreviewModal()
const { data: org } = useSelectedOrganizationQuery()
const featurePreviewContext = useFeaturePreviewContext()
const { mutate: sendEvent } = useSendEventMutation()
const { flags, onUpdateFlag } = featurePreviewContext
const selectedFeature =
featurePreviews.find((preview) => preview.key === selectedFeatureKey) ?? featurePreviews[0]
const isSelectedFeatureEnabled = flags[selectedFeatureKey]
const allFeaturePreviews = IS_PLATFORM
? featurePreviews
: featurePreviews.filter((x) => !x.isPlatformOnly)
const toggleFeature = () => {
onUpdateFlag(selectedFeature.key, !isSelectedFeatureEnabled)
sendEvent({
action: isSelectedFeatureEnabled ? 'feature_preview_disabled' : 'feature_preview_enabled',
properties: { feature: selectedFeature.key },
groups: { project: ref ?? 'Unknown', organization: org?.slug ?? 'Unknown' },
})
}
return (
<Dialog open={showFeaturePreviewModal} onOpenChange={toggleFeaturePreviewModal}>
<DialogContent size="xlarge" className="!max-w-4xl">
<DialogHeader>
<DialogTitle>Dashboard feature previews</DialogTitle>
<DialogDescription>Get early access to new features and give feedback</DialogDescription>
</DialogHeader>
<DialogSectionSeparator />
<DialogSection className="!p-0">
{featurePreviews.length > 0 ? (
<div className="flex">
<div>
<ScrollArea className="h-[550px] w-[280px] border-r">
{allFeaturePreviews.map((feature) => {
const isEnabled = flags[feature.key] ?? false
return (
<div
key={feature.key}
onClick={() => selectFeaturePreview(feature.key)}
className={cn(
'flex items-center justify-between p-4 border-b cursor-pointer bg transition',
selectedFeature.key === feature.key ? 'bg-surface-300' : 'bg-surface-100'
)}
>
<div className="flex items-center gap-x-3">
{isEnabled ? (
<Eye size={14} strokeWidth={2} className="text-brand" />
) : (
<EyeOff size={14} strokeWidth={1.5} className="text-foreground-light" />
)}
<p className="text-sm truncate" title={feature.name}>
{feature.name}
</p>
</div>
{feature.isNew && <Badge variant="success">New</Badge>}
</div>
)
})}
</ScrollArea>
</div>
<div className="flex-grow max-h-[550px] p-4 space-y-3 overflow-y-auto">
<div className="flex items-center justify-between">
<p>{selectedFeature?.name}</p>
<div className="flex items-center gap-x-2">
{selectedFeature?.discussionsUrl !== undefined && (
<Button asChild type="default" icon={<ExternalLink strokeWidth={1.5} />}>
<Link
href={selectedFeature.discussionsUrl}
target="_blank"
rel="noreferrer"
>
Give feedback
</Link>
</Button>
)}
<Button type="default" onClick={() => toggleFeature()}>
{isSelectedFeatureEnabled ? 'Disable' : 'Enable'} feature
</Button>
</div>
</div>
{FEATURE_PREVIEW_KEY_TO_CONTENT[selectedFeature.key]}
</div>
</div>
) : (
<div className="h-[550px] flex flex-col items-center justify-center">
<FlaskConical size={30} strokeWidth={1.5} className="text-foreground-light" />
<div className="mt-1 mb-3 flex flex-col items-center gap-y-0.5">
<p className="text-sm">No feature previews available</p>
<p className="text-sm text-foreground-light">
Have an idea for the dashboard? Let us know via GitHub Discussions!
</p>
</div>
<Button asChild type="default" icon={<ExternalLink strokeWidth={1.5} />}>
<Link
href="https://github.com/orgs/supabase/discussions/categories/feature-requests"
target="_blank"
rel="noreferrer"
>
GitHub Discussions
</Link>
</Button>
</div>
)}
</DialogSection>
</DialogContent>
</Dialog>
)
}