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(flags): open the edit dialog for a scheduled change (#88686)

Philleee0de228fb2
diff --git a/frontend/src/scenes/feature-flags/featureFlagScheduleEditLogic.test.ts b/frontend/src/scenes/feature-flags/featureFlagScheduleEditLogic.test.ts
new file mode 100644
index 000000000000..f72e60755741
--- /dev/null
+++ b/frontend/src/scenes/feature-flags/featureFlagScheduleEditLogic.test.ts
@@ -0,0 +1,54 @@
+import { MOCK_DEFAULT_TEAM } from 'lib/api.mock'
+
+import { initKeaTests } from '~/test/init'
+import { ScheduledChangeModels, ScheduledChangeOperationType, ScheduledChangeType, UserBasicType } from '~/types'
+
+import { featureFlagScheduleEditLogic } from './featureFlagScheduleEditLogic'
+
+describe('featureFlagScheduleEditLogic', () => {
+ let logic: ReturnType<typeof featureFlagScheduleEditLogic.build>
+
+ const scheduledChange: ScheduledChangeType = {
+ id: 7,
+ team_id: MOCK_DEFAULT_TEAM.id,
+ record_id: 1,
+ model_name: ScheduledChangeModels.FeatureFlag,
+ payload: { operation: ScheduledChangeOperationType.UpdateStatus, value: false },
+ scheduled_at: '2026-06-15T14:30:00.000Z',
+ end_date: '2026-06-30T23:59:59.999Z',
+ executed_at: null,
+ failure_reason: null,
+ created_at: '2026-06-01T09:00:00.000Z',
+ created_by: { id: 1, uuid: 'user-uuid', distinct_id: 'user-distinct-id' } as UserBasicType,
+ is_recurring: true,
+ recurrence_interval: null,
+ cron_expression: '30 14 * * *',
+ last_executed_at: null,
+ }
+
+ afterEach(() => {
+ logic?.unmount()
+ })
+
+ // Guards the dispatch itself. The reducers that fill these dates must not read the store,
+ // because Redux rejects a read while it dispatches and the dialog then never opens.
+ test.each([
+ ['UTC', '2026-06-15 14:30:00.000', '2026-06-30 23:59:59.999'],
+ ['Asia/Tokyo', '2026-06-15 23:30:00.000', '2026-07-01 08:59:59.999'],
+ ])(
+ 'openEdit fills the dialog with dates in the %s project timezone',
+ (timezone, expectedScheduledAt, expectedEndDate) => {
+ initKeaTests(true, { ...MOCK_DEFAULT_TEAM, timezone })
+ logic = featureFlagScheduleEditLogic({ id: 1 })
+ logic.mount()
+
+ logic.actions.openEdit(scheduledChange)
+
+ expect(logic.values.isEditOpen).toBe(true)
+ expect(logic.values.editScheduledAt?.format('YYYY-MM-DD HH:mm:ss.SSS')).toBe(expectedScheduledAt)
+ expect(logic.values.editEndDate?.format('YYYY-MM-DD HH:mm:ss.SSS')).toBe(expectedEndDate)
+ expect(logic.values.editCronExpression).toBe('30 14 * * *')
+ expect(logic.values.editPayloadValue).toBe(false)
+ }
+ )
+})
diff --git a/frontend/src/scenes/feature-flags/featureFlagScheduleEditLogic.ts b/frontend/src/scenes/feature-flags/featureFlagScheduleEditLogic.ts
index bc9bd4ba2542..62554a46fe97 100644
--- a/frontend/src/scenes/feature-flags/featureFlagScheduleEditLogic.ts
+++ b/frontend/src/scenes/feature-flags/featureFlagScheduleEditLogic.ts
@@ -12,12 +12,6 @@ import type { TeamPublicType, TeamType } from '../../types'
import { teamLogic } from '../teamLogic'
import { featureFlagLogic, scheduleDateFromStoredISO, scheduleDateToProjectTzISO } from './featureFlagLogic'
-// Used from reducers, which don't receive `values` — we still need a synchronous read at
-// action-dispatch time. Selectors and listeners use the reactive `projectTimezone` selector instead.
-function projectTimezoneImperative(): string {
- return teamLogic.findMounted()?.values.currentTeam?.timezone || 'UTC'
-}
-
export interface FeatureFlagScheduleEditLogicProps {
id: number | 'new' | 'link'
}
@@ -49,6 +43,7 @@ export interface featureFlagScheduleEditLogicActions {
}
openEdit: (schedule: ScheduledChangeType) => {
schedule: ScheduledChangeType
+ timezone: string
}
saveEdit: () => {
value: true
@@ -129,8 +124,11 @@ export const featureFlagScheduleEditLogic = kea<featureFlagScheduleEditLogicType
connect(() => ({
values: [teamLogic, ['currentTeam']],
})),
- actions({
- openEdit: (schedule: ScheduledChangeType) => ({ schedule }),
+ actions(({ values }) => ({
+ // The reducers below convert the stored dates into the project timezone, but a reducer may
+ // not read the store while Redux is dispatching. Resolve the timezone into the payload here,
+ // which runs before the dispatch starts.
+ openEdit: (schedule: ScheduledChangeType) => ({ schedule, timezone: values.projectTimezone }),
closeEdit: true,
setEditScheduledAt: (date: Dayjs | null) => ({ date }),
setEditCronExpression: (cron: string | null) => ({ cron }),
@@ -142,7 +140,7 @@ export const featureFlagScheduleEditLogic = kea<featureFlagScheduleEditLogicType
saveEdit: true,
saveEditSuccess: true,
saveEditFailure: true,
- }),
+ })),
reducers({
editingSchedule: [
null as ScheduledChangeType | null,
@@ -155,10 +153,8 @@ export const featureFlagScheduleEditLogic = kea<featureFlagScheduleEditLogicType
editScheduledAt: [
null as Dayjs | null,
{
- openEdit: (_, { schedule }) =>
- schedule.scheduled_at
- ? scheduleDateFromStoredISO(schedule.scheduled_at, projectTimezoneImperative())
- : null,
+ openEdit: (_, { schedule, timezone }) =>
+ schedule.scheduled_at ? scheduleDateFromStoredISO(schedule.scheduled_at, timezone) : null,
setEditScheduledAt: (_, { date }) => date,
closeEdit: () => null,
},
@@ -182,10 +178,8 @@ export const featureFlagScheduleEditLogic = kea<featureFlagScheduleEditLogicType
editEndDate: [
null as Dayjs | null,
{
- openEdit: (_, { schedule }) =>
- schedule.end_date
- ? scheduleDateFromStoredISO(schedule.end_date, projectTimezoneImperative())
- : null,
+ openEdit: (_, { schedule, timezone }) =>
+ schedule.end_date ? scheduleDateFromStoredISO(schedule.end_date, timezone) : null,
setEditEndDate: (_, { date }) => date,
closeEdit: () => null,
},