import { LOCAL_STORAGE_KEYS, useParams } from 'common' import { ExternalLink, Eye, EyeOff, FlaskConical } from 'lucide-react' import Link from 'next/link' import { useRouter } from 'next/router' import { ReactNode } from 'react' import { toast } from 'sonner' import { Accordion, AccordionContent, AccordionItem, AccordionTrigger, Badge, Button, cn, Dialog, DialogContent, DialogDescription, DialogHeader, DialogSection, DialogSectionSeparator, DialogTitle, ScrollArea, Select, SelectContent, SelectItem, SelectTrigger, Tooltip, TooltipContent, TooltipTrigger, } from 'ui' import { AdvisorRulesPreview } from './AdvisorRulesPreview' import { CLSPreview } from './CLSPreview' import { ExplorerPreview } from './ExplorerPreview' import { useFeaturePreviewContext, useFeaturePreviewModal } from './FeaturePreviewContext' import { IntegrationsLayoutPreview } from './IntegrationsLayoutPreview' import { JitDbAccessPreview } from './JitDbAccessPreview' import { PgDeltaDiffPreview } from './PgDeltaDiffPreview' import { PlatformWebhooksPreview } from './PlatformWebhooksPreview' import { SqlEditorManualSavePreview } from './SqlEditorManualSavePreview' import { StorageVersioningPreview } from './StorageVersioningPreview' import { UnifiedLogsPreview } from './UnifiedLogsPreview' import { FeaturePreview, useVisibleFeaturePreviewsByCategory } from './useFeaturePreviews' import { useBannerStack } from '@/components/ui/BannerStack/BannerStackProvider' import { ButtonTooltip } from '@/components/ui/ButtonTooltip' import { useTrack } from '@/lib/telemetry/track' const FEATURE_PREVIEW_KEY_TO_CONTENT: { [key: string]: ReactNode } = { [LOCAL_STORAGE_KEYS.UI_PREVIEW_PG_DELTA_DIFF]: , [LOCAL_STORAGE_KEYS.UI_PREVIEW_ADVISOR_RULES]: , [LOCAL_STORAGE_KEYS.UI_PREVIEW_CLS]: , [LOCAL_STORAGE_KEYS.UI_PREVIEW_UNIFIED_LOGS]: , [LOCAL_STORAGE_KEYS.UI_PREVIEW_PLATFORM_WEBHOOKS]: , [LOCAL_STORAGE_KEYS.UI_PREVIEW_JIT_DB_ACCESS]: , [LOCAL_STORAGE_KEYS.UI_PREVIEW_SQL_EDITOR_MANUAL_SAVE]: , [LOCAL_STORAGE_KEYS.UI_PREVIEW_MARKETPLACE]: , [LOCAL_STORAGE_KEYS.UI_PREVIEW_EXPLORER]: , [LOCAL_STORAGE_KEYS.UI_PREVIEW_STORAGE_VERSIONING]: , } export const FeaturePreviewModal = () => { const router = useRouter() const { ref } = useParams() const { dismissBanner } = useBannerStack() const previewsByCategory = useVisibleFeaturePreviewsByCategory() const { showFeaturePreviewModal, selectedFeatureKey, selectFeaturePreview, toggleFeaturePreviewModal, } = useFeaturePreviewModal() const featurePreviewContext = useFeaturePreviewContext() const track = useTrack() const { flags, onUpdateFlag } = featurePreviewContext const allFeaturePreviews = previewsByCategory.flatMap(({ previews }) => previews) const selectedFeature = allFeaturePreviews.find((preview) => preview.key === selectedFeatureKey) ?? allFeaturePreviews[0] const isSelectedFeatureEnabled = flags[selectedFeature?.key] const canDisableSelectedFeature = selectedFeature?.isForced !== true const selectedFeatureRoute = selectedFeature?.getRoute?.(ref) const hasRoute = selectedFeatureRoute !== undefined && ref !== undefined const toggleFeature = () => { if (!selectedFeature) return const isEnabling = !isSelectedFeatureEnabled onUpdateFlag(selectedFeature.key, isEnabling) track(isEnabling ? 'feature_preview_enabled' : 'feature_preview_disabled', { feature: selectedFeature.key, }) if (!isEnabling) { toast(`${selectedFeature.name} disabled`) return } if (hasRoute) { // Navigating away drops the `featurePreviewModal` query param, which is // what closes the modal. Don't also close it via // toggleFeaturePreviewModal — its queued nuqs URL update races the push // and can navigate back to the current page, swallowing the redirect. router.push(selectedFeatureRoute) toast.success(`${selectedFeature.name} enabled`, { description: "We've taken you to where you can try it out.", }) if (selectedFeature.bannerId) dismissBanner(selectedFeature.bannerId) } else { toggleFeaturePreviewModal(false) toast.success(`${selectedFeature.name} enabled`, { description: "It's now active across the dashboard.", }) } } return ( Dashboard feature previews Get early access to new features and give feedback {allFeaturePreviews.length > 0 ? (
category ?? 'others')} > {previewsByCategory.map(({ category, previews }) => ( {category ?? 'others'} {previews.map((feature) => ( ))} ))} {/* {allFeaturePreviews.map((feature) => ( ))} */}

{selectedFeature?.name}

{selectedFeature?.discussionsUrl !== undefined && ( )} {isSelectedFeatureEnabled && ( toggleFeature()} tooltip={{ content: { side: 'bottom', className: 'max-w-64 text-center', text: canDisableSelectedFeature ? undefined : 'This feature is now the default and can no longer be turned off', }, }} > Disable feature )} {!isSelectedFeatureEnabled && ( {hasRoute ? 'Enables the feature and takes you to where you can try it out' : 'Enables this preview across the dashboard'} )}
{FEATURE_PREVIEW_KEY_TO_CONTENT[selectedFeature?.key ?? '']}
) : (

No feature previews available

Have an idea for the dashboard? Let us know via GitHub Discussions!

)}
) } const FeaturePreviewItem = ({ feature, selectedFeature, selectFeaturePreview, className, }: { feature: FeaturePreview selectedFeature: FeaturePreview selectFeaturePreview: (key: string) => void className?: string }) => { const featurePreviewContext = useFeaturePreviewContext() const { flags } = featurePreviewContext const isEnabled = flags[feature.key] ?? false return ( ) }