Skip to content

Commit

Permalink
Add operatorId filter to ArrivalByTime widget (hasadna#204)
Browse files Browse the repository at this point in the history
  • Loading branch information
Haswell-s authored Nov 16, 2023
1 parent 7af2ba6 commit ca03c59
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/pages/components/OperatorSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const OperatorSelector = ({
disablePortal
style={{ width: '100%' }}
value={value}
onChange={(e, value) => setOperatorId(value ? value.id : '0')}
onChange={(e, value) => setOperatorId(value ? value.id : '')}
id="operator-select"
options={operators}
renderInput={(params) => <TextField {...params} label={TEXTS.choose_operator} />}
Expand Down
7 changes: 7 additions & 0 deletions src/pages/dashboard/ArrivalByTimeChart/ArrivalByTimeChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
} from 'recharts'

import './ArrivalByTimeChats.scss'
import { useMemo } from 'react'

const arrayGroup = function <T>(array: T[], f: (item: T) => string) {
const groups: Record<string, T[]> = {}
Expand All @@ -25,6 +26,7 @@ const arrayGroup = function <T>(array: T[], f: (item: T) => string) {

export default function ArrivalByTimeChart({
data,
operatorId,
}: {
data: {
id: string
Expand All @@ -35,7 +37,12 @@ export default function ArrivalByTimeChart({
gtfs_route_date: string
gtfs_route_hour: string
}[]
operatorId: string
}) {
data = useMemo(
() => data.filter((item) => !operatorId || item.id === operatorId),
[data, operatorId],
)
return (
<div className="chart">
{arrayGroup(data, (item) => item.id)
Expand Down
5 changes: 4 additions & 1 deletion src/pages/dashboard/DashboardPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,10 @@ const DashboardPage = () => {
{loadingGrap ? (
<Skeleton active />
) : (
<ArrivalByTimeChart data={convertToGraphCompatibleStruct(graphData)} />
<ArrivalByTimeChart
data={convertToGraphCompatibleStruct(graphData)}
operatorId={operatorId}
/>
)}
</div>
</Grid>
Expand Down

0 comments on commit ca03c59

Please sign in to comment.