import { useState } from 'react'; import { Link } from 'react-router'; import { useQueryClient } from '@tanstack/react-query'; import { AlertTriangle } from 'lucide-react'; import { useClient } from 'hooks/useClient'; import { Button } from '@/components/ui/button'; import { useTranslation } from '@/lib/i18n'; type ScreenErrorFallbackProps = { error: Error; reset: () => void }; /** * What the owner sees instead of a white screen. * * The recovery that matters is the last one. Every screen in the app renders a Workspace whose layout is * a jsonb blob written by the client and never validated on the way back in, so a malformed one throws * during render — and until this existed, the only way out was a psql session. Dashboards are left alone: * they are user-created and hold content, whereas a screen's layout is just where its panes sit. */ export const ScreenErrorFallback = ({ error, reset }: ScreenErrorFallbackProps) => { const client = useClient(); const queryClient = useQueryClient(); const { t } = useTranslation(); const [confirming, setConfirming] = useState(false); const [resetting, setResetting] = useState(false); const resetScreenLayouts = async () => { if (!confirming) return setConfirming(true); setResetting(true); try { const state = await client.get>('/dashboards'); const patch = Object.fromEntries( Object.keys(state) .filter((key) => key.startsWith('screens/')) .map((key) => [key, null]), ); if (Object.keys(patch).length > 0) await client.patch('/dashboards', patch); queryClient.removeQueries({ queryKey: ['DASHBOARD_STATE'] }); window.location.reload(); } catch (err) { console.error('[screen-error] could not reset screen layouts', err); setResetting(false); setConfirming(false); } }; return (

{t('screenError.title')}

{t('screenError.description')}

{error.message || t('screenError.unknownError')}
{error.stack}

{t('screenError.resetHint')} {t('screenError.dashboardsSafe')}

); };