Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(workflows): match workflow metric cards to other quill metric cards (#129629)

Sam Penningtonc638a2bb72cd
diff --git a/products/workflows/frontend/Workflows/WorkflowMetricCard.tsx b/products/workflows/frontend/Workflows/WorkflowMetricCard.tsx
index c71687e95fe0..8ac519186743 100644
--- a/products/workflows/frontend/Workflows/WorkflowMetricCard.tsx
+++ b/products/workflows/frontend/Workflows/WorkflowMetricCard.tsx
@@ -1,43 +1,30 @@
import posthog from 'posthog-js'
-import { type ErrorInfo, type ReactNode, useCallback, useMemo } from 'react'
+import { type ErrorInfo, type ReactNode, useMemo } from 'react'
import { IconArrowRight, IconInfo } from '@posthog/icons'
-import {
- DefaultTooltip,
- createTooltipDateFormatter,
- useChartTheme,
- type ChangeColor,
- type MetricChange,
- type Series,
- type TooltipContext,
-} from '@posthog/quill-charts'
+import { createTooltipDateFormatter, useChartTheme, type MetricChange, type Series } from '@posthog/quill-charts'
import {
Metric,
MetricDelta,
MetricHeader,
MetricSparkline,
+ MetricSubtitle,
MetricTitle,
MetricValue,
} from '@posthog/quill-components/metric'
import { cn, Skeleton, Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '@posthog/quill-primitives'
-import { getColorVar } from 'lib/colors'
import { AppMetricsTimeSeriesResponse } from 'lib/components/AppMetrics/appMetricsLogic'
import { formatPercentageDiff, humanFriendlyNumber } from 'lib/utils/numbers'
+import { METRICS_BAD_WHEN_RISING } from './workflowMetricsSummaryLogic'
+
const SPARKLINE_HEIGHT = 160
// `Metric` is content, not a surface, so the tile keeps the surrounding scene's chrome rather than
// quill's Card — the step tables and trends chart below it are still Lemon surfaces.
const CARD_CHROME = 'flex min-w-[16rem] flex-1 flex-col rounded border bg-surface-primary py-3'
-// The period-over-period pill stays neutral (grey), matching how these tiles reported change before —
-// several workflow metrics (Failed, Bounced, Rate Limited) are "bad when rising", so green/red good/bad
-// coloring would mislead. The chevron still shows direction.
-function neutralChange(): ChangeColor {
- return { background: 'transparent', foreground: getColorVar('muted') }
-}
-
// `Metric` contains a render throw to this tile instead of letting it take the scene down, which also
// keeps it out of error tracking — report it so a silently broken tile is still visible.
function captureRenderError(error: Error, info: ErrorInfo): void {
@@ -136,14 +123,13 @@ export function WorkflowMetricCard({
}))
}, [timeSeries, seriesColors, colorIfZero, total])
- // Only surface a comparison when there's a non-zero baseline — formatPercentageDiff returns null on
- // a zero/absent previous period, so the pill is hidden rather than showing a bogus ∞%.
- const change = useMemo<MetricChange | null>(() => {
- const label = formatPercentageDiff(total, totalPreviousPeriod)
- return label == null ? null : { value: total - totalPreviousPeriod, label }
- }, [total, totalPreviousPeriod])
+ // Hide the pill on a zero/absent previous period rather than showing a bogus ∞%.
+ const change = useMemo<MetricChange | null>(
+ () =>
+ totalPreviousPeriod === 0 ? null : { value: ((total - totalPreviousPeriod) / totalPreviousPeriod) * 100 },
+ [total, totalPreviousPeriod]
+ )
- const neutral = neutralChange()
const labelFormatter = useMemo(
() =>
timeSeries
@@ -155,18 +141,14 @@ export function WorkflowMetricCard({
: undefined,
[timeSeries?.interval, timeSeries?.labels, timeSeries?.timezone]
)
- const renderTooltip = useCallback(
- (ctx: TooltipContext) => (
- <DefaultTooltip
- {...ctx}
- sortedByValue
- showTotal
- labelFormatter={labelFormatter}
- valueFormatter={(value: number) => humanFriendlyNumber(value)}
- />
- ),
- [labelFormatter]
- )
+
+ const previousDiff =
+ total === totalPreviousPeriod ? '(no change)' : formatPercentageDiff(total, totalPreviousPeriod)
+ const restingSubtitle = !previousPeriodTimeSeries
+ ? 'Total'
+ : previousLabel
+ ? `${previousLabel}: ${humanFriendlyNumber(totalPreviousPeriod)}${previousDiff ? ` ${previousDiff}` : ''}`
+ : `vs. ${humanFriendlyNumber(totalPreviousPeriod)} prior`
const cardClassName = cn(
CARD_CHROME,
@@ -209,14 +191,14 @@ export function WorkflowMetricCard({
data={data}
series={sparklineSeries}
labels={timeSeries?.labels}
+ formatLabel={labelFormatter}
+ restingSubtitle={restingSubtitle}
theme={theme}
color={total === 0 ? colorIfZero : color}
change={previousLabel ? null : change}
- positiveColor={neutral}
- negativeColor={neutral}
+ goodDirection={METRICS_BAD_WHEN_RISING.has(name) ? 'down' : 'up'}
formatValue={(v) => humanFriendlyNumber(v)}
sparklineHeight={SPARKLINE_HEIGHT}
- sparklineTooltip={renderTooltip}
>
<MetricHeader>
<MetricTitle className="min-w-0">
@@ -241,12 +223,7 @@ export function WorkflowMetricCard({
<MetricDelta />
</MetricHeader>
<MetricValue className={compact ? 'mt-1' : 'mt-2'} />
- {previousLabel && previousPeriodTimeSeries && (
- <div className="text-xs text-muted" data-attr="workflow-metric-card-previous">
- {`${previousLabel}: ${humanFriendlyNumber(totalPreviousPeriod)}`}
- {total === totalPreviousPeriod ? ' (no change)' : change ? ` ${change.label}` : ''}
- </div>
- )}
+ <MetricSubtitle className="mt-1" />
<MetricSparkline className={compact ? '-mx-3 mt-2 h-16' : '-mx-3 mt-4'} />
</Metric>
{footer && (
diff --git a/products/workflows/frontend/Workflows/workflowMetricsSummaryLogic.ts b/products/workflows/frontend/Workflows/workflowMetricsSummaryLogic.ts
index fa6459141b1f..001edb2f8925 100644
--- a/products/workflows/frontend/Workflows/workflowMetricsSummaryLogic.ts
+++ b/products/workflows/frontend/Workflows/workflowMetricsSummaryLogic.ts
@@ -214,6 +214,21 @@ export const METRIC_COLORS: Record<string, string> = {
Triggered: getColorVar('blue'),
}
+// Keyed by display name like METRIC_COLORS. These tiles color a rise red and a fall green.
+export const METRICS_BAD_WHEN_RISING = new Set<string>([
+ 'Failed',
+ 'Bounced',
+ 'Bounce prevented',
+ 'No email address',
+ 'Frequency capped',
+ 'Marked as spam',
+ 'Suspended',
+ 'Paused',
+ 'Skipped',
+ 'Failure',
+ 'Rate Limited',
+])
+
export const WORKFLOW_SUMMARY_METRICS: Record<
WorkflowSummaryMetric,
{