Skip to content

Commit

Permalink
fix(form): fix hanging comma issue in mode selector
Browse files Browse the repository at this point in the history
  • Loading branch information
landonreed committed May 20, 2019
1 parent 2187417 commit cf6a4f6
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
22 changes: 13 additions & 9 deletions lib/components/form/settings-selector-panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ class SettingsSelectorPanel extends Component {

_setBikeOnly = () => { this._setSoloMode('BICYCLE') }

_setOwnBike = () => {
const nonBikeModes = this.props.queryModes.filter(m => !m.startsWith('BICYCLE'))
this.props.setQueryParam({ mode: 'BICYCLE,' + nonBikeModes.join(',') })
_addBikeModeToQueryModes = (bikeMode) => {
const { queryModes, setQueryParam } = this.props
const nonBikeModes = queryModes.filter(m => !m.startsWith('BICYCLE'))
setQueryParam({ mode: [...nonBikeModes, bikeMode].join(',') })
}

_setRentedBike = () => {
const nonBikeModes = this.props.queryModes.filter(m => !m.startsWith('BICYCLE'))
this.props.setQueryParam({ mode: 'BICYCLE_RENT,' + nonBikeModes.join(',') })
}
_setOwnBike = () => this._addBikeModeToQueryModes('BICYCLE')

_setRentedBike = () => this._addBikeModeToQueryModes('BICYCLE_RENT')

_toggleTransitMode (mode) {
const modeStr = mode.mode || mode
Expand Down Expand Up @@ -86,13 +86,17 @@ class SettingsSelectorPanel extends Component {
}

// If no transit modes selected, select all
if (!queryModes || queryModes.length === 0) queryModes = getTransitModes(this.props.config)
if (!queryModes || queryModes.length === 0) {
queryModes = getTransitModes(this.props.config)
}

// Add the access mode
queryModes.push(modeStr)

// Do extra stuff if mode selected was a TNC
queryParamUpdate.companies = (modeStr === 'CAR_HAIL' || modeStr === 'CAR_RENT') ? mode.company.toUpperCase() : null
queryParamUpdate.companies = (modeStr === 'CAR_HAIL' || modeStr === 'CAR_RENT')
? mode.company.toUpperCase()
: null

queryParamUpdate.mode = queryModes.join(',')

Expand Down
12 changes: 12 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2306,6 +2306,11 @@ buffer@^5.0.2:
base64-js "^1.0.2"
ieee754 "^1.1.4"

builtin-modules@^1.0.0:
version "1.1.1"
resolved "https://registry.yarnpkg.com/builtin-modules/-/builtin-modules-1.1.1.tgz#270f076c5a72c02f5b65a47df94c5fe3a278892f"
integrity sha1-Jw8HbFpywC9bZaR9+Uxf46J4iS8=

builtin-status-codes@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/builtin-status-codes/-/builtin-status-codes-3.0.0.tgz#85982878e21b98e1c66425e03d0174788f569ee8"
Expand Down Expand Up @@ -6035,6 +6040,13 @@ is-buffer@^1.1.0, is-buffer@^1.1.4, is-buffer@^1.1.5, is-buffer@~1.1.1:
resolved "https://registry.yarnpkg.com/is-buffer/-/is-buffer-1.1.6.tgz#efaa2ea9daa0d7ab2ea13a97b2b8ad51fefbe8be"
integrity sha512-NcdALwpXkTm5Zvvbk7owOUSvVvBKDgKP5/ewfXEznmQFfs4ZRmanOeKBTjRVjka3QFoN6XJ+9F3USqfHqTaU5w==

is-builtin-module@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/is-builtin-module/-/is-builtin-module-1.0.0.tgz#540572d34f7ac3119f8f76c30cbc1b1e037affbe"
integrity sha1-VAVy0096wxGfj3bDDLwbHgN6/74=
dependencies:
builtin-modules "^1.0.0"

is-callable@^1.1.3, is-callable@^1.1.4:
version "1.1.4"
resolved "https://registry.yarnpkg.com/is-callable/-/is-callable-1.1.4.tgz#1e1adf219e1eeb684d691f9d6a05ff0d30a24d75"
Expand Down

0 comments on commit cf6a4f6

Please sign in to comment.