Skip to content

Commit

Permalink
feat: add setting hidden option (#25480)
Browse files Browse the repository at this point in the history
Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
zlwaterfield and github-actions[bot] authored Oct 15, 2024
1 parent f975dd7 commit 6d7a20b
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 18 deletions.
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.
3 changes: 3 additions & 0 deletions frontend/src/scenes/settings/SettingsMap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { PersonsJoinMode } from 'scenes/settings/environment/PersonsJoinMode'
import { PersonsOnEvents } from 'scenes/settings/environment/PersonsOnEvents'
import { SessionsTableVersion } from 'scenes/settings/environment/SessionsTableVersion'

import { Realm } from '~/types'

import {
AutocaptureSettings,
ExceptionAutocaptureSettings,
Expand Down Expand Up @@ -469,6 +471,7 @@ export const SETTINGS_MAP: SettingSection[] = [
id: 'optout',
title: 'Anonymize data collection',
component: <OptOutCapture />,
hideOn: [Realm.Cloud],
},
{
id: 'hedgehog-mode',
Expand Down
53 changes: 36 additions & 17 deletions frontend/src/scenes/settings/settingsLogic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ import { actions, connect, kea, key, listeners, path, props, reducers, selectors
import { FEATURE_FLAGS } from 'lib/constants'
import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
import { copyToClipboard } from 'lib/utils/copyToClipboard'
import { preflightLogic } from 'scenes/PreflightCheck/preflightLogic'
import { urls } from 'scenes/urls'
import { userLogic } from 'scenes/userLogic'

import { Realm } from '~/types'

import type { settingsLogicType } from './settingsLogicType'
import { SETTINGS_MAP } from './SettingsMap'
import { Setting, SettingId, SettingLevelId, SettingSection, SettingSectionId, SettingsLogicProps } from './types'
Expand All @@ -14,7 +17,7 @@ export const settingsLogic = kea<settingsLogicType>([
key((props) => props.logicKey ?? 'global'),
path((key) => ['scenes', 'settings', 'settingsLogic', key]),
connect({
values: [featureFlagLogic, ['featureFlags'], userLogic, ['hasAvailableFeature']],
values: [featureFlagLogic, ['featureFlags'], userLogic, ['hasAvailableFeature'], preflightLogic, ['preflight']],
}),

actions({
Expand Down Expand Up @@ -112,8 +115,17 @@ export const settingsLogic = kea<settingsLogicType>([
s.settingId,
s.featureFlags,
s.hasAvailableFeature,
s.preflight,
],
(selectedLevel, selectedSectionId, sections, settingId, featureFlags, hasAvailableFeature): Setting[] => {
(
selectedLevel,
selectedSectionId,
sections,
settingId,
featureFlags,
hasAvailableFeature,
preflight
): Setting[] => {
let settings: Setting[] = []

if (selectedSectionId) {
Expand All @@ -128,22 +140,29 @@ export const settingsLogic = kea<settingsLogicType>([
return settings.filter((x) => x.id === settingId)
}

return settings.filter((x) => {
const isFlagConditionMet = !x.flag
? true // No flag condition
: x.flag.startsWith('!')
? !featureFlags[FEATURE_FLAGS[x.flag.slice(1)]] // Negated flag condition (!-prefixed)
: featureFlags[FEATURE_FLAGS[x.flag]] // Regular flag condition
if (x.flag && x.features) {
return x.features.some((feat) => hasAvailableFeature(feat)) || isFlagConditionMet
} else if (x.features) {
return x.features.some((feat) => hasAvailableFeature(feat))
} else if (x.flag) {
return isFlagConditionMet
}
return settings
.filter((x) => {
const isFlagConditionMet = !x.flag
? true // No flag condition
: x.flag.startsWith('!')
? !featureFlags[FEATURE_FLAGS[x.flag.slice(1)]] // Negated flag condition (!-prefixed)
: featureFlags[FEATURE_FLAGS[x.flag]] // Regular flag condition
if (x.flag && x.features) {
return x.features.some((feat) => hasAvailableFeature(feat)) || isFlagConditionMet
} else if (x.features) {
return x.features.some((feat) => hasAvailableFeature(feat))
} else if (x.flag) {
return isFlagConditionMet
}

return true
})
return true
})
.filter((x) => {
if (x.hideOn?.includes(Realm.Cloud) && preflight?.cloud) {
return false
}
return true
})
},
],
}),
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/scenes/settings/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { EitherMembershipLevel, FEATURE_FLAGS } from 'lib/constants'

import { AvailableFeature } from '~/types'
import { AvailableFeature, Realm } from '~/types'

export type SettingsLogicProps = {
logicKey?: string
Expand Down Expand Up @@ -110,6 +110,7 @@ export type Setting = {
*/
flag?: FeatureFlagKey | `!${FeatureFlagKey}`
features?: AvailableFeature[]
hideOn?: Realm[]
}

export type SettingSection = {
Expand Down

0 comments on commit 6d7a20b

Please sign in to comment.