Skip to content

Commit 88d3f4e

Browse files
committed
Add filters for scenario result type in scenario browser
1 parent 373c64b commit 88d3f4e

File tree

2 files changed

+45
-17
lines changed

2 files changed

+45
-17
lines changed

src/nscenario-report-browser/src/App.tsx

+26-16
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import React, {createContext, useContext, useEffect, useState} from 'react';
1+
import React, {useContext, useEffect, useState} from 'react';
22

33
import './App.css';
44
//import data from "./scenarios.json"
55
import DirectoryTree from 'antd/es/tree/DirectoryTree';
66
import { DataNode } from 'antd/es/tree';
7-
import { Card, Col, Row, Space, Statistic, Timeline} from "antd";
7+
import { Card, Col, Row, Statistic, Timeline} from "antd";
88

99
import {
1010
CheckCircleOutlined,
@@ -108,15 +108,27 @@ function findLongestCommonPrefix(strings: string[]): string {
108108
return prefix;
109109
}
110110

111+
enum TestResultType{
112+
All,
113+
Success,
114+
Failed
115+
}
116+
117+
export function StatisticsCtr(props: {scenarios:Scenario[], onSetFilter: (type:TestResultType) => void }) {
118+
var success = props.scenarios.filter(value => value.Status === 0).length;
119+
var failed = props.scenarios.filter(value => value.Status === 1).length;
120+
const [typeState, setTypeState] = useState(TestResultType.All)
121+
const setFilter = (type:TestResultType) => {
122+
type = typeState === type? TestResultType.All: type;
123+
props.onSetFilter(type);
124+
setTypeState(type);
125+
};
111126

112127

113-
export function StatisticsCtr(props: {scenarios:Scenario[]}) {
114-
var success = props.scenarios.filter(value => value.Status === 0).length
115-
var failed = props.scenarios.filter(value => value.Status === 1).length
116128
return (
117-
<Row gutter={16} style={{width:"100%"}}>
129+
<Row gutter={16} style={{width:"100%"}} className="filter-row">
118130
<Col span={8}>
119-
<Card bordered={false}>
131+
<Card bordered={false} onClick={()=> setFilter(TestResultType.All)} className={typeState === TestResultType.All ? "selected-filter":""}>
120132
<Statistic
121133
title="Total"
122134
value={props.scenarios.length}
@@ -126,7 +138,7 @@ export function StatisticsCtr(props: {scenarios:Scenario[]}) {
126138
</Card>
127139
</Col>
128140
<Col span={8}>
129-
<Card bordered={false}>
141+
<Card bordered={false} onClick={()=> setFilter(TestResultType.Success)} className={typeState === TestResultType.Success ? "selected-filter":""}>
130142
<Statistic
131143
title="Success"
132144
value={success}
@@ -136,7 +148,7 @@ export function StatisticsCtr(props: {scenarios:Scenario[]}) {
136148
</Card>
137149
</Col>
138150
<Col span={8}>
139-
<Card bordered={false}>
151+
<Card bordered={false} onClick={()=> setFilter(TestResultType.Failed)} className={typeState === TestResultType.Failed ? "selected-filter":""}>
140152
<Statistic
141153
title="Failed"
142154
value={failed}
@@ -183,7 +195,7 @@ export function ScenarioTitleCtr(props: {data:Scenario}) {
183195
}
184196
const ScenarioCtr = React.memo((props: {data:Scenario, isSelected:boolean}) =>{
185197
return (
186-
<Card id={props.data.ScenarioTitle.replace(/\W+/g,"-")} title={(<ScenarioTitleCtr data={props.data} /> )} style={{width:"auto", border: props.isSelected? "1px solid blue": "1px solid transparent", transition: "border-color 0.5s ease" }}>
198+
<Card className={`scenario-${props.data.Status}`} id={props.data.ScenarioTitle.replace(/\W+/g,"-")} title={(<ScenarioTitleCtr data={props.data} /> )} style={{width:"100%", border: props.isSelected? "1px solid blue": "1px solid transparent", transition: "border-color 0.5s ease", marginBottom: "20px" }}>
187199
<Timeline
188200
style={{paddingBottom:0}}
189201
mode={"left"}
@@ -248,7 +260,7 @@ function App() {
248260
const [treeState, setTreeState] = useState(treeData)
249261
const [selectedScenario, setSelectedScenario] = useState("")
250262
const [sourceControlState, setSourceControlState] = useState(scenarioData.SourceControlInfo)
251-
263+
const [typeState, setTypeState] = useState(TestResultType.All)
252264
let pathResolver = RepoPathResolver.TryToGetPathBuilder(sourceControlState, sourceControlState.RepositoryRootDir)
253265

254266
useEffect( () => {
@@ -265,7 +277,7 @@ function App() {
265277
});
266278

267279
return (
268-
<div className="App" style={{textAlign:"left", margin:0, padding:0}}>
280+
<div className={`App filter-${typeState}`} style={{textAlign:"left", margin:0, padding:0}}>
269281
<GlobalServicesContext.Provider value={{pathResolver: pathResolver}}>
270282
<Row style={{height: "calc(100vh - 10px)", background: "#EFEFEF"}}>
271283
<Col span={8} style={{ height:"100%", padding:"20px 0 20px 20px", overflowY:"scroll", overflowX:"hidden"}}>
@@ -280,12 +292,10 @@ function App() {
280292
</Col>
281293
<Col span={16} style={{height: "100%"}}>
282294
<Row justify={"center"} style={{height: "150px", padding: "20px 20px 20px 10px"}}>
283-
<StatisticsCtr scenarios={scenarioState} />
295+
<StatisticsCtr scenarios={scenarioState} onSetFilter={type => { setTypeState(type) }} />
284296
</Row>
285297
<Row style={{ height:"calc(100% - 200px)", padding:"0px 20px 20px 20px", overflowY: "scroll"}}>
286-
<Space direction={"vertical"} size="middle" style={{ display: 'flex', width: "100%"}}>
287-
{scenarioState.map(value => <ScenarioCtr data={value} isSelected={selectedScenario === value.ScenarioTitle} />)}
288-
</Space>
298+
{scenarioState.map(value => <ScenarioCtr data={value} isSelected={selectedScenario === value.ScenarioTitle} />)}
289299
</Row>
290300
<Row align={"bottom"} style={{height:"50px", }}>
291301
<Col span={24} style={{textAlign:"center", padding: "20px"}}>

src/nscenario-report-browser/src/index.css

+19-1
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,22 @@ code {
1414
.ant-timeline-item
1515
{
1616
padding-bottom: 5px!important;
17-
}
17+
}
18+
19+
.filter-row .ant-card
20+
{
21+
cursor: pointer;
22+
}
23+
.filter-row .ant-card.selected-filter
24+
{
25+
border: 1px solid blue;
26+
}
27+
28+
.App.filter-1 .scenario-1
29+
{
30+
display: none;
31+
}
32+
.App.filter-2 .scenario-0
33+
{
34+
display: none;
35+
}

0 commit comments

Comments
 (0)