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(onboarding): link config option titles to their controls (#129814)

Rafael Audibertcc4a3be22c70
diff --git a/frontend/src/scenes/onboarding/OnboardingProductConfiguration.tsx b/frontend/src/scenes/onboarding/OnboardingProductConfiguration.tsx
index 4bab8b7bcda4..6034cf8f5e37 100644
--- a/frontend/src/scenes/onboarding/OnboardingProductConfiguration.tsx
+++ b/frontend/src/scenes/onboarding/OnboardingProductConfiguration.tsx
@@ -1,7 +1,7 @@
import { useActions, useValues } from 'kea'
import React, { useEffect, useRef } from 'react'
-import { LemonDivider, LemonSelect, LemonSwitch } from '@posthog/lemon-ui'
+import { LemonDivider } from '@posthog/lemon-ui'
import { useOnMountEffect } from 'lib/hooks/useOnMountEffect'
@@ -9,27 +9,12 @@ import { OnboardingStepKey } from '~/types'
import { OnboardingStepComponentType } from './onboardingLogic'
import { ProductConfigOption, onboardingProductConfigurationLogic } from './onboardingProductConfigurationLogic'
+import {
+ OnboardingProductConfigurationOption,
+ OnboardingProductConfigurationOptionProps,
+} from './OnboardingProductConfigurationOption'
import { OnboardingStep } from './OnboardingStep'
-type ConfigType = 'toggle' | 'select'
-type PluginType = 'plugin'
-type ConfigOption =
- | {
- title: string
- description?: string
- type: ConfigType
- selectOptions?: { label: string; value: string | number }[]
- value: boolean | string | number
- onChange: (newValue: boolean | string | number) => void
- }
- | {
- title: string
- description?: string
- type: PluginType
- value: boolean
- onChange: (newValue: boolean) => void
- }
-
interface OnboardingProductConfigurationProps {
options: ProductConfigOption[]
}
@@ -50,13 +35,14 @@ export const OnboardingProductConfiguration: OnboardingStepComponentType<Onboard
setConfigOptions(options)
})
- const combinedList: ConfigOption[] = configOptions
+ const combinedList: OnboardingProductConfigurationOptionProps[] = configOptions
.filter((option) => option.visible)
.map((option) => ({
+ teamProperty: option.teamProperty,
title: option.title,
description: option.description,
- type: option.type as ConfigType,
- selectOptions: option.selectOptions,
+ type: option.type,
+ selectOptions: option.type === 'select' ? option.selectOptions : undefined,
value: option.value,
onChange: (newValue: boolean | string | number) => {
// Use the current value from the ref to ensure that onChange always accesses
@@ -81,41 +67,10 @@ export const OnboardingProductConfiguration: OnboardingStepComponentType<Onboard
>
<div className="mt-6">
<h2 className="pt-2">Options</h2>
- {combinedList.map((item, idx) => (
- <React.Fragment key={idx}>
+ {combinedList.map((item) => (
+ <React.Fragment key={item.teamProperty}>
<LemonDivider className="my-4" />
- <div className="grid grid-cols-3 gap-4">
- <div className="col-span-2">
- <label className="text-base font-semibold">{item.title}</label>
- <p className="mt-2 mb-0 prompt-text">{item.description}</p>
- </div>
- <div className="flex justify-end">
- {item.type === 'toggle' ? (
- <LemonSwitch
- onChange={item.onChange}
- className="justify-end"
- fullWidth={true}
- checked={(item.value as boolean) || false}
- />
- ) : item.type === 'plugin' ? (
- <LemonSwitch
- onChange={item.onChange}
- className="justify-end"
- fullWidth={true}
- checked={item.value || false}
- />
- ) : (
- <div className="flex gap-x-4 justify-end items-center mb-1">
- <LemonSelect
- dropdownMatchSelectWidth={false}
- onChange={item.onChange}
- options={item.selectOptions || []}
- value={item.value}
- />
- </div>
- )}
- </div>
- </div>
+ <OnboardingProductConfigurationOption {...item} />
</React.Fragment>
))}
</div>
diff --git a/frontend/src/scenes/onboarding/OnboardingProductConfigurationOption.test.tsx b/frontend/src/scenes/onboarding/OnboardingProductConfigurationOption.test.tsx
new file mode 100644
index 000000000000..9fcdf6141443
--- /dev/null
+++ b/frontend/src/scenes/onboarding/OnboardingProductConfigurationOption.test.tsx
@@ -0,0 +1,31 @@
+import '@testing-library/jest-dom'
+
+import { cleanup, fireEvent, render, screen } from '@testing-library/react'
+
+import { OnboardingProductConfigurationOption } from './OnboardingProductConfigurationOption'
+
+describe('OnboardingProductConfigurationOption', () => {
+ afterEach(() => {
+ cleanup()
+ })
+
+ it.each([
+ { value: false, expected: true },
+ { value: true, expected: false },
+ ])('clicking the toggle title flips it from $value to $expected', ({ value, expected }) => {
+ const onChange = jest.fn()
+ render(
+ <OnboardingProductConfigurationOption
+ teamProperty="heatmaps_opt_in"
+ title="Enable heatmaps"
+ type="toggle"
+ value={value}
+ onChange={onChange}
+ />
+ )
+
+ fireEvent.click(screen.getByText('Enable heatmaps'))
+
+ expect(onChange).toHaveBeenCalledWith(expected)
+ })
+})
diff --git a/frontend/src/scenes/onboarding/OnboardingProductConfigurationOption.tsx b/frontend/src/scenes/onboarding/OnboardingProductConfigurationOption.tsx
new file mode 100644
index 000000000000..4c4ad8d598cc
--- /dev/null
+++ b/frontend/src/scenes/onboarding/OnboardingProductConfigurationOption.tsx
@@ -0,0 +1,57 @@
+import { LemonSelect, LemonSelectOptions, LemonSwitch } from '@posthog/lemon-ui'
+
+export interface OnboardingProductConfigurationOptionProps {
+ teamProperty: string
+ title: string
+ description?: string
+ type: 'toggle' | 'select'
+ selectOptions?: LemonSelectOptions<any>
+ value: boolean | string | number | null
+ onChange: (newValue: boolean | string | number) => void
+}
+
+export function OnboardingProductConfigurationOption({
+ teamProperty,
+ title,
+ description,
+ type,
+ selectOptions,
+ value,
+ onChange,
+}: OnboardingProductConfigurationOptionProps): JSX.Element {
+ const controlId = `onboarding-config-${teamProperty}`
+
+ return (
+ <div className="grid grid-cols-3 gap-4">
+ <div className="col-span-2">
+ <label htmlFor={controlId} className="text-base font-semibold cursor-pointer">
+ {title}
+ </label>
+ <p className="mt-2 mb-0 prompt-text">{description}</p>
+ </div>
+ <div className="flex justify-end">
+ {type === 'toggle' ? (
+ <LemonSwitch
+ id={controlId}
+ data-attr={controlId}
+ onChange={onChange}
+ className="justify-end"
+ fullWidth={true}
+ checked={(value as boolean) || false}
+ />
+ ) : (
+ <div className="flex gap-x-4 justify-end items-center mb-1">
+ <LemonSelect
+ id={controlId}
+ data-attr={controlId}
+ dropdownMatchSelectWidth={false}
+ onChange={onChange}
+ options={selectOptions || []}
+ value={value as string | number}
+ />
+ </div>
+ )}
+ </div>
+ </div>
+ )
+}