Skip to content

Commit 68bdec0

Browse files
fix(batch-settings): only remove walk when walk is deselected
1 parent d9e1f47 commit 68bdec0

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

lib/components/form/batch-settings.tsx

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ class BatchSettings extends Component<{
8585
config: any
8686
currentQuery: any
8787
intl: IntlShape
88+
modeOptions: Mode[]
8889
possibleCombinations: Combination[]
8990
routingQuery: any
9091
setQueryParam: (queryParam: any) => void
@@ -95,7 +96,8 @@ class BatchSettings extends Component<{
9596
}
9697

9798
_onClickMode = (mode: string) => {
98-
const { currentQuery, possibleCombinations, setQueryParam } = this.props
99+
const { currentQuery, modeOptions, possibleCombinations, setQueryParam } =
100+
this.props
99101
const { selectedModes } = this.state
100102
const index = selectedModes.indexOf(mode)
101103
const enableMode = index === -1
@@ -105,11 +107,17 @@ class BatchSettings extends Component<{
105107
// Update selected modes for mode buttons.
106108
this.setState({ selectedModes: newModes })
107109
// Update the available mode combinations based on the new modes selection.
108-
const possibleModes = getModeOptions(this.props.intl).map((m) => m.mode)
109-
const disabledModes = possibleModes.filter((m) => !newModes.includes(m))
110+
const possibleModes = modeOptions.map((m) => m.mode)
111+
const disabledModes = possibleModes.filter(
112+
// WALK will be filtered out separately, later
113+
// Since we don't want to remove walk+other combos when walk is deselected.
114+
(m) => !newModes.includes(m) && m !== 'WALK'
115+
)
110116
// Do not include combination if any of its modes are found in disabled
111117
// modes list.
112118
const newCombinations = possibleCombinations
119+
// Filter out WALK only mode if walk is disabled
120+
.filter((c) => newModes.includes('WALK') || c.mode !== 'WALK')
113121
.filter((c) => !combinationHasAnyOfModes(c, disabledModes))
114122
.map(replaceTransitMode(currentQuery.mode))
115123
setQueryParam({ combinations: newCombinations, disabledModes })
@@ -153,13 +161,14 @@ class BatchSettings extends Component<{
153161
_toggleSettings = () => this.setState(this._updateExpanded('SETTINGS'))
154162

155163
render() {
156-
const { config, currentQuery, intl } = this.props
164+
const { config, currentQuery, intl, modeOptions } = this.props
157165
const { expanded, selectedModes } = this.state
158166
return (
159167
<>
160168
<ModeButtonsFullWidthContainer className="hidden-lg">
161169
<ModeButtonsFullWidth
162170
className="flex"
171+
modeOptions={modeOptions}
163172
onClick={this._onClickMode}
164173
selectedModes={selectedModes}
165174
/>
@@ -183,6 +192,7 @@ class BatchSettings extends Component<{
183192
<ModeButtonsContainerCompressed>
184193
<ModeButtonsCompressed
185194
className="visible-lg straight-corners"
195+
modeOptions={modeOptions}
186196
onClick={this._onClickMode}
187197
selectedModes={selectedModes}
188198
/>
@@ -216,6 +226,7 @@ class BatchSettings extends Component<{
216226
const mapStateToProps = (state: any) => ({
217227
config: state.otp.config,
218228
currentQuery: state.otp.currentQuery,
229+
modeOptions: state.otp.config.modes.modeOptions,
219230
possibleCombinations: state.otp.config.modes.combinations
220231
})
221232

0 commit comments

Comments
 (0)