diff --git a/ts/components/dialog/debug/DebugMenuModal.tsx b/ts/components/dialog/debug/DebugMenuModal.tsx index b0b5d4d34..cb855c63b 100644 --- a/ts/components/dialog/debug/DebugMenuModal.tsx +++ b/ts/components/dialog/debug/DebugMenuModal.tsx @@ -4,8 +4,9 @@ import { useDispatch } from 'react-redux'; import { Flex } from '../../basic/Flex'; import { SpacerMD, SpacerSM } from '../../basic/Text'; import { updateDebugMenuModal } from '../../../state/ducks/modalDialog'; -import { AboutInfo, DebugActions, FeatureFlags, OtherInfo } from './components'; +import { AboutInfo, DebugActions, OtherInfo } from './components'; import { SessionWrapperModal } from '../../SessionWrapperModal'; +import { FeatureFlags } from './FeatureFlags'; const StyledContent = styled(Flex)` padding-inline: var(--margins-sm); diff --git a/ts/components/dialog/debug/FeatureFlags.tsx b/ts/components/dialog/debug/FeatureFlags.tsx new file mode 100644 index 000000000..4cff04769 --- /dev/null +++ b/ts/components/dialog/debug/FeatureFlags.tsx @@ -0,0 +1,111 @@ +import { isBoolean } from 'lodash'; +import useUpdate from 'react-use/lib/useUpdate'; +import type { SessionFeatureFlagsKeys } from '../../../window'; +import { Flex } from '../../basic/Flex'; +import { SessionToggle } from '../../basic/SessionToggle'; +import { HintText, SpacerXS } from '../../basic/Text'; + +const unsupportedFlags = ['useTestNet']; +const untestedFlags = ['useOnionRequests', 'useClosedGroupV3', 'replaceLocalizedStringsWithKeys']; + +const handleFeatureFlagToggle = async ( + forceUpdate: () => void, + flag: SessionFeatureFlagsKeys, + parentFlag?: SessionFeatureFlagsKeys +) => { + const currentValue = parentFlag + ? (window as any).sessionFeatureFlags[parentFlag][flag] + : (window as any).sessionFeatureFlags[flag]; + + if (parentFlag) { + (window as any).sessionFeatureFlags[parentFlag][flag] = !currentValue; + window.log.debug(`[debugMenu] toggled ${parentFlag}.${flag} to ${!currentValue}`); + } else { + (window as any).sessionFeatureFlags[flag] = !currentValue; + window.log.debug(`[debugMenu] toggled ${flag} to ${!currentValue}`); + } + + forceUpdate(); +}; + +const FlagToggle = ({ + forceUpdate, + flag, + value, + parentFlag, +}: { + forceUpdate: () => void; + flag: SessionFeatureFlagsKeys; + value: any; + parentFlag?: SessionFeatureFlagsKeys; +}) => { + const key = `feature-flag-toggle${parentFlag ? `-${parentFlag}` : ''}-${flag}`; + return ( + + + {flag} + {untestedFlags.includes(flag) ? Untested : null} + + void handleFeatureFlagToggle(forceUpdate, flag, parentFlag)} + /> + + ); +}; + +export const FeatureFlags = ({ flags }: { flags: Record }) => { + const forceUpdate = useUpdate(); + return ( + + +

Feature Flags

+ Experimental +
+ + Changes are temporary. You can clear them by reloading the window or restarting the app. + + + {Object.entries(flags).map(([key, value]) => { + const flag = key as SessionFeatureFlagsKeys; + if (unsupportedFlags.includes(flag)) { + return null; + } + + if (!isBoolean(value)) { + return ( + <> +

{flag}

+ {Object.entries(value).map(([k, v]: [string, any]) => { + const nestedFlag = k as SessionFeatureFlagsKeys; + return ( + + ); + })} + + ); + } + return ; + })} +
+ ); +}; diff --git a/ts/components/dialog/debug/components.tsx b/ts/components/dialog/debug/components.tsx index 18d98b37a..1a8babd17 100644 --- a/ts/components/dialog/debug/components.tsx +++ b/ts/components/dialog/debug/components.tsx @@ -1,13 +1,9 @@ -import { isBoolean } from 'lodash'; -import useUpdate from 'react-use/lib/useUpdate'; import useAsync from 'react-use/lib/useAsync'; import { shell } from 'electron'; import useBoolean from 'react-use/lib/useBoolean'; import { useDispatch } from 'react-redux'; -import type { SessionFeatureFlagsKeys } from '../../../window'; import { Flex } from '../../basic/Flex'; -import { SessionToggle } from '../../basic/SessionToggle'; -import { HintText, SpacerXS } from '../../basic/Text'; +import { SpacerXS } from '../../basic/Text'; import { localize } from '../../../localization/localeTools'; import { CopyToClipboardIcon } from '../../buttons'; import { saveLogToDesktop } from '../../../util/logging'; @@ -103,111 +99,6 @@ export const DebugActions = () => { ); }; -const unsupportedFlags = ['useTestNet']; -const untestedFlags = ['useOnionRequests', 'useClosedGroupV3', 'replaceLocalizedStringsWithKeys']; - -const handleFeatureFlagToggle = async ( - forceUpdate: () => void, - flag: SessionFeatureFlagsKeys, - parentFlag?: SessionFeatureFlagsKeys -) => { - const currentValue = parentFlag - ? (window as any).sessionFeatureFlags[parentFlag][flag] - : (window as any).sessionFeatureFlags[flag]; - - if (parentFlag) { - (window as any).sessionFeatureFlags[parentFlag][flag] = !currentValue; - window.log.debug(`[debugMenu] toggled ${parentFlag}.${flag} to ${!currentValue}`); - } else { - (window as any).sessionFeatureFlags[flag] = !currentValue; - window.log.debug(`[debugMenu] toggled ${flag} to ${!currentValue}`); - } - - forceUpdate(); -}; - -const FlagToggle = ({ - forceUpdate, - flag, - value, - parentFlag, -}: { - forceUpdate: () => void; - flag: SessionFeatureFlagsKeys; - value: any; - parentFlag?: SessionFeatureFlagsKeys; -}) => { - const key = `feature-flag-toggle${parentFlag ? `-${parentFlag}` : ''}-${flag}`; - return ( - - - {flag} - {untestedFlags.includes(flag) ? Untested : null} - - void handleFeatureFlagToggle(forceUpdate, flag, parentFlag)} - /> - - ); -}; - -export const FeatureFlags = ({ flags }: { flags: Record }) => { - const forceUpdate = useUpdate(); - return ( - - -

Feature Flags

- Experimental -
- - Changes are temporary. You can clear them by reloading the window or restarting the app. - - - {Object.entries(flags).map(([key, value]) => { - const flag = key as SessionFeatureFlagsKeys; - if (unsupportedFlags.includes(flag)) { - return null; - } - - if (!isBoolean(value)) { - return ( - <> -

{flag}

- {Object.entries(value).map(([k, v]: [string, any]) => { - const nestedFlag = k as SessionFeatureFlagsKeys; - return ( - - ); - })} - - ); - } - return ; - })} -
- ); -}; - export const AboutInfo = () => { const environmentStates = [];