Skip to content
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(flags-hackathon): Encrypted payloads on remote config feature flags #27414

Merged
merged 157 commits into from
Feb 13, 2025
Merged
Show file tree
Hide file tree
Changes from 115 commits
Commits
Show all changes
157 commits
Select commit Hold shift + click to select a range
219f204
feat(flags-hackathon): Enabled simple remote config feature flags
havenbarnes Jan 8, 2025
a49d623
tweak
havenbarnes Jan 8, 2025
087b8e9
Update query snapshots
github-actions[bot] Jan 8, 2025
6c22d66
Update query snapshots
github-actions[bot] Jan 8, 2025
feccf0c
Merge branch 'master' of https://github.com/PostHog/posthog into encr…
havenbarnes Jan 8, 2025
56a8dfd
stash to figure out payload update bug
havenbarnes Jan 9, 2025
5cab6a4
Merge branch 'master' of https://github.com/PostHog/posthog into conf…
havenbarnes Jan 9, 2025
067e448
Merge branch 'config-flags' of https://github.com/PostHog/posthog int…
havenbarnes Jan 9, 2025
8862c46
Merge branch 'master' of https://github.com/PostHog/posthog into encr…
havenbarnes Jan 9, 2025
9aa9a3c
tweak
havenbarnes Jan 9, 2025
1e33521
Merge branch 'config-flags' of https://github.com/PostHog/posthog int…
havenbarnes Jan 9, 2025
5ce49df
Merge branch 'config-flags' of https://github.com/PostHog/posthog int…
havenbarnes Jan 9, 2025
142442b
Update UI snapshots for `chromium` (1)
github-actions[bot] Jan 9, 2025
f26d555
Update UI snapshots for `chromium` (1)
github-actions[bot] Jan 9, 2025
04e28bd
working e2e + demo-able
havenbarnes Jan 10, 2025
c1f670e
Merge branch 'encrypted-config-flags' of https://github.com/PostHog/p…
havenbarnes Jan 10, 2025
2ff3c82
Update query snapshots
github-actions[bot] Jan 10, 2025
1663960
Update query snapshots
github-actions[bot] Jan 10, 2025
81a9658
Update UI snapshots for `chromium` (1)
github-actions[bot] Jan 10, 2025
313a24d
Update UI snapshots for `chromium` (1)
github-actions[bot] Jan 10, 2025
4ebfe0f
Merge branch 'master' of https://github.com/PostHog/posthog into conf…
havenbarnes Jan 15, 2025
1d2b01d
rebase
havenbarnes Jan 15, 2025
867ee59
Merge branch 'config-flags' of https://github.com/PostHog/posthog int…
havenbarnes Jan 15, 2025
9fdf4a2
rebase and cleanup for review
havenbarnes Jan 15, 2025
d2dac16
Update UI snapshots for `chromium` (2)
github-actions[bot] Jan 15, 2025
9073b96
Update query snapshots
github-actions[bot] Jan 15, 2025
11c8499
Update UI snapshots for `chromium` (2)
github-actions[bot] Jan 15, 2025
fb8d3ff
Update UI snapshots for `chromium` (2)
github-actions[bot] Jan 15, 2025
547d498
Merge branch 'master' into config-flags
havenbarnes Jan 15, 2025
16cc9f6
fix typecheck, add cypress test
havenbarnes Jan 15, 2025
19301c3
Merge branch 'config-flags' of https://github.com/PostHog/posthog int…
havenbarnes Jan 15, 2025
c7fd448
Merge branch 'master' of https://github.com/PostHog/posthog into conf…
havenbarnes Jan 16, 2025
5cb4889
rebase
havenbarnes Jan 16, 2025
30217a1
Merge branch 'master' of https://github.com/PostHog/posthog into conf…
havenbarnes Jan 16, 2025
ceb7746
rebase
havenbarnes Jan 16, 2025
9c0713e
Merge branch 'master' into config-flags
havenbarnes Jan 16, 2025
47af6ea
addressed PR comment on config vs remote_config
havenbarnes Jan 21, 2025
e44a698
Merge branch 'config-flags' of https://github.com/PostHog/posthog int…
havenbarnes Jan 21, 2025
5531889
address the rest of comments
havenbarnes Jan 21, 2025
1fccb54
Merge branch 'master' of https://github.com/PostHog/posthog into conf…
havenbarnes Jan 21, 2025
15fc1a6
Update migration script
havenbarnes Jan 21, 2025
4fafd21
Merge branch 'master' into config-flags
havenbarnes Jan 21, 2025
df5d266
Merge branch 'master' into config-flags
havenbarnes Jan 21, 2025
201d702
Merge branch 'master' of https://github.com/PostHog/posthog into conf…
havenbarnes Jan 21, 2025
eb11f02
fix migration script, allow blank field
havenbarnes Jan 21, 2025
66732c6
Merge branch 'config-flags' of https://github.com/PostHog/posthog int…
havenbarnes Jan 21, 2025
d12a156
Merge branch 'master' of https://github.com/PostHog/posthog into conf…
havenbarnes Jan 21, 2025
9e03efc
remove some unwanted diffs
havenbarnes Jan 22, 2025
321d628
Update frontend/src/scenes/feature-flags/FeatureFlag.tsx
havenbarnes Jan 22, 2025
955be7b
Merge branch 'master' of https://github.com/PostHog/posthog into conf…
havenbarnes Jan 22, 2025
d96fae3
Add remote config flag story for visual regression test
havenbarnes Jan 22, 2025
ace41b7
Merge branch 'config-flags' of https://github.com/PostHog/posthog int…
havenbarnes Jan 22, 2025
fc09ca0
Update UI snapshots for `chromium` (1)
github-actions[bot] Jan 22, 2025
a6b67e0
Update UI snapshots for `chromium` (2)
github-actions[bot] Jan 22, 2025
0d6c4ee
Merge branch 'master' of https://github.com/PostHog/posthog into conf…
havenbarnes Jan 22, 2025
ac438e9
Merge branch 'config-flags' of https://github.com/PostHog/posthog int…
havenbarnes Jan 22, 2025
cee0f6b
Update migration script
havenbarnes Jan 22, 2025
07921ed
Fix bad rebase
havenbarnes Jan 22, 2025
ce3467a
Update UI snapshots for `chromium` (1)
github-actions[bot] Jan 22, 2025
4411a37
Update UI snapshots for `chromium` (2)
github-actions[bot] Jan 22, 2025
9034885
Merge branch 'master' into config-flags
havenbarnes Jan 22, 2025
a9617f4
Update UI snapshots for `chromium` (1)
github-actions[bot] Jan 22, 2025
7ac918a
Merge branch 'master' into config-flags
dmarticus Jan 23, 2025
f7339fb
Merge branch 'master' into config-flags
havenbarnes Jan 23, 2025
38f030b
Update UI snapshots for `chromium` (1)
github-actions[bot] Jan 23, 2025
f4d1412
Update UI snapshots for `chromium` (1)
github-actions[bot] Jan 23, 2025
e4ad6d4
Update UI snapshots for `chromium` (1)
github-actions[bot] Jan 23, 2025
5a3a345
Merge branch 'master' of https://github.com/PostHog/posthog into conf…
havenbarnes Jan 23, 2025
199366f
Merge branch 'config-flags' of https://github.com/PostHog/posthog int…
havenbarnes Jan 23, 2025
b5832df
Merge branch 'config-flags' of https://github.com/PostHog/posthog int…
havenbarnes Jan 23, 2025
2a6b0e8
Merge branch 'encrypted-config-flags' of https://github.com/PostHog/p…
havenbarnes Jan 23, 2025
95399f0
Update UI snapshots for `chromium` (1)
github-actions[bot] Jan 23, 2025
8f70101
Update UI snapshots for `chromium` (1)
github-actions[bot] Jan 23, 2025
523c9a3
Merge branch 'master' of https://github.com/PostHog/posthog into encr…
havenbarnes Jan 24, 2025
f7b13b1
stash
havenbarnes Jan 24, 2025
98d3b92
Merge branch 'master' of https://github.com/PostHog/posthog into encr…
havenbarnes Jan 24, 2025
6a42f99
Merge branch 'master' of https://github.com/PostHog/posthog into encr…
havenbarnes Jan 27, 2025
b6238c4
Merge branch 'encrypted-config-flags' of https://github.com/PostHog/p…
havenbarnes Jan 27, 2025
b645320
update migration script and model
havenbarnes Jan 27, 2025
6c162dc
Update UI snapshots for `chromium` (2)
github-actions[bot] Jan 27, 2025
d4fc96e
Fix code snippets for encrypted payloads, fix bug with list api not u…
havenbarnes Jan 28, 2025
e2ef5e2
fix typecheck failures
havenbarnes Jan 28, 2025
e4da621
Merge branch 'encrypted-config-flags' of https://github.com/PostHog/p…
havenbarnes Jan 28, 2025
457881e
add visual regression test
havenbarnes Jan 28, 2025
22630b8
Update query snapshots
github-actions[bot] Jan 28, 2025
4c6199a
Update UI snapshots for `chromium` (1)
github-actions[bot] Jan 28, 2025
6660a3f
Update UI snapshots for `chromium` (2)
github-actions[bot] Jan 28, 2025
c9a8f97
Merge branch 'master' of https://github.com/PostHog/posthog into encr…
havenbarnes Jan 28, 2025
4d05191
tweak
havenbarnes Jan 28, 2025
932c2a2
Merge branch 'encrypted-config-flags' of https://github.com/PostHog/p…
havenbarnes Jan 28, 2025
5615fc7
Update UI snapshots for `chromium` (1)
github-actions[bot] Jan 28, 2025
99b4d61
tweak
havenbarnes Jan 29, 2025
2623669
Merge branch 'encrypted-config-flags' of https://github.com/PostHog/p…
havenbarnes Jan 29, 2025
68336bc
Merge branch 'master' of https://github.com/PostHog/posthog into encr…
havenbarnes Jan 29, 2025
3a7c5fd
tweak
havenbarnes Jan 29, 2025
8f4ffd2
/remote_config endpoint working e2e, added API example snippet
havenbarnes Jan 29, 2025
ade12fd
Merge branch 'master' of https://github.com/PostHog/posthog into encr…
havenbarnes Jan 29, 2025
059c1f7
tweak
havenbarnes Jan 29, 2025
c06aad0
tweak
havenbarnes Jan 29, 2025
8b130f0
Hide other options until SDKs are supported
havenbarnes Jan 29, 2025
ab47f45
Update UI snapshots for `chromium` (1)
github-actions[bot] Jan 29, 2025
905a712
tweak
havenbarnes Jan 29, 2025
4450f4c
cleanup code snippet when making a new feature flag
havenbarnes Jan 29, 2025
6be8087
tweak
havenbarnes Jan 29, 2025
ec83ce8
Merge branch 'encrypted-config-flags' of https://github.com/PostHog/p…
havenbarnes Jan 29, 2025
4321e4b
track /remote_config request for billing
havenbarnes Jan 30, 2025
466c83e
Merge branch 'master' of https://github.com/PostHog/posthog into encr…
havenbarnes Jan 30, 2025
f706b42
fix backend tests
havenbarnes Jan 30, 2025
2c5466a
tweak
havenbarnes Jan 30, 2025
ed627fd
Merge branch 'master' of https://github.com/PostHog/posthog into encr…
havenbarnes Jan 30, 2025
dea9c87
Update query snapshots
github-actions[bot] Jan 30, 2025
ec5f190
Merge branch 'master' of https://github.com/PostHog/posthog into encr…
havenbarnes Jan 31, 2025
2fa803e
update migration script
havenbarnes Jan 31, 2025
f9d31d9
trigger update of viz regression tests
havenbarnes Jan 31, 2025
1e30af6
Update UI snapshots for `chromium` (2)
github-actions[bot] Jan 31, 2025
aa844e4
Merge branch 'master' of https://github.com/PostHog/posthog into encr…
havenbarnes Feb 10, 2025
700605b
update migration script
havenbarnes Feb 10, 2025
f7459af
Update frontend/src/scenes/feature-flags/FeatureFlagInstructions.tsx
havenbarnes Feb 11, 2025
a665b64
Update posthog/api/feature_flag.py
havenbarnes Feb 11, 2025
f0c1d42
Update posthog/helpers/encrypted_flag_payloads.py
havenbarnes Feb 11, 2025
6f83e7e
Clean up + address comments
havenbarnes Feb 11, 2025
7b19d74
Merge branch 'master' of https://github.com/PostHog/posthog into encr…
havenbarnes Feb 11, 2025
405e17c
Merge branch 'master' of https://github.com/PostHog/posthog into encr…
havenbarnes Feb 11, 2025
b332c8f
Merge branch 'encrypted-config-flags' of https://github.com/PostHog/p…
havenbarnes Feb 11, 2025
3271dbc
Update UI snapshots for `chromium` (1)
github-actions[bot] Feb 11, 2025
86cefaf
Update UI snapshots for `chromium` (2)
github-actions[bot] Feb 11, 2025
79942a7
tweak
havenbarnes Feb 11, 2025
4e5c987
Merge branch 'encrypted-config-flags' of https://github.com/PostHog/p…
havenbarnes Feb 11, 2025
a0e8116
Merge branch 'master' of https://github.com/PostHog/posthog into encr…
havenbarnes Feb 11, 2025
f42003c
Merge branch 'master' into encrypted-config-flags
dmarticus Feb 11, 2025
26316ca
rebase
havenbarnes Feb 12, 2025
b8ff971
Merge branch 'master' of https://github.com/PostHog/posthog into encr…
havenbarnes Feb 12, 2025
99dd4e7
rebase
havenbarnes Feb 12, 2025
4a07873
Update UI snapshots for `chromium` (2)
github-actions[bot] Feb 12, 2025
794fb19
Merge branch 'master' of https://github.com/PostHog/posthog into encr…
havenbarnes Feb 12, 2025
e4c6060
Allow flag id or flag key to be passed to endpoint
havenbarnes Feb 12, 2025
3762815
Merge branch 'encrypted-config-flags' of https://github.com/PostHog/p…
havenbarnes Feb 12, 2025
e9f1706
Merge branch 'master' of https://github.com/PostHog/posthog into encr…
havenbarnes Feb 12, 2025
2ac8d56
tweak
havenbarnes Feb 12, 2025
3c9cc87
cleanup code examples
havenbarnes Feb 12, 2025
0b191e9
Update UI snapshots for `chromium` (2)
github-actions[bot] Feb 12, 2025
bc0ece0
tweak
havenbarnes Feb 12, 2025
78124fe
Update frontend/src/scenes/feature-flags/FeatureFlag.tsx
havenbarnes Feb 12, 2025
f6b9f3b
Merge branch 'encrypted-config-flags' of https://github.com/PostHog/p…
havenbarnes Feb 12, 2025
bef61aa
Merge branch 'master' of https://github.com/PostHog/posthog into encr…
havenbarnes Feb 12, 2025
03b5fa0
Update UI snapshots for `chromium` (1)
github-actions[bot] Feb 12, 2025
4f92670
Update UI snapshots for `chromium` (1)
github-actions[bot] Feb 12, 2025
c8a8243
Merge branch 'master' of https://github.com/PostHog/posthog into encr…
havenbarnes Feb 13, 2025
b1cfe5d
update migration script
havenbarnes Feb 13, 2025
3a7eeca
Merge branch 'master' into encrypted-config-flags
havenbarnes Feb 13, 2025
393d5bf
tweak
havenbarnes Feb 13, 2025
bea9665
Merge branch 'encrypted-config-flags' of https://github.com/PostHog/p…
havenbarnes Feb 13, 2025
c8b41c4
Merge branch 'master' of https://github.com/PostHog/posthog into encr…
havenbarnes Feb 13, 2025
230fd1b
update migration script
havenbarnes Feb 13, 2025
bbec6e9
Merge branch 'master' into encrypted-config-flags
havenbarnes Feb 13, 2025
3874b4b
Update query snapshots
github-actions[bot] Feb 13, 2025
7f25158
Update query snapshots
github-actions[bot] Feb 13, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
86 changes: 72 additions & 14 deletions frontend/src/scenes/feature-flags/FeatureFlag.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -745,6 +745,8 @@ function FeatureFlagRollout({ readOnly }: { readOnly?: boolean }): JSX.Element {
recordingFilterForFlag,
flagStatus,
flagType,
flagTypeString,
hasEncryptedPayloadBeenSaved,
} = useValues(featureFlagLogic)
const {
distributeVariantsEqually,
Expand All @@ -754,6 +756,7 @@ function FeatureFlagRollout({ readOnly }: { readOnly?: boolean }): JSX.Element {
setFeatureFlag,
saveFeatureFlag,
setRemoteConfigEnabled,
resetEncryptedPayload,
} = useActions(featureFlagLogic)

const filterGroups: FeatureFlagGroupType[] = featureFlag.filters.groups || []
Expand All @@ -776,6 +779,24 @@ function FeatureFlagRollout({ readOnly }: { readOnly?: boolean }): JSX.Element {
})
}

