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

Add configuration types. #1017

Merged
merged 20 commits into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
b0dd5d0
refactor(config-types): Add config type file, use in app menu and pop…
binh-dam-ibigroup Sep 26, 2023
ce3e6f5
refactor(config-types): Add more types and reuse in desktop-nav.
binh-dam-ibigroup Sep 26, 2023
406f49d
refactor(config-types): Tweak types and comments.
binh-dam-ibigroup Sep 26, 2023
8f1bc56
refactor(config-types): Add phone format, reuse in phone notification…
binh-dam-ibigroup Sep 26, 2023
00c1b2d
refactor(config-types): Add more types
binh-dam-ibigroup Sep 26, 2023
db839d6
refactor(config-types): Add more types.
binh-dam-ibigroup Sep 27, 2023
0970b80
refactor(config-types): Tweak map types, add companies config.
binh-dam-ibigroup Sep 27, 2023
9961dd5
refactor(config-types): Add itinerary config
binh-dam-ibigroup Sep 27, 2023
6380069
refactor(sortOptions): Reuse types from config-types
binh-dam-ibigroup Sep 27, 2023
842a70a
refactor(config-types): Add carbon config
binh-dam-ibigroup Sep 27, 2023
f652d06
refactor(connected-trip-details): Remove displayCalories config field.
binh-dam-ibigroup Sep 27, 2023
e085a80
refactor(config-types): Add autoplan config
binh-dam-ibigroup Sep 27, 2023
ebee4c5
refactor(config-types): Add geocoder config
binh-dam-ibigroup Sep 27, 2023
21f730c
refactor(config-modes): Add modes config, reuse types.
binh-dam-ibigroup Sep 27, 2023
f6d2fbb
refactor(state-types): Introduce a basic redux state type, reuse in m…
binh-dam-ibigroup Sep 28, 2023
1c9f6e3
refactor(config-types): Add transit operators
binh-dam-ibigroup Sep 28, 2023
4f9cc21
refactor(config-types): Add accessibility score
binh-dam-ibigroup Sep 28, 2023
380094d
refactor(config-types): Add and tweak types.
binh-dam-ibigroup Sep 28, 2023
197f7ba
Merge branch 'dev' into config-typescript
binh-dam-ibigroup Sep 28, 2023
b807459
Merge branch 'dev' into config-typescript
binh-dam-ibigroup Oct 5, 2023
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: 0 additions & 2 deletions example-config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -351,8 +351,6 @@ itinerary:
disableMetroSeperatorDot: false
# Shows the duration of a leg below the leg in the metro itinerary summary
showLegDurations: false
# Allows calorie counts to be hidden
displayCalories: true
Comment on lines -354 to -355
Copy link
Collaborator

Choose a reason for hiding this comment

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

Was this behavior removed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Displaying calories was completely removed from OTP-UI, so this doesn't apply anymore.

# The sort option to use by default
# Available sort options: 'BEST', 'DURATION', 'ARRIVALTIME', 'WALKTIME', 'COST', 'DEPARTURETIME'
# defaultSort: "BEST" # Default
Expand Down
27 changes: 13 additions & 14 deletions lib/components/app/app-menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import type { WrappedComponentProps } from 'react-intl'
import * as callTakerActions from '../../actions/call-taker'
import * as fieldTripActions from '../../actions/field-trip'
import * as uiActions from '../../actions/ui'
import { AppMenuItemConfig, LanguageConfig } from '../../util/config-types'
import { AppReduxState } from '../../util/state-types'
import { ComponentContext } from '../../util/contexts'
import { getLanguageOptions } from '../../util/i18n'
import { isModuleEnabled, Modules } from '../../util/config'
Expand All @@ -29,28 +31,27 @@ import PopupTriggerText from './popup-trigger-text'
type MenuItem = {
children?: MenuItem[]
href?: string
iconType: string | JSX.Element
iconType?: string | JSX.Element
iconUrl?: string
id: string
isSelected?: boolean
label: string | JSX.Element
label?: string | JSX.Element
lang?: string
onClick?: () => void
skipLocales?: boolean
subMenuDivider: boolean
subMenuDivider?: boolean
}

