: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
fix(cohorts): show locked cohort type and populate selectors as read-only (#68318)
posthog[bot]722cab5d726b
diff --git a/frontend/snapshots.yml b/frontend/snapshots.ymlindex ce02ede0324b..432a241a97a8 100644--- a/frontend/snapshots.yml+++ b/frontend/snapshots.yml@@ -6367,13 +6367,13 @@ snapshots:scenes-app-oauth-authorize--with-required-scopes--light:hash: v1.k794b7964.e951fac95b4bfb2628774621d6ac6f479abf8e8d10efb58cbcfad998c62a96be.-ZMfxl773NvFryFdUT6AJlVnUiwplGzEUPhvBD6kSWwscenes-app-people-cohorts--cohort-edit-dynamic--dark:- hash: v1.k794b7964.e2f3fed91cc1e603808a766fc8b3e457342e0a22e6ec1d157822ef8654bcdb6a.eLEFZ9RPmh6MbIH__SjcSgHgttnqBoYIkcfqXpwXZ9Y+ hash: v1.k794b7964.29528fe9c6743a11a17bf839e152d3ed0d45a571dc704b0fbeafc0e469213d61.u8BPurAlJ3JdThf5TpcoGw-6KWkWwHlFETCXvt2Y6usscenes-app-people-cohorts--cohort-edit-dynamic--light:- hash: v1.k794b7964.b8d0d0e945aa0c1df99ee1e7f0b405c9ff2d709bbbf253de82178f5825e8458e.YKL2nsVET2lxr17KYpqLh4-6aTU4kdHwY-1PoeEcOt0+ hash: v1.k794b7964.68a8f57efed3143da4feec04312c071aa8d6bb92e475945589b843ad881b69e9.v7QDELbVd7iBn4lZs6VDsX1slTQVBZb3w8z6sO3BNJ4scenes-app-people-cohorts--cohort-edit-static--dark:- hash: v1.k794b7964.ef37198cc5a928efea4b8a66c84fa68a4959683ab5f7a98979be7b88a37132e9.3OKA0_L5x-lglGraiRsK957X_ReB1kqlQ1YtBRMo9ls+ hash: v1.k794b7964.02d0747e4c10c736c348f8ec64e6c40f7613e9b3c750802c707e807f8d513199.uayJO_46qM2XEfrPzVhPHBxuAi1bH7wTaAc41c-PngYscenes-app-people-cohorts--cohort-edit-static--light:- hash: v1.k794b7964.0038a414eda6d172fce15a56c298c8f53bec12c1c5bcb528f5f0ec4d3a309527.N2T70nj12RgABrk0qadKu_4UO_ZD0Sd_MJf8ntgA5FQ+ hash: v1.k794b7964.ccfdd12041c23093f9dfdea3d74a8be8672f017b838ca9171c9713eb49418899.NFNZNNezQtqlEbBSbXoGbIKJQllVOfqNMGJgCYdKRGcscenes-app-people-cohorts--cohort-new--dark:hash: v1.k794b7964.ad06461fec9e86b589fdd27f1dc1ea74c673c06dd2945d7d95d96fd6db03bc60.hilKwZIabJOnPepZU0WRMVrsNXbq7LLFr-2wmF4g7OMscenes-app-people-cohorts--cohort-new--light:diff --git a/frontend/src/scenes/cohorts/CohortEdit.test.tsx b/frontend/src/scenes/cohorts/CohortEdit.test.tsxindex c35985cdb3d1..0d928fbd456c 100644--- a/frontend/src/scenes/cohorts/CohortEdit.test.tsx+++ b/frontend/src/scenes/cohorts/CohortEdit.test.tsx@@ -490,4 +490,47 @@ describe('cohortEditLogic', () => {})})++ describe('locked type and populate-from controls on existing cohorts', () => {+ afterEach(() => {+ cleanup()+ })++ it('renders locked controls as a read-only value with an info tooltip, not a dead-click dropdown', async () => {+ const cohortId = 10++ useMocks({+ get: {+ [`/api/projects/:team_id/cohorts/${cohortId}/`]: {+ id: cohortId,+ name: 'Static Cohort',+ is_static: true,+ // Non-empty filter values so `inferStaticCohortMode` resolves to 'criteria' —+ // an empty `values` array is read as the 'people' (upload/manual) mode instead.+ filters: mockCohort.filters,+ version: 1,+ pending_version: 1,+ is_calculating: false,+ last_calculation: '2024-01-01T00:00:00Z',+ },+ },+ })++ render(<CohortEdit id={cohortId} />)++ // The current value is always visible in plain text; the "why can't I change this"+ // explanation lives in an info tooltip instead of being repeated inline.+ const typeContainer = (await screen.findByText('Static')).closest('[data-attr="cohort-type"]')+ const populateFromContainer = screen+ .getByText('Criteria · One-time snapshot')+ .closest('[data-attr="static-cohort-mode"]')+ expect(typeContainer).toBeInTheDocument()+ expect(populateFromContainer).toBeInTheDocument()++ // The locked controls are read-only text, not interactive select buttons (the dead click):+ // a LemonSelect would render the data-attr onto a <button>+ expect(typeContainer?.tagName).not.toBe('BUTTON')+ expect(populateFromContainer?.tagName).not.toBe('BUTTON')+ })+ })})diff --git a/frontend/src/scenes/cohorts/CohortEdit.tsx b/frontend/src/scenes/cohorts/CohortEdit.tsxindex ed4219fc4d14..cb5beab1ad98 100644--- a/frontend/src/scenes/cohorts/CohortEdit.tsx+++ b/frontend/src/scenes/cohorts/CohortEdit.tsx@@ -2,7 +2,7 @@ import { BindLogic, BuiltLogic, Logic, LogicWrapper, useActions, useValues } froimport { Form } from 'kea-forms'import { router } from 'kea-router'-import { IconClock, IconCopy, IconRefresh, IconTrash, IconUpload, IconWarning } from '@posthog/icons'+import { IconClock, IconCopy, IconInfo, IconRefresh, IconTrash, IconUpload, IconWarning } from '@posthog/icons'import { LemonBanner, LemonDialog, LemonDivider, LemonFileInput, LemonTabs, Link, Tooltip } from '@posthog/lemon-ui'import { ActivityLog } from 'lib/components/ActivityLog/ActivityLog'@@ -20,7 +20,7 @@ import { featureFlagLogic } from 'lib/logic/featureFlagLogic'import { useAttachedLogic } from 'lib/logic/scenes/useAttachedLogic'import { ButtonPrimitive } from 'lib/ui/Button/ButtonPrimitives'import { cn } from 'lib/utils/css-classes'-import { cohortEditLogic } from 'scenes/cohorts/cohortEditLogic'+import { StaticCohortMode, cohortEditLogic } from 'scenes/cohorts/cohortEditLogic'import { CohortCriteriaGroups } from 'scenes/cohorts/CohortFilters/CohortCriteriaGroups'import { COHORT_TYPE_OPTIONS } from 'scenes/cohorts/CohortFilters/constants'import { interProjectCopyLogic } from 'scenes/resource-transfer/interProjectCopyLogic'@@ -53,6 +53,11 @@ import { PersonDisplayNameType, RemovePersonFromCohortButton } from './RemovePerconst RESOURCE_TYPE = 'cohort'+const POPULATE_FROM_OPTIONS: { label: string; value: StaticCohortMode }[] = [+ { label: 'Criteria · One-time snapshot', value: 'criteria' },+ { label: 'Upload or add people', value: 'people' },+]+function UsedInBanner({ usedIn }: { usedIn: CohortUsedInResponseApi }): JSX.Element | null {const sections = [{@@ -380,61 +385,89 @@ export function CohortEdit({ id, attachTo }: CohortEditProps): JSX.Element {<div className={cn(activeTab === 'overview' ? 'contents' : 'hidden')}><SceneSection- title="Type"- description="Static cohorts are created once and never updated, while dynamic cohorts are recalculated based on the latest data."+ title={isNewCohort ? 'Type' : undefined}+ description={+ isNewCohort+ ? 'Static cohorts are created once and never updated, while dynamic cohorts are recalculated based on the latest data.'+ : undefined+ }className="max-w-200 flex flex-col gap-y-2"hideTitleAndDescription><div className="flex gap-4 flex-wrap"><div className={cn('flex-1 flex flex-col gap-y-4')}>- <LemonField name="is_static" label={null}>- {({ value, onChange }) => (- <LemonSelect- disabledReason={- isNewCohort- ? null- : 'Create a new cohort to use a different type of cohort.'- }- options={COHORT_TYPE_OPTIONS}- value={value ? CohortTypeEnum.Static : CohortTypeEnum.Dynamic}- onChange={(cohortType) => {- onChange(cohortType === CohortTypeEnum.Static)- }}- fullWidth- data-attr="cohort-type"- />- )}- </LemonField>+ {isNewCohort ? (+ <LemonField name="is_static" label={null}>+ {({ value, onChange }) => (+ <LemonSelect+ options={COHORT_TYPE_OPTIONS}+ value={value ? CohortTypeEnum.Static : CohortTypeEnum.Dynamic}+ onChange={(cohortType) => {+ onChange(cohortType === CohortTypeEnum.Static)+ }}+ fullWidth+ data-attr="cohort-type"+ />+ )}+ </LemonField>+ ) : (+ <div className="flex items-center gap-x-2" data-attr="cohort-type">+ <span className="text-sm text-secondary">+ Type:{' '}+ <strong className="font-medium text-default">+ {cohort.is_static ? 'Static' : 'Dynamic'}+ </strong>+ </span>+ <Tooltip title="Create a new cohort to use a different type of cohort.">+ <IconInfo className="text-secondary text-base" />+ </Tooltip>+ </div>+ )}{cohort.is_static && (<div className="flex flex-col gap-y-2">- <h2 className="text-base mb-0">Populate from</h2>- <p className="text-sm text-secondary my-0 max-w-prose">- {staticCohortMode === 'criteria'- ? 'People matching the criteria below will be snapshotted into a fixed list when the cohort is created. Unlike a dynamic cohort, the list will not update as people change.'- : 'Manually add people via CSV upload or by selecting them individually.'}- </p>- <LemonSelect- disabledReason={- isNewCohort- ? undefined- : 'Create a new cohort to change how a static cohort is populated.'- }- options={[- {- label: 'Criteria · One-time snapshot',- value: 'criteria' as const,- },- {- label: 'Upload or add people',- value: 'people' as const,- },- ]}- value={staticCohortMode}- onChange={(value) => setStaticCohortMode(value)}- fullWidth- data-attr="static-cohort-mode"- />+ {isNewCohort ? (+ <>+ <h2 className="text-base mb-0">Populate from</h2>+ <p className="text-sm text-secondary my-0 max-w-prose">+ {staticCohortMode === 'criteria'+ ? 'People matching the criteria below will be snapshotted into a fixed list when the cohort is created. Unlike a dynamic cohort, the list will not update as people change.'+ : 'Manually add people via CSV upload or by selecting them individually.'}+ </p>+ <LemonSelect+ options={POPULATE_FROM_OPTIONS}+ value={staticCohortMode}+ onChange={(value) => setStaticCohortMode(value)}+ fullWidth+ data-attr="static-cohort-mode"+ />+ </>+ ) : (+ <div+ className="flex items-center gap-x-2"+ data-attr="static-cohort-mode"+ >+ <span className="text-sm text-secondary">+ Populate from:{' '}+ <strong className="font-medium text-default">+ {+ POPULATE_FROM_OPTIONS.find(+ (option) => option.value === staticCohortMode+ )?.label+ }+ </strong>+ </span>+ <Tooltip+ title={+ staticCohortMode === 'criteria'+ ? 'This cohort was snapshotted from criteria at creation time and will not update as people change. Create a new cohort to change how a static cohort is populated.'+ : 'This cohort was populated by uploading a CSV or selecting people individually. Create a new cohort to change how a static cohort is populated.'+ }+ >+ <IconInfo className="text-secondary text-base" />+ </Tooltip>+ </div>+ )}</div>)}@@ -557,7 +590,6 @@ export function CohortEdit({ id, attachTo }: CohortEditProps): JSX.Element {{/* TODO: @adamleithp Allow users to download a template CSV file */}{/* TODO: @adamleithp Tell users that adding ANOTHER file will NOT(?) replace the current one */}{/* TODO: @adamleithp Render the csv file and validate it */}- {/* TODO: @adamleithp Adding a csv file doesn't show up with cohort.csv... */}<LemonField name="csv" data-attr="cohort-csv">{({ onChange }) => (<LemonFileInput