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 operatorId filter to ArrivalByTime widget #204

Merged
merged 8 commits into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from 4 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
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
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const arrayGroup = function <T>(array: T[], f: (item: T) => string) {

export default function ArrivalByTimeChart({
data,
operatorId
}: {
data: {
id: string
Expand All @@ -34,8 +35,13 @@ export default function ArrivalByTimeChart({
percent: number
gtfs_route_date: string
gtfs_route_hour: string
}[]
}[],
operatorId: string
}) {
// Filter data if an operator is selected
if(operatorId !== ''){
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if(operatorId !== ''){
if(operatorId){

data = data.filter( item => operatorId && item.id === operatorId);
Copy link
Member

Choose a reason for hiding this comment

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

consider useMemo

	const blabla = useMemo(()=>data.filter( item => !operatorId || item.id === operatorId), [data, operatorId])

}
return (
<div className="chart">
{arrayGroup(data, (item) => item.id)
Expand Down
2 changes: 1 addition & 1 deletion src/pages/dashboard/DashboardPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ const DashboardPage = () => {
{loadingGrap ? (
<Skeleton active />
) : (
<ArrivalByTimeChart data={convertToGraphCompatibleStruct(graphData)} />
<ArrivalByTimeChart data={convertToGraphCompatibleStruct(graphData)} operatorId={operatorId} />
)}
</div>
</Grid>
Expand Down
1 change: 0 additions & 1 deletion src/pages/dashboard/HbarChart/HbarChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ export function HbarChart({
percent: percents[idx],
...entry,
}))
console.log(rows[0])

const wrapWithTooltip = (element: React.ReactElement, entry: Entry) => {
return (
Expand Down