-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(toolbar): support feature flag payload overrides in the flag toolbar #28058
Open
dmarticus
wants to merge
24
commits into
master
Choose a base branch
from
feat/support-payload-overrides-in-flag-toolbar
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
a006864
added support for setting payload overrides
dmarticus 9bbe892
use latest version from posthog-js
dmarticus cf1cd93
merge master
dmarticus 8f81c61
Update UI snapshots for `chromium` (2)
github-actions[bot] 05850ce
greptile feedback
dmarticus b32cb58
Merge branch 'feat/support-payload-overrides-in-flag-toolbar' of gith…
dmarticus 93c2630
Update UI snapshots for `chromium` (1)
github-actions[bot] 5453459
Update UI snapshots for `chromium` (1)
github-actions[bot] 7abe2aa
use latest posthog-js
dmarticus d081f45
Merge branch 'feat/support-payload-overrides-in-flag-toolbar' of gith…
dmarticus 4629b76
heckin conflicts
dmarticus 5cc6e60
fix docs
dmarticus 6b308cc
Merge branch 'master' into feat/support-payload-overrides-in-flag-too…
dmarticus d72bd7d
Update UI snapshots for `chromium` (1)
github-actions[bot] c2bd8ab
Update UI snapshots for `chromium` (1)
github-actions[bot] c28c89e
Update UI snapshots for `chromium` (1)
github-actions[bot] 0b9f2d7
fix tsc
dmarticus b099ee0
Merge branch 'feat/support-payload-overrides-in-flag-toolbar' of gith…
dmarticus 6f906c7
Merge branch 'master' into feat/support-payload-overrides-in-flag-too…
dmarticus a14f8a1
Update UI snapshots for `chromium` (2)
github-actions[bot] 843e840
Update UI snapshots for `chromium` (2)
github-actions[bot] d73e80c
override these
dmarticus e3a20b5
Update UI snapshots for `chromium` (2)
github-actions[bot] f35e1c9
Update UI snapshots for `chromium` (1)
github-actions[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Binary file modified
BIN
-29 Bytes
(100%)
frontend/__snapshots__/replay-player-success--second-recording-in-list--dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-68 Bytes
(100%)
...nd/__snapshots__/scenes-app-pipeline--pipeline-node-new-hog-function--light.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+5.78 KB
(120%)
frontend/__snapshots__/scenes-other-toolbar--feature-flags--dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+5.6 KB
(110%)
frontend/__snapshots__/scenes-other-toolbar--feature-flags--light.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+5.46 KB
(110%)
frontend/__snapshots__/scenes-other-toolbar--feature-flags-dark--dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+5.87 KB
(120%)
frontend/__snapshots__/scenes-other-toolbar--feature-flags-dark--light.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+818 Bytes
(110%)
frontend/__snapshots__/scenes-other-toolbar--inspect-dark--light.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,8 @@ import { CombinedFeatureFlagAndValueType } from '~/types' | |
|
||
import type { flagsToolbarLogicType } from './flagsToolbarLogicType' | ||
|
||
export type PayloadOverrides = Record<string, any> | ||
|
||
export const flagsToolbarLogic = kea<flagsToolbarLogicType>([ | ||
path(['toolbar', 'flags', 'flagsToolbarLogic']), | ||
connect(() => ({ | ||
|
@@ -22,11 +24,23 @@ export const flagsToolbarLogic = kea<flagsToolbarLogicType>([ | |
flags, | ||
variants, | ||
}), | ||
setOverriddenUserFlag: (flagKey: string, overrideValue: string | boolean) => ({ flagKey, overrideValue }), | ||
setOverriddenUserFlag: ( | ||
flagKey: string, | ||
overrideValue: string | boolean, | ||
payloadOverride?: PayloadOverrides | ||
) => ({ | ||
flagKey, | ||
overrideValue, | ||
payloadOverride, | ||
}), | ||
setPayloadOverride: (flagKey: string, payload: any) => ({ flagKey, payload }), | ||
deleteOverriddenUserFlag: (flagKey: string) => ({ flagKey }), | ||
setSearchTerm: (searchTerm: string) => ({ searchTerm }), | ||
checkLocalOverrides: true, | ||
storeLocalOverrides: (localOverrides: Record<string, string | boolean>) => ({ localOverrides }), | ||
setDraftPayload: (flagKey: string, draftPayload: string) => ({ flagKey, draftPayload }), | ||
savePayloadOverride: (flagKey: string) => ({ flagKey }), | ||
setPayloadError: (flagKey: string, error: string | null) => ({ flagKey, error }), | ||
}), | ||
loaders(({ values }) => ({ | ||
userFlags: [ | ||
|
@@ -70,11 +84,52 @@ export const flagsToolbarLogic = kea<flagsToolbarLogicType>([ | |
}, | ||
}, | ||
], | ||
payloadOverrides: [ | ||
{} as PayloadOverrides, | ||
{ | ||
setPayloadOverride: (state, { flagKey, payload }) => ({ | ||
...state, | ||
[flagKey]: payload, | ||
}), | ||
deleteOverriddenUserFlag: (state, { flagKey }) => { | ||
const newState = { ...state } | ||
delete newState[flagKey] | ||
return newState | ||
}, | ||
}, | ||
], | ||
draftPayloads: [ | ||
{} as Record<string, string>, | ||
{ | ||
setDraftPayload: (state, { flagKey, draftPayload }) => ({ | ||
...state, | ||
[flagKey]: draftPayload, | ||
}), | ||
deleteOverriddenUserFlag: (state, { flagKey }) => { | ||
const newState = { ...state } | ||
delete newState[flagKey] | ||
return newState | ||
}, | ||
}, | ||
], | ||
payloadErrors: [ | ||
{} as Record<string, string | null>, | ||
{ | ||
setPayloadError: (state, { flagKey, error }) => ({ | ||
...state, | ||
[flagKey]: error, | ||
}), | ||
setDraftPayload: (state, { flagKey }) => ({ | ||
...state, | ||
[flagKey]: null, | ||
}), | ||
}, | ||
], | ||
}), | ||
selectors({ | ||
userFlagsWithOverrideInfo: [ | ||
(s) => [s.userFlags, s.localOverrides, s.posthogClientFlagValues], | ||
(userFlags, localOverrides, posthogClientFlagValues) => { | ||
(s) => [s.userFlags, s.localOverrides, s.posthogClientFlagValues, s.payloadOverrides], | ||
(userFlags, localOverrides, posthogClientFlagValues, payloadOverrides) => { | ||
return userFlags.map((flag) => { | ||
const hasVariants = (flag.feature_flag.filters?.multivariate?.variants?.length || 0) > 0 | ||
|
||
|
@@ -88,6 +143,7 @@ export const flagsToolbarLogic = kea<flagsToolbarLogicType>([ | |
hasVariants, | ||
currentValue, | ||
hasOverride: flag.feature_flag.key in localOverrides, | ||
payloadOverride: payloadOverrides[flag.feature_flag.key], | ||
} | ||
}) | ||
}, | ||
|
@@ -115,12 +171,19 @@ export const flagsToolbarLogic = kea<flagsToolbarLogicType>([ | |
actions.storeLocalOverrides(locallyOverrideFeatureFlags) | ||
} | ||
}, | ||
setOverriddenUserFlag: ({ flagKey, overrideValue }) => { | ||
setOverriddenUserFlag: ({ flagKey, overrideValue, payloadOverride }) => { | ||
const clientPostHog = values.posthog | ||
if (clientPostHog) { | ||
clientPostHog.featureFlags.override({ ...values.localOverrides, [flagKey]: overrideValue }) | ||
const payloads = payloadOverride ? { [flagKey]: payloadOverride } : undefined | ||
clientPostHog.featureFlags.overrideFeatureFlags({ | ||
flags: { ...values.localOverrides, [flagKey]: overrideValue }, | ||
payloads: payloads, | ||
}) | ||
toolbarPosthogJS.capture('toolbar feature flag overridden') | ||
actions.checkLocalOverrides() | ||
if (payloadOverride) { | ||
actions.setPayloadOverride(flagKey, payloadOverride) | ||
} | ||
clientPostHog.featureFlags.reloadFeatureFlags() | ||
} | ||
}, | ||
|
@@ -130,15 +193,26 @@ export const flagsToolbarLogic = kea<flagsToolbarLogicType>([ | |
const updatedFlags = { ...values.localOverrides } | ||
delete updatedFlags[flagKey] | ||
if (Object.keys(updatedFlags).length > 0) { | ||
clientPostHog.featureFlags.override({ ...updatedFlags }) | ||
clientPostHog.featureFlags.overrideFeatureFlags({ flags: updatedFlags }) | ||
} else { | ||
clientPostHog.featureFlags.override(false) | ||
clientPostHog.featureFlags.overrideFeatureFlags(false) | ||
} | ||
toolbarPosthogJS.capture('toolbar feature flag override removed') | ||
actions.checkLocalOverrides() | ||
clientPostHog.featureFlags.reloadFeatureFlags() | ||
} | ||
}, | ||
savePayloadOverride: ({ flagKey }) => { | ||
try { | ||
const draftPayload = values.draftPayloads[flagKey] | ||
const payload = draftPayload ? JSON.parse(draftPayload) : null | ||
actions.setPayloadError(flagKey, null) | ||
actions.setOverriddenUserFlag(flagKey, true, payload) | ||
} catch (e) { | ||
actions.setPayloadError(flagKey, 'Invalid JSON') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice! |
||
console.error('Invalid JSON:', e) | ||
} | ||
}, | ||
})), | ||
permanentlyMount(), | ||
]) | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: redundant key/val pair