Skip to content

Commit

Permalink
Using full line route ids
Browse files Browse the repository at this point in the history
  • Loading branch information
devinmatte committed Sep 1, 2024
1 parent 1240053 commit fcaf3c8
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 26 deletions.
34 changes: 34 additions & 0 deletions common/components/inputs/BranchSelector.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import React from 'react';
import { ButtonGroup } from '../general/ButtonGroup';
import type { LineRouteId } from '../../types/lines';

interface BranchSelectorProps {
routeId: LineRouteId;
setRouteId: (routeId: LineRouteId) => void;
}

enum GreenLineBranchOptions {
'Green-B' = 'B Branch',
'Green-C' = 'C Branch',
'Green-D' = 'D Branch',
'Green-E' = 'E Branch',
}

export const BranchSelector: React.FunctionComponent<BranchSelectorProps> = ({
routeId,
setRouteId,
}) => {
const selectedIndex = Object.keys(GreenLineBranchOptions).findIndex((route) => route === routeId);

return (
<div className={'flex w-full justify-center pt-2'}>
<ButtonGroup
selectedIndex={selectedIndex}
pressFunction={setRouteId}
options={Object.entries(GreenLineBranchOptions)}
additionalDivClass="md:w-auto"
additionalButtonClass="md:w-fit"
/>
</div>
);
};
2 changes: 1 addition & 1 deletion common/types/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export type FetchDeliveredTripMetricsOptions = {
export type FetchAlertDelaysByLineOptions = {
start_date?: string;
end_date?: string;
line?: Line;
line?: LineRouteId;
};

export enum FetchDeliveredTripMetricsParams {
Expand Down
13 changes: 12 additions & 1 deletion modules/delays/DelaysDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ import { Widget } from '../../common/components/widgets';
import { TotalDelayGraph } from './charts/TotalDelayGraph';
import { DelayBreakdownGraph } from './charts/DelayBreakdownGraph';
import { DelayByCategoryGraph } from './charts/DelayByCategoryGraph';
import { BranchSelector } from '../../common/components/inputs/BranchSelector';

Check failure on line 16 in modules/delays/DelaysDetails.tsx

View workflow job for this annotation

GitHub Actions / frontend (20, 3.12)

`../../common/components/inputs/BranchSelector` import should occur before import of `./charts/TotalDelayGraph`
import { lineToDefaultRouteId } from '../predictions/utils/utils';

Check failure on line 17 in modules/delays/DelaysDetails.tsx

View workflow job for this annotation

GitHub Actions / frontend (20, 3.12)

`../predictions/utils/utils` import should occur before import of `./charts/TotalDelayGraph`
import { LineRouteId } from '../../common/types/lines';

Check failure on line 18 in modules/delays/DelaysDetails.tsx

View workflow job for this annotation

GitHub Actions / frontend (20, 3.12)

`../../common/types/lines` import should occur before import of `./charts/TotalDelayGraph`

Check failure on line 18 in modules/delays/DelaysDetails.tsx

View workflow job for this annotation

GitHub Actions / frontend (20, 3.12)

All imports in the declaration are only used as types. Use `import type`

dayjs.extend(utc);

Expand All @@ -22,12 +25,17 @@ export function DelaysDetails() {
query: { startDate, endDate },
} = useDelimitatedRoute();

const [routeId, setRouteId] = React.useState<LineRouteId>(lineToDefaultRouteId(line));
const greenBranchToggle = React.useMemo(() => {
return line === 'line-green' && <BranchSelector routeId={routeId} setRouteId={setRouteId} />;
}, [line, routeId]);

const enabled = Boolean(startDate && endDate && line);
const alertDelays = useAlertDelays(
{
start_date: startDate,
end_date: endDate,
line,
line: routeId,
},
enabled
);
Expand All @@ -47,6 +55,7 @@ export function DelaysDetails() {
<ChartPlaceHolder query={alertDelays} />
</div>
)}
{greenBranchToggle}
</Widget>
<Widget title="Delay Time by Reason" ready={[alertDelays]}>
{delaysReady ? (
Expand All @@ -56,6 +65,7 @@ export function DelaysDetails() {
<ChartPlaceHolder query={alertDelays} />
</div>
)}
{greenBranchToggle}
</Widget>
<Widget title="Delay Time by Reason" ready={[alertDelays]}>
{delaysReady ? (
Expand All @@ -65,6 +75,7 @@ export function DelaysDetails() {
<ChartPlaceHolder query={alertDelays} />
</div>
)}
{greenBranchToggle}
</Widget>
</ChartPageDiv>
</PageWrapper>
Expand Down
26 changes: 3 additions & 23 deletions modules/predictions/PredictionsDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,15 @@ import { PageWrapper } from '../../common/layouts/PageWrapper';
import { ChartPageDiv } from '../../common/components/charts/ChartPageDiv';
import { usePredictionData } from '../../common/api/hooks/predictions';
import type { LineRouteId } from '../../common/types/lines';
import { ButtonGroup } from '../../common/components/general/ButtonGroup';
import { WidgetDiv } from '../../common/components/widgets/WidgetDiv';
import { Accordion } from '../../common/components/accordion/Accordion';
import { BranchSelector } from '../../common/components/inputs/BranchSelector';
import { lineToDefaultRouteId } from './utils/utils';
import { PredictionsGraphWrapper } from './charts/PredictionsGraphWrapper';
import { PredictionsBinsGraphWrapper } from './charts/PredictionsBinsGraphWrapper';

dayjs.extend(utc);

enum GreenLineBranchOptions {
'Green-B' = 'B Branch',
'Green-C' = 'C Branch',
'Green-D' = 'D Branch',
'Green-E' = 'E Branch',
}

export function PredictionsDetails() {
const {
line,
Expand All @@ -38,23 +31,10 @@ export function PredictionsDetails() {
React.useEffect(() => {
setRouteId(lineToDefaultRouteId(line));
}, [line]);
const selectedIndex = Object.keys(GreenLineBranchOptions).findIndex((route) => route === routeId);

const greenBranchToggle = React.useMemo(() => {
return (
line === 'line-green' && (
<div className={'flex w-full justify-center pt-2'}>
<ButtonGroup
selectedIndex={selectedIndex}
pressFunction={setRouteId}
options={Object.entries(GreenLineBranchOptions)}
additionalDivClass="md:w-auto"
additionalButtonClass="md:w-fit"
/>
</div>
)
);
}, [line, selectedIndex]);
return line === 'line-green' && <BranchSelector routeId={routeId} setRouteId={setRouteId} />;
}, [line, routeId]);

const predictions = usePredictionData(
{
Expand Down
10 changes: 9 additions & 1 deletion server/chalicelib/delays.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,15 @@ def delay_time_by_line(params: AlertDelaysByLineParams):
start_date = params["start_date"]
end_date = params["end_date"]
line = params["line"]
if line not in ["line-red", "line-blue", "line-green", "line-orange"]:
if line not in [
"Red",
"Blue",
"Orange",
"Green-B",
"Green-C",
"Green-D",
"Green-E",
]:
raise BadRequestError("Invalid Line key.")
except KeyError:
raise BadRequestError("Missing or invalid parameters.")
Expand Down

0 comments on commit fcaf3c8

Please sign in to comment.