Skip to content

Commit

Permalink
Changed Scenario UI structure
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert Schüler committed Mar 1, 2024
1 parent 0e6e778 commit 3af69b6
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 99 deletions.
10 changes: 6 additions & 4 deletions new/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import "./App.css";
import ReportModel, { ReportStatistics } from "./reportModel";
import ReportModel, {ReportStatistics} from "./reportModel";
import * as guaranteedStateScenario from "./sampleData/GuaranteedStateTestScenario.json";
import { SingleScenarioView } from "./components/Scenarios/SingleScenarioView";
import {ScenarioOverview} from "./components/Scenarios/ScenarioOverview";
import {useParams} from "react-router-dom";

export const statistics: ReportStatistics[] = [
Expand All @@ -25,9 +25,11 @@ function App() {
return (
<div className="App" aria-label="App">
{result}
<SingleScenarioView
<ScenarioOverview
title={"Mein Titel"}
description={"Meine Description"}
reportName={guaranteedStateReport.name}
scenario={guaranteedStateReport.scenarios[0]}
scenarios={[guaranteedStateReport.scenarios[0]]}
/>
</div>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ const Content = styled("div")(({ theme }) => ({
padding: theme.spacing(3)
}));

export function ScenarioOverview(props: ScenarioOverviewProps) {
export function ScenarioHead(props: ScenarioOverviewProps) {
return (
<div style={{ display: "flex" }}>
<Content>
Expand Down
88 changes: 88 additions & 0 deletions new/src/components/Scenarios/ScenarioOverview.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import { ReportStatistics, ScenarioModel } from "../../reportModel";
import { MenuBar, ScenarioHead } from "../ScenarioOverview/ScenarioHead";
import { Scenario } from "./Scenario";
import { useState } from "react";
import { Grid } from "@mui/material";

export function ScenarioOverview(props: { reportName: string, title: string, description: string, scenarios: ScenarioModel[] }) {
const [expanded, setExpanded] = useState(false);
return (
<>
<Grid container>
<Grid item xs={12} md={1}>
<div style={{ height: "100vh" }}>
<MenuBar />
</div>
</Grid>
<Grid item xs={12} md={11}>
{" "}
{/* Workshop: Extract to new component. */}
<Grid container direction="column">
<Grid item xs={12}>
<div style={{ height: "20em" }}>
<ScenarioHead
headers={{
aboveHeader: props.description,
header: props.title,
}}
statistic={createStatistics(props.scenarios)}
targets={{
minusButtonTarget: () => {
console.log("Collapsing stuff");
setExpanded(false);
},
plusButtonTarget: () => {
console.log("Expanding stuff");
setExpanded(true);
},
printButtonTarget: () => {
console.error("print not implemented");
},
bookmarkButtonTarget: () => {
console.error("bookmark not implemented");
}
}}
/>
</div>
</Grid>
</Grid>
<Grid item xs={12}>
<div style={{ height: "40em" }}>
<Scenario
reportName={props.reportName}
scenario={props.scenarios[0]}
accordionExpansion={{
expanded: expanded,
setExpanded: setExpanded
}}
></Scenario>
</div>
</Grid>
</Grid>
</Grid>
</>
);
}

function createStatistics(scenarios: ScenarioModel[]): ReportStatistics {
return {
numClasses: 1,
numScenarios: 1,
// numFailedScenarios: Math.sign(
// findNumberOfCasesWithStatus(scenario.scenarioCases, "FAILED")
// ),
numFailedScenarios: 1,
numCases: 1, //scenario.scenarioCases.length,
numFailedCases: 1, //findNumberOfCasesWithStatus(scenario.scenarioCases, "FAILED"),
numSteps: 1, //scenario.scenarioCases.map(value => value.steps.length).reduce(sum),
durationInNanos: 1, //scenario.durationInNanos,
numPendingScenarios: 1,
//Math.sign(
// findNumberOfCasesWithStatus(scenario.scenarioCases, "SCENARIO_PENDING")
//),
numSuccessfulScenarios: 1,
//Math.sign(
// findNumberOfCasesWithStatus(scenario.scenarioCases, "SUCCESS")
//)
};
}
97 changes: 3 additions & 94 deletions new/src/components/Scenarios/SingleScenarioView.tsx
Original file line number Diff line number Diff line change
@@ -1,96 +1,5 @@
import { ReportStatistics, ScenarioCaseModel, ScenarioModel } from "../../reportModel";
import { MenuBar, ScenarioOverview } from "../ScenarioOverview/ScenarioOverview";
import { Scenario } from "./Scenario";
import { useState } from "react";
import { Grid } from "@mui/material";
import {ScenarioProps} from "./Scenario";

export function SingleScenarioView(props: { reportName: string; scenario: ScenarioModel }) {
const [expanded, setExpanded] = useState(false);
return (
<>
<Grid container>
<Grid item xs={12} md={1}>
<div style={{ height: "100vh" }}>
<MenuBar />
</div>
</Grid>
<Grid item xs={12} md={11}>
{" "}
{/* Workshop: Extract to new component. */}
<Grid container direction="column">
<Grid item xs={12}>
<div style={{ height: "20em" }}>
<ScenarioOverview
headers={{
aboveHeader: props.scenario.className,
header: props.scenario.description
}}
statistic={createStatistics(props.scenario)}
targets={{
minusButtonTarget: () => {
console.log("Collapsing stuff");
setExpanded(false);
},
plusButtonTarget: () => {
console.log("Expanding stuff");
setExpanded(true);
},
printButtonTarget: () => {
console.error("print not implemented");
},
bookmarkButtonTarget: () => {
console.error("bookmark not implemented");
}
}}
/>
</div>
</Grid>
</Grid>
<Grid item xs={12}>
<div style={{ height: "40em" }}>
<Scenario
reportName={props.reportName}
scenario={props.scenario}
accordionExpansion={{
expanded: expanded,
setExpanded: setExpanded
}}
></Scenario>
</div>
</Grid>
</Grid>
</Grid>
</>
);
}
export function SingleScenarioView(scenario: ScenarioProps) {

function createStatistics(scenario: ScenarioModel): ReportStatistics {
return {
numClasses: 1,
numScenarios: 1,
numFailedScenarios: Math.sign(
findNumberOfCasesWithStatus(scenario.scenarioCases, "FAILED")
),
numCases: scenario.scenarioCases.length,
numFailedCases: findNumberOfCasesWithStatus(scenario.scenarioCases, "FAILED"),
numSteps: scenario.scenarioCases.map(value => value.steps.length).reduce(sum),
durationInNanos: scenario.durationInNanos,
numPendingScenarios: Math.sign(
findNumberOfCasesWithStatus(scenario.scenarioCases, "SCENARIO_PENDING")
),
numSuccessfulScenarios: Math.sign(
findNumberOfCasesWithStatus(scenario.scenarioCases, "SUCCESS")
)
};
}

function findNumberOfCasesWithStatus(
scenarioCases: ScenarioCaseModel[],
status: ScenarioCaseModel["status"]
): number {
return scenarioCases.filter(value => value.status === status).length;
}

function sum(left: number, right: number): number {
return left + right;
}
}

0 comments on commit 3af69b6

Please sign in to comment.