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(empty-states): make flag and cluster preview controls respond (#113440)

posthog[bot]377ff227a4c4
diff --git a/products/ai_observability/frontend/emptyState/ClustersPreview.scss b/products/ai_observability/frontend/emptyState/ClustersPreview.scss
index 4b8a4b1ae49e..f4644ee54c84 100644
--- a/products/ai_observability/frontend/emptyState/ClustersPreview.scss
+++ b/products/ai_observability/frontend/emptyState/ClustersPreview.scss
@@ -58,11 +58,13 @@
font-weight: 600;
}
+ // Decorative only: the list below drives the selection.
&__scatter {
display: block;
width: 100%;
height: 120px;
padding: 0.25rem 0.5rem;
+ cursor: default;
}
// Unselected clusters fade back; the selected one is painted at full strength below.
@@ -197,30 +199,38 @@
// Selected cluster, driven purely by the hidden radios.
-#clusters-preview-billing:checked ~ * .ClustersPreview__when-billing,
-#clusters-preview-bugs:checked ~ * .ClustersPreview__when-bugs,
-#clusters-preview-howto:checked ~ * .ClustersPreview__when-howto {
+.ClustersPreview__radio--billing:checked ~ * .ClustersPreview__when-billing,
+.ClustersPreview__radio--bugs:checked ~ * .ClustersPreview__when-bugs,
+.ClustersPreview__radio--howto:checked ~ * .ClustersPreview__when-howto {
@include preview-swap-visible;
}
-#clusters-preview-billing:checked ~ .ClustersPreview__list .ClustersPreview__row--billing,
-#clusters-preview-bugs:checked ~ .ClustersPreview__list .ClustersPreview__row--bugs,
-#clusters-preview-howto:checked ~ .ClustersPreview__list .ClustersPreview__row--howto {
- background: color-mix(in oklab, var(--clusters-preview-accent) 8%, transparent);
- border-color: color-mix(in oklab, var(--clusters-preview-accent) 40%, transparent);
+.ClustersPreview__radio--billing:checked ~ .ClustersPreview__list .ClustersPreview__row--billing,
+.ClustersPreview__radio--bugs:checked ~ .ClustersPreview__list .ClustersPreview__row--bugs,
+.ClustersPreview__radio--howto:checked ~ .ClustersPreview__list .ClustersPreview__row--howto {
+ background: color-mix(in oklab, var(--clusters-preview-accent) 14%, transparent);
+ border-color: var(--clusters-preview-accent);
+ box-shadow: inset 3px 0 0 var(--clusters-preview-accent);
+
+ .ClustersPreview__name {
+ @include preview-accent-text(var(--clusters-preview-accent));
+ }
}
-#clusters-preview-billing:checked ~ .ClustersPreview__plot .ClustersPreview__group--billing .ClustersPreview__point,
-#clusters-preview-bugs:checked ~ .ClustersPreview__plot .ClustersPreview__group--bugs .ClustersPreview__point,
-#clusters-preview-howto:checked ~ .ClustersPreview__plot .ClustersPreview__group--howto .ClustersPreview__point {
+.ClustersPreview__radio--billing:checked
+ ~ .ClustersPreview__plot
+ .ClustersPreview__group--billing
+ .ClustersPreview__point,
+.ClustersPreview__radio--bugs:checked ~ .ClustersPreview__plot .ClustersPreview__group--bugs .ClustersPreview__point,
+.ClustersPreview__radio--howto:checked ~ .ClustersPreview__plot .ClustersPreview__group--howto .ClustersPreview__point {
opacity: 1;
}
// The ambient bit: one trace in the selected cluster keeps arriving.
.ClustersPreview:not(.ClustersPreview--static) {
- #clusters-preview-billing:checked ~ .ClustersPreview__plot .ClustersPreview__group--billing,
- #clusters-preview-bugs:checked ~ .ClustersPreview__plot .ClustersPreview__group--bugs,
- #clusters-preview-howto:checked ~ .ClustersPreview__plot .ClustersPreview__group--howto {
+ .ClustersPreview__radio--billing:checked ~ .ClustersPreview__plot .ClustersPreview__group--billing,
+ .ClustersPreview__radio--bugs:checked ~ .ClustersPreview__plot .ClustersPreview__group--bugs,
+ .ClustersPreview__radio--howto:checked ~ .ClustersPreview__plot .ClustersPreview__group--howto {
.ClustersPreview__point:first-child {
transform-box: fill-box;
transform-origin: center;
@@ -231,9 +241,9 @@
// The radios stay keyboard-focusable while visually hidden, so the row they label
// needs a visible focus indicator (WCAG 2.4.7).
-#clusters-preview-billing:focus-visible ~ .ClustersPreview__list .ClustersPreview__row--billing,
-#clusters-preview-bugs:focus-visible ~ .ClustersPreview__list .ClustersPreview__row--bugs,
-#clusters-preview-howto:focus-visible ~ .ClustersPreview__list .ClustersPreview__row--howto {
+.ClustersPreview__radio--billing:focus-visible ~ .ClustersPreview__list .ClustersPreview__row--billing,
+.ClustersPreview__radio--bugs:focus-visible ~ .ClustersPreview__list .ClustersPreview__row--bugs,
+.ClustersPreview__radio--howto:focus-visible ~ .ClustersPreview__list .ClustersPreview__row--howto {
outline: 2px solid var(--clusters-preview-accent);
outline-offset: 1px;
}
diff --git a/products/ai_observability/frontend/emptyState/ClustersPreview.tsx b/products/ai_observability/frontend/emptyState/ClustersPreview.tsx
index bd461e281aa3..e12a71b0be69 100644
--- a/products/ai_observability/frontend/emptyState/ClustersPreview.tsx
+++ b/products/ai_observability/frontend/emptyState/ClustersPreview.tsx
@@ -1,5 +1,7 @@
import './ClustersPreview.scss'
+import { useId } from 'react'
+
import type { ProductEmptyStateMode } from 'lib/components/ProductEmptyState/types'
import { LemonTag } from 'lib/lemon-ui/LemonTag'
import { cn } from 'lib/utils/css-classes'
@@ -81,6 +83,10 @@ const CLUSTERS: PreviewCluster[] = [
*/
export function ClustersPreview({ mode }: { mode: ProductEmptyStateMode }): JSX.Element {
const isStatic = inStorybook() || inStorybookTestRunner()
+ // The preview can mount more than once on a page. Fixed ids and a shared radio
+ // name would let one instance's labels select another instance's radios.
+ const idPrefix = useId()
+ const radioId = (clusterId: string): string => `${idPrefix}-${clusterId}`
return (
<div className={cn('ClustersPreview', isStatic && 'ClustersPreview--static')}>
@@ -88,10 +94,10 @@ export function ClustersPreview({ mode }: { mode: ProductEmptyStateMode }): JSX.
<input
key={cluster.id}
type="radio"
- name="clusters-preview-cluster"
- id={`clusters-preview-${cluster.id}`}
+ name={idPrefix}
+ id={radioId(cluster.id)}
defaultChecked={i === 0}
- className="ClustersPreview__radio"
+ className={`ClustersPreview__radio ClustersPreview__radio--${cluster.id}`}
/>
))}
@@ -115,7 +121,7 @@ export function ClustersPreview({ mode }: { mode: ProductEmptyStateMode }): JSX.
{CLUSTERS.map((cluster) => (
<label
key={cluster.id}
- htmlFor={`clusters-preview-${cluster.id}`}
+ htmlFor={radioId(cluster.id)}
className={`ClustersPreview__row ClustersPreview__row--${cluster.id}`}
>
<span
diff --git a/products/feature_flags/frontend/emptyState/FeatureFlagPreview.scss b/products/feature_flags/frontend/emptyState/FeatureFlagPreview.scss
index b30d8e094c1d..f8e0695676c2 100644
--- a/products/feature_flags/frontend/emptyState/FeatureFlagPreview.scss
+++ b/products/feature_flags/frontend/emptyState/FeatureFlagPreview.scss
@@ -44,6 +44,14 @@
@include preview-swap-visible;
}
+ &__if-enabled {
+ @include preview-swap-visible;
+ }
+
+ &__if-disabled {
+ @include preview-swap-hidden;
+ }
+
&__head {
display: flex;
align-items: center;
@@ -72,13 +80,15 @@
border-radius: var(--radius);
}
- &__row--hero {
+ &__row--hero,
+ &__row--toggle {
cursor: pointer;
user-select: none;
transition: background-color 150ms ease;
}
- &__row--hero:hover {
+ &__row--hero:hover,
+ &__row--toggle:hover {
background: var(--color-bg-fill-highlight-50);
}
@@ -352,15 +362,15 @@
// Pinned-on state (user clicked the flag row)
-.FlagPreview__checkbox:checked ~ * .FlagPreview__when-on {
+.FlagPreview__checkbox--hero:checked ~ * .FlagPreview__when-on {
@include preview-swap-visible;
}
-.FlagPreview__checkbox:checked ~ * .FlagPreview__when-off {
+.FlagPreview__checkbox--hero:checked ~ * .FlagPreview__when-off {
@include preview-swap-hidden;
}
-.FlagPreview__checkbox:checked ~ .FlagPreview__panel .FlagPreview__row--hero .FlagPreview__switch {
+.FlagPreview__checkbox--hero:checked ~ .FlagPreview__panel .FlagPreview__row--hero .FlagPreview__switch {
background: var(--flag-preview-accent);
&::after {
@@ -368,25 +378,56 @@
}
}
-.FlagPreview__checkbox:checked ~ .FlagPreview__panel .FlagPreview__bar-fill--hero {
+.FlagPreview__checkbox--hero:checked ~ .FlagPreview__panel .FlagPreview__bar-fill--hero {
width: 100%;
}
-.FlagPreview__checkbox:checked ~ .FlagPreview__app .FlagPreview__cta {
+.FlagPreview__checkbox--hero:checked ~ .FlagPreview__app .FlagPreview__cta {
color: var(--color-bg-surface-primary);
background: var(--flag-preview-accent);
}
// The checkbox stays keyboard-focusable while visually hidden, so the row it labels
// needs a visible focus indicator (WCAG 2.4.7).
-.FlagPreview__checkbox:focus-visible ~ .FlagPreview__panel .FlagPreview__row--hero {
+.FlagPreview__checkbox--hero:focus-visible ~ .FlagPreview__panel .FlagPreview__row--hero {
+ outline: 2px solid var(--flag-preview-accent);
+ outline-offset: 1px;
+}
+
+// Supporting flags flip their own row only.
+
+.FlagPreview__checkbox--dark-mode:not(:checked) ~ .FlagPreview__panel .FlagPreview__row--dark-mode,
+.FlagPreview__checkbox--beta-invites:not(:checked) ~ .FlagPreview__panel .FlagPreview__row--beta-invites {
+ .FlagPreview__switch {
+ background: color-mix(in oklab, var(--color-text-secondary) 25%, var(--color-fill-secondary));
+
+ &::after {
+ transform: none;
+ }
+ }
+
+ .FlagPreview__bar-fill {
+ width: 0;
+ }
+
+ .FlagPreview__if-enabled {
+ @include preview-swap-hidden;
+ }
+
+ .FlagPreview__if-disabled {
+ @include preview-swap-visible;
+ }
+}
+
+.FlagPreview__checkbox--dark-mode:focus-visible ~ .FlagPreview__panel .FlagPreview__row--dark-mode,
+.FlagPreview__checkbox--beta-invites:focus-visible ~ .FlagPreview__panel .FlagPreview__row--beta-invites {
outline: 2px solid var(--flag-preview-accent);
outline-offset: 1px;
}
// Nudge attention at the hero switch until it's flipped.
.FlagPreview:not(.FlagPreview--static)
- .FlagPreview__checkbox:not(:checked)
+ .FlagPreview__checkbox--hero:not(:checked)
~ .FlagPreview__panel
.FlagPreview__row--hero
.FlagPreview__switch {
diff --git a/products/feature_flags/frontend/emptyState/FeatureFlagPreview.tsx b/products/feature_flags/frontend/emptyState/FeatureFlagPreview.tsx
index 833d38217989..0bc38fe2fc77 100644
--- a/products/feature_flags/frontend/emptyState/FeatureFlagPreview.tsx
+++ b/products/feature_flags/frontend/emptyState/FeatureFlagPreview.tsx
@@ -1,5 +1,7 @@
import './FeatureFlagPreview.scss'
+import { useId } from 'react'
+
import * as noir1Png from '@posthog/brand/hoggies/png/noir-1'
import * as partyPng from '@posthog/brand/hoggies/png/party'
@@ -17,21 +19,63 @@ function areaPath(line: string): string {
return `${line} L 100 40 L 0 40 Z`
}
+// Supporting flags. Each row flips its own switch and rollout bar, but only the hero
+// flag drives the app and chart below.
+const SUPPORTING_FLAG_KEYS = ['dark-mode', 'beta-invites'] as const
+
+function SupportingFlagRow({
+ flagKey,
+ rollout,
+ inputId,
+}: {
+ flagKey: string
+ rollout: string
+ inputId: string
+}): JSX.Element {
+ return (
+ <label htmlFor={inputId} className={`FlagPreview__row FlagPreview__row--toggle FlagPreview__row--${flagKey}`}>
+ <span className="FlagPreview__key">{flagKey}</span>
+ <span className="FlagPreview__bar">
+ <span className="FlagPreview__bar-fill" style={{ '--w': rollout } as React.CSSProperties} />
+ </span>
+ <span className="FlagPreview__swap">
+ <span className="FlagPreview__rollout FlagPreview__if-enabled">{rollout}</span>
+ <span className="FlagPreview__rollout FlagPreview__if-disabled">0%</span>
+ </span>
+ <span className="FlagPreview__switch FlagPreview__switch--on" aria-hidden="true" />
+ </label>
+ )
+}
+
/**
* Example-data preview for the feature flags empty state: a mini flag list wired to a
* mini app and a conversion sparkline, so flipping the hero flag re-skins the app's
- * checkout UI and steps the conversion chart up at the release marker. The whole
- * interaction is one hidden checkbox driving `:checked ~` styles - no timers or state,
+ * checkout UI and steps the conversion chart up at the release marker. Each flag is a
+ * hidden checkbox driving `:checked ~` styles - no timers or state,
* per the preview rules in the `building-product-empty-states` skill. On/off pairs are
* stacked in `__swap` grids and crossfaded, so flipping never changes the layout's size.
*/
export function FeatureFlagPreview(): JSX.Element {
const isStatic = inStorybook() || inStorybookTestRunner()
+ // The preview can mount more than once on a page, so fixed ids would let one
+ // instance's labels toggle another instance's checkboxes.
+ const idPrefix = useId()
+ const heroId = `${idPrefix}-hero`
+ const supportingId = (flagKey: string): string => `${idPrefix}-${flagKey}`
return (
<div className={cn('FlagPreview', isStatic && 'FlagPreview--static')}>
{/* Flag state, before all three cards so `:checked ~` can style them. */}
- <input type="checkbox" id="flag-preview-toggle" className="FlagPreview__checkbox" />
+ <input type="checkbox" id={heroId} className="FlagPreview__checkbox FlagPreview__checkbox--hero" />
+ {SUPPORTING_FLAG_KEYS.map((key) => (
+ <input
+ key={key}
+ type="checkbox"
+ id={supportingId(key)}
+ defaultChecked
+ className={`FlagPreview__checkbox FlagPreview__checkbox--${key}`}
+ />
+ ))}
<div className="FlagPreview__panel">
<div className="FlagPreview__head">
@@ -40,15 +84,8 @@ export function FeatureFlagPreview(): JSX.Element {
</div>
<div className="FlagPreview__rows">
- <div className="FlagPreview__row">
- <span className="FlagPreview__key">dark-mode</span>
- <span className="FlagPreview__bar">
- <span className="FlagPreview__bar-fill" style={{ '--w': '100%' } as React.CSSProperties} />
- </span>
- <span className="FlagPreview__rollout">100%</span>
- <span className="FlagPreview__switch FlagPreview__switch--on" aria-hidden="true" />
- </div>
- <label htmlFor="flag-preview-toggle" className="FlagPreview__row FlagPreview__row--hero">
+ <SupportingFlagRow flagKey="dark-mode" rollout="100%" inputId={supportingId('dark-mode')} />
+ <label htmlFor={heroId} className="FlagPreview__row FlagPreview__row--hero">
<span className="FlagPreview__key">one-click-checkout</span>
<span className="FlagPreview__bar">
<span className="FlagPreview__bar-fill FlagPreview__bar-fill--hero" />
@@ -61,14 +98,7 @@ export function FeatureFlagPreview(): JSX.Element {
</span>
<span className="FlagPreview__switch" aria-hidden="true" />
</label>
- <div className="FlagPreview__row">
- <span className="FlagPreview__key">beta-invites</span>
- <span className="FlagPreview__bar">
- <span className="FlagPreview__bar-fill" style={{ '--w': '25%' } as React.CSSProperties} />
- </span>
- <span className="FlagPreview__rollout">25%</span>
- <span className="FlagPreview__switch FlagPreview__switch--on" aria-hidden="true" />
- </div>
+ <SupportingFlagRow flagKey="beta-invites" rollout="25%" inputId={supportingId('beta-invites')} />
</div>
<div className="FlagPreview__hint FlagPreview__swap">