const confirmEncryptedPayloadReset = (): void => {
LemonDialog.open({
title: 'Reset payload?',
description: 'The existing payload will not be deleted until the feature flag is saved.',
havenbarnes marked this conversation as resolved.
Show resolved Hide resolved
primaryButton: {
children: 'Confirm',
onClick: resetEncryptedPayload,
size: 'small',
status: 'danger',
},
secondaryButton: {
children: 'Cancel',
type: 'tertiary',
size: 'small',
},
})
}
havenbarnes marked this conversation as resolved.
Show resolved Hide resolved

const reportViewRecordingsClicked = (variantKey?: string): void => {
const properties: Record<string, string> = {
multivariate: multivariateEnabled.toString(),
Expand Down Expand Up @@ -858,11 +879,7 @@ function FeatureFlagRollout({ readOnly }: { readOnly?: boolean }): JSX.Element {
)}
</div>
<div className="col-span-6">
<span className="mt-1">
{featureFlag.filters.multivariate
? 'Multiple variants with rollout percentages (A/B/n test)'
: 'Release toggle (boolean)'}
</span>
<span className="mt-1">{flagTypeString}</span>
</div>
</div>

Expand Down Expand Up @@ -1040,19 +1057,60 @@ function FeatureFlagRollout({ readOnly }: { readOnly?: boolean }): JSX.Element {
</>
)}
</div>
<Group name={['filters', 'payloads']}>
<LemonField name="true">
<JSONEditorInput
readOnly={readOnly}
placeholder={'Examples: "A string", 2500, {"key": "value"}'}
/>
{featureFlag.is_remote_configuration && (
<LemonField name="has_encrypted_payloads">
{({ value, onChange }) => (
<div className="border rounded mb-4 p-4">
<LemonCheckbox
id="flag-payload-encrypted-checkbox"
label="Encrypt remote configuration payload"
onChange={() => onChange(!value)}
checked={value}
dataAttr="feature-flag-payload-encrypted-checkbox"
disabledReason={
hasEncryptedPayloadBeenSaved &&
'An encrypted payload has already been saved for this flag. Reset the payload or create a new flag to create an unencrypted configuration payload.'
}
havenbarnes marked this conversation as resolved.
Show resolved Hide resolved
/>
</div>
)}
</LemonField>
</Group>
)}
<div className="flex gap-2">
<Group name={['filters', 'payloads']}>
<LemonField name="true" className="grow">
<JSONEditorInput
readOnly={
readOnly ||
(featureFlag.has_encrypted_payloads &&
Boolean(featureFlag.filters?.payloads?.['true']))
}
placeholder={'Examples: "A string", 2500, {"key": "value"}'}
/>
</LemonField>
</Group>
{featureFlag.has_encrypted_payloads && (
<LemonButton
className="grow-0"
icon={<IconTrash />}
type="secondary"
size="small"
status="danger"
onClick={confirmEncryptedPayloadReset}
>
Reset
</LemonButton>
)}
</div>
{featureFlag.is_remote_configuration && (
<div className="text-sm text-muted mt-4">
Note: remote config flags must be accessed through payloads, e.g.{' '}
<span className="font-mono font-bold">getFeatureFlagPayload</span>. Using
standard SDK methods such as{' '}
<span className="font-mono font-bold">
{featureFlag.has_encrypted_payloads
? 'getDecryptedFeatureFlagPayload'
: 'getFeatureFlagPayload'}
</span>
. Using standard SDK methods such as{' '}
<span className="font-mono font-bold">getFeatureFlag</span> or{' '}
<span className="font-mono font-bold">isFeatureEnabled</span> will always return{' '}
<span className="font-mono font-bold">true</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const REGULAR_FEATURE_FLAG: FeatureFlagType = {
tags: [],
surveys: [],
is_remote_configuration: false,
has_encrypted_payloads: false,
}

const GROUP_FEATURE_FLAG: FeatureFlagType = {
Expand Down
5 changes: 5 additions & 0 deletions frontend/src/scenes/feature-flags/FeatureFlagCodeOptions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ export const OPTIONS: InstructionOption[] = [
export const LOCAL_EVALUATION_LIBRARIES: string[] = [SDKKey.NODE_JS, SDKKey.PYTHON, SDKKey.RUBY, SDKKey.PHP, SDKKey.GO]

export const PAYLOAD_LIBRARIES: string[] = [
SDKKey.API,
SDKKey.JS_WEB,
SDKKey.NODE_JS,
SDKKey.PYTHON,
Expand All @@ -163,8 +164,12 @@ export const PAYLOAD_LIBRARIES: string[] = [
SDKKey.REACT_NATIVE,
SDKKey.IOS,
SDKKey.FLUTTER,
SDKKey.GO,
]

// TODO(havenbarnes): Add SDKKey.NODE_JS, SDKKey.PYTHON, SDKKey.GO, SDKKey.RUBY after new methods are published
export const ENCRYPTED_PAYLOAD_LIBRARIES: string[] = [SDKKey.API]
havenbarnes marked this conversation as resolved.
Show resolved Hide resolved

export const BOOTSTRAPPING_OPTIONS: InstructionOption[] = [
{
value: 'JavaScript',
Expand Down
96 changes: 59 additions & 37 deletions frontend/src/scenes/feature-flags/FeatureFlagInstructions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ import { eventUsageLogic } from 'lib/utils/eventUsageLogic'
import { useEffect, useState } from 'react'

import { groupsModel } from '~/models/groupsModel'
import { FeatureFlagType, GroupTypeIndex } from '~/types'
import { FeatureFlagType, GroupTypeIndex, SDKKey } from '~/types'

import {
BOOTSTRAPPING_OPTIONS,
ENCRYPTED_PAYLOAD_LIBRARIES,
FF_ANCHOR,
InstructionOption,
LibraryType,
Expand Down Expand Up @@ -56,7 +57,10 @@ export function CodeInstructions({
showAdvancedOptions = true,
showFooter = true,
}: CodeInstructionsProps): JSX.Element {
const [defaultSelectedOption] = options
const encryptedPayload = featureFlag?.has_encrypted_payloads

const [defaultSelectedOption] = encryptedPayload ? options.filter((option) => option.key === SDKKey.API) : options
havenbarnes marked this conversation as resolved.
Show resolved Hide resolved

const [selectedOption, setSelectedOption] = useState(defaultSelectedOption)
const [bootstrapOption, setBootstrapOption] = useState(BOOTSTRAPPING_OPTIONS[0])
const [showPayloadCode, setShowPayloadCode] = useState(
Expand Down Expand Up @@ -120,12 +124,13 @@ export function CodeInstructions({
setShowBootstrapCode(false)
}
}

useEffect(() => {
if (selectedLanguage) {
selectOption(selectedLanguage)
} else {
// When flag definition changes, de-select any options that can't be selected anymore
selectOption(selectedOption.key)
selectOption(defaultSelectedOption.key)
}

if (
Expand Down Expand Up @@ -155,47 +160,62 @@ export function CodeInstructions({

const randomProperty = groups.find((group) => group.properties?.length)?.properties?.[0]?.key

const allFlagLibraries = [
{
title: 'Client libraries',
options: OPTIONS.filter((option) => option.type == LibraryType.Client).map((option) => ({
value: option.key,
label: option.value,
'data-attr': `feature-flag-instructions-select-option-${option.key}`,
labelInMenu: (
<div className="flex items-center space-x-2">
<option.Icon />
<span>{option.value}</span>
</div>
),
})),
},
{
title: 'Server libraries',
options: OPTIONS.filter((option) => option.type == LibraryType.Server).map((option) => ({
value: option.key,
label: option.value,
'data-attr': `feature-flag-instructions-select-option-${option.key}`,
labelInMenu: (
<div className="flex items-center space-x-2">
<option.Icon />
<span>{option.value}</span>
</div>
),
})),
},
]
const encryptedPayloadLibraries = [
{
title: 'Server libraries',
options: OPTIONS.filter((option) => ENCRYPTED_PAYLOAD_LIBRARIES.includes(option.key)).map((option) => ({
value: option.key,
label: option.value,
'data-attr': `feature-flag-instructions-select-option-${option.key}`,
labelInMenu: (
<div className="flex items-center space-x-2">
<option.Icon />
<span>{option.value}</span>
</div>
),
})),
},
]
const supportedLibraries = encryptedPayload ? encryptedPayloadLibraries : allFlagLibraries

return (
<div>
{showAdvancedOptions && (
<div className="flex items-center gap-6">
<div>
<LemonSelect
data-attr={'feature-flag-instructions-select' + (dataAttr ? `-${dataAttr}` : '')}
options={[
{
title: 'Client libraries',
options: OPTIONS.filter((option) => option.type == LibraryType.Client).map(
(option) => ({
value: option.key,
label: option.value,
'data-attr': `feature-flag-instructions-select-option-${option.key}`,
labelInMenu: (
<div className="flex items-center space-x-2">
<option.Icon />
<span>{option.value}</span>
</div>
),
})
),
},
{
title: 'Server libraries',
options: OPTIONS.filter((option) => option.type == LibraryType.Server).map(
(option) => ({
value: option.key,
label: option.value,
'data-attr': `feature-flag-instructions-select-option-${option.key}`,
labelInMenu: (
<div className="flex items-center space-x-2">
<option.Icon />
<span>{option.value}</span>
</div>
),
})
),
},
]}
options={supportedLibraries}
onChange={(val) => {
if (val) {
selectOption(val)
Expand Down Expand Up @@ -260,6 +280,7 @@ export function CodeInstructions({
reportFlagsCodeExampleInteraction('local evaluation')
}}
disabled={
encryptedPayload ||
!LOCAL_EVALUATION_LIBRARIES.includes(selectedOption.key) ||
!!featureFlag?.ensure_experience_continuity
}
Expand Down Expand Up @@ -297,6 +318,7 @@ export function CodeInstructions({
groupType={groupType}
localEvaluation={showLocalEvalCode}
payload={true}
encryptedPayload={encryptedPayload}
/>
</>
)}
Expand Down
Loading
Loading