-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
moved AllLinesChart to separate component (#272)
* moved AllLinesChart to separate component * moved WorstLinesChart logic to separate component * moved startDate and endDate to Dashboard, fix typo
- Loading branch information
Showing
4 changed files
with
143 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { Tooltip } from '@mui/material' | ||
import { Skeleton } from 'antd' | ||
import { Fragment } from 'react' | ||
import { TEXTS } from 'src/resources/texts' | ||
import OperatorHbarChart from '../OperatorHbarChart/OperatorHbarChart' | ||
import { GroupByRes, useGroupBy } from 'src/api/groupByService' | ||
import { FC } from 'react' | ||
import { Moment } from 'moment/moment' | ||
|
||
const convertToChartCompatibleStruct = (arr: GroupByRes[]) => { | ||
return arr.map((item: GroupByRes) => ({ | ||
id: item.operator_ref?.agency_id || 'Unknown', | ||
name: item.operator_ref?.agency_name || 'Unknown', | ||
total: item.total_planned_rides, | ||
actual: item.total_actual_rides, | ||
})) | ||
} | ||
|
||
interface AllChartComponentProps { | ||
startDate: Moment | ||
endDate: Moment | ||
} | ||
|
||
export const AllLinesChart: FC<AllChartComponentProps> = ({ startDate, endDate }) => { | ||
const [groupByOperatorData, groupByOperatorLoading] = useGroupBy({ | ||
dateTo: endDate, | ||
dateFrom: startDate, | ||
groupBy: 'operator_ref', | ||
}) | ||
|
||
return ( | ||
<div className="widget"> | ||
<h2 className="title"> | ||
{TEXTS.dashboard_page_title} | ||
<Tooltip | ||
title={convertLineFeedToHtmlTags(TEXTS.dashboard_tooltip_content)} | ||
placement="left" | ||
arrow> | ||
<span className="tooltip-icon">i</span> | ||
</Tooltip> | ||
</h2> | ||
{groupByOperatorLoading ? ( | ||
<Skeleton active /> | ||
) : ( | ||
<OperatorHbarChart operators={convertToChartCompatibleStruct(groupByOperatorData)} /> | ||
)} | ||
</div> | ||
) | ||
} | ||
|
||
function convertLineFeedToHtmlTags(srt: string): React.ReactNode { | ||
return srt.split('\n').map((row, i) => ( | ||
<Fragment key={i}> | ||
{row} | ||
<br /> | ||
</Fragment> | ||
)) | ||
} | ||
|
||
export default AllLinesChart |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { Skeleton } from 'antd' | ||
import { GroupByRes, useGroupBy } from 'src/api/groupByService' | ||
import LinesHbarChart from '../LineHbarChart/LinesHbarChart' | ||
import { TEXTS } from 'src/resources/texts' | ||
import { FC } from 'react' | ||
import { Moment } from 'moment/moment' | ||
|
||
interface WorstLinesChartProps { | ||
startDate: Moment | ||
endDate: Moment | ||
operatorId: string | ||
} | ||
|
||
export const WorstLinesChart: FC<WorstLinesChartProps> = ({ startDate, endDate, operatorId }) => { | ||
const [groupByLineData, lineDataLoading] = useGroupBy({ | ||
dateTo: endDate, | ||
dateFrom: startDate, | ||
groupBy: 'operator_ref,line_ref', | ||
}) | ||
|
||
const convertToWorstLineChartCompatibleStruct = (arr: GroupByRes[], operatorId: string) => { | ||
if (!arr || !arr.length) return [] | ||
return arr | ||
.filter( | ||
(row: GroupByRes) => row.operator_ref?.agency_id === operatorId || !Number(operatorId), | ||
) | ||
.map((item: GroupByRes) => ({ | ||
id: `${item.line_ref}|${item.operator_ref?.agency_id}` || 'Unknown', | ||
operator_name: item.operator_ref?.agency_name || 'Unknown', | ||
short_name: JSON.parse(item.route_short_name)[0], | ||
long_name: item.route_long_name, | ||
total: item.total_planned_rides, | ||
actual: item.total_actual_rides, | ||
})) | ||
} | ||
|
||
return ( | ||
<div className="widget"> | ||
<h2 className="title">{TEXTS.worst_lines_page_title}</h2> | ||
{lineDataLoading ? ( | ||
<Skeleton active /> | ||
) : ( | ||
<LinesHbarChart | ||
lines={convertToWorstLineChartCompatibleStruct(groupByLineData, operatorId)} | ||
operators_whitelist={['אלקטרה אפיקים', 'דן', 'מטרופולין', 'קווים', 'אגד']} | ||
/> | ||
)} | ||
</div> | ||
) | ||
} | ||
|
||
export default WorstLinesChart |