Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass user's mobilityProfile to plan queries #1099

Closed
wants to merge 30 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
a38eb68
feat(apiV2): Pass user's mobilityProfile (if present) to plan queries.
binh-dam-ibigroup Dec 28, 2023
3418d81
Merge branch 'dev' into mobility-profile-routing
binh-dam-ibigroup Jan 19, 2024
7c26245
Merge branch 'dev' into mobility-profile-routing
binh-dam-ibigroup Jan 25, 2024
49c0e67
chore(deps): Add reference to OTP-UI branch for mobility profile
binh-dam-ibigroup Jan 29, 2024
ad6c453
Merge branch 'dev' into mobility-profile-routing
binh-dam-ibigroup Feb 2, 2024
5036045
Merge branch 'dev' into mobility-profile-routing
binh-dam-ibigroup Feb 8, 2024
12d0911
Merge branch 'dev' into mobility-profile-routing
binh-dam-ibigroup Mar 4, 2024
9cd8840
Merge branch 'dev' into mobility-profile-routing
binh-dam-ibigroup Mar 14, 2024
9032b75
Merge branch 'dev' into mobility-profile-routing
binh-dam-ibigroup Mar 22, 2024
d876e2c
Merge branch 'dev' into mobility-profile-routing
binh-dam-ibigroup Mar 28, 2024
dbcdd46
Merge branch 'dev' into mobility-profile-routing
binh-dam-ibigroup Apr 8, 2024
b3a6135
fix(actions/user): Replan with profile after fetching user data.
binh-dam-ibigroup Apr 10, 2024
f082068
fix(actions/user): Don't replan if within the account screens.
binh-dam-ibigroup Apr 11, 2024
981040b
Merge branch 'dev' into mobility-profile-routing
binh-dam-ibigroup Apr 24, 2024
d9b7b55
Merge branch 'dev' into mobility-profile-routing
binh-dam-ibigroup Apr 26, 2024
7354a9d
refactor(MobilityPane): Use new Link component to navigate to mobilit…
binh-dam-ibigroup Apr 26, 2024
0c6b24c
Merge branch 'dev' into mobility-profile-routing
binh-dam-ibigroup May 1, 2024
e0cfb11
Merge branch 'dev' into mobility-profile-routing
binh-dam-ibigroup May 9, 2024
ceeea83
fix(NavLoginButton): Make help link valid when running locally
binh-dam-ibigroup May 16, 2024
c60c4e4
Merge branch 'dev' into mobility-profile-routing
binh-dam-ibigroup May 16, 2024
41e7f79
Merge branch 'dev' into mobility-profile-routing
binh-dam-ibigroup May 17, 2024
def95b6
Merge branch 'dev' into mobility-profile-routing
binh-dam-ibigroup May 20, 2024
4857ae5
Merge branch 'dev' into mobility-profile-routing
binh-dam-ibigroup Jul 17, 2024
f6cb60e
Merge branch 'dev' into mobility-profile-routing
binh-dam-ibigroup Jul 26, 2024
87eed37
chore(deps): Downgrade some packages
binh-dam-ibigroup Jul 26, 2024
fdd9c7a
chore(deps): Update core-utils to 11.4.2-mobility-profile
binh-dam-ibigroup Jul 29, 2024
cbd0f67
Merge branch 'dev' into mobility-profile-routing
binh-dam-ibigroup Aug 14, 2024
26fde56
chore(deps): Update core-utils to 1.4.3-mobility-profile
binh-dam-ibigroup Aug 14, 2024
49826a2
Merge branch 'dev' into mobility-profile-routing
binh-dam-ibigroup Sep 9, 2024
78be055
Merge branch 'dev' into mobility-profile-routing
binh-dam-ibigroup Sep 25, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/actions/apiV2.js
Original file line number Diff line number Diff line change
Expand Up @@ -924,6 +924,7 @@ export function routingQuery(searchId = null, updateSearchInReducer) {
return function (dispatch, getState) {
const state = getState()
const { config, currentQuery, modeSettingDefinitions } = state.otp
const { loggedInUser } = state.user
const persistenceMode = getPersistenceMode(config.persistence)
const activeItinerary =
getActiveItinerary(state) ||
Expand Down Expand Up @@ -998,6 +999,7 @@ export function routingQuery(searchId = null, updateSearchInReducer) {
},
date,
from: currentQuery.from,
mobilityProfile: loggedInUser?.mobilityProfile?.mobilityMode,
modes: modes || activeModes,
modeSettings,
time,
Expand Down
20 changes: 19 additions & 1 deletion lib/actions/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,8 @@ function setUser(user, fetchTrips) {
return function (dispatch, getState) {
positionHomeAndWorkFirst(user)
// If mobility profile is enabled, set a default selection for "no mobility devices".
if (getState().otp.config.mobilityProfile) {
const hasMobilityProfile = !!getState().otp.config.mobilityProfile
if (hasMobilityProfile) {
setAtLeastNoMobilityDevice(user)
}
dispatch(setCurrentUser(user))
Expand All @@ -262,6 +263,23 @@ function setUser(user, fetchTrips) {
if (!isBlank(preferredLocale)) {
dispatch(setLocale(preferredLocale))
}

// Also replan itinerary search for the current user profile.
if (
hasMobilityProfile &&
!getState().router.location.pathname.startsWith('/account')
) {
// TODO: Refactor below.
// This prevents some kind of race condition whose origin I can't figure
// out. Unless this is called after redux catches up with routing to the '/'
// path, then the old path will be used and the screen won't change.
// Therefore, this timeout occurs so that the view of the homepage has time
// to render itself.
// FIXME: remove hack
setTimeout(() => {
dispatch(routingQuery())
}, 300)
}
}
}

Expand Down
27 changes: 8 additions & 19 deletions lib/components/user/mobility-profile/mobility-pane.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,17 @@
import { Button } from 'react-bootstrap'
import { connect } from 'react-redux'
import { FormattedList, FormattedMessage } from 'react-intl'
import { FormikProps } from 'formik'
import React, { useCallback } from 'react'
import React from 'react'

import * as uiActions from '../../../actions/ui'
import { EditedUser } from '../types'
import { NONE_SINGLETON } from '../../../util/user'

interface Props extends FormikProps<EditedUser> {
routeTo: (url: string) => void
}
import Link from '../../util/link'

/**
* Renders a button to show the mobility profile settings.
*/
const MobilityPane = ({ routeTo, values: userData }: Props): JSX.Element => {
const handleClick = useCallback(() => {
routeTo('/account/mobilityProfile/')
}, [routeTo])
const MobilityPane = ({
values: userData
}: FormikProps<EditedUser>): JSX.Element => {
const {
isMobilityLimited,
mobilityDevices = [],
Expand Down Expand Up @@ -54,15 +47,11 @@ const MobilityPane = ({ routeTo, values: userData }: Props): JSX.Element => {
id={`components.MobilityProfile.LimitationsPane.visionLimitations.${visionLimitation}`}
/>
</p>
<Button bsStyle="primary" onClick={handleClick}>
<Link className="btn btn-primary" to="/account/mobilityProfile/">
<FormattedMessage id="components.MobilityProfile.MobilityPane.button" />
</Button>
</Link>
</div>
)
}

const mapDispatchToProps = {
routeTo: uiActions.routeTo
}

export default connect(null, mapDispatchToProps)(MobilityPane)
export default MobilityPane
1 change: 1 addition & 0 deletions lib/components/user/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export type VisionLimitation = typeof visionLimitations[number]
export interface MobilityProfile {
isMobilityLimited: boolean
mobilityDevices: string[]
mobilityMode: string
visionLimitation: VisionLimitation
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"@floating-ui/react": "^0.19.2",
"@opentripplanner/base-map": "^3.2.2",
"@opentripplanner/building-blocks": "^1.2.3",
"@opentripplanner/core-utils": "^11.4.4",
"@opentripplanner/core-utils": "11.4.3-mobility-profile",
"@opentripplanner/endpoints-overlay": "^2.1.4",
"@opentripplanner/from-to-location-picker": "^2.1.14",
"@opentripplanner/geocoder": "^3.0.2",
Expand Down
18 changes: 18 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2408,6 +2408,24 @@
resolved "https://registry.yarnpkg.com/@opentripplanner/building-blocks/-/building-blocks-1.2.3.tgz#404e8f9038867d66d55f51adf8855b1326c51ed5"
integrity sha512-I0AxiZrTZu+e7+av4u0tHW2ijqpxH0AkLHrhf75BHf1Ep2FOGxaul/v+8UT18mNYiM5eHNstOX3XiXaDjtCUaw==

"@opentripplanner/[email protected]":
version "11.4.3-mobility-profile"
resolved "https://registry.yarnpkg.com/@opentripplanner/core-utils/-/core-utils-11.4.3-mobility-profile.tgz#b1d5675c6c1f85a3454234b720059efa03ad6ed2"
integrity sha512-+6IjMwXCUZHNmTLnZZ+u23Awtm2v4DcRVmkyxy8m8Dd5GxB9tMxXBhvvwxuzD2KV6Wf4tk4j+HqiAf8gW0Dfbg==
dependencies:
"@conveyal/lonlat" "^1.4.1"
"@mapbox/polyline" "^1.1.0"
"@opentripplanner/geocoder" "^3.0.0"
"@styled-icons/foundation" "^10.34.0"
"@turf/along" "^6.0.1"
chroma-js "^2.4.2"
date-fns "^2.28.0"
date-fns-tz "^1.2.2"
graphql "^16.6.0"
lodash.clonedeep "^4.5.0"
lodash.isequal "^4.5.0"
qs "^6.9.1"

"@opentripplanner/core-utils@^11.4.0":
version "11.4.2"
resolved "https://registry.yarnpkg.com/@opentripplanner/core-utils/-/core-utils-11.4.2.tgz#cc6034fb80ccda44e50f7f0a1e80a7bad8387f84"
Expand Down
Loading