Skip to content

Commit

Permalink
Merge branch 'dev' into route-viewer-links
Browse files Browse the repository at this point in the history
  • Loading branch information
binh-dam-ibigroup authored May 31, 2024
2 parents ec9b552 + d3f4f65 commit 8080533
Show file tree
Hide file tree
Showing 9 changed files with 640 additions and 658 deletions.
1 change: 1 addition & 0 deletions .github/workflows/codespell.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ jobs:
- uses: codespell-project/actions-codespell@master
with:
check_filenames: true
ignore_words_list: MapPin
# skip git, yarn, pixel test script and HAR file, and all i18n resources.
# Also, the a11y test file has a false positive and the ignore list does not work
# see https://github.com/opentripplanner/otp-react-redux/pull/436/checks?check_run_id=3369380014
Expand Down
18 changes: 18 additions & 0 deletions __tests__/components/util/link.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import '../../test-utils/mock-window-url'

import { isSubpath } from '../../../lib/components/util/link'

describe('components > util > Link > isSubpath', () => {
it('should be true on a path that starts with the tracked path', () => {
expect(isSubpath('/', '/')).toBeTruthy()
expect(isSubpath('/trips', '/trips')).toBeTruthy()
expect(isSubpath('/trips/trip123', '/trips')).toBeTruthy()
})
it('should be false on a path that starts differently than the tracked path', () => {
expect(isSubpath('/trips/trip123', '/route')).toBeFalsy()
expect(isSubpath('/', '/route')).toBeFalsy()
})
it('should be false if tracking home (/) and on a path that is not home.', () => {
expect(isSubpath('/trips/trip123', '/')).toBeFalsy()
})
})
1,154 changes: 577 additions & 577 deletions __tests__/components/viewers/__snapshots__/nearby-view.js.snap

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ exports[`components > viewers > stop viewer should render with initial stop id a
>
<Styled(styled.span)>
<span
className="sc-dkAqVg sc-jifHHV dwdQnb czUBjn"
className="sc-jifHHV sc-hkwmXC frJUIW gWGcte"
>
<ArrowLeft>
<StyledIconBase
Expand Down Expand Up @@ -267,11 +267,11 @@ exports[`components > viewers > stop viewer should render with initial stop id a
</div>
<styled.div>
<div
className="sc-gUUBao kMeMAw"
className="sc-hJxDiT dbjOgr"
>
<styled.div>
<div
className="sc-edoYdd jGAQLh"
className="sc-jlIlqL sdJoA"
>
<h1>
<FormattedMessage
Expand Down
8 changes: 5 additions & 3 deletions lib/actions/apiV2.js
Original file line number Diff line number Diff line change
Expand Up @@ -1005,6 +1005,10 @@ export function routingQuery(searchId = null, updateSearchInReducer) {
// This is likely due to the fact that BICYCLE_RENT is treated as a transit submode.
const combinations = modes ? [baseQuery] : generateCombinations(baseQuery)

if (combinations.length === 0) {
return RoutingQueryCallResult.INVALID_MODE_SELECTION
}

dispatch(
routingRequest({
activeItinerary,
Expand Down Expand Up @@ -1171,9 +1175,7 @@ export function routingQuery(searchId = null, updateSearchInReducer) {
dispatch(updateOtpUrlParams(state, searchId))
}

return combinations.length === 0
? RoutingQueryCallResult.INVALID_MODE_SELECTION
: RoutingQueryCallResult.SUCCESS
return RoutingQueryCallResult.SUCCESS
}
}

Expand Down
71 changes: 14 additions & 57 deletions lib/components/map/point-popup.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { connect } from 'react-redux'
import { FocusTrapWrapper } from '@opentripplanner/map-popup/lib'
import { Popup } from '@opentripplanner/base-map'
import { Search } from '@styled-icons/fa-solid/Search'
import { useIntl, WrappedComponentProps } from 'react-intl'
import { useMap } from 'react-map-gl'
import FromToLocationPicker from '@opentripplanner/from-to-location-picker'
import React, { useCallback, useMemo } from 'react'
import React, { useCallback } from 'react'
import styled from 'styled-components'
import type { Location } from '@opentripplanner/types'

import * as mapActions from '../../actions/map'
import { getEntryRelativeTo } from '../util/get-entry-relative-to'
import { Icon } from '../util/styledIcon'
import { renderCoordinates } from '../../util/i18n'
import { SetLocationHandler, ZoomToPlaceHandler } from '../util/types'
Expand Down Expand Up @@ -51,49 +51,6 @@ function MapPopup({
const intl = useIntl()
const { current: map } = useMap()

/**
* Creates a focus trap within map popup that can be dismissed with esc.
* https://medium.com/cstech/achieving-focus-trapping-in-a-react-modal-component-3f28f596f35b
*/

/**
* Check to see which keys are down by tracking keyUp and keyDown events
* in order to see when "tab" and "shift" are pressed at the same time.
*/
let keysDown: string[] = useMemo(() => [], [])

// Argument for document.querySelectorAll to target focusable elements.
const queryId = 'button#zoom-btn, #from-to button'

const _handleKeyDown = useCallback(
(e) => {
keysDown.push(e.key)
const element = e.target as HTMLElement
switch (e.key) {
case 'Escape':
clearMapPopupLocation()
break
case 'Tab':
if (keysDown.includes('Shift')) {
e.preventDefault()
getEntryRelativeTo(queryId, element, -1)?.focus()
} else {
e.preventDefault()
getEntryRelativeTo(queryId, element, 1)?.focus()
}
break
case ' ':
break
default:
}
},
[clearMapPopupLocation, keysDown]
)

const _handleKeyUp = (e: any) => {
keysDown = keysDown.filter((key) => key !== e.key)
}

// Memoize callbacks that shouldn't change from one render to the next.
const onSetLocationFromPopup = useCallback(
(payload) => {
Expand All @@ -116,16 +73,16 @@ function MapPopup({
})

return (
<div onKeyDown={_handleKeyDown} onKeyUp={_handleKeyUp} role="presentation">
<Popup
closeButton={false}
closeOnClick
latitude={mapPopupLocation.lat}
longitude={mapPopupLocation.lon}
onClose={clearMapPopupLocation}
// Override inline style supplied by react-map-gl to accommodate long "plan a trip" translations.
style={{ maxWidth: '260px', width: '260px' }}
>
<Popup
closeButton={false}
closeOnClick
latitude={mapPopupLocation.lat}
longitude={mapPopupLocation.lon}
onClose={clearMapPopupLocation}
// Override inline style supplied by react-map-gl to accommodate long "plan a trip" translations.
style={{ maxWidth: '260px', width: '260px' }}
>
<FocusTrapWrapper closePopup={clearMapPopupLocation} id="stop-popup">
<PopupTitleWrapper>
<PopupTitle>
{typeof popupName === 'string' && popupName.split(',').length > 3
Expand All @@ -148,8 +105,8 @@ function MapPopup({
setLocation={onSetLocationFromPopup}
/>
</div>
</Popup>
</div>
</FocusTrapWrapper>
</Popup>
)
}

Expand Down
8 changes: 6 additions & 2 deletions lib/components/util/link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ interface OwnProps extends AnchorHTMLAttributes<HTMLAnchorElement> {
tracking?: boolean
}

/** Determines whether the given path is a subpath of the 'to' prop. */
export function isSubpath(path: string, to: string): boolean {
return !isBlank(to) && (path === to || path.startsWith(`${to}/`))
}

/**
* Renders an anchor element <a> with specified path and query params,
* that preserves other existing query params.
Expand All @@ -25,8 +30,7 @@ const mapStateToProps = (state: AppReduxState, ownProps: OwnProps) => {
const queryParams = combineQueryParams(toParams)
const href = `#${to}${isBlank(queryParams) ? '' : `?${queryParams}`}`

const isActive =
tracking && !isBlank(to) && state.router.location.pathname === to
const isActive = tracking && isSubpath(state.router.location.pathname, to)
return {
className:
className && isActive
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@
"@opentripplanner/geocoder": "^2.2.2",
"@opentripplanner/humanize-distance": "^1.2.0",
"@opentripplanner/icons": "^2.0.10",
"@opentripplanner/itinerary-body": "^5.2.8",
"@opentripplanner/itinerary-body": "^5.3.0",
"@opentripplanner/location-field": "^2.0.17",
"@opentripplanner/location-icon": "^1.4.1",
"@opentripplanner/map-popup": "^3.0.3",
"@opentripplanner/map-popup": "^3.1.0",
"@opentripplanner/otp2-tile-overlay": "^1.0.12",
"@opentripplanner/park-and-ride-overlay": "^2.0.8",
"@opentripplanner/printable-itinerary": "^2.0.20",
Expand Down
28 changes: 14 additions & 14 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2434,7 +2434,7 @@
"@opentripplanner/location-icon" "^1.4.1"
flat "^5.0.2"

"@opentripplanner/geocoder@^2.0.1", "@opentripplanner/geocoder@^2.2.2":
"@opentripplanner/geocoder@^2.2.2":
version "2.2.2"
resolved "https://registry.yarnpkg.com/@opentripplanner/geocoder/-/geocoder-2.2.2.tgz#8ddc669287ccdfff1a5cce14d1fa8049421c6480"
integrity sha512-tJIOOE5N9kpMj0ji1YyVfWwg4yAFVs7Ks+EET67acql768bXwRE6rHoX6oaHvKhbCDjaQ7kuPIwi1BYWHQgg0Q==
Expand All @@ -2458,14 +2458,14 @@
"@opentripplanner/core-utils" "^11.2.3"
prop-types "^15.7.2"

"@opentripplanner/itinerary-body@^5.2.6", "@opentripplanner/itinerary-body@^5.2.8":
version "5.2.8"
resolved "https://registry.yarnpkg.com/@opentripplanner/itinerary-body/-/itinerary-body-5.2.8.tgz#12cb356dc3c203af9603541d46b2c30f0cc8dbe1"
integrity sha512-D/gH80BlTR/J4XYyhVG234J5qVatzYwEjObHUY01u17X+uUgRcl05zv9vNSLx9Va0UDxPc7oR+Ro5VnkW+QkKA==
"@opentripplanner/itinerary-body@^5.2.6", "@opentripplanner/itinerary-body@^5.3.0":
version "5.3.0"
resolved "https://registry.yarnpkg.com/@opentripplanner/itinerary-body/-/itinerary-body-5.3.0.tgz#1a611dc6c49438666e58c34d0f1f88ab6ff48f2d"
integrity sha512-yNMluEX4jJMEdvObGcivnJCS8wMqzZ1j+zJ/40oE9uK9XNyT6o3ascpcsDPN45ZJTIUBoj1FVhItvrfLxaRYMA==
dependencies:
"@opentripplanner/core-utils" "^11.2.3"
"@opentripplanner/core-utils" "^11.3.1"
"@opentripplanner/humanize-distance" "^1.2.0"
"@opentripplanner/icons" "^2.0.9"
"@opentripplanner/icons" "^2.0.10"
"@opentripplanner/location-icon" "^1.4.1"
"@styled-icons/fa-solid" "^10.34.0"
"@styled-icons/foundation" "^10.34.0"
Expand Down Expand Up @@ -2497,14 +2497,14 @@
"@styled-icons/fa-regular" "^10.34.0"
"@styled-icons/fa-solid" "^10.34.0"

"@opentripplanner/map-popup@^3.0.2", "@opentripplanner/map-popup@^3.0.3":
version "3.0.3"
resolved "https://registry.yarnpkg.com/@opentripplanner/map-popup/-/map-popup-3.0.3.tgz#4ded505bcf23f505b07abfe5d24142eb2faa483a"
integrity sha512-AvXLUfnEj5PoDHd8eFdpMXsXqmLyreSPPeiVIggNvZUDTm6uHpCAovSrSOOoFT3nOIEaUw4TCcjamJeV0gaNJw==
"@opentripplanner/map-popup@^3.0.2", "@opentripplanner/map-popup@^3.1.0":
version "3.1.0"
resolved "https://registry.yarnpkg.com/@opentripplanner/map-popup/-/map-popup-3.1.0.tgz#51627e4d4c902d10bec6fffa2c3e3eed0994a42c"
integrity sha512-UzQ9OYOslNqDxvGWIPOZ4KyIJ7R0CO2riC56AJeHz5EI0JSv1Rlt1b6JTz0BtJ9cbHksB2QB43x8bJs6if7mfg==
dependencies:
"@opentripplanner/base-map" "^3.0.16"
"@opentripplanner/core-utils" "^11.2.3"
"@opentripplanner/from-to-location-picker" "^2.1.11"
"@opentripplanner/base-map" "^3.1.0"
"@opentripplanner/core-utils" "^11.3.1"
"@opentripplanner/from-to-location-picker" "^2.1.12"
flat "^5.0.2"

"@opentripplanner/otp2-tile-overlay@^1.0.12":
Expand Down

0 comments on commit 8080533

Please sign in to comment.