type AppMenuProps = {
activeLocale: string
callTakerEnabled?: boolean
extraMenuItems?: MenuItem[]
extraMenuItems?: AppMenuItemConfig[]
fieldTripEnabled?: boolean
// Typescript TODO language and language options based on configLanguage.
language: Record<string, any> | null
language?: LanguageConfig
languageOptions: Record<string, any> | null
location: { search: string }
mailablesEnabled?: boolean
popupTarget: string
popupTarget?: string
reactRouterConfig?: { basename: string }
resetAndToggleCallHistory?: () => void
resetAndToggleFieldTrips?: () => void
Expand Down Expand Up @@ -89,7 +90,7 @@ class AppMenu extends Component<

_triggerPopup = () => {
const { popupTarget, setPopupContent } = this.props
setPopupContent(popupTarget)
if (popupTarget) setPopupContent(popupTarget)
Copy link
Member

Choose a reason for hiding this comment

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

Why is this change added?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

popupTarget is optional, so TypeScript forces this truthy check before triggering the popup.

}

_togglePane = () => {
Expand Down Expand Up @@ -288,10 +289,8 @@ class AppMenu extends Component<

// connect to the redux store

// FIXME: type otp config
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const mapStateToProps = (state: Record<string, any>) => {
const { extraMenuItems, language } = state.otp.config
const mapStateToProps = (state: AppReduxState) => {
const { extraMenuItems, language, popups } = state.otp.config
return {
activeLocale: state.otp.ui.locale,
callTakerEnabled: isModuleEnabled(state, Modules.CALL_TAKER),
Expand All @@ -300,7 +299,7 @@ const mapStateToProps = (state: Record<string, any>) => {
language,
languageOptions: getLanguageOptions(language),
mailablesEnabled: isModuleEnabled(state, Modules.MAILABLES),
popupTarget: state.otp.config?.popups?.launchers?.sidebarLink
popupTarget: popups?.launchers?.sidebarLink
}
}

Expand All @@ -324,7 +323,7 @@ export const Icon = ({
iconType,
iconUrl
}: {
iconType: string
iconType?: string
iconUrl?: string
}): JSX.Element => {
// FIXME: add types to context
Expand Down
12 changes: 7 additions & 5 deletions lib/components/app/desktop-nav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import styled from 'styled-components'

import * as uiActions from '../../actions/ui'
import { accountLinks, getAuth0Config } from '../../util/auth'
import { AppConfig } from '../../util/config-types'
import { AppReduxState } from '../../util/state-types'
import { DEFAULT_APP_TITLE } from '../../util/constants'
import InvisibleA11yLabel from '../util/invisible-a11y-label'
import NavLoginButtonAuth0 from '../user/nav-login-button-auth0'
Expand Down Expand Up @@ -40,7 +42,7 @@ const NavItemOnLargeScreens = styled(NavbarItem)`
// Typscript TODO: otpConfig type
export type Props = {
locale: string
otpConfig: any
otpConfig: AppConfig
popupTarget?: string
setPopupContent: (url: string) => void
}
Expand Down Expand Up @@ -143,12 +145,12 @@ const DesktopNav = ({
}

// connect to the redux store
// Typescript TODO: state type
const mapStateToProps = (state: any) => {
const mapStateToProps = (state: AppReduxState) => {
const { config: otpConfig } = state.otp
return {
locale: state.otp.ui.locale,
otpConfig: state.otp.config,
popupTarget: state.otp.config?.popups?.launchers?.toolbar
otpConfig,
popupTarget: otpConfig.popups?.launchers?.toolbar
}
}

Expand Down
8 changes: 3 additions & 5 deletions lib/components/app/popup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,13 @@ import coreUtils from '@opentripplanner/core-utils'
import React, { useCallback, useEffect } from 'react'
import styled from 'styled-components'

import { PopupLauncher, PopupTargetConfig } from '../../util/config-types'
import { StyledIconWrapper } from '../util/styledIcon'
import PageTitle from '../util/page-title'

type Props = {
content?: {
appendLocale?: boolean
id?: string
modal?: boolean
url?: string
content?: PopupTargetConfig & {
id?: PopupLauncher
}
hideModal: () => void
}
Expand Down
12 changes: 4 additions & 8 deletions lib/components/map/enhanced-stop-marker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,10 @@ import tinycolor from 'tinycolor2'

import * as mapActions from '../../actions/map'
import * as uiActions from '../../actions/ui'
import { AppReduxState } from '../../util/state-types'
import { ComponentContext } from '../../util/contexts'
import {
ConfiguredTransitMode,
SetLocationHandler,
SetViewedStopHandler
} from '../util/types'
import { getModeFromStop, getStopName } from '../../util/viewer'
import { SetLocationHandler, SetViewedStopHandler } from '../util/types'

interface OwnProps {
stop: Stop
Expand Down Expand Up @@ -166,12 +163,11 @@ class EnhancedStopMarker extends Component<Props> {
}
}

const mapStateToProps = (state: any, ownProps: OwnProps) => {
const mapStateToProps = (state: AppReduxState, ownProps: OwnProps) => {
const { highlightedStop } = state.otp.ui

const transitModes = state.otp.config.modes.transitModes
const modeColors: ModeColors = {}
transitModes.forEach((mode: ConfiguredTransitMode) => {
state.otp.config.modes.transitModes.forEach((mode) => {
Copy link
Member

Choose a reason for hiding this comment

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

Do you want to also add the
const { config: otpConfig } = state.otp here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Not needed, in this file, it is used only on this line.

modeColors[mode.mode] = mode.color
})

Expand Down
4 changes: 0 additions & 4 deletions lib/components/narrative/connected-trip-details.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@ const mapStateToProps = (state) => {
mediumId: null,
riderCategoryId: null
},
displayCalories:
typeof itinerary?.displayCalories === 'boolean'
Comment on lines -23 to -24
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why was this removed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Displaying calories was completely removed from OTP-UI, so this doesn't apply anymore.

? itinerary?.displayCalories
: undefined,
fareDetailsLayout: itinerary?.fareDetailsLayout || undefined,
fareKeyNameMap: itinerary?.fareKeyNameMap || {}
}
Expand Down
5 changes: 3 additions & 2 deletions lib/components/narrative/narrative-itineraries-header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import React, { useCallback } from 'react'
import styled from 'styled-components'

import { IconWithText, StyledIconWrapper } from '../util/styledIcon'
import { sortOptions, SortOptionsType } from '../util/sortOptions'
import { ItinerarySortOption } from '../../util/config-types'
import { sortOptions } from '../util/sortOptions'
import { SortResultsDropdown } from '../util/dropdown'
import { UnstyledButton } from '../util/unstyled-button'
import InvisibleA11yLabel from '../util/invisible-a11y-label'
Expand Down Expand Up @@ -53,7 +54,7 @@ export default function NarrativeItinerariesHeader({
sort
}: {
customBatchUiBackground?: boolean
enabledSortModes: SortOptionsType[]
enabledSortModes: ItinerarySortOption[]
errors: unknown[]
itineraries: unknown[]
itinerary: Itinerary
Expand Down
17 changes: 10 additions & 7 deletions lib/components/user/notification-prefs-pane.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import { ListGroup, ListGroupItem } from 'react-bootstrap'
import React from 'react'
import styled from 'styled-components'

import { AppReduxState } from '../../util/state-types'
import { GRAY_ON_WHITE } from '../util/colors'
import { PhoneFormatConfig } from '../../util/config-types'

import { FieldSet } from './styled'
import { PhoneVerificationSubmitHandler } from './phone-verification-form'
Expand All @@ -19,9 +21,7 @@ interface Props extends FormikProps<User> {
loggedInUser: User
onRequestPhoneVerificationCode: PhoneCodeRequestHandler
onSendPhoneVerificationCode: PhoneVerificationSubmitHandler
phoneFormatOptions: {
countryCode: string
}
phoneFormatOptions: PhoneFormatConfig
}

const allNotificationChannels = ['email', 'sms', 'push']
Expand Down Expand Up @@ -121,14 +121,17 @@ const NotificationPrefsPane = ({
)
}

const mapStateToProps = (state: any) => {
const { supportsPushNotifications } =
state.otp.config.persistence?.otp_middleware || {}
const mapStateToProps = (state: AppReduxState) => {
const { persistence, phoneFormatOptions } = state.otp.config
const supportsPushNotifications =
persistence && 'otp_middleware' in persistence
? persistence.otp_middleware?.supportsPushNotifications
: false
return {
allowedNotificationChannels: supportsPushNotifications
? allNotificationChannels
: emailAndSms,
phoneFormatOptions: state.otp.config.phoneFormatOptions
phoneFormatOptions
}
}

Expand Down
5 changes: 2 additions & 3 deletions lib/components/user/phone-change-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import React, {
import styled from 'styled-components'

import { InlineLoading } from '../narrative/loading'
import { PhoneFormatConfig } from '../../util/config-types'
import InvisibleA11yLabel from '../util/invisible-a11y-label'

import { ControlStrip, phoneFieldStyle } from './styled'
Expand Down Expand Up @@ -59,9 +60,7 @@ interface Props {
isSubmitting: boolean
onCancel: () => void
onSubmit: PhoneChangeSubmitHandler
phoneFormatOptions: {
countryCode: string
}
phoneFormatOptions: PhoneFormatConfig
showCancel?: boolean
}

Expand Down
5 changes: 2 additions & 3 deletions lib/components/user/phone-number-editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import styled from 'styled-components'
import { getAriaPhoneNumber } from '../../util/a11y'
import { GRAY_ON_WHITE } from '../util/colors'
import { isBlank } from '../../util/ui'
import { PhoneFormatConfig } from '../../util/config-types'
import InvisibleA11yLabel from '../util/invisible-a11y-label'

import { ControlStrip } from './styled'
Expand Down Expand Up @@ -40,9 +41,7 @@ interface Props {
intl: IntlShape
onRequestCode: PhoneCodeRequestHandler
onSubmitCode: PhoneVerificationSubmitHandler
phoneFormatOptions: {
countryCode: string
}
phoneFormatOptions: PhoneFormatConfig
}

interface State {
Expand Down
17 changes: 4 additions & 13 deletions lib/components/util/sortOptions.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,20 @@
import { IntlShape } from 'react-intl'

export type SortOptionsType =
| 'BEST'
| 'DURATION'
| 'ARRIVALTIME'
| 'DEPARTURETIME'
| 'WALKTIME'
| 'COST'
import { ItinerarySortOption } from '../../util/config-types'

type SortOptionEntry = { text: string; value: SortOptionsType }
type SortOptionEntry = { text: string; value: ItinerarySortOption }

export const sortOptions = (
intl: IntlShape,
enabledOptions: SortOptionsType[] = [
enabledOptions: ItinerarySortOption[] = [
'BEST',
'DURATION',
'ARRIVALTIME',
'WALKTIME',
'COST',
'DEPARTURETIME'
]
): {
text: string
value: string
}[] => {
): SortOptionEntry[] => {
const sortOptionsArray: SortOptionEntry[] = [
{
text: intl.formatMessage({
Expand Down
7 changes: 0 additions & 7 deletions lib/components/util/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,3 @@ export type SetViewedRouteHandler = (route?: ViewedRouteState) => void
export type SetViewedStopHandler = (payload: { stopId: string } | null) => void

export type SetLocationHandler = (payload: MapLocationActionArg) => void

export interface ConfiguredTransitMode {
Copy link
Member

Choose a reason for hiding this comment

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

Why is this interface being removed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I moved it to config-types.ts, and it is now called TransitModeConfig.

color?: string
label?: string
mode: string
showWheelchairSetting?: boolean
}
Loading
Loading