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

auto-set sort direction on sort type change #1315

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open
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
7 changes: 6 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 {
DepartArriveDirectionMap,
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,7 @@ const DateTimeOptions = ({
importedUpdateItineraryFilter({
sort: {
...sort,
direction: DepartArriveDirectionMap[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 DepartArriveDirectionMap: Record<
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe rename to DepartArriveDefaultSortMap or something like this, to clarify it is a default setting?

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:
DepartArriveDirectionMap[
params.departArrive as DepartArriveValue
] || sort.direction,
type: DepartArriveTypeMap[params.departArrive as DepartArriveValue]
}
})
Expand Down
Loading