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

Fix map expand button #1025

Merged
merged 7 commits into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
46 changes: 33 additions & 13 deletions __tests__/util/ui.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { getItineraryView, ItineraryView } from '../../lib/util/ui'
import {
getItineraryView,
getMapToggleNewItineraryView,
ItineraryView
} from '../../lib/util/ui'

describe('util > ui', () => {
describe('getItineraryView', () => {
Expand All @@ -17,18 +21,21 @@ describe('util > ui', () => {
)
})
it('returns an itinerary list view if URL contains ui_activeItinerary=-1 regardless of ui_itineraryView', () => {
expect(
getItineraryView({
ui_activeItinerary: -1,
ui_itineraryView: ItineraryView.FULL
})
).toBe(ItineraryView.LIST)
expect(
getItineraryView({
ui_activeItinerary: -1,
ui_itineraryView: ItineraryView.LEG
})
).toBe(ItineraryView.LIST)
const expectedValues = {
[ItineraryView.FULL]: ItineraryView.LIST,
[ItineraryView.LEG]: ItineraryView.LIST,
[ItineraryView.LEG_HIDDEN]: ItineraryView.LIST,
[ItineraryView.LIST]: ItineraryView.LIST,
[ItineraryView.LIST_HIDDEN]: ItineraryView.LIST_HIDDEN
}
Object.entries(expectedValues).forEach(([k, v]) => {
expect(
getItineraryView({
ui_activeItinerary: -1,
ui_itineraryView: k
})
).toBe(v)
})
})
it('returns the specified view mode when set in URL', () => {
expect(
Expand All @@ -39,4 +46,17 @@ describe('util > ui', () => {
).toBe(ItineraryView.LEG)
})
})
describe('getMapToggleNewItineraryView', () => {
it('should obtain the new itinerary view value', () => {
const expectedValues = {
[ItineraryView.LEG]: ItineraryView.LEG_HIDDEN,
[ItineraryView.LEG_HIDDEN]: ItineraryView.LEG,
[ItineraryView.LIST]: ItineraryView.LIST_HIDDEN,
[ItineraryView.LIST_HIDDEN]: ItineraryView.LIST
}
Object.entries(expectedValues).forEach(([k, v]) => {
expect(getMapToggleNewItineraryView(k)).toBe(v)
})
})
})
})
2 changes: 0 additions & 2 deletions lib/actions/apiV2.js
Original file line number Diff line number Diff line change
Expand Up @@ -879,8 +879,6 @@ export function routingQuery(searchId = null, updateSearchInReducer) {
})
)

dispatch(setItineraryView(ItineraryView.LIST))

