Skip to content

Commit

Permalink
refactor(config-types): Add and tweak types.
Browse files Browse the repository at this point in the history
  • Loading branch information
binh-dam-ibigroup committed Sep 28, 2023
1 parent 4f9cc21 commit 380094d
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 30 deletions.
23 changes: 17 additions & 6 deletions lib/components/app/app-menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,36 @@ 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'
import {
LanguageConfig,
AppMenuItemConfig as MenuItem
} from '../../util/config-types'
import { MainPanelContent } from '../../actions/ui-constants'
import { setMainPanelContent } from '../../actions/ui'
import startOver from '../util/start-over'

import AppMenuItem from './app-menu-item'
import PopupTriggerText from './popup-trigger-text'

type MenuItem = {
children?: MenuItem[]
href?: string
iconType?: string | JSX.Element
iconUrl?: string
id: string
isSelected?: boolean
label?: string | JSX.Element
lang?: string
onClick?: () => void
skipLocales?: boolean
subMenuDivider?: boolean
}

type AppMenuProps = {
activeLocale: string
callTakerEnabled?: boolean
extraMenuItems?: MenuItem[]
extraMenuItems?: AppMenuItemConfig[]
fieldTripEnabled?: boolean
language?: LanguageConfig
languageOptions: Record<string, any> | null
Expand Down Expand Up @@ -312,7 +323,7 @@ export const Icon = ({
iconType,
iconUrl
}: {
iconType: string
iconType?: string
iconUrl?: string
}): JSX.Element => {
// FIXME: add types to context
Expand Down
78 changes: 54 additions & 24 deletions lib/util/config-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,18 @@ import {
} from '@opentripplanner/types'
import { GeocoderConfig as GeocoderConfigOtpUI } from '@opentripplanner/geocoder'

/** Accessibility threshold settings */
export interface AccessibilityScoreThresholdConfig {
color: string
icon: string
text?: string
}

/** All accessibility score settings */
export interface AccessibilityScoreConfig {
gradationMap: Record<string, AccessibilityScoreThresholdConfig>
}

/** OTP URL settings */
export interface ApiConfig {
host: string
Expand All @@ -29,14 +41,10 @@ export interface ApiConfig {
export interface AppMenuItemConfig {
children?: AppMenuItemConfig[]
href?: string
iconType: string | JSX.Element
iconType?: string
iconUrl?: string
id: string
isSelected?: boolean
label: string | JSX.Element
lang?: string
onClick?: () => void
skipLocales?: boolean
label?: string
subMenuDivider?: boolean
}

Expand Down Expand Up @@ -71,23 +79,22 @@ export interface Auth0Config {
domain: string
}

/** OTP Middleware (Personas) settings */
export interface OtpMiddlewareConfig {
apiBaseUrl: string
apiKey?: string
supportsPushNotifications?: boolean
}

/** Local persistence setting */
export interface LocalPersistenceConfig {
strategy: 'localStorage'
// eslint-disable-next-line camelcase
terms_of_storage?: boolean
}

/** OTP Middleware (Personas) settings */
export interface MiddlewarePersistenceConfig {
auth0: Auth0Config
// eslint-disable-next-line camelcase
otp_middleware: OtpMiddlewareConfig
otp_middleware: {
apiBaseUrl: string
apiKey?: string
supportsPushNotifications?: boolean
}
strategy: 'otp_middleware'
}

Expand Down Expand Up @@ -249,8 +256,9 @@ export interface CO2Config extends CO2ConfigType {
}

export interface GeocoderConfig extends GeocoderConfigOtpUI {
layerColorMap?: Record<string, string>
maxNearbyStops?: number
resultColors?: Record<string, string>
resultsCount?: number
type: string
}

Expand Down Expand Up @@ -282,22 +290,41 @@ export interface TransitOperatorConfig extends TransitOperator {
modeColors?: Record<string, ModeColorConfig>
}

export interface AccessibilityScoreThresholdConfig {
color: string
icon: string
text?: string
}

export interface AccessibilityScoreConfig {
gradationMap: Record<string, AccessibilityScoreThresholdConfig>
/** Route Viewer config */
export interface RouteViewerConfig {
/** Whether to hide the route linear shape inside a flex zone of that route. */
hideRouteShapesWithinFlexZones?: boolean
/** Disable vehicle highlight if necessary (e.g. custom or inverted icons) */
vehicleIconHighlight?: boolean
/** Customize vehicle icon padding (the default iconPadding is 2px in otp-ui) */
vehicleIconPadding?: number
/** Interval for refreshing vehicle positions */
vehiclePositionRefreshSeconds?: number
}

/** Stop Viewer Config */
export interface StopViewerConfig {
/** Radius (in meters) for searching nearby stops, rental vehicles, park and rides etc. */
nearbyRadius?: number
/** The max. departures to show for each trip pattern in the Next Arrivals view */
numberOfDepartures?: number
/** Whether to display block IDs with each departure in the schedule view. */
showBlockIds?: boolean
/**
* Time window, in seconds, in which to search for next arrivals,
* so that, for example, if it is Friday and a route does
* not begin service again until Monday, we are showing its next
* departure and it is not entirely excluded from display.
*/
timeRange?: number
}

/** The main application configuration object */
export interface AppConfig {
accessibilityScore?: AccessibilityScoreConfig
api: ApiConfig
// Optional on declaration, populated with defaults in reducer if not configured.
autoPlan: AutoPlanConfig
autoPlan?: boolean | AutoPlanConfig
/** Whether the header brand should be clickable, and if so, reset the UI. */
brandClickable?: boolean
branding?: string
Expand All @@ -323,8 +350,11 @@ export interface AppConfig {
phoneFormatOptions: PhoneFormatConfig
popups?: PopupConfig
reportIssue?: ReportIssueConfig
routeModeOverrides?: Record<string, string>
routeViewer?: RouteViewerConfig
/** Approx delay in seconds to reset the UI to an initial URL if there is no user activity */
sessionTimeoutSeconds?: number
stopViewer?: StopViewerConfig
/** App title shown in the browser title bar. */
title?: string
transitOperators?: TransitOperatorConfig[]
Expand Down

0 comments on commit 380094d

Please sign in to comment.