(expandedLinesState);
@@ -50,28 +61,19 @@ export const LinesValidityList = ({
useEffect(() => {
setSelectedValidity(defaultSelectedValidity);
- }, [defaultSelectedValidity])
+ }, [defaultSelectedValidity]);
useEffect(() => {
lineStatistics &&
- setSortedLineNumbers(
- sortLines(sorting, lineStatistics, selectedValidity),
- );
+ setSortedLineNumbers(
+ sortLines(sorting, lineStatistics, selectedValidity),
+ );
}, [lineStatistics, selectedValidity, sorting]);
- const DayTypesValidity = ({
- index,
- lineNumber,
- }: {
- index: number;
- lineNumber: string;
- }) => (
+ const DayTypesValidity = ({ lineNumber }: { lineNumber: string }) => (
<>
{lineStatistics.linesMap[lineNumber].lines.map((l, i) => (
-
+
))}
>
);
@@ -80,51 +82,70 @@ export const LinesValidityList = ({
<>
{listTitle}
-
+
{!sortedLineNumbers || sortedLineNumbers.length === 0 ? (
{selectedValidity === Validity.ALL
? infoText(locale).noLinesFoundInfo
- : infoText(locale).foundNot(validityCategoryLabel(locale)[selectedValidity])}
+ : infoText(locale).foundNot(
+ validityCategoryLabel(locale)[selectedValidity],
+ )}
) : (
<>
- {sortedLineNumbers.length > 1 &&
-
- }
- {sortedLineNumbers.map((lineNumber, index) => (
- <>
- toggleLineOpen(lineNumber)}
- effectivePeriodsForLineNumber={lineStatistics.linesMap[lineNumber].effectivePeriods as PeriodValidity[]}
- lineNumber={lineNumber}
- lineNames={lineStatistics.linesMap[lineNumber].lineNames.join(', ')}
- key={`LineItem${randomId}${index}`}
- numberOfDaysHeader={
- 1 && (
+
+ )}
+ {sortedLineNumbers
+ .filter(
+ (lineNumber) =>
+ selectedLineType === LineType.ALL ||
+ !lineStatistics.linesMap[lineNumber].lineType ||
+ lineStatistics.linesMap[lineNumber].lineType ===
+ selectedLineType,
+ )
+ .map((lineNumber, index) => (
+ <>
+ toggleLineOpen(lineNumber)}
+ effectivePeriodsForLineNumber={
+ lineStatistics.linesMap[lineNumber]
+ .effectivePeriods as PeriodValidity[]
+ }
+ lineNumber={lineNumber}
+ lineNames={lineStatistics.linesMap[
+ lineNumber
+ ].lineNames.join(', ')}
+ key={`LineItem${randomId}${index}`}
+ numberOfDaysHeader={
+
+ }
+ linesValidityListHeader={
+
+ }
+ >
+
- }
- linesValidityListHeader={
-
- }
- >
-
-
- >
- ))}
+
+ >
+ ))}
>
)}
diff --git a/src/lineStatistics/exportedLineStatisticsForAllProviders.tsx b/src/lineStatistics/exportedLineStatisticsForAllProviders.tsx
index bb157cd..768ed03 100644
--- a/src/lineStatistics/exportedLineStatisticsForAllProviders.tsx
+++ b/src/lineStatistics/exportedLineStatisticsForAllProviders.tsx
@@ -1,20 +1,31 @@
-import React from 'react';
-import { Provider, Validity } from './lineStatistics.types';
+import React, { useState } from 'react';
+import { LineType, Provider, Validity } from './lineStatistics.types';
import style from './lineStatistics.module.scss';
import { useLocale } from '../appContext';
-import { LineStatisticsPerProviderId } from "./apiHooks/lineStatistics.response.types";
-import { Card } from "./components/card/card";
-import { titleText } from "./lineStatistics.constants";
-import { LinesValidityList } from "./components/linesValidity/linesValidityList";
+import { LineStatisticsPerProviderId } from './apiHooks/lineStatistics.response.types';
+import { Card } from './components/card/card';
+import { titleText } from './lineStatistics.constants';
+import { LinesValidityList } from './components/linesValidity/linesValidityList';
+import { LineTypeChips } from './components/linesValidity/linesFilters/lineTypeChips';
interface Props {
onClose: () => void;
allProviders: Provider[] | undefined;
exportedLineStatistics: LineStatisticsPerProviderId | undefined;
+ defaultSelectedLineType: LineType;
}
-export const ExportedLineStatisticsForAllProviders = ({ onClose, allProviders, exportedLineStatistics }: Props) => {
+export const ExportedLineStatisticsForAllProviders = ({
+ onClose,
+ allProviders,
+ exportedLineStatistics,
+ defaultSelectedLineType,
+}: Props) => {
const locale = useLocale();
+ const [selectedLineType, setSelectedLineType] = useState(
+ defaultSelectedLineType,
+ );
+
return (
<>
+
{allProviders &&
- exportedLineStatistics && (
- allProviders
- .filter(
- (provider) =>
- Object.keys(exportedLineStatistics).some(
- (key) => key === String(provider.id),
- ),
- )
- .map((provider, index) => (
-
- )
- )
- )}
+ exportedLineStatistics &&
+ allProviders
+ .filter((provider) =>
+ Object.keys(exportedLineStatistics).some(
+ (key) => key === String(provider.id),
+ ),
+ )
+ .map((provider, index) => (
+
+ ))}
>
diff --git a/src/lineStatistics/lineStatistics.constants.ts b/src/lineStatistics/lineStatistics.constants.ts
index 7fdcd68..b70969a 100644
--- a/src/lineStatistics/lineStatistics.constants.ts
+++ b/src/lineStatistics/lineStatistics.constants.ts
@@ -1,4 +1,14 @@
-import { Locale, Validity } from './lineStatistics.types';
+import { LineType, Locale, Validity } from './lineStatistics.types';
+
+export const lineTypeLabel = (locale?: Locale) => ({
+ [LineType.ALL]: textForLocale('Alle', 'All', locale),
+ [LineType.FIXED]: textForLocale('Faste linjer', 'Fixed lines', locale),
+ [LineType.FLEXIBLE]: textForLocale(
+ 'Flexible linjer',
+ 'Flexible lines',
+ locale,
+ ),
+});
export const validityCategoryLabel = (locale?: Locale) => ({
[Validity.INVALID]: textForLocale('Utgåtte linjer', 'Expired lines', locale),
@@ -52,7 +62,8 @@ export const infoText = (locale?: Locale) => ({
export const titleText = (locale?: Locale) => ({
sortLines: textForLocale('Sorter linjer', 'Sort lines', locale),
- selectLines: textForLocale('Velg linjer ', 'Select lines', locale),
+ selectLines: textForLocale('Velg linjer', 'Select lines', locale),
+ selectLineTypes: textForLocale('Velg linjetype', 'Select line type', locale),
lineStatisticsFromNplan: textForLocale(
'Linjestatus fra NPlan',
'Line statistics from Nplan',
diff --git a/src/lineStatistics/lineStatistics.types.ts b/src/lineStatistics/lineStatistics.types.ts
index 25a6f56..ebe4de1 100644
--- a/src/lineStatistics/lineStatistics.types.ts
+++ b/src/lineStatistics/lineStatistics.types.ts
@@ -46,6 +46,7 @@ export interface PublicLine {
lineNumber: string;
lineNames: string[];
effectivePeriods: Period[] | PeriodValidity[];
+ lineType: LineType;
lines: Line[];
}
@@ -57,3 +58,9 @@ export enum Locale {
NO = 'NO',
EN = 'EN',
}
+
+export enum LineType {
+ ALL = 'ALL',
+ FIXED = 'FIXED',
+ FLEXIBLE = 'FLEXIBLE',
+}
diff --git a/src/lineStatistics/lineStatisticsCalculator/exportedLineStatisticsCalculator.ts b/src/lineStatistics/lineStatisticsCalculator/exportedLineStatisticsCalculator.ts
index 90e8763..dcc5f94 100644
--- a/src/lineStatistics/lineStatisticsCalculator/exportedLineStatisticsCalculator.ts
+++ b/src/lineStatistics/lineStatisticsCalculator/exportedLineStatisticsCalculator.ts
@@ -1,10 +1,10 @@
import moment, { Moment } from 'moment';
import {
+ Line,
LineNumbers,
LinesMap,
LineStatistics,
PeriodValidity,
- Timetable,
Validity,
} from '../lineStatistics.types';
import {
@@ -21,7 +21,6 @@ import { ExportedLineStatisticsResponse } from '../apiHooks/lineStatistics.respo
export const calculateExportedLineStatistics = (
exportedLineStatisticsResponse: ExportedLineStatisticsResponse,
): LineStatistics => {
-
const startDateLine: Moment = moment(
exportedLineStatisticsResponse.startDate,
'YYYY-MM-DD',
@@ -86,47 +85,41 @@ export const calculateExportedLineStatistics = (
const daysValid: number =
getDaysRange(startDateLine, publicLineValidPeriod) || 0;
-
- const timetables: Timetable[] = publicLine.lines.flatMap(
- (line, lineIndex) => {
- return line.exportedDayTypesStatistics.map(
- (dayType, dayTypeIndex) => ({
- id: dayTypeIndex,
- objectId: dayType.serviceJourneyName
- ? `${dayType.dayTypeNetexId} (${dayType.serviceJourneyName})`
- : dayType.dayTypeNetexId,
- periods: [
- {
- to: dayType.operatingPeriodTo,
- from: dayType.operatingPeriodFrom,
- timelineStartPosition: findTimeLineStartPositionForTimeTable(
- dayType.operatingPeriodFrom,
- startDateLine,
- 180,
- ),
- timelineEndPosition: findTimeLineEndPositionForTimeTable(
- dayType.operatingPeriodTo,
- endDateLine,
- 180,
- ),
- },
- ],
- }),
- );
- },
- );
+ const lines: Line[] = publicLine.lines.flatMap((line) => ({
+ timetables: line.exportedDayTypesStatistics.map(
+ (dayType, dayTypeIndex) => ({
+ id: dayTypeIndex,
+ objectId: dayType.serviceJourneyName
+ ? `${dayType.dayTypeNetexId} (${dayType.serviceJourneyName})`
+ : dayType.dayTypeNetexId,
+ periods: [
+ {
+ to: dayType.operatingPeriodTo,
+ from: dayType.operatingPeriodFrom,
+ timelineStartPosition: findTimeLineStartPositionForTimeTable(
+ dayType.operatingPeriodFrom,
+ startDateLine,
+ 180,
+ ),
+ timelineEndPosition: findTimeLineEndPositionForTimeTable(
+ dayType.operatingPeriodTo,
+ endDateLine,
+ 180,
+ ),
+ },
+ ],
+ }),
+ ),
+ }));
return {
[publicLine.publicCode]: {
lineNumber: publicLine.publicCode,
lineNames: publicLine.lines.map((line) => line.lineName),
effectivePeriods: [effectivePeriodFormatted],
- lines: [
- {
- timetables,
- },
- ],
+ lines: lines,
daysValid: daysValid,
+ lineType: publicLine.lines[0].lineType,
},
};
})
diff --git a/src/lineStatistics/lineStatisticsForAllProviders.tsx b/src/lineStatistics/lineStatisticsForAllProviders.tsx
index 126fc6e..a44458d 100644
--- a/src/lineStatistics/lineStatisticsForAllProviders.tsx
+++ b/src/lineStatistics/lineStatisticsForAllProviders.tsx
@@ -1,20 +1,18 @@
import React, { useState } from 'react';
import { useAllProviders } from './apiHooks/useAllProviders';
import { useLineStatisticsForAllProviders } from './apiHooks/useLineStatisticsForAllProviders';
-import { Locale, Provider, Validity } from './lineStatistics.types';
+import { LineType, Locale, Provider, Validity } from './lineStatistics.types';
import { LinesValidity } from './components/linesValidity/linesValidity';
import { PieStatisticsForAllProviders } from './pieStatisticsForAllProviders';
import { useExportedLineStatisticsForAllProviders } from './apiHooks/useExportedLineStatisticsForAllProviders';
-import {
- IncompleteLineStatisticsError
-} from './components/incompleteLineStatisticsError/incompleteLineStatisticsError';
+import { IncompleteLineStatisticsError } from './components/incompleteLineStatisticsError/incompleteLineStatisticsError';
import { LoadingLineStatistics } from './components/loadingLineStatistics';
import { Card } from './components/card/card';
import style from './lineStatistics.module.scss';
import { useLocale } from '../appContext';
-import { FloatingButton } from "@entur/button";
-import { ExportedLineStatisticsForAllProviders } from "./exportedLineStatisticsForAllProviders";
-import { titleText } from "./lineStatistics.constants";
+import { FloatingButton } from '@entur/button';
+import { ExportedLineStatisticsForAllProviders } from './exportedLineStatisticsForAllProviders';
+import { titleText } from './lineStatistics.constants';
export const LineStatisticsForAllProviders = () => {
const locale = useLocale();
@@ -29,7 +27,8 @@ export const LineStatisticsForAllProviders = () => {
const [defaultSelectedValidity, setDefaultSelectedValidity] =
useState(Validity.ALL);
const [selectedProvider, setSelectedProvider] = useState();
- const [showAllExportedLineStatistics, setShowAllExportedLineStatistics] = useState(false);
+ const [showAllExportedLineStatistics, setShowAllExportedLineStatistics] =
+ useState(false);
const handlePieOnClick = (
selectedValidityCategory: Validity,
@@ -48,16 +47,19 @@ export const LineStatisticsForAllProviders = () => {
(!allProviders && !allProvidersError) ||
(!lineStatisticsForAllProviders && !lineStatisticsForAllProvidersError) ||
(!exportedLineStatisticsForAllProviders &&
- !exportedLineStatisticsForAllProvidersError);
+ !exportedLineStatisticsForAllProvidersError);
return (
- {showAllExportedLineStatistics ?
+ {showAllExportedLineStatistics ? (
setShowAllExportedLineStatistics(false)}
exportedLineStatistics={exportedLineStatisticsForAllProviders}
allProviders={allProviders}
- /> : <>
+ defaultSelectedLineType={LineType.ALL}
+ />
+ ) : (
+ <>
{selectedProvider ? (
setSelectedProvider(undefined)}
@@ -92,34 +94,38 @@ export const LineStatisticsForAllProviders = () => {
/>
{allProviders &&
- (lineStatisticsForAllProviders ||
- exportedLineStatisticsForAllProviders) && (
- <>
- {exportedLineStatisticsForAllProviders &&
-
setShowAllExportedLineStatistics(true)}
- style={{ margin: "20px" }}
- >
- {titleText(locale).showAllLinesFromNplan}
-
- }
-
- >
- )}
+ (lineStatisticsForAllProviders ||
+ exportedLineStatisticsForAllProviders) && (
+ <>
+ {exportedLineStatisticsForAllProviders && (
+
setShowAllExportedLineStatistics(true)}
+ style={{ margin: '20px' }}
+ >
+ {titleText(locale).showAllLinesFromNplan}
+
+ )}
+
+ >
+ )}
)}
>
- }
+ )}
);
};