Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import posthog from 'posthog-js'
import { Component, type ErrorInfo, type ReactNode } from 'react'

import { isChunkLoadError } from 'lib/utils/isChunkLoadError'

import { DashboardUnavailable } from './DashboardUnavailable'
import type { Dashboard } from './document/dashboardTypes'

type DashboardErrorState = {
failed: boolean
error?: unknown
dashboard: Dashboard
}

Expand All @@ -24,15 +27,22 @@ export class DashboardErrorBoundary extends Component<
return props.dashboard === state.dashboard ? null : { failed: false, dashboard: props.dashboard }
}

static getDerivedStateFromError(): Partial<DashboardErrorState> {
return { failed: true }
static getDerivedStateFromError(error: unknown): Partial<DashboardErrorState> {
return { failed: true, error }
}

override componentDidCatch(error: Error, info: ErrorInfo): void {
if (isChunkLoadError(error)) {
return
}
posthog.captureException(error, { tag: 'dashboards-v2-dashboard', componentStack: info.componentStack })
}

override render(): ReactNode {
// A widget's failed code download goes on up to the app's chunk boundary, which reloads the page.
if (this.state.failed && isChunkLoadError(this.state.error)) {
throw this.state.error
}
return this.state.failed ? <DashboardUnavailable problem="error" /> : this.props.children
}
}
22 changes: 18 additions & 4 deletions products/dashboards_v2/frontend/dashboard/DashboardUnavailable.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
import clsx from 'clsx'
import type { ReactNode } from 'react'

import * as errorHoggie from '@posthog/brand/hoggies/png/error'
import * as magnifyingGlass from '@posthog/brand/hoggies/png/magnifying-glass'
import * as stampDenied from '@posthog/brand/hoggies/png/stamp-denied'
import { Empty, EmptyContent, EmptyDescription, EmptyHeader, EmptyMedia, EmptyTitle } from '@posthog/quill'
import { IconWarning } from '@posthog/icons'
import {
Empty,
EmptyContent,
EmptyDescription,
EmptyHeader,
EmptyMedia,
EmptyTitle,
IconStack,
IconStackItem,
} from '@posthog/quill'

import { pngHoggie } from 'lib/brand/hoggies'

const HedgehogSearching = pngHoggie(magnifyingGlass)
const HedgehogDenied = pngHoggie(stampDenied)
const HedgehogError = pngHoggie(errorHoggie)

export type UnavailableReason = 'notFound' | 'noAccess' | 'error'

Expand All @@ -32,7 +40,13 @@ const DEFAULT_VIEWS: Record<UnavailableReason, ProblemView> = {
description: 'Ask the dashboard owner or a project admin to give you access.',
},
error: {
illustration: <HedgehogError />,
illustration: (
<IconStack>
<IconStackItem color="var(--destructive-foreground)">
<IconWarning />
</IconStackItem>
</IconStack>
),
title: "This dashboard couldn't be shown",
description: 'Refresh the page, and if it keeps happening contact support.',
},
Expand Down
41 changes: 15 additions & 26 deletions products/dashboards_v2/frontend/widgets/core/WidgetView.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
import { type ComponentType, Suspense, memo, useContext, useLayoutEffect } from 'react'

import * as constructionHoggie from '@posthog/brand/hoggies/png/construction-1'
import * as errorHoggie from '@posthog/brand/hoggies/png/error'
import * as panicHoggie from '@posthog/brand/hoggies/png/panic'
import * as puzzleHoggie from '@posthog/brand/hoggies/png/puzzle'
import { IconLineGraph } from '@posthog/icons'
import { IconLineGraph, IconPuzzle, IconWarning, IconWrench } from '@posthog/icons'
import { Empty, EmptyDescription, EmptyHeader, EmptyTitle, IconStack, IconStackItem, Skeleton } from '@posthog/quill'

import { pngHoggie } from 'lib/brand/hoggies'

import type { SavedWidget } from '../../dashboard/document/dashboardTypes'
import type { WidgetType } from './widgetDefinition'
import { WidgetErrorBoundary } from './WidgetErrorBoundary'
Expand All @@ -21,29 +15,24 @@ function HoldsLoad(): null {
return null
}

const HedgehogError = pngHoggie(errorHoggie)
const HedgehogPuzzle = pngHoggie(puzzleHoggie)
const HedgehogConstruction = pngHoggie(constructionHoggie)
const HedgehogPanic = pngHoggie(panicHoggie)

/** Why a widget shows a message instead of its content. A problem gets a hedgehog, and an empty result an icon. */
/** Why a widget shows a message instead of its content. */
export type WidgetProblem = 'error' | 'unknownType' | 'invalidSettings' | 'failedQuery' | 'empty'

const HOGGIE_CLASS = 'size-10 shrink-0 object-contain @min-[20rem]:size-16'

// The empty icon matches the quill empty state on v1 insights, so an empty chart reads the same on both dashboards.
const ILLUSTRATIONS: Record<WidgetProblem, JSX.Element> = {
error: <HedgehogError className={HOGGIE_CLASS} />,
unknownType: <HedgehogPuzzle className={HOGGIE_CLASS} />,
invalidSettings: <HedgehogConstruction className={HOGGIE_CLASS} />,
failedQuery: <HedgehogPanic className={HOGGIE_CLASS} />,
empty: (
function ProblemIcon({ icon, color }: { icon: JSX.Element; color: string }): JSX.Element {
return (
<IconStack>
<IconStackItem color="var(--color-product-product-analytics-light)">
<IconLineGraph />
</IconStackItem>
<IconStackItem color={color}>{icon}</IconStackItem>
</IconStack>
),
)
}

// Icons and colors match the quill states on v1 insights, so a tile reads the same on both dashboards.
const ILLUSTRATIONS: Record<WidgetProblem, JSX.Element> = {
error: <ProblemIcon icon={<IconWarning />} color="var(--destructive-foreground)" />,
unknownType: <ProblemIcon icon={<IconPuzzle />} color="var(--warning-foreground)" />,
invalidSettings: <ProblemIcon icon={<IconWrench />} color="var(--warning-foreground)" />,
failedQuery: <ProblemIcon icon={<IconWarning />} color="var(--destructive-foreground)" />,
empty: <ProblemIcon icon={<IconLineGraph />} color="var(--color-product-product-analytics-light)" />,
}

const LINE_WIDTHS = ['w-3/4', 'w-full', 'w-5/6', 'w-2/3']
Expand Down
Loading