Skip to content

Commit

Permalink
fix(subsettings-pane): handle change when all settings that add a tra…
Browse files Browse the repository at this point in the history
…nsport mode are false
  • Loading branch information
josh-willis-arcadis committed Sep 10, 2024
1 parent b800d70 commit 7f4c816
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions packages/trip-form/src/MetroModeSelector/SubSettingsPane.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -191,18 +191,26 @@ export default function SubSettingsPane({

const handleSettingChange = useCallback(
(setting: ModeSetting) => (evt: QueryParamChangeEvent) => {
if (
(setting.type === "CHECKBOX" || setting.type === "SUBMODE") &&
setting.addTransportMode
) {
// rental mode settings do not have type "SUBMODE"
const settingsWithTransportMode = modeButton.modeSettings.filter(
(s: ModeSetting) =>
(s.type === "CHECKBOX" || s.type === "SUBMODE") && s.addTransportMode
);
// check if setting is a transport mode setting
if (settingsWithTransportMode.find(s => s.key === setting.key)) {
// check if all submodes are disabled
if (
settingsOnlySubmodes.every(
settingsWithTransportMode.every(
s => Object.keys(evt).includes(s.key) || s.value === false
)
) {
settingsWithTransportMode.forEach(s => {
evt[s.key] = Object.keys(evt).includes(s.key) || !s.value;
});
onAllSubmodesDisabled && onAllSubmodesDisabled(modeButton);
}
}

onSettingUpdate(evt);
},
[onSettingUpdate]
Expand Down

0 comments on commit 7f4c816

Please sign in to comment.