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.

feat(flags): Disabling and Archiving CTA in disable confirmation (#69525)

ruby childs2908c0015ab6
diff --git a/frontend/src/lib/constants.tsx b/frontend/src/lib/constants.tsx
index 44966c03e507..e8d602050dc9 100644
--- a/frontend/src/lib/constants.tsx
+++ b/frontend/src/lib/constants.tsx
@@ -176,6 +176,7 @@ export const FEATURE_FLAGS = {
// UX flags, used to control the UX of the app
CMD_K_NAV_EXPERIMENT: 'cmd-k-nav-experiment', // owner: @rafaeelaudibert #team-platform-ux multivariate=control,search-bar,footer-hint,tools-row,footer-callout - surfaces the Cmd+K command menu more prominently in the left nav: search-bar = full-width search field below the nav header, footer-hint = extra Search row in the nav footer, tools-row = Search row after the Tools item in the Project section, footer-callout = dismissible callout card in the nav ad slot for users a few days after signup
CREATE_BUTTON_NAV_EXPERIMENT: 'create-button-nav-experiment', // owner: #team-platform-ux multivariate=control,test — adds a Create dropdown to the top of the Browse tab in the left nav
+ FEATURE_FLAG_DISABLE_AND_ARCHIVE_EXPERIMENT: 'feature-flag-disable-and-archive-experiment', // owner: #team-feature-flags multivariate=control,test, makes "Disable and archive" the primary CTA in the disable-flag confirmation dialog, control keeps the plain disable confirmation
INSIGHT_NOTIFICATION_ENTRYPOINT: 'insight-notification-entrypoint', // owner: #team-product-analytics multivariate=control,notifications,get-updates,monitor — tests notification-entry-point copy against the prominent Subscribe button
NEW_INSIGHT_MENU_EXPERIMENT: 'new-insight-menu-experiment', // owner: @thmsobrmlr #team-product-analytics multivariate=control,chips,grouped — experiment on the saved insights "New" menu: control = text list, chips = visual card grid with sub-insight chips, grouped = two-column card grid grouped by question
STARRED_REORDER: 'starred-reorder', // owner: #team-platform-ux, drag-and-drop reorder of starred shortcuts in the side panel
diff --git a/frontend/src/scenes/feature-flags/ConfirmationModal.tsx b/frontend/src/scenes/feature-flags/ConfirmationModal.tsx
index 8e1c0b4516f5..1980ed785d78 100644
--- a/frontend/src/scenes/feature-flags/ConfirmationModal.tsx
+++ b/frontend/src/scenes/feature-flags/ConfirmationModal.tsx
@@ -20,6 +20,7 @@ interface ConfirmationModalProps {
isBeingDisabled?: boolean // Whether the flag is being disabled (controls dependent flags warning)
featureFlagConfirmationEnabled?: boolean // Whether the team has feature flag confirmation enabled in settings
onConfirm: () => void
+ onCancel?: () => void
}
/**
@@ -36,6 +37,7 @@ export function openConfirmationModal({
isBeingDisabled = false,
featureFlagConfirmationEnabled = false,
onConfirm,
+ onCancel,
}: ConfirmationModalProps): void {
let title: string
let description: JSX.Element
@@ -153,6 +155,7 @@ export function openConfirmationModal({
},
secondaryButton: {
children: 'Cancel',
+ onClick: onCancel,
},
})
}
diff --git a/frontend/src/scenes/feature-flags/FeatureFlag.tsx b/frontend/src/scenes/feature-flags/FeatureFlag.tsx
index 26eddf9ce204..1d7a44342930 100644
--- a/frontend/src/scenes/feature-flags/FeatureFlag.tsx
+++ b/frontend/src/scenes/feature-flags/FeatureFlag.tsx
@@ -401,10 +401,10 @@ export function FeatureFlag({ id }: FeatureFlagLogicProps): JSX.Element {
}
onClick={() => {
if (featureFlag.archived) {
- updateFeatureFlagArchived(false)
+ updateFeatureFlagArchived({ archived: false })
} else {
openFeatureFlagArchiveDialog(featureFlag, () =>
- updateFeatureFlagArchived(true)
+ updateFeatureFlagArchived({ archived: true, via: 'archive-dialog' })
)
}
}}
@@ -465,7 +465,7 @@ export function FeatureFlag({ id }: FeatureFlagLogicProps): JSX.Element {
featureFlag.can_edit
? {
children: 'Unarchive',
- onClick: () => updateFeatureFlagArchived(false),
+ onClick: () => updateFeatureFlagArchived({ archived: false }),
disabledReason: featureFlagActiveUpdateLoading ? 'Updating…' : undefined,
}
: undefined
diff --git a/frontend/src/scenes/feature-flags/FeatureFlags.tsx b/frontend/src/scenes/feature-flags/FeatureFlags.tsx
index d93bc1335b5a..757af333027f 100644
--- a/frontend/src/scenes/feature-flags/FeatureFlags.tsx
+++ b/frontend/src/scenes/feature-flags/FeatureFlags.tsx
@@ -149,7 +149,7 @@ function FeatureFlagRowActions({ featureFlag }: { featureFlag: FeatureFlagType }
const { currentProjectId } = useValues(projectLogic)
const flagLogic = featureFlagsLogic({})
const { featureFlagsUpdating } = useValues(flagLogic)
- const { updateFeatureFlag, loadFeatureFlags } = useActions(flagLogic)
+ const { toggleFeatureFlagActive, updateFeatureFlagArchived, loadFeatureFlags } = useActions(flagLogic)
const isUpdating = featureFlag.id ? featureFlagsUpdating[featureFlag.id] : false
const [isQuickSurveyModalOpen, setIsQuickSurveyModalOpen] = useState(false)
@@ -193,58 +193,9 @@ function FeatureFlagRowActions({ featureFlag }: { featureFlag: FeatureFlagType }
}}
fullWidth
>
- Copy feature flag key
+ Copy key
</LemonButton>
- <AccessControlAction
- resourceType={AccessControlResourceType.FeatureFlag}
- minAccessLevel={AccessControlLevel.Editor}
- userAccessLevel={featureFlag.user_access_level}
- >
- <LemonButton
- data-attr={`feature-flag-${featureFlag.key}-switch`}
- onClick={() => {
- const newValue = !featureFlag.active
- LemonDialog.open({
- title: `${newValue === true ? 'Enable' : 'Disable'} this flag?`,
- description: `This flag will be immediately ${
- newValue === true ? 'rolled out to' : 'rolled back from'
- } the users matching the release conditions.`,
- primaryButton: {
- children: 'Confirm',
- type: 'primary',
- onClick: () => {
- featureFlag.id
- ? updateFeatureFlag({
- id: featureFlag.id,
- payload: { active: newValue },
- })
- : null
- },
- size: 'small',
- },
- secondaryButton: {
- children: 'Cancel',
- type: 'tertiary',
- size: 'small',
- },
- })
- }}
- id={`feature-flag-${featureFlag.id}-switch`}
- fullWidth
- loading={isUpdating}
- disabledReason={
- isUpdating
- ? 'Updating…'
- : featureFlag.archived
- ? 'Unarchive this flag before enabling it.'
- : undefined
- }
- >
- {featureFlag.active ? 'Disable' : 'Enable'} feature flag
- </LemonButton>
- </AccessControlAction>
-
{featureFlag.id && (
<AccessControlAction
resourceType={AccessControlResourceType.FeatureFlag}
@@ -287,6 +238,31 @@ function FeatureFlagRowActions({ featureFlag }: { featureFlag: FeatureFlagType }
<LemonDivider />
+ <AccessControlAction
+ resourceType={AccessControlResourceType.FeatureFlag}
+ minAccessLevel={AccessControlLevel.Editor}
+ userAccessLevel={featureFlag.user_access_level}
+ >
+ <LemonButton
+ data-attr={`feature-flag-${featureFlag.key}-switch`}
+ onClick={() =>
+ featureFlag.id && toggleFeatureFlagActive(featureFlag.id, !featureFlag.active)
+ }
+ id={`feature-flag-${featureFlag.id}-switch`}
+ fullWidth
+ loading={isUpdating}
+ disabledReason={
+ isUpdating
+ ? 'Updating…'
+ : featureFlag.archived
+ ? 'Unarchive this flag before enabling it.'
+ : undefined
+ }
+ >
+ {featureFlag.active ? 'Disable' : 'Enable'}
+ </LemonButton>
+ </AccessControlAction>
+
{featureFlag.id && (
<AccessControlAction
resourceType={AccessControlResourceType.FeatureFlag}
@@ -298,17 +274,15 @@ function FeatureFlagRowActions({ featureFlag }: { featureFlag: FeatureFlagType }
onClick={() => {
if (featureFlag.archived) {
featureFlag.id &&
- updateFeatureFlag({
- id: featureFlag.id,
- payload: { archived: false },
- })
+ updateFeatureFlagArchived({ id: featureFlag.id, archived: false })
return
}
openFeatureFlagArchiveDialog(featureFlag, () => {
featureFlag.id &&
- updateFeatureFlag({
+ updateFeatureFlagArchived({
id: featureFlag.id,
- payload: { archived: true, active: false },
+ archived: true,
+ via: 'archive-dialog',
})
})
}}
@@ -316,7 +290,7 @@ function FeatureFlagRowActions({ featureFlag }: { featureFlag: FeatureFlagType }
loading={isUpdating}
disabledReason={isUpdating ? 'Updating…' : undefined}
>
- {featureFlag.archived ? 'Unarchive' : 'Archive'} feature flag
+ {featureFlag.archived ? 'Unarchive' : 'Archive'}
</LemonButton>
</AccessControlAction>
)}
@@ -347,7 +321,7 @@ function FeatureFlagRowActions({ featureFlag }: { featureFlag: FeatureFlagType }
}
fullWidth
>
- Delete feature flag
+ Delete
</LemonButton>
</AccessControlAction>
)}
diff --git a/frontend/src/scenes/feature-flags/featureFlagArchiveDialog.tsx b/frontend/src/scenes/feature-flags/featureFlagArchiveDialog.tsx
index 0f5115d49d02..cd4938f589c2 100644
--- a/frontend/src/scenes/feature-flags/featureFlagArchiveDialog.tsx
+++ b/frontend/src/scenes/feature-flags/featureFlagArchiveDialog.tsx
@@ -1,7 +1,15 @@
+import posthog from 'posthog-js'
+
import { LemonDialog } from '@posthog/lemon-ui'
import { FeatureFlagType } from '~/types'
+export type FeatureFlagArchivedSource = 'archive-dialog' | 'disable-confirmation'
+
+export function reportFeatureFlagArchived(via: FeatureFlagArchivedSource): void {
+ posthog.capture('feature flag archived', { via })
+}
+
/**
* Opens the archive confirmation dialog for a feature flag. The warning copy lives here so the
* detail page and the list share one source of truth — only the confirm callback differs.
diff --git a/frontend/src/scenes/feature-flags/featureFlagConfirmationLogic.test.ts b/frontend/src/scenes/feature-flags/featureFlagConfirmationLogic.test.ts
new file mode 100644
index 000000000000..3253aed3b4b9
--- /dev/null
+++ b/frontend/src/scenes/feature-flags/featureFlagConfirmationLogic.test.ts
@@ -0,0 +1,81 @@
+import posthog from 'posthog-js'
+
+import { LemonDialog } from '@posthog/lemon-ui'
+
+import { NEW_FLAG } from 'scenes/feature-flags/featureFlagLogic'
+
+import { FeatureFlagType } from '~/types'
+
+import { checkFeatureFlagConfirmation } from './featureFlagConfirmationLogic'
+import { DependentFlag } from './featureFlagLogic'
+
+jest.mock('posthog-js')
+
+describe('checkFeatureFlagConfirmation', () => {
+ let onConfirm: jest.Mock
+ let onDisableAndArchive: jest.Mock
+ let openDialog: jest.SpyInstance
+
+ const activeFlag = { ...NEW_FLAG, id: 1, key: 'my-flag', active: true } as FeatureFlagType
+ const disabledFlag = { ...activeFlag, active: false }
+ const dependent: DependentFlag = { id: 2, key: 'depends-on-my-flag' } as DependentFlag
+
+ const disableDialogReached = (): boolean =>
+ (posthog.capture as jest.Mock).mock.calls.some(
+ ([name, props]) =>
+ name === 'feature flag disable confirmation shown' && props?.source === 'feature-flag-detail'
+ )
+
+ // shouldDisplayConfirmation is derived the way featureFlagLogic derives it before calling in,
+ // so a case that sets only dependentFlags reaches the gate the same way production does.
+ const disableFlag = ({
+ featureFlagConfirmationEnabled = false,
+ dependentFlags = [],
+ }: {
+ featureFlagConfirmationEnabled?: boolean
+ dependentFlags?: DependentFlag[]
+ } = {}): boolean =>
+ checkFeatureFlagConfirmation(
+ activeFlag,
+ disabledFlag,
+ featureFlagConfirmationEnabled || dependentFlags.length > 0,
+ undefined,
+ featureFlagConfirmationEnabled,
+ onConfirm,
+ dependentFlags,
+ true,
+ true,
+ onDisableAndArchive
+ )
+
+ beforeEach(() => {
+ onConfirm = jest.fn()
+ onDisableAndArchive = jest.fn()
+ openDialog = jest.spyOn(LemonDialog, 'open').mockImplementation(() => {})
+ ;(posthog.capture as jest.Mock).mockClear()
+ })
+
+ afterEach(() => {
+ jest.restoreAllMocks()
+ })
+
+ // The disable-and-archive shortcut must stay behind the confirmation gate: archiving a flag
+ // other flags read from, or skipping a team's required confirmation, is worse than losing an
+ // experiment exposure.
+ it.each<[string, { featureFlagConfirmationEnabled?: boolean; dependentFlags?: DependentFlag[] }]>([
+ ['other flags depend on it', { dependentFlags: [dependent] }],
+ ['the team requires confirmation', { featureFlagConfirmationEnabled: true }],
+ ])('does not offer disable-and-archive when %s', (_label, options) => {
+ expect(disableFlag(options)).toBe(true)
+
+ expect(disableDialogReached()).toBe(false)
+ expect(onDisableAndArchive).not.toHaveBeenCalled()
+ expect(openDialog).toHaveBeenCalledTimes(1)
+ })
+
+ it('routes to the disable dialog when nothing else claims the confirmation', () => {
+ expect(disableFlag()).toBe(true)
+
+ expect(disableDialogReached()).toBe(true)
+ })
+})
diff --git a/frontend/src/scenes/feature-flags/featureFlagConfirmationLogic.ts b/frontend/src/scenes/feature-flags/featureFlagConfirmationLogic.ts
index 9a78c3f91398..9f898e31e639 100644
--- a/frontend/src/scenes/feature-flags/featureFlagConfirmationLogic.ts
+++ b/frontend/src/scenes/feature-flags/featureFlagConfirmationLogic.ts
@@ -5,6 +5,7 @@ import { objectsEqual } from 'lib/utils/objects'
import { FeatureFlagType } from '~/types'
import { openConfirmationModal } from './ConfirmationModal'
+import { openFeatureFlagDisableDialog } from './featureFlagDisableDialog'
import { DependentFlag } from './featureFlagLogic'
/**
@@ -112,7 +113,8 @@ export function checkFeatureFlagConfirmation(
onConfirm: () => void,
dependentFlags?: DependentFlag[],
isBeingDisabled?: boolean,
- requireStatusConfirmation = false
+ requireStatusConfirmation = false,
+ onDisableAndArchive?: () => void
): boolean {
// Check if confirmation is needed
const needsConfirmation = !!updatedFlag.id && shouldDisplayConfirmation
@@ -137,12 +139,29 @@ export function checkFeatureFlagConfirmation(
}
if (requireStatusConfirmation && originalFlag?.active !== updatedFlag.active) {
- openConfirmationModal({
- featureFlag: updatedFlag,
- type: 'flag-status',
- activeNewValue: updatedFlag.active,
- onConfirm,
- })
+ const openStatusConfirmationModal = (onConfirmModal?: () => void, onCancelModal?: () => void): void =>
+ openConfirmationModal({
+ featureFlag: updatedFlag,
+ type: 'flag-status',
+ activeNewValue: updatedFlag.active,
+ onConfirm: onConfirmModal ?? onConfirm,
+ onCancel: onCancelModal,
+ })
+
+ // Disabling can offer "Disable and archive" behind the disable-and-archive experiment.
+ // Deliberately below the confirmation gate: a flag with dependents, or a team that set up
+ // its own confirmation, gets that modal instead. Losing an experiment exposure beats
+ // archiving a flag others read from.
+ if (!updatedFlag.active && onDisableAndArchive) {
+ openFeatureFlagDisableDialog({
+ source: 'feature-flag-detail',
+ onDisable: onConfirm,
+ onDisableAndArchive,
+ openControlDialog: openStatusConfirmationModal,
+ })
+ return true
+ }
+ openStatusConfirmationModal()
return true
}
diff --git a/frontend/src/scenes/feature-flags/featureFlagDisableDialog.test.ts b/frontend/src/scenes/feature-flags/featureFlagDisableDialog.test.ts
new file mode 100644
index 000000000000..c35d345abae6
--- /dev/null
+++ b/frontend/src/scenes/feature-flags/featureFlagDisableDialog.test.ts
@@ -0,0 +1,112 @@
+import posthog from 'posthog-js'
+
+import { LemonDialog } from '@posthog/lemon-ui'
+
+import { FEATURE_FLAGS } from 'lib/constants'
+import { featureFlagLogic as enabledFeaturesLogic } from 'lib/logic/featureFlagLogic'
+
+import { initKeaTests } from '~/test/init'
+
+import { FeatureFlagDisableDialogOption, openFeatureFlagDisableDialog } from './featureFlagDisableDialog'
+
+jest.mock('posthog-js')
+
+const EXPERIMENT_KEY = FEATURE_FLAGS.FEATURE_FLAG_DISABLE_AND_ARCHIVE_EXPERIMENT
+
+describe('openFeatureFlagDisableDialog', () => {
+ let flagsLogic: ReturnType<typeof enabledFeaturesLogic.build>
+ let onDisable: jest.Mock
+ let onDisableAndArchive: jest.Mock
+ let openControlDialog: jest.Mock
+ let openDialog: jest.SpyInstance
+
+ const setVariant = (variant: string | boolean): void => {
+ flagsLogic.actions.setFeatureFlags([EXPERIMENT_KEY], { [EXPERIMENT_KEY]: variant })
+ }
+
+ const open = (): void =>
+ openFeatureFlagDisableDialog({
+ source: 'feature-flags-list',
+ onDisable,
+ onDisableAndArchive,
+ openControlDialog,
+ })
+
+ const optionCapturesOf = (option: FeatureFlagDisableDialogOption): any[][] =>
+ (posthog.capture as jest.Mock).mock.calls.filter(
+ ([name, props]) => name === 'feature flag disable confirmation option selected' && props?.option === option
+ )
+
+ beforeEach(() => {
+ initKeaTests()
+ flagsLogic = enabledFeaturesLogic()
+ flagsLogic.mount()
+ onDisable = jest.fn()
+ onDisableAndArchive = jest.fn()
+ openControlDialog = jest.fn()
+ openDialog = jest.spyOn(LemonDialog, 'open').mockImplementation(() => {})
+ ;(posthog.capture as jest.Mock).mockClear()
+ })
+
+ afterEach(() => {
+ flagsLogic.unmount()
+ jest.restoreAllMocks()
+ })
+
+ describe('variant routing', () => {
+ it('offers "Disable and archive" to the test variant', () => {
+ setVariant('test')
+ open()
+
+ expect(openControlDialog).not.toHaveBeenCalled()
+ expect(openDialog.mock.calls[0][0].primaryButton.children).toBe('Disable and archive')
+ expect(openDialog.mock.calls[0][0].secondaryButton.children).toBe('Disable only')
+ })
+
+ it.each<[string, string | boolean]>([
+ ['control', 'control'],
+ ['an unset flag', false],
+ ['an unexpected variant', 'holdout'],
+ ])("falls back to the caller's own dialog for %s", (_label, variant) => {
+ setVariant(variant)
+ open()
+
+ expect(openDialog).not.toHaveBeenCalled()
+ expect(openControlDialog).toHaveBeenCalledTimes(1)
+ })
+ })
+
+ describe('option telemetry', () => {
+ // A fresh dialog per case, so each one can assert the other callback stayed untouched.
+ it.each<[FeatureFlagDisableDialogOption, 'primaryButton' | 'secondaryButton' | 'tertiaryButton']>([
+ ['disable_and_archive', 'primaryButton'],
+ ['disable', 'secondaryButton'],
+ ['cancel', 'tertiaryButton'],
+ ])('reports %s and runs only its own callback', (option, button) => {
+ setVariant('test')
+ open()
+
+ openDialog.mock.calls[0][0][button].onClick()
+
+ expect(optionCapturesOf(option)).toEqual([
+ ['feature flag disable confirmation option selected', { source: 'feature-flags-list', option }],
+ ])
+ expect(onDisableAndArchive).toHaveBeenCalledTimes(option === 'disable_and_archive' ? 1 : 0)
+ expect(onDisable).toHaveBeenCalledTimes(option === 'disable' ? 1 : 0)
+ })
+
+ it('wraps the control dialog callbacks so control reports the same options', () => {
+ setVariant('control')
+ open()
+ const [confirm, cancel] = openControlDialog.mock.calls[0]
+
+ confirm()
+ expect(optionCapturesOf('disable')).toHaveLength(1)
+ expect(onDisable).toHaveBeenCalledTimes(1)
+
+ cancel()
+ expect(optionCapturesOf('cancel')).toHaveLength(1)
+ expect(onDisableAndArchive).not.toHaveBeenCalled()
+ })
+ })
+})
diff --git a/frontend/src/scenes/feature-flags/featureFlagDisableDialog.tsx b/frontend/src/scenes/feature-flags/featureFlagDisableDialog.tsx
new file mode 100644
index 000000000000..5be74690db76
--- /dev/null
+++ b/frontend/src/scenes/feature-flags/featureFlagDisableDialog.tsx
@@ -0,0 +1,85 @@
+import posthog from 'posthog-js'
+
+import { LemonDialog } from '@posthog/lemon-ui'
+
+import { FEATURE_FLAGS } from 'lib/constants'
+import { featureFlagLogic as enabledFeaturesLogic } from 'lib/logic/featureFlagLogic'
+
+export type FeatureFlagDisableDialogSource = 'feature-flags-list' | 'feature-flag-detail'
+
+export type FeatureFlagDisableDialogOption = 'disable' | 'disable_and_archive' | 'cancel'
+
+export function reportFeatureFlagDisableDialogOptionSelected(
+ source: FeatureFlagDisableDialogSource,
+ option: FeatureFlagDisableDialogOption
+): void {
+ posthog.capture('feature flag disable confirmation option selected', { source, option })
+}
+
+/**
+ * Opens the disable confirmation dialog for a feature flag. The test variant of the
+ * disable-and-archive experiment gets "Disable and archive" as the primary CTA alongside a
+ * "Disable only" option; control keeps each caller's pre-existing dialog, with this dialog's own
+ * option-selected telemetry wrapped around the caller's confirm/cancel. The experiment flag is
+ * read here rather than at render so the exposure lines up with the dialog actually opening.
+ */
+export function openFeatureFlagDisableDialog({
+ source,
+ onDisable,
+ onDisableAndArchive,
+ openControlDialog,
+}: {
+ source: FeatureFlagDisableDialogSource
+ onDisable: () => void
+ onDisableAndArchive: () => void
+ /** The pre-experiment dialog, shown to the control variant. Called with confirm/cancel
+ * callbacks that already report the selected option — the caller only needs to wire them
+ * into its own dialog's primary/secondary buttons. */
+ openControlDialog: (onConfirm?: () => void, onCancel?: () => void) => void
+}): void {
+ const inTestVariant =
+ enabledFeaturesLogic.findMounted()?.values.featureFlags[
+ FEATURE_FLAGS.FEATURE_FLAG_DISABLE_AND_ARCHIVE_EXPERIMENT
+ ] === 'test'
+
+ posthog.capture('feature flag disable confirmation shown', { source })
+
+ const selectDisable = (): void => {
+ reportFeatureFlagDisableDialogOptionSelected(source, 'disable')
+ onDisable()
+ }
+ const selectCancel = (): void => reportFeatureFlagDisableDialogOptionSelected(source, 'cancel')
+ const selectDisableAndArchive = (): void => {
+ reportFeatureFlagDisableDialogOptionSelected(source, 'disable_and_archive')
+ onDisableAndArchive()
+ }
+
+ if (!inTestVariant) {
+ openControlDialog(selectDisable, selectCancel)
+ return
+ }
+
+ LemonDialog.open({
+ title: 'Disable this flag?',
+ description:
+ 'This flag will be immediately rolled back from the users matching the release conditions. Done with it for good? Archive it too: archived flags are hidden from the flag list, but linked experiments and surveys keep their data.',
+ primaryButton: {
+ children: 'Disable and archive',
+ type: 'primary',
+ size: 'small',
+ onClick: selectDisableAndArchive,
+ },
+ secondaryButton: {
+ children: 'Disable only',
+ type: 'secondary',
+ size: 'small',
+ onClick: selectDisable,
+ },
+ tertiaryButton: {
+ children: 'Cancel',
+ type: 'tertiary',
+ size: 'small',
+ onClick: selectCancel,
+ },
+ })
+}
diff --git a/frontend/src/scenes/feature-flags/featureFlagLogic.test.ts b/frontend/src/scenes/feature-flags/featureFlagLogic.test.ts
index 56ecae2f8bf7..18f56527d128 100644
--- a/frontend/src/scenes/feature-flags/featureFlagLogic.test.ts
+++ b/frontend/src/scenes/feature-flags/featureFlagLogic.test.ts
@@ -8,10 +8,14 @@ import {
import { router } from 'kea-router'
import { expectLogic, partial } from 'kea-test-utils'
+import posthog from 'posthog-js'
+import api from 'lib/api'
+import { FEATURE_FLAGS } from 'lib/constants'
import { dayjs } from 'lib/dayjs'
import { LemonDialog } from 'lib/lemon-ui/LemonDialog'
import { lemonToast } from 'lib/lemon-ui/LemonToast/LemonToast'
+import { featureFlagLogic as enabledFeaturesLogic } from 'lib/logic/featureFlagLogic'
import { urls } from 'scenes/urls'
import { resumeKeaLoadersErrors, silenceKeaLoadersErrors } from '~/initKea'
@@ -59,6 +63,12 @@ import {
} from './featureFlagLogic'
import { featureFlagsLogic } from './featureFlagsLogic'
+jest.mock('posthog-js')
+
+function capturesOf(event: string): any[][] {
+ return (posthog.capture as jest.Mock).mock.calls.filter(([name]) => name === event)
+}
+
// jest.config.ts sets clearMocks: true, so these mock.fn() call histories reset before every test.
jest.mock('lib/lemon-ui/LemonToast/LemonToast', () => ({
lemonToast: {
@@ -1800,6 +1810,63 @@ describe('featureFlagLogic', () => {
expect(dialogProps.primaryButton?.children).toBe('Disable flag')
dialogOpenSpy.mockRestore()
})
+
+ // onDisableAndArchive is optional at every hop between this listener and
+ // checkFeatureFlagConfirmation, so dropping it anywhere still compiles and would silently
+ // put test-variant users back on the control dialog.
+ it('offers disable and archive to the test variant, archiving via the disable confirmation', async () => {
+ const dialogOpenSpy = jest.spyOn(LemonDialog, 'open').mockImplementation(() => {})
+ jest.spyOn(api, 'update').mockResolvedValueOnce({
+ ...MOCK_FEATURE_FLAG,
+ archived: true,
+ active: false,
+ })
+ enabledFeaturesLogic.actions.setFeatureFlags([FEATURE_FLAGS.FEATURE_FLAG_DISABLE_AND_ARCHIVE_EXPERIMENT], {
+ [FEATURE_FLAGS.FEATURE_FLAG_DISABLE_AND_ARCHIVE_EXPERIMENT]: 'test',
+ })
+ logic.actions.setFeatureFlag({ ...MOCK_FEATURE_FLAG, active: true })
+
+ await expectLogic(logic, () => logic.actions.toggleFeatureFlagActive(false)).toFinishAllListeners()
+
+ const dialogProps = dialogOpenSpy.mock.calls[0][0]
+ expect(dialogProps.primaryButton?.children).toBe('Disable and archive')
+
+ dialogProps.primaryButton?.onClick?.(undefined as any)
+ await expectLogic(logic).toFinishAllListeners()
+
+ expect(capturesOf('feature flag archived')).toEqual([
+ ['feature flag archived', { via: 'disable-confirmation' }],
+ ])
+ dialogOpenSpy.mockRestore()
+ })
+ })
+
+ describe('updateFeatureFlagArchived archive telemetry', () => {
+ // One test here rejects the archive request on purpose; kea-loaders would log the failure
+ beforeEach(silenceKeaLoadersErrors)
+ afterEach(resumeKeaLoadersErrors)
+
+ beforeEach(() => {
+ ;(posthog.capture as jest.Mock).mockClear()
+ })
+
+ it('captures "feature flag archived" only after the archive succeeds', async () => {
+ jest.spyOn(api, 'update').mockResolvedValueOnce({ ...MOCK_FEATURE_FLAG, archived: true, active: false })
+
+ logic.actions.updateFeatureFlagArchived({ archived: true, via: 'archive-dialog' })
+ await expectLogic(logic).toFinishAllListeners()
+
+ expect(capturesOf('feature flag archived')).toEqual([['feature flag archived', { via: 'archive-dialog' }]])
+ })
+
+ it('does not capture "feature flag archived" when the archive request fails', async () => {
+ jest.spyOn(api, 'update').mockRejectedValueOnce({ status: 409, data: { detail: 'Conflict' } })
+
+ logic.actions.updateFeatureFlagArchived({ archived: true, via: 'archive-dialog' })
+ await expectLogic(logic).toFinishAllListeners()
+
+ expect(capturesOf('feature flag archived')).toHaveLength(0)
+ })
})
describe('copyFlagSuccess', () => {
diff --git a/frontend/src/scenes/feature-flags/featureFlagLogic.ts b/frontend/src/scenes/feature-flags/featureFlagLogic.ts
index e96b2f8ab2ad..d8f3d484ed3d 100644
--- a/frontend/src/scenes/feature-flags/featureFlagLogic.ts
+++ b/frontend/src/scenes/feature-flags/featureFlagLogic.ts
@@ -114,6 +114,7 @@ import type { DefaultEvaluationContextsResponse } from './defaultEvaluationConte
import { defaultReleaseConditionsLogic, resolveDefaultReleaseConditions } from './defaultReleaseConditionsLogic'
import type { DefaultReleaseConditionsResponse } from './defaultReleaseConditionsLogic'
import { uniformAggregationGroupTypeIndex } from './defaultReleaseConditionsUtils'
+import { FeatureFlagArchivedSource, reportFeatureFlagArchived } from './featureFlagArchiveDialog'
import { checkFeatureFlagConfirmation } from './featureFlagConfirmationLogic'
import type { FlagIntent } from './featureFlagIntentWarningLogic'
import { flagToggleKey, updateFlagActiveInProject } from './updateFlagActiveInProject'
@@ -1551,6 +1552,7 @@ export interface featureFlagLogicActions {
dependentFlags: DependentFlag[]
isBeingDisabled?: boolean
onConfirm: () => void
+ onDisableAndArchive?: () => void
originalFlag: FeatureFlagType | null
requireStatusConfirmation?: boolean
updatedFlag: Partial<FeatureFlagType>
@@ -1558,6 +1560,7 @@ export interface featureFlagLogicActions {
dependentFlags: DependentFlag[]
isBeingDisabled?: boolean | undefined
onConfirm: () => void
+ onDisableAndArchive?: (() => void) | undefined
originalFlag: FeatureFlagType | null
requireStatusConfirmation?: boolean | undefined
updatedFlag: Partial<FeatureFlagType>
@@ -1770,7 +1773,17 @@ export interface featureFlagLogicActions {
featureFlagActiveUpdate: FeatureFlagType
payload?: boolean
}
- updateFeatureFlagArchived: (archived: boolean) => boolean
+ updateFeatureFlagArchived: ({
+ archived,
+ via,
+ }: {
+ archived: boolean
+ /** Telemetry source; only meaningful (and only captured) when archiving, not unarchiving. */
+ via?: FeatureFlagArchivedSource
+ }) => {
+ archived: boolean
+ via?: FeatureFlagArchivedSource
+ }
updateFeatureFlagArchivedFailure: (
error: string,
errorObject?: any
@@ -1780,10 +1793,16 @@ export interface featureFlagLogicActions {
}
updateFeatureFlagArchivedSuccess: (
featureFlagActiveUpdate: FeatureFlagType,
- payload?: boolean
+ payload?: {
+ archived: boolean
+ via?: FeatureFlagArchivedSource
+ }
) => {
featureFlagActiveUpdate: FeatureFlagType
- payload?: boolean
+ payload?: {
+ archived: boolean
+ via?: FeatureFlagArchivedSource
+ }
}
}
@@ -1794,6 +1813,7 @@ export interface featureFlagLogicMeta {
checkDependentFlagsAndConfirm: (
payload: {
onConfirm: () => void
+ onDisableAndArchive?: (() => void) | undefined
originalFlag: FeatureFlagType | null
requireStatusConfirmation?: boolean | undefined
updatedFlag: Partial<FeatureFlagType>
@@ -1803,6 +1823,7 @@ export interface featureFlagLogicMeta {
type: string
payload: {
onConfirm: () => void
+ onDisableAndArchive?: (() => void) | undefined
originalFlag: FeatureFlagType | null
requireStatusConfirmation?: boolean | undefined
updatedFlag: Partial<FeatureFlagType>
@@ -1815,6 +1836,7 @@ export interface featureFlagLogicMeta {
dependentFlags: DependentFlag[]
isBeingDisabled?: boolean | undefined
onConfirm: () => void
+ onDisableAndArchive?: (() => void) | undefined
originalFlag: FeatureFlagType | null
requireStatusConfirmation?: boolean | undefined
updatedFlag: Partial<FeatureFlagType>
@@ -1826,6 +1848,7 @@ export interface featureFlagLogicMeta {
dependentFlags: DependentFlag[]
isBeingDisabled?: boolean | undefined
onConfirm: () => void
+ onDisableAndArchive?: (() => void) | undefined
originalFlag: FeatureFlagType | null
requireStatusConfirmation?: boolean | undefined
updatedFlag: Partial<FeatureFlagType>
@@ -2020,6 +2043,7 @@ export const featureFlagLogic = kea<featureFlagLogicType>([
dependentFlags: DependentFlag[]
isBeingDisabled?: boolean
requireStatusConfirmation?: boolean
+ onDisableAndArchive?: () => void
}) => payload,
saveDescriptionInline: (name: string) => ({ name }),
saveTagsInline: (tags: string[]) => ({ tags }),
@@ -2573,8 +2597,15 @@ export const featureFlagLogic = kea<featureFlagLogicType>([
updatedFlag: Partial<FeatureFlagType>
onConfirm: () => void
requireStatusConfirmation?: boolean
+ onDisableAndArchive?: () => void
}) => {
- const { originalFlag, updatedFlag, onConfirm, requireStatusConfirmation = false } = payload
+ const {
+ originalFlag,
+ updatedFlag,
+ onConfirm,
+ requireStatusConfirmation = false,
+ onDisableAndArchive,
+ } = payload
const isBeingDisabled = !!updatedFlag.id && originalFlag?.active === true && updatedFlag.active === false
let dependentFlagsForConfirmation: DependentFlag[] = []
@@ -2601,6 +2632,7 @@ export const featureFlagLogic = kea<featureFlagLogicType>([
isBeingDisabled,
dependentFlags: dependentFlagsForConfirmation,
requireStatusConfirmation,
+ onDisableAndArchive,
})
},
showDependentFlagsConfirmation: (payload: {
@@ -2610,6 +2642,7 @@ export const featureFlagLogic = kea<featureFlagLogicType>([
dependentFlags: DependentFlag[]
isBeingDisabled?: boolean
requireStatusConfirmation?: boolean
+ onDisableAndArchive?: () => void
}) => {
const {
originalFlag,
@@ -2618,6 +2651,7 @@ export const featureFlagLogic = kea<featureFlagLogicType>([
dependentFlags,
isBeingDisabled = false,
requireStatusConfirmation = false,
+ onDisableAndArchive,
} = payload
const featureFlagConfirmationEnabled = !!values.currentTeam?.feature_flag_confirmation_enabled
@@ -2637,7 +2671,8 @@ export const featureFlagLogic = kea<featureFlagLogicType>([
onConfirm,
dependentFlags,
isBeingDisabled,
- requireStatusConfirmation
+ requireStatusConfirmation,
+ onDisableAndArchive
)
// If no confirmation was shown, proceed immediately
@@ -2903,7 +2938,14 @@ export const featureFlagLogic = kea<featureFlagLogicType>([
return variantKeyToIndexFeatureFlagPayloads(savedFlag)
},
// Shares the featureFlagActiveUpdate loader key (and its loading/success state)
- updateFeatureFlagArchived: async (archived: boolean) => {
+ updateFeatureFlagArchived: async ({
+ archived,
+ via,
+ }: {
+ archived: boolean
+ /** Telemetry source; only meaningful (and only captured) when archiving, not unarchiving. */
+ via?: FeatureFlagArchivedSource
+ }) => {
if (!values.featureFlag.id) {
throw new Error('Cannot archive an unsaved flag')
}
@@ -2913,6 +2955,9 @@ export const featureFlagLogic = kea<featureFlagLogicType>([
archived ? { archived: true, active: false } : { archived: false }
)
savedFlag.id && refreshTreeItem('feature_flag', String(savedFlag.id))
+ if (archived && via) {
+ reportFeatureFlagArchived(via)
+ }
return variantKeyToIndexFeatureFlagPayloads(savedFlag)
},
},
@@ -3957,6 +4002,9 @@ export const featureFlagLogic = kea<featureFlagLogicType>([
actions.updateFeatureFlagActive(active)
},
requireStatusConfirmation: true,
+ onDisableAndArchive: () => {
+ actions.updateFeatureFlagArchived({ archived: true, via: 'disable-confirmation' })
+ },
},
breakpoint,
action as any,
diff --git a/frontend/src/scenes/feature-flags/featureFlagsLogic.test.ts b/frontend/src/scenes/feature-flags/featureFlagsLogic.test.ts
index 0ebf2a796dee..0de96ff1598b 100644
--- a/frontend/src/scenes/feature-flags/featureFlagsLogic.test.ts
+++ b/frontend/src/scenes/feature-flags/featureFlagsLogic.test.ts
@@ -1,7 +1,11 @@
import { router } from 'kea-router'
import { expectLogic } from 'kea-test-utils'
+import posthog from 'posthog-js'
import api from 'lib/api'
+import { FEATURE_FLAGS } from 'lib/constants'
+import { LemonDialog } from 'lib/lemon-ui/LemonDialog'
+import { featureFlagLogic as enabledFeaturesLogic } from 'lib/logic/featureFlagLogic'
import { showApprovalRequiredToast } from 'scenes/approvals/ApprovalRequiredBanner'
import { NEW_FLAG } from 'scenes/feature-flags/featureFlagLogic'
import {
@@ -23,6 +27,11 @@ import { FeatureFlagType } from '~/types'
jest.mock('scenes/approvals/ApprovalRequiredBanner', () => ({
showApprovalRequiredToast: jest.fn(),
}))
+jest.mock('posthog-js')
+
+function capturesOf(event: string): any[][] {
+ return (posthog.capture as jest.Mock).mock.calls.filter(([name]) => name === event)
+}
describe('flagMatchesSearch', () => {
const flag = { ...NEW_FLAG, id: 1, key: 'my-feature', name: 'My Feature Flag' } as FeatureFlagType
@@ -360,3 +369,95 @@ describe('updateFeatureFlag 409 handling', () => {
expect(showApprovalRequiredToast).not.toHaveBeenCalled()
})
})
+
+describe('updateFeatureFlagArchived', () => {
+ let logic: ReturnType<typeof featureFlagsLogic.build>
+
+ // One test here rejects the archive request on purpose; kea-loaders would log the failure
+ beforeEach(silenceKeaLoadersErrors)
+ afterEach(resumeKeaLoadersErrors)
+
+ beforeEach(() => {
+ useMocks({
+ get: {
+ '/api/projects/:projectId/feature_flags/': () => [
+ 200,
+ {
+ results: [{ id: 1, key: 'test-flag', active: true }],
+ count: 1,
+ },
+ ],
+ },
+ })
+ initKeaTests()
+ logic = featureFlagsLogic()
+ logic.mount()
+ ;(posthog.capture as jest.Mock).mockClear()
+ })
+
+ afterEach(() => {
+ logic?.unmount()
+ jest.restoreAllMocks()
+ })
+
+ it('captures "feature flag archived" only after the archive succeeds', async () => {
+ jest.spyOn(api, 'update').mockResolvedValueOnce({ id: 1, key: 'test-flag', archived: true, active: false })
+
+ logic.actions.updateFeatureFlagArchived({ id: 1, archived: true, via: 'archive-dialog' })
+ await expectLogic(logic).toFinishAllListeners()
+
+ expect(capturesOf('feature flag archived')).toEqual([['feature flag archived', { via: 'archive-dialog' }]])
+ })
+
+ it('does not capture "feature flag archived" when the archive request fails', async () => {
+ jest.spyOn(api, 'update').mockRejectedValueOnce({ status: 409, data: { detail: 'Conflict' } })
+
+ logic.actions.updateFeatureFlagArchived({ id: 1, archived: true, via: 'archive-dialog' })
+ await expectLogic(logic).toFinishAllListeners()
+
+ expect(capturesOf('feature flag archived')).toHaveLength(0)
+ })
+
+ it('marks the row as updating until the archive resolves', async () => {
+ jest.spyOn(api, 'update').mockResolvedValueOnce({ id: 1, key: 'test-flag', archived: true, active: false })
+
+ logic.actions.updateFeatureFlagArchived({ id: 1, archived: true, via: 'archive-dialog' })
+ expect(logic.values.featureFlagsUpdating[1]).toBe(true)
+
+ await expectLogic(logic).toFinishAllListeners()
+ expect(logic.values.featureFlagsUpdating[1]).toBeUndefined()
+ })
+
+ // The list arm of the disable-and-archive experiment: the row toggle has to reach
+ // updateFeatureFlagArchived with the list's own via, not the archive dialog's.
+ it('archives via the disable confirmation when the test variant picks it', async () => {
+ const openDialog = jest.spyOn(LemonDialog, 'open').mockImplementation(() => {})
+ jest.spyOn(api, 'update').mockResolvedValueOnce({ id: 1, key: 'test-flag', archived: true, active: false })
+ const flagsLogic = enabledFeaturesLogic()
+ flagsLogic.mount()
+ flagsLogic.actions.setFeatureFlags([FEATURE_FLAGS.FEATURE_FLAG_DISABLE_AND_ARCHIVE_EXPERIMENT], {
+ [FEATURE_FLAGS.FEATURE_FLAG_DISABLE_AND_ARCHIVE_EXPERIMENT]: 'test',
+ })
+
+ logic.actions.toggleFeatureFlagActive(1, false)
+ expect(openDialog.mock.calls[0][0].primaryButton?.children).toBe('Disable and archive')
+
+ openDialog.mock.calls[0][0].primaryButton?.onClick?.(undefined as any)
+ await expectLogic(logic).toFinishAllListeners()
+
+ expect(capturesOf('feature flag archived')).toEqual([
+ ['feature flag archived', { via: 'disable-confirmation' }],
+ ])
+ })
+
+ it('leaves other rows spinning when one archive fails', async () => {
+ jest.spyOn(api, 'update').mockRejectedValueOnce({ status: 409, data: { detail: 'Conflict' } })
+ logic.actions.setFeatureFlagUpdating(2, true)
+
+ logic.actions.updateFeatureFlagArchived({ id: 1, archived: true, via: 'archive-dialog' })
+ await expectLogic(logic).toFinishAllListeners()
+
+ expect(logic.values.featureFlagsUpdating[1]).toBeUndefined()
+ expect(logic.values.featureFlagsUpdating[2]).toBe(true)
+ })
+})
diff --git a/frontend/src/scenes/feature-flags/featureFlagsLogic.ts b/frontend/src/scenes/feature-flags/featureFlagsLogic.ts
index 77e303d71cb0..89f6927ca68e 100644
--- a/frontend/src/scenes/feature-flags/featureFlagsLogic.ts
+++ b/frontend/src/scenes/feature-flags/featureFlagsLogic.ts
@@ -2,7 +2,7 @@ import { MakeLogicType, actions, connect, kea, listeners, path, props, reducers,
import { loaders } from 'kea-loaders'
import { actionToUrl, router, urlToAction } from 'kea-router'
-import { PaginationManual } from '@posthog/lemon-ui'
+import { LemonDialog, PaginationManual } from '@posthog/lemon-ui'
import api, { CountedPaginatedResponse } from 'lib/api'
import { SetupTaskId, globalSetupLogic } from 'lib/components/ProductSetup'
@@ -16,6 +16,9 @@ import { urls } from 'scenes/urls'
import { SIDE_PANEL_CONTEXT_KEY, SidePanelSceneContext } from '~/layout/navigation-3000/sidepanel/types'
import { ActivityScope, Breadcrumb, FeatureFlagType } from '~/types'
+import { FeatureFlagArchivedSource, reportFeatureFlagArchived } from './featureFlagArchiveDialog'
+import { openFeatureFlagDisableDialog } from './featureFlagDisableDialog'
+
export const FLAGS_PER_PAGE = 100
export function flagMatchesSearch(flag: FeatureFlagType, search?: string): boolean {
@@ -156,6 +159,26 @@ export interface FlagLogicProps {
flagPrefix?: string // used to filter flags by prefix e.g. for the user interview flags
}
+type FlagsUpdatingState = Record<number, boolean>
+
+// Shared by the updateFeatureFlag and updateFeatureFlagArchived reducer cases, which track the
+// per-row spinner identically.
+const markFlagUpdating = (state: FlagsUpdatingState, { id }: { id: number }): FlagsUpdatingState => ({
+ ...state,
+ [id]: true,
+})
+
+const clearFlagUpdating = (
+ state: FlagsUpdatingState,
+ { featureFlags }: { featureFlags: { lastUpdatedFlagId?: number | null } }
+): FlagsUpdatingState => {
+ if (!featureFlags.lastUpdatedFlagId) {
+ return state
+ }
+ const { [featureFlags.lastUpdatedFlagId]: _, ...rest } = state
+ return rest
+}
+
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface featureFlagsLogicValues {
currentProjectId: number | null // projectLogic
@@ -229,10 +252,67 @@ export interface featureFlagsLogicActions {
filters: Partial<FeatureFlagsFilters>
replace: boolean | undefined
}
+ toggleFeatureFlagActive: (
+ id: number,
+ active: boolean
+ ) => {
+ active: boolean
+ id: number
+ }
updateFeatureFlag: ({ id, payload }: { id: number; payload: Partial<FeatureFlagType> }) => {
id: number
payload: Partial<FeatureFlagType>
}
+ updateFeatureFlagArchived: ({
+ id,
+ archived,
+ via,
+ }: {
+ archived: boolean
+ id: number
+ /** Telemetry source; only meaningful (and only captured) when archiving, not unarchiving. */
+ via?: FeatureFlagArchivedSource
+ }) => {
+ id: number
+ archived: boolean
+ via?: FeatureFlagArchivedSource
+ }
+ updateFeatureFlagArchivedFailure: (
+ error: string,
+ errorObject?: any
+ ) => {
+ error: string
+ errorObject?: any
+ }
+ updateFeatureFlagArchivedSuccess: (
+ featureFlags: {
+ count: number
+ filters?: FeatureFlagsFilters | null | undefined
+ lastUpdatedFlagId: number
+ next?: string | null | undefined
+ previous?: string | null | undefined
+ results: any[]
+ },
+ payload?: {
+ id: number
+ archived: boolean
+ via?: FeatureFlagArchivedSource
+ }
+ ) => {
+ featureFlags: {
+ count: number
+ filters?: FeatureFlagsFilters | null | undefined
+ lastUpdatedFlagId: number
+ next?: string | null | undefined
+ previous?: string | null | undefined
+ results: any[]
+ }
+ payload?: {
+ id: number
+ archived: boolean
+ via?: FeatureFlagArchivedSource
+ }
+ }
updateFeatureFlagFailure: (
error: string,
errorObject?: any
@@ -342,10 +422,11 @@ export const featureFlagsLogic = kea<featureFlagsLogicType>([
deleteFlag: (id: number) => ({ id }),
setActiveTab: (tabKey: FeatureFlagsTab) => ({ tabKey }),
setFeatureFlagsFilters: (filters: Partial<FeatureFlagsFilters>, replace?: boolean) => ({ filters, replace }),
+ toggleFeatureFlagActive: (id: number, active: boolean) => ({ id, active }),
closeEnrichAnalyticsNotice: true,
setFeatureFlagUpdating: (id: number, updating: boolean) => ({ id, updating }),
}),
- loaders(({ values }) => ({
+ loaders(({ values, actions }) => ({
featureFlags: [
{ results: [], count: 0, filters: DEFAULT_FILTERS, offset: 0 } as FeatureFlagsResult,
{
@@ -366,11 +447,14 @@ export const featureFlagsLogic = kea<featureFlagsLogicType>([
`api/projects/${values.currentProjectId}/feature_flags/${id}`,
payload
)
- const updatedFlags = [...values.featureFlags.results].map((flag) =>
+ const updatedFlags = values.featureFlags.results.map((flag) =>
flag.id === response.id ? response : flag
)
return { ...values.featureFlags, results: updatedFlags, lastUpdatedFlagId: id }
} catch (e: any) {
+ // Clear this row only. The *Failure actions carry no id, so a reducer case
+ // there would have to wipe every row's spinner, including in-flight ones.
+ actions.setFeatureFlagUpdating(id, false)
const actionDescription =
payload.active === true
? 'enable this feature flag'
@@ -381,6 +465,40 @@ export const featureFlagsLogic = kea<featureFlagsLogicType>([
throw e
}
},
+ // Separate from updateFeatureFlag so archive telemetry fires from the loader after the write
+ // resolves, mirroring featureFlagLogic.ts's sibling action.
+ updateFeatureFlagArchived: async ({
+ id,
+ archived,
+ via,
+ }: {
+ id: number
+ archived: boolean
+ /** Telemetry source; only meaningful (and only captured) when archiving, not unarchiving. */
+ via?: FeatureFlagArchivedSource
+ }) => {
+ try {
+ const response = await api.update(
+ `api/projects/${values.currentProjectId}/feature_flags/${id}`,
+ archived ? { archived: true, active: false } : { archived: false }
+ )
+ const updatedFlags = values.featureFlags.results.map((flag) =>
+ flag.id === response.id ? response : flag
+ )
+ if (archived && via) {
+ reportFeatureFlagArchived(via)
+ }
+ return { ...values.featureFlags, results: updatedFlags, lastUpdatedFlagId: id }
+ } catch (e: any) {
+ actions.setFeatureFlagUpdating(id, false)
+ handleFlagApprovalRequired(
+ e,
+ id,
+ archived ? 'archive this feature flag' : 'unarchive this feature flag'
+ )
+ throw e
+ }
+ },
},
],
})),
@@ -408,9 +526,8 @@ export const featureFlagsLogic = kea<featureFlagsLogicType>([
loadFeatureFlagsSuccess: (_, { featureFlags }) => {
return featureFlags.results
},
- updateFeatureFlagSuccess: (_, { featureFlags }) => {
- return featureFlags.results
- },
+ updateFeatureFlagSuccess: (_, { featureFlags }) => featureFlags.results,
+ updateFeatureFlagArchivedSuccess: (_, { featureFlags }) => featureFlags.results,
updateFlag: (state, { flag }) => state.map((f) => (f.id === flag.id ? flag : f)),
updateFlagFromPartial: (state, { flag }) =>
state.map((f) => (f.id === flag.id ? { ...f, ...flag } : f)),
@@ -452,15 +569,10 @@ export const featureFlagsLogic = kea<featureFlagsLogicType>([
const { [id]: _, ...rest } = state
return rest
},
- updateFeatureFlag: (state, { id }) => ({ ...state, [id]: true }),
- updateFeatureFlagSuccess: (state, { featureFlags }) => {
- if (featureFlags.lastUpdatedFlagId) {
- const { [featureFlags.lastUpdatedFlagId]: _, ...rest } = state
- return rest
- }
- return state
- },
- updateFeatureFlagFailure: () => ({}),
+ updateFeatureFlag: markFlagUpdating,
+ updateFeatureFlagSuccess: clearFlagUpdating,
+ updateFeatureFlagArchived: markFlagUpdating,
+ updateFeatureFlagArchivedSuccess: clearFlagUpdating,
},
],
}),
@@ -536,6 +648,46 @@ export const featureFlagsLogic = kea<featureFlagsLogicType>([
updateFlagActive: ({ id, active }) => {
actions.updateFeatureFlag({ id, payload: { active } })
},
+ // Mirrors featureFlagLogic's listener of the same name, so both surfaces of the
+ // disable-and-archive experiment are driven from a logic rather than from the row component.
+ toggleFeatureFlagActive: ({ id, active }) => {
+ const applyUpdate = (payload: Partial<FeatureFlagType>): void => {
+ actions.updateFeatureFlag({ id, payload })
+ }
+ const openControlDialog = (onConfirm?: () => void, onCancel?: () => void): void => {
+ LemonDialog.open({
+ title: `${active ? 'Enable' : 'Disable'} this flag?`,
+ description: `This flag will be immediately ${
+ active ? 'rolled out to' : 'rolled back from'
+ } the users matching the release conditions.`,
+ primaryButton: {
+ children: 'Confirm',
+ type: 'primary',
+ onClick: onConfirm ?? (() => applyUpdate({ active })),
+ size: 'small',
+ },
+ secondaryButton: {
+ children: 'Cancel',
+ type: 'tertiary',
+ size: 'small',
+ onClick: onCancel,
+ },
+ })
+ }
+
+ if (active) {
+ openControlDialog()
+ return
+ }
+
+ openFeatureFlagDisableDialog({
+ source: 'feature-flags-list',
+ onDisable: () => applyUpdate({ active: false }),
+ onDisableAndArchive: () =>
+ actions.updateFeatureFlagArchived({ id, archived: true, via: 'disable-confirmation' }),
+ openControlDialog,
+ })
+ },
setFeatureFlagsFilters: async (_, breakpoint) => {
if (values.activeTab === FeatureFlagsTab.OVERVIEW) {
await breakpoint(300)