Skip to content

Commit

Permalink
fix(flags): prevent error when editing flag which lacks payloads (#27994
Browse files Browse the repository at this point in the history
)
  • Loading branch information
havenbarnes authored Jan 29, 2025
1 parent 849d3d4 commit 581b80c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions frontend/src/scenes/feature-flags/activityDescriptions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ const featureFlagActionsMapping: Record<
} else {
filtersAfter.payloads &&
Object.keys(filtersAfter.payloads).forEach((key: string) => {
const changedPayload = filtersAfter.payloads[key]?.toString() || null
const changedPayload = filtersAfter.payloads?.[key]?.toString() || null
changes.push(<SentenceList listParts={[changedPayload]} prefix="changed payload to" />)
})

Expand Down Expand Up @@ -145,7 +145,7 @@ const featureFlagActionsMapping: Record<
if (isMultivariateFlag) {
filtersAfter.payloads &&
Object.keys(filtersAfter.payloads).forEach((key: string) => {
const changedPayload = filtersAfter.payloads[key]?.toString() || null
const changedPayload = filtersAfter.payloads?.[key]?.toString() || null
changes.push(
<SentenceList
listParts={[
Expand Down
8 changes: 4 additions & 4 deletions frontend/src/scenes/feature-flags/featureFlagLogic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ export function validateFeatureFlagKey(key: string): string | undefined {
: undefined
}

function validatePayloadRequired(payload: JsonType, is_remote_configuration: boolean): string | undefined {
function validatePayloadRequired(is_remote_configuration: boolean, payload?: JsonType): string | undefined {
if (!is_remote_configuration) {
return undefined
}
Expand Down Expand Up @@ -322,9 +322,9 @@ export const featureFlagLogic = kea<featureFlagLogicType>([
ValidationErrorType
>[],
payloads: {
true: validatePayloadRequired(filters?.payloads['true'], is_remote_configuration),
} as unknown as DeepPartialMap<Record<string, JsonType>, ValidationErrorType> | undefined,
// Forced cast necessary to prevent Kea's typechecking from raising "Type instantiation
true: validatePayloadRequired(is_remote_configuration, filters?.payloads?.['true']),
} as any,
// Forced any cast necessary to prevent Kea's typechecking from raising "Type instantiation
// is excessively deep and possibly infinite" error
},
}
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2956,9 +2956,9 @@ export interface MultivariateFlagOptions {

export interface FeatureFlagFilters {
groups: FeatureFlagGroupType[]
multivariate: MultivariateFlagOptions | null
multivariate?: MultivariateFlagOptions | null
aggregation_group_type_index?: integer | null
payloads: Record<string, JsonType>
payloads?: Record<string, JsonType>
super_groups?: FeatureFlagGroupType[]
}

Expand Down

0 comments on commit 581b80c

Please sign in to comment.