: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
feat(experiments): show health checks as a list with a detail panel (#128224)
Marcel Poelkerc56e20380d36
diff --git a/frontend/snapshots.yml b/frontend/snapshots.ymlindex 5f96419f918d..f4a76d7b1d82 100644--- a/frontend/snapshots.yml+++ b/frontend/snapshots.yml@@ -3405,37 +3405,41 @@ snapshots:errortracking-volumesparkline--events-before-data-range--light:hash: v1.k794b7964.c88c4e3b028915efba3fdbbac7107a063662d8210dfb6ba8667e96d719fa3d4f.tzwEQFa4F1f1O9PGqBkcaqSavbFVgAwPAjyh9Uf9NL8experiments-healthchecksoverview--check-details-of-a-check-that-does-not-apply--dark:- hash: v1.k794b7964.ebb5b817b0a9b4bb6bae2c3cd45a0b38818584e8866134b61c08ffd93f3362d5.MUjVFifBOedHd2GA6TtvfKp-Nx8Mj5I-UTOq1JPnVzY+ hash: v1.k794b7964.ac9691ae7fc3d5474c510b5e55920aec536a30642aab1c9fd7aff05357b410b5.q2-oBgQnvLkgb0wTyPc79z7c9XIwv3KeWXcJMfCmyH8experiments-healthchecksoverview--check-details-of-a-check-that-does-not-apply--light:- hash: v1.k794b7964.f5e4913a62e1e01741dc4e880598bb8c201005b0f704d7fe720d1797c9718fc1.VQCG4WEsoHK-jWyrAJAH1N5TdIS0d2F3ZiPiQO-k_cs+ hash: v1.k794b7964.d624e91300f29ae3764d991314bca061ee3f4ce82e95b4e80d47c9486e949428.ZeSDib1epm7V-v0za6cgt1fOQrbzdbyJfPKpgo7LOKQexperiments-healthchecksoverview--check-details-with-a-measurement--dark:- hash: v1.k794b7964.beea1b208d24c851f82094bed9f3a39aae5ae3caad0481d24de610ca9a8253b1.Ok3EDpxjH9-hXggrp7MlVAZDCy_lmYhSr-cM_GVPdqw+ hash: v1.k794b7964.5c0fe861f003d8d40ef6fb2c1ef865e4e33a99c00c7806f927c4c1d124a4da5b.g8YZDTqe7h9wK_zfgCwKK3rWtBmxe4dPY7H1kZ56Rqkexperiments-healthchecksoverview--check-details-with-a-measurement--light:- hash: v1.k794b7964.38a1738c641bdffa21c9644f5b673732b5aedbd8d09c36f4a1cce484393614cd.bW-xQzxh7qk1_h1dsXbx_H9IaA0S21haMS3KfULxCts+ hash: v1.k794b7964.2285a46e750551fcf1517e608aa44c2e0ff21063073163b5cc3cdfe11299fe19.RGf6GJMCnDe9524DnNmaXbiwfJTzKC5VPhtSwoxLNjkexperiments-healthchecksoverview--checks-that-could-not-run--dark:- hash: v1.k794b7964.f7edab6e955759c878ca746667f1eca6ec1db0c1fae2347081e5856d0bc6ed91.xWcWzMN0s2HjBOE6c2Js6i_vQZnPNevNCI05GBRw6KQ+ hash: v1.k794b7964.4f9a1d79253a510d61a042b769ea713fe81a0dfd69f637793a3b4885767b4ebf.KEXIDF1qOULpEjp9trhlH1Q2NyDsE-Ts0L_xuRMqETgexperiments-healthchecksoverview--checks-that-could-not-run--light:- hash: v1.k794b7964.e7f8cc191ade33ceec892f3a06bd905baec01a0e29ffef5e7ebddad7b9204723.eU-HWniM8QwPua44W2kUqH3juub-oTKnfi-kyhwKTmk+ hash: v1.k794b7964.6a3b2955e394047ece6233bf17b3a12ed0c969aab5b514b511879f2289b11f4e.txKJCMAIXncg726hJ4ev6YS3xDPue5hXCrHrjeoXFZUexperiments-healthchecksoverview--draft--dark:- hash: v1.k794b7964.d16ac34a2d5ace6fbd43f4e3326b70de8f2ef8136650781aa81b569a4a0ac379.upf1fasUVWnNtl__hRaoDQEjhdA5__LtqImlkqR7JYo+ hash: v1.k794b7964.227cc0afccb826a9b2e2be4f71f568298b3d71274cbaeb7c6efca8ac1f1ad781.ndRiDlo2tQLo6JYkTZiZvKkzdw_4ZZLugU2Dz8yPfBYexperiments-healthchecksoverview--draft--light:- hash: v1.k794b7964.fbeeca6537a201435f6d6b87a88c52b26fdec333d84b731c4523c20290b34c0d.YlZcgD0vIoCVuaNCHq-GXYgUcplhODFha-FyOkfjMKY+ hash: v1.k794b7964.c67c443f646df3902b4b1d7f29abdb44e2d4daba0f8316176be44999ec5ec06d.JCtVFPHsbvHcrPf_jx5vCQbZJyZVU2pec7z9Kl3MsZEexperiments-healthchecksoverview--draft-with-events-not-received--dark:- hash: v1.k794b7964.593d931ef10e1dfa13c3b9e84fcac505808e5dcf9e251def8fd74f8e477a09b8.5TO3tRdAiqZRSkQ5z_fSXmh-tcU448WwZrpoQt0AhPA+ hash: v1.k794b7964.dd76a5cb3a731fff2c1cc9f27273daf6d9d35d7dd6c5afab250c63b7a92251b8.YyL-Hh9vEkAP2WqWWCcV2YQA53bHaH3GoxMO1zU8w0kexperiments-healthchecksoverview--draft-with-events-not-received--light:- hash: v1.k794b7964.cdbd81729b929387c92c3445151ffa0b44db0dbcb669edf5530a9218d42d88a5.zEyeK3-4p_p-O_-RziKypXwXiOr7_c_GsqMjGzjFMCk+ hash: v1.k794b7964.e7f16fc830a5d3fb7f7ec2a62373cac995c145471ccee8fca6a32887ae65b844.9hBRYTORg7jy_A9qVN96BU6f2MY-EmkyHUhzVRnWA3k+ experiments-healthchecksoverview--narrow-with-a-check-picked--dark:+ hash: v1.k794b7964.5506c13a990e9a69b2d2fdeeba5ef49e0ec36e910ebd687abb78b8032bfbfc36.jFkmbmtjk6TUMg6zK5zU59pUmyKDaoghH9nFl90RKmM+ experiments-healthchecksoverview--narrow-with-a-check-picked--light:+ hash: v1.k794b7964.4f7b9d85c2056e42771ceedfc5ebfbd54ea7277b749e05bbaf1652162f82e775.LC8RwdJpkXnwWYuas947fm8syybLy3QDAFAbf8ZXWRsexperiments-healthchecksoverview--running-with-an-issue--dark:- hash: v1.k794b7964.4eaa36867b90c26f36b146f519ddaa00e9668301064716efe0992beeb572f516.5uSKe33yLu7tuwvNIsF4GWofGFvge6niuE4tcyCDz4c+ hash: v1.k794b7964.fe8cf445d9e5ed4f406c794bf62357aa827742beb8c53464e2925f75843abc9b.Kbi8IXqEetITzgs_VhDwPQYsxEvJawQwHEoKpGhdCLYexperiments-healthchecksoverview--running-with-an-issue--light:- hash: v1.k794b7964.36d898bc716c594dacd4998dae84414ff0b7e70171426e6b07e7c0b732bd98d3.bmoF1F9NGvYbtS6R_uKhPLBnKlwMCfROEPMcGaYDDMw+ hash: v1.k794b7964.844ee662239ead860dbbfe305ab35133e43419fae91b7fcd6fc2e784817bb9d3.pm1SyPteJF0wjcsY89B_yhp63O9rZrqX3uueA9Nv9ykexperiments-healthchecksoverview--running-with-metric-windows-not-complete--dark:- hash: v1.k794b7964.3678a64cb528ceaca7d91459a0eddd12fe61c50c9190bd04c0b773db27771002.G4JwFDn0J8aXv3Qo3Jaf6M0tmhqwp_D4GP_QfqVmGAo+ hash: v1.k794b7964.2aa9d15debf2e7a5c3e89c97544307912994e5068cd11411b22b69703f861d6b.V8kz3w27dBeWJAyP0Wd9VEBZz7tQpYJAtQ3nYlP0kqIexperiments-healthchecksoverview--running-with-metric-windows-not-complete--light:- hash: v1.k794b7964.6f0f2095c2fac0466734599b45d96b043bb2a16b147df6346a27198e9d001aeb.Nf_8pb45Uk1zPZhHVpuMRLc7QSPmp2i5Wxei_PqSVRU+ hash: v1.k794b7964.aab9171c323a4de21008508fe6c03bd64c4b84b8603c934e1bb2b494992155ba.U4_d1SnqQ3VhuW6H43277T0YpsflKV8lpfSu1txOnKYexperiments-healthchecksoverview--running-with-significance-on-a-small-sample--dark:- hash: v1.k794b7964.5e53a67703b82bcc386061e3cfb32654c7abe3deb61711f5047260de67ba950c.uakl2Ik2xiH0o4dIAjpjHsbnPipnwoYx6uNZX4uIcto+ hash: v1.k794b7964.780b197f87a7ed50a5e0da73e9e66e6de2b86308e8127fd581c0c01b741080ad.vdVUcA3q7eLsQKRrTfuiXkkVGnkHWvq89a-mQYRE0b0experiments-healthchecksoverview--running-with-significance-on-a-small-sample--light:- hash: v1.k794b7964.1fc60ac88944e51bc7ac686cd4ea4bab33e265c0b6234562eb9ac2f7871d99c7.-B5a36kS4xMd0A0ZkCfd6Q3zwVLieVcNJjLbuUhfCv8+ hash: v1.k794b7964.b048631809f04945042086b7ddc687ebd3744d4077cd5ad3d4a198b61581d8b2.QeR91ugmGnSAhNZ7BB35BKu-2mN0kU0H3aYsXsk4Wr0experiments-howtoreadtooltip--intervals-bayesian--dark:hash: v1.k794b7964.a06d267cee9cb54bafc732335b35d461d3c1a59250c6daa8becace0fcb8492d2.vR5tecOozn6B51xE8LrByAFVsi03J4w-iUu-j2hQUTUexperiments-howtoreadtooltip--intervals-bayesian--light:diff --git a/frontend/src/scenes/experiments/ExperimentView/ExperimentView.tsx b/frontend/src/scenes/experiments/ExperimentView/ExperimentView.tsxindex 5566a6dbba4c..298a7f5e296c 100644--- a/frontend/src/scenes/experiments/ExperimentView/ExperimentView.tsx+++ b/frontend/src/scenes/experiments/ExperimentView/ExperimentView.tsx@@ -158,23 +158,14 @@ export function ExperimentView(): JSX.Element {const healthIssueCount = healthIssues(healthFindings).length- // Ordered as: results (Metrics), configuration (Settings, Code, Variants), feature tabs (Recordings,- // User feedback), audit trail (History), checks (Health, then the staff-only Health debug).+ // Ordered as: results (Metrics, then the Health checks that say whether to trust them), configuration+ // (Settings, Code, Variants), feature tabs (Recordings, User feedback), audit trail (History), and the+ // staff-only Health debug.// Which of these actually render is resolved by experimentSceneLogic's availableTabs, so the tab set,// the URL, and the tracked tab stay in agreement.const tabs: LemonTab<ExperimentTab>[] = ([{ key: 'metrics', label: 'Metrics', content: <MetricsTab /> },- { key: 'settings', label: 'Settings', content: <SettingsTab /> },- { key: 'code', label: 'Code', content: <CodeTab /> },- { key: 'variants', label: 'Variants', content: <VariantsTab /> },- { key: 'recordings', label: 'Recordings', content: <ExperimentReplayTab experiment={experiment} /> },- { key: 'feedback', label: 'User feedback', content: <ExperimentFeedbackTab experiment={experiment} /> },- {- key: 'history',- label: 'History',- content: <ActivityLog scope={ActivityScope.EXPERIMENT} id={experimentId} />,- },{key: 'health',label: (@@ -195,6 +186,16 @@ export function ExperimentView(): JSX.Element {),content: <ExperimentHealthTab />,},+ { key: 'settings', label: 'Settings', content: <SettingsTab /> },+ { key: 'code', label: 'Code', content: <CodeTab /> },+ { key: 'variants', label: 'Variants', content: <VariantsTab /> },+ { key: 'recordings', label: 'Recordings', content: <ExperimentReplayTab experiment={experiment} /> },+ { key: 'feedback', label: 'User feedback', content: <ExperimentFeedbackTab experiment={experiment} /> },+ {+ key: 'history',+ label: 'History',+ content: <ActivityLog scope={ActivityScope.EXPERIMENT} id={experimentId} />,+ },{ key: 'health-debug', label: 'Health debug', content: <ExperimentHealthDebug /> },] satisfies LemonTab<ExperimentTab>[]).filter((tab) => availableTabs.includes(tab.key))diff --git a/frontend/src/scenes/experiments/ExperimentView/healthFindingReporting.test.tsx b/frontend/src/scenes/experiments/ExperimentView/healthFindingReporting.test.tsxindex 0acc01f3c7aa..5f649a21e3ab 100644--- a/frontend/src/scenes/experiments/ExperimentView/healthFindingReporting.test.tsx+++ b/frontend/src/scenes/experiments/ExperimentView/healthFindingReporting.test.tsx@@ -123,7 +123,16 @@ describe('health finding reporting', () => {diagnostic_ref: 'A5',},],- checks: [],+ checks: [+ {+ key: 'no_metric',+ name: 'Metrics not set up',+ description: 'Checks that a launched experiment has at least one metric.',+ status: 'passed',+ reason: null,+ measurement: null,+ },+ ],})logic.actions.loadExposuresSuccess(exposures)render(@@ -137,6 +146,11 @@ describe('health finding reporting', () => {)}+ // The detail repeats the title of the picked finding or check, and the list comes first in the page.+ const pickFromList = async (title: string): Promise<void> => {+ await userEvent.click(screen.getAllByText(title)[0])+ }+beforeEach(() => {const emptyList = { count: 0, next: null, previous: null, results: [] }useMocks({@@ -216,8 +230,15 @@ describe('health finding reporting', () => {})it.each([- { control: 'Open feature flag', step: 'acted on', code: 'flag_off_while_running', kind: 'open_feature_flag' },{+ pick: null,+ control: 'Open feature flag',+ step: 'acted on',+ code: 'flag_off_while_running',+ kind: 'open_feature_flag',+ },+ {+ pick: 'The uneven split may bias the results',control: 'Use first seen variant',step: 'acted on',code: 'bias_risk_multiple_excluded',@@ -225,8 +246,11 @@ describe('health finding reporting', () => {},])('reports $code as $step with $kind when a person uses "$control" in the health tab',- async ({ control, step, code, kind }) => {+ async ({ pick, control, step, code, kind }) => {renderHealth(UNEVEN_EXPOSURES)+ if (pick) {+ await pickFromList(pick)+ }captureSpy.mockClear()await userEvent.click(screen.getByText(control))@@ -235,18 +259,64 @@ describe('health finding reporting', () => {})- it('shows the detail of an issue on the health tab without reporting it as opened until a person reopens it', async () => {- renderHealth(NO_EXPOSURES)- expect(screen.getByText(/The linked feature flag is disabled/)).toBeInTheDocument()- captureSpy.mockClear()+ it.each([+ {+ container: 'wide',+ isNarrow: false,+ expected: [+ ['experiment health finding opened', 'srm'],+ ['experiment health check expanded', 'no_metric'],+ ],+ },+ {+ container: 'narrow',+ isNarrow: true,+ expected: [+ ['experiment health finding opened', 'flag_off_while_running'],+ ['experiment health finding opened', 'srm'],+ ['experiment health finding opened', 'srm'],+ ['experiment health check expanded', 'no_metric'],+ ],+ },+ ])(+ 'reports each finding or check a person opens on the health tab in a $container container',+ async ({ isNarrow, expected }) => {+ // jsdom applies no container query, so the detail stays beside the list until `hidden` takes effect,+ // as it does below the breakpoint.+ const narrowStyles = document.head.appendChild(document.createElement('style'))+ narrowStyles.textContent = isNarrow ? '.hidden { display: none; }' : ''+ try {+ renderHealth(UNEVEN_EXPOSURES)+ expect(screen.getByText(/The linked feature flag is disabled/)).toBeInTheDocument()+ const pickEvents = (): (string | undefined)[][] =>+ captureSpy.mock.calls+ .filter(([event]) =>+ ['experiment health finding opened', 'experiment health check expanded'].includes(+ String(event)+ )+ )+ .map(([event, properties]) => [event, properties.finding_code ?? properties.check_key])+ expect(pickEvents()).toEqual([])- const [flagStateWhy] = screen.getAllByText('Why?')- await userEvent.click(flagStateWhy)- expect(findingEvents()).toEqual([])- await userEvent.click(flagStateWhy)+ // A narrow container shows the list or the detail, so the reader goes back to the list between picks.+ for (const title of [+ 'The experiment is paused',+ 'Users are not split across variants as configured',+ 'Users are not split across variants as configured',+ 'Metrics not set up',+ ]) {+ await pickFromList(title)+ if (isNarrow) {+ await userEvent.click(screen.getByText('All checks'))+ }+ }- expect(findingEvents()).toEqual([['experiment health finding opened', 'flag_off_while_running', 'why']])- })+ expect(pickEvents()).toEqual(expected)+ } finally {+ narrowStyles.remove()+ }+ }+ )it('reports zero exposures only from the open panel, as shown and then as opened', async () => {renderWarnings(NO_EXPOSURES)diff --git a/frontend/src/scenes/experiments/experimentSceneLogic.tsx b/frontend/src/scenes/experiments/experimentSceneLogic.tsxindex bf09e928215e..5deccb21f8e7 100644--- a/frontend/src/scenes/experiments/experimentSceneLogic.tsx+++ b/frontend/src/scenes/experiments/experimentSceneLogic.tsx@@ -53,13 +53,13 @@ function reportExperimentTabViewed(experimentId: ExperimentIdType, tab: string):export const EXPERIMENT_TABS = ['metrics',+ 'health','settings','code','variants','recordings','feedback','history',- 'health','health-debug',] as constexport type ExperimentTab = (typeof EXPERIMENT_TABS)[number]diff --git a/products/experiments/frontend/health/ExperimentHealthTab.tsx b/products/experiments/frontend/health/ExperimentHealthTab.tsxindex d2dd19cb0887..5b956d781ed6 100644--- a/products/experiments/frontend/health/ExperimentHealthTab.tsx+++ b/products/experiments/frontend/health/ExperimentHealthTab.tsx@@ -22,8 +22,7 @@ export function ExperimentHealthTab(): JSX.Element {}return (- // A reading width, so a finding's buttons stay next to its title.- <div className="flex flex-col gap-2 max-w-3xl" data-attr="experiment-health-tab">+ <div className="flex flex-col gap-2" data-attr="experiment-health-tab"><LemonCard hoverEffect={false} className="p-0"><HealthChecksOverviewchecks={healthChecks}diff --git a/products/experiments/frontend/health/HealthCheckDetail.tsx b/products/experiments/frontend/health/HealthCheckDetail.tsxnew file mode 100644index 000000000000..71100bf69ef6--- /dev/null+++ b/products/experiments/frontend/health/HealthCheckDetail.tsx@@ -0,0 +1,28 @@+import { HEALTH_CHECK_STATUS_DISPLAY, healthCheckStatusText } from './healthCheckStatusDisplay'+import { type ListedHealthCheck, healthMeasurementText } from './healthPanelChecks'++export function HealthCheckDetail({ check }: { check: ListedHealthCheck }): JSX.Element {+ return (+ <div className="flex flex-col gap-4" data-attr="experiment-health-check-detail">+ <div className="flex flex-col gap-1">+ <h3 className="m-0 flex items-center gap-2 text-base font-semibold">+ <span className="flex shrink-0">{HEALTH_CHECK_STATUS_DISPLAY[check.status].icon}</span>+ <span>{check.name}</span>+ </h3>+ <span className="pl-6 text-xs text-secondary">{healthCheckStatusText(check)}</span>+ </div>+ {check.description && (+ <section className="flex flex-col gap-1">+ <h4 className="m-0 text-xs font-semibold text-secondary">What it looks for</h4>+ <p className="m-0 max-w-prose">{check.description}</p>+ </section>+ )}+ {check.measurement && (+ <section className="flex flex-col gap-1">+ <h4 className="m-0 text-xs font-semibold text-secondary">Result</h4>+ <p className="m-0 max-w-prose">{healthMeasurementText(check.measurement)}</p>+ </section>+ )}+ </div>+ )+}diff --git a/products/experiments/frontend/health/HealthCheckList.tsx b/products/experiments/frontend/health/HealthCheckList.tsxindex addf0e339be0..94afe5385be9 100644--- a/products/experiments/frontend/health/HealthCheckList.tsx+++ b/products/experiments/frontend/health/HealthCheckList.tsx@@ -1,17 +1,10 @@-import { IconCheck, IconMinus, IconQuestion } from '@posthog/icons'-import { HealthCheckPlainRow } from './HealthCheckPlainRow'import { HealthCheckRow } from './HealthCheckRow'+import { HEALTH_CHECK_STATUS_DISPLAY } from './healthCheckStatusDisplay'import type { ListedHealthCheck } from './healthPanelChecks'type ListedStatus = ListedHealthCheck['status']-const STATUS_DISPLAY: Record<ListedStatus, { icon: JSX.Element; label: string }> = {- not_checked: { icon: <IconQuestion className="text-secondary" />, label: "Couldn't check" },- passed: { icon: <IconCheck className="text-success" />, label: 'No issue found' },- not_applicable: { icon: <IconMinus className="text-tertiary" />, label: "Doesn't apply" },-}-interface CheckGroup {label: stringstatus: ListedStatus@@ -22,7 +15,7 @@ interface CheckGroup {function groupByOutcome(checks: ListedHealthCheck[]): CheckGroup[] {const groups = new Map<string, CheckGroup>()for (const check of checks) {- const label = check.reason ?? STATUS_DISPLAY[check.status].label+ const label = check.reason ?? HEALTH_CHECK_STATUS_DISPLAY[check.status].labelconst key = `${check.status}:${label}`const group = groups.get(key) ?? { label, status: check.status, checks: [] }group.checks.push(check)@@ -34,9 +27,13 @@ function groupByOutcome(checks: ListedHealthCheck[]): CheckGroup[] {export function HealthCheckList({checks,exposureChecksMissing,+ selectedKey,+ onSelect,}: {checks: ListedHealthCheck[]exposureChecksMissing: boolean+ selectedKey: ListedHealthCheck['key'] | null+ onSelect: (check: ListedHealthCheck) => void}): JSX.Element {return (<div className="flex flex-col gap-4 px-3 py-2" data-attr="experiment-health-check-list">@@ -46,8 +43,8 @@ export function HealthCheckList({<span className="text-xs font-semibold text-secondary">Couldn't check. Refresh the results to run these checks.</span>- <ul className="m-0 p-0 list-none flex flex-col">- <HealthCheckPlainRow icon={STATUS_DISPLAY.not_checked.icon}>+ <ul className="-mx-2 m-0 p-0 list-none flex flex-col">+ <HealthCheckPlainRow icon={HEALTH_CHECK_STATUS_DISPLAY.not_checked.icon}><span>Exposure checks</span></HealthCheckPlainRow></ul>@@ -56,9 +53,15 @@ export function HealthCheckList({{groupByOutcome(checks).map((group) => (<div key={`${group.status}:${group.label}`} className="flex flex-col gap-1"><span className="text-xs font-semibold text-secondary">{group.label}</span>- <ul className="m-0 p-0 list-none flex flex-col">+ <ul className="-mx-2 m-0 p-0 list-none flex flex-col">{group.checks.map((check) => (- <HealthCheckRow key={check.key} check={check} icon={STATUS_DISPLAY[group.status].icon} />+ <HealthCheckRow+ key={check.key}+ check={check}+ icon={HEALTH_CHECK_STATUS_DISPLAY[group.status].icon}+ isSelected={check.key === selectedKey}+ onSelect={() => onSelect(check)}+ />))}</ul></div>diff --git a/products/experiments/frontend/health/HealthCheckPlainRow.tsx b/products/experiments/frontend/health/HealthCheckPlainRow.tsxindex 7dc49ccb4c3e..8378a6b4def3 100644--- a/products/experiments/frontend/health/HealthCheckPlainRow.tsx+++ b/products/experiments/frontend/health/HealthCheckPlainRow.tsx@@ -3,7 +3,7 @@ import type { ReactNode } from 'react'/** A row that opens nothing. It copies the height, gap and sizes of the xsmall button rows, so both kinds line up. */export function HealthCheckPlainRow({ icon, children }: { icon: JSX.Element; children: ReactNode }): JSX.Element {return (- <li className="flex items-center gap-1 min-h-[1.625rem] pl-0.5 text-xs">+ <li className="flex items-center gap-1 min-h-[1.625rem] pl-2 text-xs"><span className="flex shrink-0 text-sm">{icon}</span>{children}</li>diff --git a/products/experiments/frontend/health/HealthCheckRow.tsx b/products/experiments/frontend/health/HealthCheckRow.tsxindex 8d0d8e2ca90c..666f35dba1af 100644--- a/products/experiments/frontend/health/HealthCheckRow.tsx+++ b/products/experiments/frontend/health/HealthCheckRow.tsx@@ -1,18 +1,21 @@-import { useActions } from 'kea'-import { useId, useState } from 'react'-import { LemonButton } from '@posthog/lemon-ui'import { cn } from 'lib/utils/css-classes'-import { experimentLogic } from 'scenes/experiments/experimentLogic'import { HealthCheckPlainRow } from './HealthCheckPlainRow'-import { type ListedHealthCheck, healthMeasurementText } from './healthPanelChecks'+import type { ListedHealthCheck } from './healthPanelChecks'-export function HealthCheckRow({ check, icon }: { check: ListedHealthCheck; icon: JSX.Element }): JSX.Element {- const [isDetailOpen, setIsDetailOpen] = useState(false)- const detailId = useId()- const { reportHealthCheckExpanded } = useActions(experimentLogic)+export function HealthCheckRow({+ check,+ icon,+ isSelected,+ onSelect,+}: {+ check: ListedHealthCheck+ icon: JSX.Element+ isSelected: boolean+ onSelect: () => void+}): JSX.Element {const name = <span className={cn(check.status === 'not_applicable' && 'text-secondary')}>{check.name}</span>if (!check.description) {@@ -21,29 +24,18 @@ export function HealthCheckRow({ check, icon }: { check: ListedHealthCheck; icon}return (- <li className="flex flex-col">+ <li><LemonButtonsize="xsmall"+ fullWidthicon={icon}- className="-mx-1"- onClick={() => {- if (!isDetailOpen) {- reportHealthCheckExpanded(check)- }- setIsDetailOpen(!isDetailOpen)- }}- aria-expanded={isDetailOpen}- aria-controls={detailId}+ active={isSelected}+ onClick={onSelect}+ aria-current={isSelected ? 'true' : undefined}data-attr="experiment-health-check">{name}</LemonButton>- {isDetailOpen && (- <div id={detailId} className="flex flex-col gap-1 pl-5 pb-1 text-xs">- <p className="m-0 text-secondary">{check.description}</p>- {check.measurement && <span>{healthMeasurementText(check.measurement)}</span>}- </div>- )}</li>)}diff --git a/products/experiments/frontend/health/HealthChecksOverview.stories.tsx b/products/experiments/frontend/health/HealthChecksOverview.stories.tsxindex 561975e4d8f9..debfb47da52b 100644--- a/products/experiments/frontend/health/HealthChecksOverview.stories.tsx+++ b/products/experiments/frontend/health/HealthChecksOverview.stories.tsx@@ -53,7 +53,7 @@ const meta: Meta<typeof HealthChecksOverview> = {args: { onFindingActedOn: () => {} },decorators: [(Story) => (- <div className="w-96">+ <div className="w-[60rem]"><Story /></div>),@@ -283,3 +283,19 @@ export const CheckDetailsOfACheckThatDoesNotApply: Story = {)},}++export const NarrowWithACheckPicked: Story = {+ args: CheckDetailsWithAMeasurement.args,+ decorators: [+ (Story) => (+ <div className="w-[32rem]">+ <Story />+ </div>+ ),+ ],+ play: async ({ canvasElement }) => {+ await userEvent.click(+ await within(canvasElement).findByRole('button', { name: /Split of users across variants/ })+ )+ },+}diff --git a/products/experiments/frontend/health/HealthChecksOverview.tsx b/products/experiments/frontend/health/HealthChecksOverview.tsxindex 9d31f22c0007..eb171e71b563 100644--- a/products/experiments/frontend/health/HealthChecksOverview.tsx+++ b/products/experiments/frontend/health/HealthChecksOverview.tsx@@ -1,10 +1,21 @@-import { LemonTag } from '@posthog/lemon-ui'+import { useActions } from 'kea'+import { useRef, useState } from 'react'+import { IconChevronLeft } from '@posthog/icons'+import { LemonButton, LemonTag } from '@posthog/lemon-ui'++import { cn } from 'lib/utils/css-classes'+import { experimentLogic } from 'scenes/experiments/experimentLogic'++import { HealthCheckDetail } from './HealthCheckDetail'import { HealthCheckList } from './HealthCheckList'import { HealthChecksSummary } from './HealthChecksSummary'-import { HealthFindingRow } from './HealthFindingRow'+import { HealthChecksSummaryDetail } from './HealthChecksSummaryDetail'+import { HealthFindingDetail } from './HealthFindingDetail'+import { HealthFindingListItem } from './HealthFindingListItem'import { type HealthPanelCheck, listedHealthChecks } from './healthPanelChecks'import { type HealthPanelFinding, healthIssues } from './healthPanelFindings'+import { type HealthPanelSelection, healthFindingKey, resolveHealthPanelSelection } from './healthPanelSelection'export function HealthChecksOverview({checks,@@ -20,36 +31,103 @@ export function HealthChecksOverview({exposureChecksMissing: booleanonFindingActedOn?: () => void}): JSX.Element {+ const [pickedSelection, setPickedSelection] = useState<HealthPanelSelection | null>(null)+ // A narrow container shows the list or the detail, not both. Wide containers ignore this.+ const [isDetailOpenWhenNarrow, setIsDetailOpenWhenNarrow] = useState(false)+ const { reportHealthCheckExpanded } = useActions(experimentLogic)const listedChecks = listedHealthChecks(checks)+ const issueCount = healthIssues(findings).length+ const selection = resolveHealthPanelSelection(pickedSelection, findings, listedChecks)++ const detailRef = useRef<HTMLElement>(null)++ // Returns whether the pick puts a detail on screen, which is what reports it as opened. The first issue shows+ // without a click, but only beside the list: a narrow container hides the detail behind the list, so there a+ // click opens even the item that is already picked. Only the container query knows the width, so ask the page.+ const select = (next: HealthPanelSelection, isSelected: boolean): boolean => {+ const opensDetail = !isSelected || !detailRef.current || getComputedStyle(detailRef.current).display === 'none'+ setPickedSelection(next)+ setIsDetailOpenWhenNarrow(true)+ return opensDetail+ }return (- <div className="flex flex-col w-full" data-attr="experiment-health-overview">- <div className="flex flex-col gap-1 px-3 py-2">- <div className="flex items-center gap-2">- <span className="text-sm font-semibold">Health checks</span>- <LemonTag type="completion">Beta</LemonTag>- </div>- <HealthChecksSummary checks={checks} issueCount={healthIssues(findings).length} isDraft={isDraft} />+ <div className="@container/health-checks w-full" data-attr="experiment-health-overview">+ <div className="flex flex-col @min-[48rem]/health-checks:flex-row">+ <nav+ aria-label="Health checks"+ className={cn(+ 'flex-col @min-[48rem]/health-checks:flex @min-[48rem]/health-checks:w-80 @min-[48rem]/health-checks:shrink-0 @min-[48rem]/health-checks:border-r',+ isDetailOpenWhenNarrow ? 'hidden' : 'flex'+ )}+ >+ <div className="flex flex-col gap-1 px-3 py-2">+ <div className="flex items-center gap-2">+ <span className="text-sm font-semibold">Health checks</span>+ <LemonTag type="completion">Beta</LemonTag>+ </div>+ <HealthChecksSummary checks={checks} issueCount={issueCount} isDraft={isDraft} />+ </div>+ {findings.length > 0 && (+ // A note mounts, and so reports as shown, only when the reader opens the health tab. An issue+ // reports once per load, from the header chip or from here, whichever shows it first.+ <ul className="m-0 list-none flex flex-col gap-0.5 border-t px-1 py-2">+ {findings.map((finding) => {+ const key = healthFindingKey(finding)+ const isSelected = selection.kind === 'finding' && selection.key === key+ return (+ <HealthFindingListItem+ key={key}+ finding={finding}+ isSelected={isSelected}+ onSelect={() => select({ kind: 'finding', key }, isSelected)}+ />+ )+ })}+ </ul>+ )}+ {(listedChecks.length > 0 || exposureChecksMissing) && (+ <div className="border-t">+ <HealthCheckList+ checks={listedChecks}+ exposureChecksMissing={exposureChecksMissing}+ selectedKey={selection.kind === 'check' ? selection.key : null}+ onSelect={(check) => {+ const isSelected = selection.kind === 'check' && selection.key === check.key+ if (select({ kind: 'check', key: check.key }, isSelected)) {+ reportHealthCheckExpanded(check)+ }+ }}+ />+ </div>+ )}+ </nav>+ <section+ ref={detailRef}+ aria-label="Health check details"+ className={cn(+ 'flex-1 min-w-0 flex-col gap-3 px-4 py-3 @min-[48rem]/health-checks:flex',+ isDetailOpenWhenNarrow ? 'flex' : 'hidden'+ )}+ >+ <LemonButton+ size="small"+ icon={<IconChevronLeft />}+ className="self-start @min-[48rem]/health-checks:hidden"+ onClick={() => setIsDetailOpenWhenNarrow(false)}+ data-attr="experiment-health-back-to-list"+ >+ All checks+ </LemonButton>+ {selection.kind === 'finding' ? (+ <HealthFindingDetail finding={selection.finding} onActedOn={onFindingActedOn} />+ ) : selection.kind === 'check' ? (+ <HealthCheckDetail check={selection.check} />+ ) : (+ <HealthChecksSummaryDetail checks={checks} issueCount={issueCount} />+ )}+ </section></div>- {findings.length > 0 && (- // A note mounts, and so reports as shown, only when the reader opens the health tab. An issue reports once- // per load, from the header chip or from here, whichever shows it first.- <div className="divide-y border-t">- {findings.map((finding) => (- <HealthFindingRow- key={`${finding.code}:${finding.subcode ?? ''}`}- finding={finding}- onActedOn={onFindingActedOn}- isDetailOpenAtFirst={finding.severity !== 'info'}- />- ))}- </div>- )}- {(listedChecks.length > 0 || exposureChecksMissing) && (- <div className="border-t">- <HealthCheckList checks={listedChecks} exposureChecksMissing={exposureChecksMissing} />- </div>- )}</div>)}diff --git a/products/experiments/frontend/health/HealthChecksSummary.tsx b/products/experiments/frontend/health/HealthChecksSummary.tsxindex 5616cd2e56e1..10656bc82c75 100644--- a/products/experiments/frontend/health/HealthChecksSummary.tsx+++ b/products/experiments/frontend/health/HealthChecksSummary.tsx@@ -1,6 +1,6 @@import { pluralize } from 'lib/utils/strings'-import { type HealthPanelCheck, countHealthChecks } from './healthPanelChecks'+import { type HealthPanelCheck, countHealthChecks, healthChecksVerdict } from './healthPanelChecks'export function HealthChecksSummary({checks,@@ -11,18 +11,11 @@ export function HealthChecksSummary({issueCount: numberisDraft: boolean}): JSX.Element {- const passedCount = countHealthChecks(checks, 'passed')const notCheckedCount = countHealthChecks(checks, 'not_checked')return (<div className="flex flex-col gap-0.5" data-attr="experiment-health-summary">- <span className="font-semibold">- {issueCount > 0- ? `${pluralize(issueCount, 'issue')} found`- : passedCount > 0- ? `No problems found by ${pluralize(passedCount, 'check')}`- : 'No checks apply to this experiment yet'}- </span>+ <span className="font-semibold">{healthChecksVerdict(checks, issueCount)}</span><p className="m-0 text-secondary">{notCheckedCount > 0 && <span>{pluralize(notCheckedCount, 'check')} couldn't run. </span>}{isDraft && <span>More checks run after launch. </span>}diff --git a/products/experiments/frontend/health/HealthChecksSummaryDetail.tsx b/products/experiments/frontend/health/HealthChecksSummaryDetail.tsxnew file mode 100644index 000000000000..bd2880d045a8--- /dev/null+++ b/products/experiments/frontend/health/HealthChecksSummaryDetail.tsx@@ -0,0 +1,30 @@+import { pluralize } from 'lib/utils/strings'++import { type HealthPanelCheck, countHealthChecks, healthChecksVerdict } from './healthPanelChecks'++export function HealthChecksSummaryDetail({+ checks,+ issueCount,+}: {+ checks: HealthPanelCheck[]+ issueCount: number+}): JSX.Element {+ const passedCount = countHealthChecks(checks, 'passed')+ const notApplicableCount = countHealthChecks(checks, 'not_applicable')+ const text = [+ passedCount > 0 ? `${pluralize(passedCount, 'check')} found no issue.` : null,+ notApplicableCount > 0+ ? `${pluralize(notApplicableCount, 'check')} ${notApplicableCount === 1 ? "doesn't" : "don't"} apply to this experiment.`+ : null,+ 'Pick a check to see what it looks for.',+ ]+ .filter(Boolean)+ .join(' ')++ return (+ <div className="flex flex-col gap-1" data-attr="experiment-health-summary-detail">+ <h3 className="m-0 text-base font-semibold">{healthChecksVerdict(checks, issueCount)}</h3>+ <p className="m-0 max-w-prose text-secondary">{text}</p>+ </div>+ )+}diff --git a/products/experiments/frontend/health/HealthFindingDetail.tsx b/products/experiments/frontend/health/HealthFindingDetail.tsxnew file mode 100644index 000000000000..b9331f51f124--- /dev/null+++ b/products/experiments/frontend/health/HealthFindingDetail.tsx@@ -0,0 +1,50 @@+import { HealthFindingActionButton } from './HealthFindingActionButton'+import { HealthFindingSeverityIcon } from './HealthFindingSeverityIcon'+import { HEALTH_FINDING_SEVERITY_LABELS, type HealthPanelFinding } from './healthPanelFindings'+import { useHealthFindingReporting } from './useHealthFindingReporting'++export function HealthFindingDetail({+ finding,+ onActedOn,+}: {+ finding: HealthPanelFinding+ onActedOn?: () => void+}): JSX.Element {+ const { reportActedOn } = useHealthFindingReporting({+ code: finding.code,+ subcode: finding.subcode ?? undefined,+ severity: finding.severity,+ reason: finding.reason ?? undefined,+ })++ return (+ <div className="flex flex-col gap-3" data-attr="experiment-health-finding-detail">+ <div className="flex flex-wrap items-start justify-between gap-2">+ <div className="flex flex-col gap-1 min-w-0">+ <h3 className="m-0 flex items-center gap-2 text-base font-semibold">+ <HealthFindingSeverityIcon severity={finding.severity} />+ <span>{finding.title}</span>+ </h3>+ <span className="pl-6 text-xs text-secondary">+ {HEALTH_FINDING_SEVERITY_LABELS[finding.severity]}+ </span>+ </div>+ {finding.actions.length > 0 && (+ <div className="flex flex-wrap items-center gap-2">+ {finding.actions.map((actionKind) => (+ <HealthFindingActionButton+ key={actionKind}+ actionKind={actionKind}+ onClick={() => {+ reportActedOn(actionKind)+ onActedOn?.()+ }}+ />+ ))}+ </div>+ )}+ </div>+ <p className="m-0 max-w-prose text-secondary whitespace-pre-line">{finding.detail}</p>+ </div>+ )+}diff --git a/products/experiments/frontend/health/HealthFindingListItem.tsx b/products/experiments/frontend/health/HealthFindingListItem.tsxnew file mode 100644index 000000000000..6e22248b3c00--- /dev/null+++ b/products/experiments/frontend/health/HealthFindingListItem.tsx@@ -0,0 +1,44 @@+import { LemonButton } from '@posthog/lemon-ui'++import { HealthFindingSeverityIcon } from './HealthFindingSeverityIcon'+import type { HealthPanelFinding } from './healthPanelFindings'+import { useHealthFindingReporting } from './useHealthFindingReporting'++export function HealthFindingListItem({+ finding,+ isSelected,+ onSelect,+}: {+ finding: HealthPanelFinding+ isSelected: boolean+ /** Returns whether the pick puts the detail of the finding on screen. */+ onSelect: () => boolean+}): JSX.Element {+ const { reportOpened } = useHealthFindingReporting({+ code: finding.code,+ subcode: finding.subcode ?? undefined,+ severity: finding.severity,+ reason: finding.reason ?? undefined,+ })++ return (+ <li>+ <LemonButton+ size="small"+ fullWidth+ active={isSelected}+ icon={<HealthFindingSeverityIcon severity={finding.severity} />}+ onClick={() => {+ if (onSelect()) {+ // pinned: insights count `why` as opening the detail of a finding+ reportOpened('why')+ }+ }}+ aria-current={isSelected ? 'true' : undefined}+ data-attr="experiment-health-finding"+ >+ <span className="font-semibold">{finding.title}</span>+ </LemonButton>+ </li>+ )+}diff --git a/products/experiments/frontend/health/HealthFindingRow.tsx b/products/experiments/frontend/health/HealthFindingRow.tsxdeleted file mode 100644index 021a7738e737..000000000000--- a/products/experiments/frontend/health/HealthFindingRow.tsx+++ /dev/null@@ -1,96 +0,0 @@-import { useId, useState } from 'react'--import { IconChevronDown, IconChevronRight, IconInfo, IconWarning } from '@posthog/icons'-import { LemonButton, Tooltip } from '@posthog/lemon-ui'--import { cn } from 'lib/utils/css-classes'--import { HealthFindingActionButton } from './HealthFindingActionButton'-import type { HealthPanelFinding } from './healthPanelFindings'-import { useHealthFindingReporting } from './useHealthFindingReporting'--// The icons differ in shape and color only, so each says its severity in words too.-const SEVERITY_LABELS: Record<HealthPanelFinding['severity'], string> = {- info: 'Note',- warning: 'Warning',- critical: 'Critical',-}--export function HealthFindingRow({- finding,- onActedOn,- isDetailOpenAtFirst = false,-}: {- finding: HealthPanelFinding- onActedOn?: () => void- /** Shows the detail without a click. Only a click reports the finding as opened, so this sends no event. */- isDetailOpenAtFirst?: boolean-}): JSX.Element {- const [isDetailOpen, setIsDetailOpen] = useState(isDetailOpenAtFirst)- const detailId = useId()- const { reportOpened, reportActedOn } = useHealthFindingReporting({- code: finding.code,- subcode: finding.subcode ?? undefined,- severity: finding.severity,- reason: finding.reason ?? undefined,- })-- return (- <div className="flex flex-col gap-1 px-3 py-2" data-attr="experiment-health-finding">- <div className="flex flex-wrap items-center justify-between gap-2">- <div className="flex items-center gap-2 min-w-0">- <Tooltip title={SEVERITY_LABELS[finding.severity]}>- <span role="img" aria-label={SEVERITY_LABELS[finding.severity]} className="flex shrink-0">- {finding.severity === 'info' ? (- <IconInfo className="text-secondary text-lg" />- ) : (- <IconWarning- className={cn(- 'text-lg',- finding.severity === 'critical' ? 'text-danger' : 'text-warning'- )}- />- )}- </span>- </Tooltip>- <span className="font-semibold">{finding.title}</span>- <LemonButton- size="xsmall"- type="tertiary"- sideIcon={isDetailOpen ? <IconChevronDown /> : <IconChevronRight />}- onClick={() => {- if (!isDetailOpen) {- reportOpened('why')- }- setIsDetailOpen(!isDetailOpen)- }}- aria-expanded={isDetailOpen}- aria-controls={detailId}- data-attr="experiment-health-finding-why"- >- Why?- </LemonButton>- </div>- {finding.actions.length > 0 && (- <div className="flex flex-wrap items-center gap-2">- {finding.actions.map((actionKind) => (- <HealthFindingActionButton- key={actionKind}- actionKind={actionKind}- onClick={() => {- reportActedOn(actionKind)- onActedOn?.()- }}- />- ))}- </div>- )}- </div>- {isDetailOpen && (- <p id={detailId} className="m-0 pl-7 text-secondary whitespace-pre-line">- {finding.detail}- </p>- )}- </div>- )-}diff --git a/products/experiments/frontend/health/HealthFindingSeverityIcon.tsx b/products/experiments/frontend/health/HealthFindingSeverityIcon.tsxnew file mode 100644index 000000000000..edd518c2df21--- /dev/null+++ b/products/experiments/frontend/health/HealthFindingSeverityIcon.tsx@@ -0,0 +1,20 @@+import { IconInfo, IconWarning } from '@posthog/icons'+import { Tooltip } from '@posthog/lemon-ui'++import { cn } from 'lib/utils/css-classes'++import { HEALTH_FINDING_SEVERITY_LABELS, type HealthPanelFinding } from './healthPanelFindings'++export function HealthFindingSeverityIcon({ severity }: { severity: HealthPanelFinding['severity'] }): JSX.Element {+ return (+ <Tooltip title={HEALTH_FINDING_SEVERITY_LABELS[severity]}>+ <span role="img" aria-label={HEALTH_FINDING_SEVERITY_LABELS[severity]} className="flex shrink-0">+ {severity === 'info' ? (+ <IconInfo className="text-secondary" />+ ) : (+ <IconWarning className={cn(severity === 'critical' ? 'text-danger' : 'text-warning')} />+ )}+ </span>+ </Tooltip>+ )+}diff --git a/products/experiments/frontend/health/healthCheckStatusDisplay.tsx b/products/experiments/frontend/health/healthCheckStatusDisplay.tsxnew file mode 100644index 000000000000..f8b5b82fa2e7--- /dev/null+++ b/products/experiments/frontend/health/healthCheckStatusDisplay.tsx@@ -0,0 +1,18 @@+import { IconCheck, IconMinus, IconQuestion } from '@posthog/icons'++import type { ListedHealthCheck } from './healthPanelChecks'++export const HEALTH_CHECK_STATUS_DISPLAY: Record<ListedHealthCheck['status'], { icon: JSX.Element; label: string }> = {+ not_checked: { icon: <IconQuestion className="text-secondary" />, label: "Couldn't check" },+ passed: { icon: <IconCheck className="text-success" />, label: 'No issue found' },+ not_applicable: { icon: <IconMinus className="text-tertiary" />, label: "Doesn't apply" },+}++export function healthCheckStatusText(check: ListedHealthCheck): string {+ const { label } = HEALTH_CHECK_STATUS_DISPLAY[check.status]+ if (!check.reason) {+ return label+ }+ // A reason for a check that couldn't run already starts with "Couldn't check" or "Couldn't read".+ return check.status === 'not_checked' ? check.reason : `${label} · ${check.reason}`+}diff --git a/products/experiments/frontend/health/healthPanelChecks.ts b/products/experiments/frontend/health/healthPanelChecks.tsindex 5b08df56d7a5..0b8b5ba875c9 100644--- a/products/experiments/frontend/health/healthPanelChecks.ts+++ b/products/experiments/frontend/health/healthPanelChecks.ts@@ -79,6 +79,16 @@ export function countHealthChecks(checks: HealthPanelCheck[], status: HealthPanereturn checks.filter((check) => check.status === status).length}+export function healthChecksVerdict(checks: HealthPanelCheck[], issueCount: number): string {+ const passedCount = countHealthChecks(checks, 'passed')+ if (issueCount > 0) {+ return `${pluralize(issueCount, 'issue')} found`+ }+ return passedCount > 0+ ? `No problems found by ${pluralize(passedCount, 'check')}`+ : 'No checks apply to this experiment yet'+}+export function healthChipState(findings: HealthPanelFinding[] | null,checks: HealthPanelCheck[] | null,diff --git a/products/experiments/frontend/health/healthPanelFindings.ts b/products/experiments/frontend/health/healthPanelFindings.tsindex c40b4eae2820..6b9a46bce08a 100644--- a/products/experiments/frontend/health/healthPanelFindings.ts+++ b/products/experiments/frontend/health/healthPanelFindings.ts@@ -16,6 +16,13 @@ export type HealthPanelFinding = Pick<const SEVERITY_ORDER: Record<HealthPanelFinding['severity'], number> = { critical: 0, warning: 1, info: 2 }+// The icons differ in shape and color only, so each says its severity in words too.+export const HEALTH_FINDING_SEVERITY_LABELS: Record<HealthPanelFinding['severity'], string> = {+ info: 'Note',+ warning: 'Warning',+ critical: 'Critical',+}+export function hoursSinceStart(startDate: string | null | undefined): number | null {return startDate ? dayjs().diff(startDate, 'hour', true) : null}diff --git a/products/experiments/frontend/health/healthPanelSelection.ts b/products/experiments/frontend/health/healthPanelSelection.tsnew file mode 100644index 000000000000..a1ea6bfbfb43--- /dev/null+++ b/products/experiments/frontend/health/healthPanelSelection.ts@@ -0,0 +1,45 @@+import type { ListedHealthCheck } from './healthPanelChecks'+import { type HealthPanelFinding, healthIssues } from './healthPanelFindings'++export type HealthPanelSelection =+ | { kind: 'summary' }+ | { kind: 'finding'; key: string }+ | { kind: 'check'; key: ListedHealthCheck['key'] }++export type ResolvedHealthPanelSelection =+ | { kind: 'summary' }+ | { kind: 'finding'; key: string; finding: HealthPanelFinding }+ | { kind: 'check'; key: ListedHealthCheck['key']; check: ListedHealthCheck }++export function healthFindingKey(finding: HealthPanelFinding): string {+ return `${finding.code}:${finding.subcode ?? ''}`+}++// A refresh can remove the picked finding or check, so the pick holds only while it is still on the list.+export function resolveHealthPanelSelection(+ picked: HealthPanelSelection | null,+ findings: HealthPanelFinding[],+ checks: ListedHealthCheck[]+): ResolvedHealthPanelSelection {+ switch (picked?.kind) {+ case 'finding': {+ const finding = findings.find((candidate) => healthFindingKey(candidate) === picked.key)+ if (finding) {+ return { ...picked, finding }+ }+ break+ }+ case 'check': {+ const check = checks.find((candidate) => candidate.key === picked.key)+ if (check) {+ return { ...picked, check }+ }+ break+ }+ }+ // A note states a fact and needs no action, so only an issue opens without a click.+ const [firstIssue] = healthIssues(findings)+ return firstIssue+ ? { kind: 'finding', key: healthFindingKey(firstIssue), finding: firstIssue }+ : { kind: 'summary' }+}