From 19d50731d2e35572b980fee6337ac1490ceb661c Mon Sep 17 00:00:00 2001 From: Julius Jurgelenas Date: Sun, 15 Sep 2024 18:07:46 +0300 Subject: [PATCH 1/2] Some user defines should be available in expert mode only --- src/ui/components/UserDefinesList/index.tsx | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/ui/components/UserDefinesList/index.tsx b/src/ui/components/UserDefinesList/index.tsx index ea9e0da0..f8d033fe 100644 --- a/src/ui/components/UserDefinesList/index.tsx +++ b/src/ui/components/UserDefinesList/index.tsx @@ -98,7 +98,23 @@ const UserDefinesList: FunctionComponent = (props) => { return ( {options.map((item) => { - if (!isExpertModeEnabled && item.key === UserDefineKey.RX_AS_TX) { + const expertDefines: UserDefineKey[] = [ + UserDefineKey.RX_AS_TX, + UserDefineKey.LOCK_ON_FIRST_CONNECTION, + UserDefineKey.MY_STARTUP_MELODY, + UserDefineKey.AUTO_WIFI_ON_INTERVAL, + UserDefineKey.DISABLE_ALL_BEEPS, + UserDefineKey.DISABLE_STARTUP_BEEP, + UserDefineKey.DEVICE_NAME, + UserDefineKey.RCVR_INVERT_TX, + UserDefineKey.RCVR_UART_BAUD, + UserDefineKey.RX_AS_TX, + UserDefineKey.TLM_REPORT_INTERVAL_MS, + UserDefineKey.UART_INVERTED, + UserDefineKey.UNLOCK_HIGHER_POWER, + UserDefineKey.USE_R9MM_R9MINI_SBUS, + ]; + if (!isExpertModeEnabled && expertDefines.includes(item.key)) { return null; } return ( From 3dcf948f5ca0954db5e845bba4824db01761d06a Mon Sep 17 00:00:00 2001 From: Julius Jurgelenas Date: Tue, 17 Sep 2024 00:08:35 +0300 Subject: [PATCH 2/2] Refactor expert mode user defines --- src/ui/components/DeviceOptionsForm/index.tsx | 36 ++++++++++++++++--- src/ui/components/UserDefinesList/index.tsx | 22 ------------ src/ui/storage/index.ts | 6 +++- 3 files changed, 36 insertions(+), 28 deletions(-) diff --git a/src/ui/components/DeviceOptionsForm/index.tsx b/src/ui/components/DeviceOptionsForm/index.tsx index a46ee754..53ce3878 100644 --- a/src/ui/components/DeviceOptionsForm/index.tsx +++ b/src/ui/components/DeviceOptionsForm/index.tsx @@ -76,8 +76,26 @@ export type UserDefinesKeysByCategory = { [key in UserDefineCategory]: UserDefineKey[]; }; +const EXPERT_MODE_USER_DEFINES: UserDefineKey[] = [ + UserDefineKey.RX_AS_TX, + UserDefineKey.LOCK_ON_FIRST_CONNECTION, + UserDefineKey.MY_STARTUP_MELODY, + UserDefineKey.AUTO_WIFI_ON_INTERVAL, + UserDefineKey.DISABLE_ALL_BEEPS, + UserDefineKey.DISABLE_STARTUP_BEEP, + UserDefineKey.DEVICE_NAME, + UserDefineKey.RCVR_INVERT_TX, + UserDefineKey.RCVR_UART_BAUD, + UserDefineKey.RX_AS_TX, + UserDefineKey.TLM_REPORT_INTERVAL_MS, + UserDefineKey.UART_INVERTED, + UserDefineKey.UNLOCK_HIGHER_POWER, + UserDefineKey.USE_R9MM_R9MINI_SBUS, +]; + const userDefinesToCategories = ( - userDefines: UserDefine[] + userDefines: UserDefine[], + isExpertModeEnabled: boolean ): UserDefinesByCategory => { const result: UserDefinesByCategory = { [UserDefineCategory.RegulatoryDomainsISM]: [], @@ -146,7 +164,13 @@ const userDefinesToCategories = ( }; userDefines.forEach((userDefine) => { - result[defineToCategory(userDefine.key)].push(userDefine); + if ( + isExpertModeEnabled || + (!isExpertModeEnabled && + !EXPERT_MODE_USER_DEFINES.includes(userDefine.key)) + ) { + result[defineToCategory(userDefine.key)].push(userDefine); + } }); return result; @@ -166,7 +190,11 @@ const DeviceOptionsForm: FunctionComponent = ( props ) => { const { target, deviceOptions, onChange } = props; - const categories = userDefinesToCategories(deviceOptions.userDefineOptions); + const { isExpertModeEnabled } = useAppState(); + const categories = userDefinesToCategories( + deviceOptions.userDefineOptions, + isExpertModeEnabled + ); const { t } = useTranslation(); const onOptionUpdate = (data: UserDefine) => { @@ -254,8 +282,6 @@ const DeviceOptionsForm: FunctionComponent = ( }); }; - const { isExpertModeEnabled } = useAppState(); - return ( <> {isExpertModeEnabled && ( diff --git a/src/ui/components/UserDefinesList/index.tsx b/src/ui/components/UserDefinesList/index.tsx index f8d033fe..6ff60bbc 100644 --- a/src/ui/components/UserDefinesList/index.tsx +++ b/src/ui/components/UserDefinesList/index.tsx @@ -19,7 +19,6 @@ import { import Omnibox from '../Omnibox'; import UserDefineDescription from '../UserDefineDescription'; import SensitiveTextField from '../SensitiveTextField'; -import useAppState from '../../hooks/useAppState'; const styles: Record> = { icon: { @@ -93,30 +92,9 @@ const UserDefinesList: FunctionComponent = (props) => { } }; - const { isExpertModeEnabled } = useAppState(); - return ( {options.map((item) => { - const expertDefines: UserDefineKey[] = [ - UserDefineKey.RX_AS_TX, - UserDefineKey.LOCK_ON_FIRST_CONNECTION, - UserDefineKey.MY_STARTUP_MELODY, - UserDefineKey.AUTO_WIFI_ON_INTERVAL, - UserDefineKey.DISABLE_ALL_BEEPS, - UserDefineKey.DISABLE_STARTUP_BEEP, - UserDefineKey.DEVICE_NAME, - UserDefineKey.RCVR_INVERT_TX, - UserDefineKey.RCVR_UART_BAUD, - UserDefineKey.RX_AS_TX, - UserDefineKey.TLM_REPORT_INTERVAL_MS, - UserDefineKey.UART_INVERTED, - UserDefineKey.UNLOCK_HIGHER_POWER, - UserDefineKey.USE_R9MM_R9MINI_SBUS, - ]; - if (!isExpertModeEnabled && expertDefines.includes(item.key)) { - return null; - } return ( { - const key = `${DEVICE_OPTIONS_BY_TARGET_KEYSPACE}.${device}`; + const isExpertModeEnabled = this.getExpertModeEnabled(); + // in order to preserve backwards compatibility of device options we add a + // keyspace modifier to separate non experd mode device options + const expertStr = isExpertModeEnabled ? '' : '.non_expert_mode'; + const key = `${DEVICE_OPTIONS_BY_TARGET_KEYSPACE}.${device}${expertStr}`; const value = localStorage.getItem(key); if (value === null) { return null;