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

Some user defines should be available in expert mode only #679

Merged
merged 2 commits into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
36 changes: 31 additions & 5 deletions src/ui/components/DeviceOptionsForm/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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]: [],
Expand Down Expand Up @@ -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;
Expand All @@ -166,7 +190,11 @@ const DeviceOptionsForm: FunctionComponent<DeviceOptionsFormProps> = (
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) => {
Expand Down Expand Up @@ -254,8 +282,6 @@ const DeviceOptionsForm: FunctionComponent<DeviceOptionsFormProps> = (
});
};

const { isExpertModeEnabled } = useAppState();

return (
<>
{isExpertModeEnabled && (
Expand Down
6 changes: 0 additions & 6 deletions src/ui/components/UserDefinesList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, SxProps<Theme>> = {
icon: {
Expand Down Expand Up @@ -93,14 +92,9 @@ const UserDefinesList: FunctionComponent<UserDefinesListProps> = (props) => {
}
};

const { isExpertModeEnabled } = useAppState();

return (
<List>
{options.map((item) => {
if (!isExpertModeEnabled && item.key === UserDefineKey.RX_AS_TX) {
return null;
}
return (
<React.Fragment key={item.key}>
<ListItem
Expand Down
6 changes: 5 additions & 1 deletion src/ui/storage/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,11 @@ export default class ApplicationStorage implements IApplicationStorage {
}

async getDeviceOptions(device: string): Promise<DeviceOptions | null> {
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;
Expand Down
Loading