: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): mark required and optional fields in the create wizard (#108054)
ruby childs94fd0ae2ef23
diff --git a/frontend/src/lib/components/TestAccountFiltersSwitch.tsx b/frontend/src/lib/components/TestAccountFiltersSwitch.tsxindex 75ad4849a73c..d33a410c3ab6 100644--- a/frontend/src/lib/components/TestAccountFiltersSwitch.tsx+++ b/frontend/src/lib/components/TestAccountFiltersSwitch.tsx@@ -1,7 +1,7 @@import { useValues } from 'kea'import React from 'react'-import { IconGear } from '@posthog/icons'+import { IconExternal, IconGear } from '@posthog/icons'import { LemonButton, LemonSwitch, LemonSwitchProps } from '@posthog/lemon-ui'import { teamLogic } from 'scenes/teamLogic'@@ -38,6 +38,7 @@ type TestAccountFilterProps = Partial<LemonSwitchProps> & {/** Runs instead of navigating to project settings when the gear is clicked. Surfaces that hold* unsaved state, such as a wizard step, use this to configure the filters without leaving. */onConfigure?: () => void+ settingsLinkIcon?: 'gear' | 'new-tab'}export function TestAccountFilterSwitch({@@ -45,12 +46,14 @@ export function TestAccountFilterSwitch({onChange,applicableFilterTypes,onConfigure,+ settingsLinkIcon = 'gear',...props}: TestAccountFilterProps): JSX.Element | null {const { currentTeam } = useValues(teamLogic)const filters = currentTeam?.test_account_filters || []const hasFilters = filters.length > 0const unusedReason = applicableFilterTypes ? getUnusedTestAccountFilterReason(filters, applicableFilterTypes) : null+ const showNewTabIcon = settingsLinkIcon === 'new-tab' && !onConfigurereturn (<LemonSwitchid="test-account-filter"@@ -58,7 +61,7 @@ export function TestAccountFilterSwitch({{...props}disabledReason={!hasFilters- ? "You haven't set any internal test filters. Click the gear icon to configure."+ ? `You haven't set any internal test filters. Click the ${showNewTabIcon ? 'link' : 'gear'} icon to configure.`: (unusedReason ?? props.disabledReason)}checked={checked}@@ -71,7 +74,7 @@ export function TestAccountFilterSwitch({disabledReason below actively sends people here when no filters are set up.Callers that can configure the filters in place pass onConfigure instead. */}<LemonButton- icon={<IconGear />}+ icon={showNewTabIcon ? <IconExternal className="size-3.5" /> : <IconGear />}size="small"noPaddingclassName="ml-1"diff --git a/frontend/src/scenes/experiments/ExperimentForm/ExposureCriteriaPanel.tsx b/frontend/src/scenes/experiments/ExperimentForm/ExposureCriteriaPanel.tsxindex e56e61afb774..9583faf5df3f 100644--- a/frontend/src/scenes/experiments/ExperimentForm/ExposureCriteriaPanel.tsx+++ b/frontend/src/scenes/experiments/ExperimentForm/ExposureCriteriaPanel.tsx@@ -231,6 +231,7 @@ function ExposureCriteriaFields({}}bordered={false}fullWidth+ settingsLinkIcon="new-tab"className="p-0"/></div>@@ -375,16 +376,21 @@ export function ExposureCriteriaPanel({ experiment, onChange, compact }: Exposur/></div>- <TestAccountFilterSwitch- checked={hasFilters && !!experiment.exposure_criteria?.filterTestAccounts}- onChange={(checked: boolean) => {- onChange({ filterTestAccounts: checked })- }}- bordered={false}- fullWidth- labelClassName="text-secondary font-normal"- className="p-0"- />+ {/* As tall as the small selects above, so the three labels are evenly spaced */}+ <div className="flex min-h-[2.0625rem] items-center">+ <TestAccountFilterSwitch+ checked={hasFilters && !!experiment.exposure_criteria?.filterTestAccounts}+ onChange={(checked: boolean) => {+ onChange({ filterTestAccounts: checked })+ }}+ bordered={false}+ fullWidth+ settingsLinkIcon="new-tab"+ // Keep the label to its text, or the whole row becomes a click target for the switch+ labelClassName="text-secondary font-normal !flex-none"+ className="p-0 justify-between"+ />+ </div></div>)}diff --git a/frontend/src/scenes/experiments/ExperimentWizard/experimentWizardLogic.test.tsx b/frontend/src/scenes/experiments/ExperimentWizard/experimentWizardLogic.test.tsxindex ae528b0a7d3f..8d088e9a6544 100644--- a/frontend/src/scenes/experiments/ExperimentWizard/experimentWizardLogic.test.tsx+++ b/frontend/src/scenes/experiments/ExperimentWizard/experimentWizardLogic.test.tsx@@ -140,10 +140,10 @@ describe('experimentWizardLogic', () => {</BindLogic>)- const nameInput = screen.getByPlaceholderText('e.g., New checkout flow test')+ const nameInput = screen.getByPlaceholderText('e.g. New checkout flow test')await userEvent.type(nameInput, 'My Cool Experiment')- expect(screen.getByPlaceholderText('e.g., new-checkout-flow-test')).toHaveValue('my-cool-experiment')+ expect(screen.getByPlaceholderText('e.g. new-checkout-flow-test')).toHaveValue('my-cool-experiment')})it('selecting an existing flag sets key and variants from the flag', async () => {diff --git a/frontend/src/scenes/experiments/ExperimentWizard/steps/AboutStep.tsx b/frontend/src/scenes/experiments/ExperimentWizard/steps/AboutStep.tsxindex 91244aafd130..6fb9b654834d 100644--- a/frontend/src/scenes/experiments/ExperimentWizard/steps/AboutStep.tsx+++ b/frontend/src/scenes/experiments/ExperimentWizard/steps/AboutStep.tsx@@ -1,7 +1,8 @@import { useActions, useValues } from 'kea'import { useDebouncedCallback } from 'use-debounce'-import { LemonButton, LemonInput, Link } from '@posthog/lemon-ui'+import { IconInfo } from '@posthog/icons'+import { LemonButton, LemonInput, Link, Tooltip } from '@posthog/lemon-ui'import { LemonField } from 'lib/lemon-ui/LemonField'import { LemonTextArea } from 'lib/lemon-ui/LemonTextArea'@@ -17,6 +18,17 @@ import { VariantsPanelLinkFeatureFlag } from '../../ExperimentForm/VariantsPanelimport { getFlagVariants } from '../../utils'import { experimentWizardLogic } from '../experimentWizardLogic'+function RequiredMark(): JSX.Element {+ return (+ <>+ <span className="text-accent ml-0.5" aria-hidden="true">+ *+ </span>+ <span className="sr-only">(required)</span>+ </>+ )+}+export function AboutStep(): JSX.Element {const { experiment, linkedFeatureFlag, featureFlagKeyValidation, featureFlagKeyValidationLoading, departedSteps } =useValues(experimentWizardLogic)@@ -62,9 +74,19 @@ export function AboutStep(): JSX.Element {<div className="space-y-6"><h3 className="text-lg font-semibold">What are we testing?</h3>- <LemonField.Pure label="Experiment name" error={nameError}>+ <LemonField.Pure+ label={+ <span className="whitespace-nowrap">+ Experiment name+ <RequiredMark />+ </span>+ }+ error={nameError}+ htmlFor="experiment-wizard-name"+ ><LemonInput- placeholder="e.g., New checkout flow test"+ id="experiment-wizard-name"+ placeholder="e.g. New checkout flow test"value={experiment.name}onChange={(value) => {setExperimentValue('name', value)@@ -82,8 +104,14 @@ export function AboutStep(): JSX.Element {/></LemonField.Pure>- <LemonField.Pure label="Hypothesis" info="Describe what you expect to happen and why.">+ <LemonField.Pure+ label="Hypothesis"+ info="Describe what you expect to happen and why."+ showOptional+ htmlFor="experiment-wizard-hypothesis"+ ><LemonTextArea+ id="experiment-wizard-hypothesis"placeholder="We believe that ... will result in ... because ..."value={experiment.description ?? ''}onChange={(value) => setExperimentValue('description', value)}@@ -106,8 +134,16 @@ export function AboutStep(): JSX.Element {) : (<LemonField.Purelabel={- <div className="flex items-center justify-between w-full">- <span>Feature flag key</span>+ <div className="flex flex-wrap items-center justify-between gap-x-4 gap-y-1 w-full">+ <span className="flex items-center gap-1 whitespace-nowrap">+ <span>+ Feature flag key+ <RequiredMark />+ </span>+ <Tooltip title="The experiment uses this flag to decide which variant each person sees. Your code checks it to show them that variant.">+ <IconInfo className="text-xl text-secondary shrink-0" />+ </Tooltip>+ </span><span className="text-muted text-sm font-normal">Do you have a feature flag already?{' '}<Link@@ -121,6 +157,7 @@ export function AboutStep(): JSX.Element {</div>}error={featureFlagKeyError}+ htmlFor="experiment-wizard-flag-key"renderError={existingFlag? (error) => (@@ -141,7 +178,10 @@ export function AboutStep(): JSX.Element {}><LemonInput- placeholder="e.g., new-checkout-flow-test"+ id="experiment-wizard-flag-key"+ // The label also holds the "Select existing flag" prompt, so name the input on its own+ aria-label="Feature flag key (required)"+ placeholder="e.g. new-checkout-flow-test"value={experiment.feature_flag_key ?? ''}onChange={(value) => {const normalizedValue = slugifyFeatureFlagKey(value)