Skip to content

Commit

Permalink
filter returns scenario model array
Browse files Browse the repository at this point in the history
Signed-off-by: l-1squared <[email protected]>
  • Loading branch information
l-1squared committed Mar 1, 2024
1 parent 47d5088 commit aeb747d
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 51 deletions.
10 changes: 4 additions & 6 deletions new/src/ReportFilter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,29 +27,27 @@ describe("Report filter status filter", () => {
test("should filter by status", () => {
jest.spyOn(repository, "getReport").mockReturnValue(fullReport);

expect(filterByStatus(ScenarioStatusFilter.SUCCESS)
.flatMap(rep => rep.scenarios))
expect(filterByStatus(ScenarioStatusFilter.SUCCESS))
.toEqual([fullReport.scenarios[0].scenarios[0]]);
});

test("should ignore null status", () => {
jest.spyOn(repository, "getReport").mockReturnValue(fullReport);

expect(filterByStatus(ScenarioStatusFilter.SUCCESS, null)
.flatMap(rep => rep.scenarios))
expect(filterByStatus(ScenarioStatusFilter.SUCCESS, null))
.toEqual([fullReport.scenarios[0].scenarios[0]]);
});

test('should return the full report if no status is provided', () => {
jest.spyOn(repository, "getReport").mockReturnValue(fullReport);

expect(filterByStatus()).toEqual(fullReport.scenarios);
expect(filterByStatus()).toEqual(fullReport.scenarios.flatMap(s => s.scenarios));
});

test('should return the full report if null is provided', () => {
jest.spyOn(repository, "getReport").mockReturnValue(fullReport);

expect(filterByStatus(null)).toEqual(fullReport.scenarios);
expect(filterByStatus(null)).toEqual(fullReport.scenarios.flatMap(s => s.scenarios));

});
});
Expand Down
12 changes: 5 additions & 7 deletions new/src/ReportFilter.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
import {repository} from "./repository";
import ReportModel from "./reportModel";
import ReportModel, {ScenarioModel} from "./reportModel";
import {ScenarioStatusFilter} from "./components/ScenarioOverview/ScenarioCollectionHead";

export function filterByStatus(...statusParameter: (ScenarioStatusFilter | null)[]): ReportModel[] {
export function filterByStatus(...statusParameter: (ScenarioStatusFilter | null)[]): ScenarioModel[] {
const fullReport = repository.getReport();
const status = statusParameter
.filter(status => status !== null)
.map(s => s as ScenarioStatusFilter);

if (status.length === 0) {
return fullReport.scenarios;
}
const filteredReports = status.length === 0 ? fullReport.scenarios : filterReportByScenarioStatus(fullReport.scenarios, ...status);

return filterScenarios(fullReport.scenarios, ...status);
return filteredReports.flatMap(report => report.scenarios);
}

function filterScenarios(reports: ReportModel[], ...status: ScenarioStatusFilter[]) {
function filterReportByScenarioStatus(reports: ReportModel[], ...status: ScenarioStatusFilter[]) {
const filteredReports = [];
for (const report of reports) {
const filteredScenarios = report.scenarios.filter(
Expand Down
26 changes: 11 additions & 15 deletions new/src/components/Scenarios/ScenarioOverview.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import { ReportStatistics, ScenarioModel } from "../../reportModel";
import {
MenuBar,
ScenarioCollectionHead,
ScenarioStatusFilter
} from "../ScenarioOverview/ScenarioCollectionHead";
import { Scenario } from "./Scenario";
import { useState } from "react";
import { Grid } from "@mui/material";
import { filterByStatus } from "../../ReportFilter";
import { useSearchParams } from "react-router-dom";
import {ReportStatistics, ScenarioModel} from "../../reportModel";
import {MenuBar, ScenarioCollectionHead, ScenarioStatusFilter} from "../ScenarioOverview/ScenarioCollectionHead";
import {Scenario} from "./Scenario";
import {useState} from "react";
import {Grid} from "@mui/material";
import {filterByStatus} from "../../ReportFilter";
import {useSearchParams} from "react-router-dom";

export enum ExpansionState {
COLLAPSED,
Expand Down Expand Up @@ -64,8 +60,8 @@ export function ScenarioOverview(props: {
<div style={{ height: "40em" }}>
{filterByStatus(
searchParams.get("result") as ScenarioStatusFilter | null
).flatMap(reportModel => {
return reportModel.scenarios.map(scenario => (
).flatMap(scenario =>
(
<Scenario
reportName={props.reportName}
scenario={scenario}
Expand All @@ -77,8 +73,8 @@ export function ScenarioOverview(props: {
setAllExpanded(ExpansionState.INTERMEDIATE);
}}
/>
));
})}
)
)}
</div>
</Grid>
</Grid>
Expand Down
23 changes: 0 additions & 23 deletions new/src/test.test.ts

This file was deleted.

0 comments on commit aeb747d

Please sign in to comment.