From 556e47f7e44f7f533fbea49b1e6623c5c3d247a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Sch=C3=BCler?= Date: Fri, 3 May 2024 10:59:20 +0200 Subject: [PATCH] Refactored Scenario component - moved all Accordion controls to the Scenario component - unified syntax for component properties - Put sub-components into dedicated files - Removed (currently) unnecessary properties to avoid confusion --- new/src/components/Scenarios/Scenario.tsx | 106 +++++++----------- new/src/components/Scenarios/ScenarioCase.tsx | 30 +++++ new/src/components/Scenarios/ScenarioHead.tsx | 47 ++------ .../components/Scenarios/ScenarioOverview.tsx | 1 - new/src/components/Scenarios/ScenarioStep.tsx | 18 +++ 5 files changed, 103 insertions(+), 99 deletions(-) create mode 100644 new/src/components/Scenarios/ScenarioCase.tsx create mode 100644 new/src/components/Scenarios/ScenarioStep.tsx diff --git a/new/src/components/Scenarios/Scenario.tsx b/new/src/components/Scenarios/Scenario.tsx index 030a9c74..f215cf69 100644 --- a/new/src/components/Scenarios/Scenario.tsx +++ b/new/src/components/Scenarios/Scenario.tsx @@ -1,62 +1,80 @@ -import type {ScenarioCaseModel, ScenarioModel, StepModel} from "../../reportModel"; -import {Accordion, AccordionDetails, Box, Link, Typography} from "@mui/material"; +import type {ScenarioModel} from "../../reportModel"; +import {Accordion, AccordionDetails} from "@mui/material"; import {useCallback, useEffect, useState} from "react"; -import {processWords} from "../../wordProcessor"; import {ExpansionState} from "./ScenarioOverview"; import {ScenarioHead} from "./ScenarioHead"; -import {ScenarioCaption} from "./ScenarioCaption"; -import {addRuntimeInSeconds} from "../utils"; +import {ScenarioCase} from "./ScenarioCase"; +import {styled} from "@mui/material/styles"; +import MuiAccordionSummary, {AccordionSummaryProps} from "@mui/material/AccordionSummary"; +import ArrowForwardIosSharpIcon from "@mui/icons-material/ArrowForwardIosSharp"; export interface ScenarioProps { scenario: ScenarioModel; globalExpansionState: ExpansionState; onExpansionCallback: () => void; onCollapsionCallback: () => void; - reportName?: string; } -export function Scenario(props: ScenarioProps) { +const AccordionSummary = styled((props: AccordionSummaryProps) => ( + } + {...props} + /> +))(({ theme }) => ({ + backgroundColor: + theme.palette.mode === "dark" ? "rgba(255, 255, 255, .05)" : "rgba(0, 0, 0, .03)", + flexDirection: "row-reverse", + "& .MuiAccordionSummary-expandIconWrapper.Mui-expanded": { + transform: "rotate(90deg)" + }, + "& .MuiAccordionSummary-content": { + marginLeft: theme.spacing(1) + } +})); + +export function Scenario({ scenario, onExpansionCallback, onCollapsionCallback, globalExpansionState}: ScenarioProps) { const [expanded, setExpanded] = useState(false); useEffect(() => { - if (props.globalExpansionState === ExpansionState.COLLAPSED) { + if (globalExpansionState === ExpansionState.COLLAPSED) { setExpanded(false); } - if (props.globalExpansionState === ExpansionState.EXPANDED) { + if (globalExpansionState === ExpansionState.EXPANDED) { setExpanded(true); } - }, [props.globalExpansionState]); + }, [globalExpansionState]); const onExpansionChanged = useCallback( (isExpansion: boolean) => { setExpanded(isExpansion); - isExpansion ? props.onExpansionCallback() : props.onCollapsionCallback(); + isExpansion ? onExpansionCallback() : onCollapsionCallback(); }, [expanded] ); return (
- + { + onExpansionChanged(!expanded); + }} + > + + { - props.scenario.scenarioCases.map((scenarioCase) => { - return { + return } ) @@ -66,41 +84,3 @@ export function Scenario(props: ScenarioProps) {
); } - -function SingleCaseScenario(props: { - scenarioCase: ScenarioCaseModel; - expanded: boolean; - setExpanded: (expanded: boolean) => void; - reportName?: string; - summary: string; - className: string; -}) { - return ( - - {props.scenarioCase.steps.map((step: StepModel, index) => ( - - ))} - - - {props.className} - - - - ); -} - -function ScenarioStep(props: { step: StepModel }) { - const stepDescription = processWords(props.step.words); - return ( - - {stepDescription} {addRuntimeInSeconds(props.step.durationInNanos)} - - ); -} - - diff --git a/new/src/components/Scenarios/ScenarioCase.tsx b/new/src/components/Scenarios/ScenarioCase.tsx new file mode 100644 index 00000000..ccb5478d --- /dev/null +++ b/new/src/components/Scenarios/ScenarioCase.tsx @@ -0,0 +1,30 @@ +import {Box, Link, Typography} from "@mui/material"; +import { ScenarioCaseModel, StepModel } from "../../reportModel"; +import {ScenarioStep} from "./ScenarioStep"; + +export interface ScenarioCaseProps { + className: string, + scenarioCase: ScenarioCaseModel, +} +export function ScenarioCase({ + scenarioCase, + className, +} : ScenarioCaseProps) { + return ( + + {scenarioCase.steps.map((step: StepModel, index) => ( + + ))} + + + {className} + + + + ); +} \ No newline at end of file diff --git a/new/src/components/Scenarios/ScenarioHead.tsx b/new/src/components/Scenarios/ScenarioHead.tsx index 3d50f64c..9fb1b034 100644 --- a/new/src/components/Scenarios/ScenarioHead.tsx +++ b/new/src/components/Scenarios/ScenarioHead.tsx @@ -2,54 +2,31 @@ import {Grid, Typography} from "@mui/material"; import {ScenarioModel} from "../../reportModel"; import {processWords} from "../../wordProcessor"; import {StatusIcon} from "../StatusIconSelector"; -import {styled} from "@mui/material/styles"; -import MuiAccordionSummary, {AccordionSummaryProps} from "@mui/material/AccordionSummary"; -import ArrowForwardIosSharpIcon from "@mui/icons-material/ArrowForwardIosSharp"; import {ScenarioCaption} from "./ScenarioCaption"; import {addRuntimeInMilliseconds} from "../utils"; -export function ScenarioHead(props: { + +export interface ScenarioHeadProps { scenario: ScenarioModel; - expanded: boolean; - setExpanded: (expanded: boolean) => void; - reportName?: string; -}) { - const AccordionSummary = styled((props: AccordionSummaryProps) => ( - } - {...props} - /> - ))(({ theme }) => ({ - backgroundColor: - theme.palette.mode === "dark" ? "rgba(255, 255, 255, .05)" : "rgba(0, 0, 0, .03)", - flexDirection: "row-reverse", - "& .MuiAccordionSummary-expandIconWrapper.Mui-expanded": { - transform: "rotate(90deg)" - }, - "& .MuiAccordionSummary-content": { - marginLeft: theme.spacing(1) - } - })); +} - return { - props.setExpanded(!props.expanded); - }} - > +export function ScenarioHead({ + scenario, +} : ScenarioHeadProps) { + return ( - {props.scenario.classTitle} + {scenario.classTitle} - {processWords(props.scenario.description)} + {processWords(scenario.description)} - + - {addRuntimeInMilliseconds(props.scenario.scenarioCases[0].durationInNanos)} + {addRuntimeInMilliseconds(scenario.scenarioCases[0].durationInNanos)} - + ); } \ No newline at end of file diff --git a/new/src/components/Scenarios/ScenarioOverview.tsx b/new/src/components/Scenarios/ScenarioOverview.tsx index 27321a40..fd2786f1 100644 --- a/new/src/components/Scenarios/ScenarioOverview.tsx +++ b/new/src/components/Scenarios/ScenarioOverview.tsx @@ -63,7 +63,6 @@ export function ScenarioOverview(props: { .sort(compareByClassTitleAndDescriptionFn) .map(scenario => ( { diff --git a/new/src/components/Scenarios/ScenarioStep.tsx b/new/src/components/Scenarios/ScenarioStep.tsx new file mode 100644 index 00000000..18608720 --- /dev/null +++ b/new/src/components/Scenarios/ScenarioStep.tsx @@ -0,0 +1,18 @@ +import {processWords} from "../../wordProcessor"; +import {Typography} from "@mui/material"; +import {ScenarioCaption} from "./ScenarioCaption"; +import {addRuntimeInSeconds} from "../utils"; +import { StepModel } from "../../reportModel"; + +export interface ScenarioStepProps { + step: StepModel; +} + +export function ScenarioStep({ step }: ScenarioStepProps) { + const stepDescription = processWords(step.words); + return ( + + {stepDescription} {addRuntimeInSeconds(step.durationInNanos)} + + ); +} \ No newline at end of file