diff --git a/lib/components/form/advanced-settings-panel.tsx b/lib/components/form/advanced-settings-panel.tsx index ab83513be..7f1500f23 100644 --- a/lib/components/form/advanced-settings-panel.tsx +++ b/lib/components/form/advanced-settings-panel.tsx @@ -29,7 +29,6 @@ import PageTitle from '../util/page-title' import { addCustomSettingLabels, addModeButtonIcon, - onAdvancedModeSubsettingsUpdate, onSettingsUpdate, pipe, populateSettingWithIcon, @@ -186,6 +185,10 @@ const AdvancedSettingsPanel = ({ onSettingsUpdate(setQueryParam) ) + const handleAllSubmodesDisabled = (modeButton: ModeButtonDefinition) => { + handleModeButtonToggle(modeButton.key, false) + } + return ( @@ -223,11 +226,8 @@ const AdvancedSettingsPanel = ({ fillModeIcons label="test" modeButtons={processedModeButtons} - onSettingsUpdate={onAdvancedModeSubsettingsUpdate( - setQueryParam, - processedModeButtons, - handleModeButtonToggle - )} + onAllSubmodesDisabled={handleAllSubmodesDisabled} + onSettingsUpdate={onSettingsUpdate(setQueryParam)} onToggleModeButton={handleModeButtonToggle} /> { - return modeButtons.find((button: ModeButtonDefinition) => { - if (button.modeSettings) { - return button.modeSettings.some((setting: ModeSetting) => { - // check if transport mode - if ( - (setting.type === 'CHECKBOX' || setting.type === 'SUBMODE') && - setting.addTransportMode - ) { - return setting.key === key - } - return false - }) - } - return false - }) -} - -export const onAdvancedModeSubsettingsUpdate = - ( - setQueryParam: (evt: any) => void, - processedModeButtons: ModeButtonDefinition[], - handleModeButtonToggle: (buttonId: string, newState: boolean) => void - ) => - (params: any) => { - // check if setting is a transport mode and get the mode button that contains it - const modeButton = getModeButtonFromSubmode( - Object.keys(params)[0], - processedModeButtons - ) - if (modeButton && modeButton.modeSettings && !Object.values(params)[0]) { - const transportModeSettings = modeButton.modeSettings.filter( - (setting: ModeSetting) => - (setting.type === 'CHECKBOX' || setting.type === 'SUBMODE') && - setting.addTransportMode - ) - // if we're disabling a transport mode, we need to check if the mode button needs to be disabled (all of its subsettings are false) - const allFalse = transportModeSettings.every((setting: ModeSetting) => { - if (setting.key === Object.keys(params)[0]) { - return !Object.values(params)[0] - } - return !setting.value - }) - if (allFalse) { - transportModeSettings.forEach((setting) => (params[setting.key] = true)) - handleModeButtonToggle(modeButton.key, false) - } - } - setQueryParam({ queryParamData: params, ...params }) - } - export const setModeButton = (enabledModeButtons: string[], updateHandler: (params: any) => void) => (buttonId: string, newState: boolean) => {