Skip to content

Commit

Permalink
Merge pull request #1315 from opentripplanner/auto-sort-on-sort
Browse files Browse the repository at this point in the history
auto-set sort direction on sort type change
  • Loading branch information
miles-grant-ibigroup authored Dec 26, 2024
2 parents 576b26b + 34e6266 commit e567ee7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lib/components/form/call-taker/date-time-picker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ import React, {
} from 'react'

import { AppReduxState, FilterType, SortType } from '../../../util/state-types'
import { DepartArriveTypeMap, DepartArriveValue } from '../date-time-modal'
import {
DepartArriveDefaultSortDirectionMap,
DepartArriveTypeMap,
DepartArriveValue
} from '../date-time-modal'
import { updateItineraryFilter } from '../../../actions/narrative'

const { getCurrentDate, OTP_API_DATE_FORMAT, OTP_API_TIME_FORMAT } =
Expand Down Expand Up @@ -220,6 +224,9 @@ const DateTimeOptions = ({
importedUpdateItineraryFilter({
sort: {
...sort,
direction:
DepartArriveDefaultSortDirectionMap[departArrive] ||
sort.direction,
type: DepartArriveTypeMap[newValue]
}
})
Expand Down
13 changes: 13 additions & 0 deletions lib/components/form/date-time-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@ export const DepartArriveTypeMap: Record<
NOW: 'DURATION'
}

export const DepartArriveDefaultSortDirectionMap: Record<
DepartArriveValue,
FilterType['sort']['direction']
> = {
ARRIVE: 'ASC',
DEPART: 'DESC',
NOW: 'DESC'
}

function DateTimeModal({
config,
date,
Expand All @@ -57,6 +66,10 @@ function DateTimeModal({
updateItineraryFilter({
sort: {
...sort,
direction:
DepartArriveDefaultSortDirectionMap[
params.departArrive as DepartArriveValue
] || sort.direction,
type: DepartArriveTypeMap[params.departArrive as DepartArriveValue]
}
})
Expand Down

0 comments on commit e567ee7

Please sign in to comment.