combinations.forEach((combo, index) => {
const query = generateOtp2Query(combo)
dispatch(
Expand Down
32 changes: 11 additions & 21 deletions lib/actions/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ import {
getMatchingLocaleString,
loadLocaleData
} from '../util/i18n'
import { getModesForActiveAgencyFilter, getUiUrlParams } from '../util/state'
import {
getItineraryView,
getMapToggleNewItineraryView,
getPathFromParts,
isDefinedAndNotEqual,
ItineraryView
} from '../util/ui'
import { getModesForActiveAgencyFilter, getUiUrlParams } from '../util/state'

import {
clearActiveSearch,
Expand All @@ -39,7 +41,7 @@ export const setHoveredStop = createAction('SET_HOVERED_STOP')
const viewTrip = createAction('SET_VIEWED_TRIP')
const viewRoute = createAction('SET_VIEWED_ROUTE')
export const toggleAutoRefresh = createAction('TOGGLE_AUTO_REFRESH')
const setPreviousItineraryView = createAction('SET_PREVIOUS_ITINERARY_VIEW')
const settingItineraryView = createAction('SET_ITINERARY_VIEW')
export const setPopupContent = createAction('SET_POPUP_CONTENT')

// This code-less action calls the reducer code
Expand Down Expand Up @@ -314,21 +316,15 @@ export function handleBackButtonPress(e) {
export function setItineraryView(value) {
return function (dispatch, getState) {
const urlParams = coreUtils.query.getUrlParams()
const prevItineraryView = urlParams.ui_itineraryView || ItineraryView.LIST

// If the itinerary value is changed,
// set the desired ui query param
// set the desired ui query param (even if LIST, so it replaces the current value)
// and store the current view as previousItineraryView.
if (value !== urlParams.ui_itineraryView) {
if (value !== ItineraryView.LIST) {
urlParams.ui_itineraryView = value
} else if (urlParams.ui_itineraryView) {
// Remove the ui_itineraryView param if it is set to LIST (default).
delete urlParams.ui_itineraryView
}
if (value !== getItineraryView(urlParams)) {
urlParams.ui_itineraryView = value

dispatch(setUrlSearch(urlParams))
dispatch(setPreviousItineraryView(prevItineraryView))
dispatch(settingItineraryView(value))
}
}
}
Expand All @@ -340,16 +336,10 @@ export function setItineraryView(value) {
export function toggleBatchResultsMap() {
return function (dispatch, getState) {
const urlParams = coreUtils.query.getUrlParams()
const itineraryView = urlParams.ui_itineraryView || ItineraryView.LIST
const itineraryView = getItineraryView(urlParams)

if (itineraryView === ItineraryView.LEG) {
dispatch(setItineraryView(ItineraryView.LEG_HIDDEN))
} else if (itineraryView === ItineraryView.LIST) {
dispatch(setItineraryView(ItineraryView.LIST_HIDDEN))
} else {
const { previousItineraryView } = getState().otp.ui
dispatch(setItineraryView(previousItineraryView))
}
const newView = getMapToggleNewItineraryView(itineraryView)
dispatch(setItineraryView(newView))
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/components/mobile/batch-results-screen.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ const mapStateToProps = (state) => {
activeLeg: activeSearch ? activeSearch.activeLeg : null,
errors: getResponsesWithErrors(state),
itineraries: getActiveItineraries(state),
itineraryView: getItineraryView(urlParams)
itineraryView: getItineraryView(urlParams) || state.otp.ui.itineraryView
}
}

Expand Down
4 changes: 2 additions & 2 deletions lib/reducers/create-otp-reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -1053,9 +1053,9 @@ function createOtpReducer(config) {
})
case 'UPDATE_ITINERARY_FILTER':
return update(state, { filter: { $set: action.payload } })
case 'SET_PREVIOUS_ITINERARY_VIEW':
case 'SET_ITINERARY_VIEW':
return update(state, {
ui: { previousItineraryView: { $set: action.payload } }
ui: { itineraryView: { $set: action.payload } }
})
case 'UPDATE_LOCALE':
return update(state, {
Expand Down
22 changes: 21 additions & 1 deletion lib/util/ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,29 @@ export function getItineraryView({
((ui_activeItinerary === null ||
ui_activeItinerary === undefined ||
`${ui_activeItinerary}` === '-1') &&
ItineraryView.LIST) ||
(ui_itineraryView === ItineraryView.LIST_HIDDEN
? ItineraryView.LIST_HIDDEN
: ItineraryView.LIST)) ||
ui_itineraryView ||
(isDefinedAndNotEqual(ui_activeItinerary, -1) && ItineraryView.FULL) ||
ItineraryView.LIST
)
}

/**
* Gets the new itinerary view to display based on current view.
*/
export function getMapToggleNewItineraryView(
currentView: ItineraryView
): ItineraryView {
switch (currentView) {
case ItineraryView.LEG:
return ItineraryView.LEG_HIDDEN
case ItineraryView.LIST:
return ItineraryView.LIST_HIDDEN
case ItineraryView.LEG_HIDDEN:
return ItineraryView.LEG
default:
return ItineraryView.LIST
}
}
Loading