Skip to content

Commit 2ee4b74

Browse files
committed
refactor(web-ts-results): minor updates
Format the prettier files. Add some a11y. Improve directory structure Change the React import. Change the `moduleResolution` property from `Node` to `bundler` in tsconfig.json. Move the component props to the `Props` interfaces Remove `react-scripts` types. Remove unnecessary `JSX.Element` types. Remove unnecessary `<div>` types in DropDown.
1 parent 8977f28 commit 2ee4b74

37 files changed

+881
-772
lines changed

webdriver-ts-results/src/App.tsx

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,28 @@
1-
import * as React from "react";
1+
import React from "react";
22
import "./App.css";
33
import { FrameworkType, knownIssues } from "./Common";
4-
import ResultTable from "./ResultTable";
5-
import { SelectionBar } from "./selection/SelectionBar";
4+
import ResultTable from "./components/ResultTable";
5+
import { SelectionBar } from "./components/selection/SelectionBar";
66

7-
const App = (): JSX.Element => {
7+
const KnownIssuesList = () => {
8+
return (
9+
<>
10+
<h3>Known issues and notes</h3>
11+
{knownIssues.map((issue) => (
12+
<dl key={issue.issue.toFixed()} id={issue.issue.toFixed()}>
13+
<dt>
14+
<a target="_blank" rel="noopener noreferrer" href={issue.link}>
15+
{issue.issue.toFixed()}
16+
</a>
17+
</dt>
18+
<dd>{issue.text}</dd>
19+
</dl>
20+
))}
21+
</>
22+
);
23+
};
24+
25+
const App = () => {
826
// eslint-disable-next-line no-constant-condition
927
const disclaimer = false ? (
1028
<div>
@@ -29,29 +47,23 @@ const App = (): JSX.Element => {
2947
</p>
3048
);
3149

50+
const testEnvironmentInfo = (
51+
<p>
52+
The benchmark was run on a MacBook Pro 14 (32 GB RAM, 8/14 Cores, OSX 13.5
53+
(c)), Chrome 116.0.5845.82 (arm64) using the puppeteer benchmark driver
54+
with reduced tracing.
55+
</p>
56+
);
57+
3258
return (
3359
<div>
3460
{disclaimer}
35-
<p>
36-
The benchmark was run on a MacBook Pro 14 (32 GB RAM, 8/14 Cores, OSX
37-
13.5 (c)), Chrome 116.0.5845.82 (arm64)) using the puppeteer benchmark
38-
driver with reduced tracing.
39-
</p>
61+
{testEnvironmentInfo}
62+
4063
<SelectionBar showDurationSelection={false} />
4164
<ResultTable type={FrameworkType.KEYED} />
4265
<ResultTable type={FrameworkType.NON_KEYED} />
43-
44-
<h3>Known issues and notes</h3>
45-
{knownIssues.map((issue) => (
46-
<dl key={issue.issue.toFixed()} id={issue.issue.toFixed()}>
47-
<dt>
48-
<a target="_blank" rel="noopener noreferrer" href={issue.link}>
49-
{issue.issue.toFixed()}
50-
</a>
51-
</dt>
52-
<dd>{issue.text}</dd>
53-
</dl>
54-
))}
66+
<KnownIssuesList></KnownIssuesList>
5567
</div>
5668
);
5769
};
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import React, { useRef, useEffect } from "react";
2+
import Plotly from "plotly.js-cartesian-dist";
3+
4+
interface BoxPlotData {
5+
framework: string;
6+
values: number[];
7+
}
8+
9+
interface Props {
10+
traces: Array<BoxPlotData>;
11+
}
12+
13+
const BoxPlotTableChart = ({ traces }: Props) => {
14+
const elemRef = useRef(null);
15+
16+
useEffect(() => {
17+
const plotlTtraces = traces.map((t) => ({
18+
type: "box",
19+
y: t.values,
20+
boxpoints: false,
21+
jitter: 0.5,
22+
name: t.framework,
23+
boxmean: "sd",
24+
}));
25+
26+
const layout = {
27+
showlegend: false,
28+
margin: {
29+
l: 40,
30+
r: 0,
31+
b: 120,
32+
t: 0,
33+
pad: 0,
34+
},
35+
};
36+
Plotly.newPlot(elemRef.current, plotlTtraces, layout, {
37+
staticPlot: true,
38+
editable: false,
39+
});
40+
}, [traces]);
41+
return <div ref={elemRef} style={{ height: "100%", width: "100%" }}></div>;
42+
};
43+
44+
export default BoxPlotTableChart;
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import React from "react";
2+
import {
3+
Benchmark,
4+
Framework,
5+
ResultLookup,
6+
CpuDurationMode,
7+
} from "../../Common";
8+
import BoxPlotTableChart from "./BoxPlotTableChart";
9+
10+
interface Props {
11+
frameworks: Array<Framework>;
12+
benchmark: Benchmark;
13+
results: ResultLookup;
14+
currentSortKey: string;
15+
sortBy: (name: string) => void;
16+
cpuDurationMode: CpuDurationMode;
17+
}
18+
19+
const BoxPlotTableRow = ({
20+
frameworks,
21+
benchmark,
22+
results,
23+
currentSortKey,
24+
sortBy,
25+
cpuDurationMode,
26+
}: Props) => {
27+
const resultsValues = (framework: Framework) =>
28+
results(benchmark, framework)?.results[cpuDurationMode].values ?? [];
29+
30+
const handleSortByBenchmarkResults = (event: React.MouseEvent) => {
31+
event.preventDefault();
32+
sortBy(benchmark.id);
33+
};
34+
35+
const traces = frameworks.map((framework) => ({
36+
framework: framework.name,
37+
values: resultsValues(framework),
38+
}));
39+
40+
return (
41+
<tr key={benchmark.id} style={{ height: 400 }}>
42+
<th className="benchname">
43+
<button
44+
className={
45+
currentSortKey === benchmark.id
46+
? "sortKey textButton"
47+
: "textButton"
48+
}
49+
onClick={handleSortByBenchmarkResults}
50+
aria-label="Sort by benchmark results (from best to worst)"
51+
>
52+
{benchmark.label}
53+
</button>
54+
<div className="rowCount">{benchmark.description}</div>
55+
</th>
56+
<td>
57+
<BoxPlotTableChart traces={traces} />
58+
</td>
59+
</tr>
60+
);
61+
};
62+
63+
export default BoxPlotTableRow;
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import React from "react";
2+
import {
3+
Benchmark,
4+
Framework,
5+
ResultLookup,
6+
CpuDurationMode,
7+
} from "../../Common";
8+
import BoxPlotTableRow from "./BoxPlotTableRow";
9+
10+
interface Props {
11+
frameworks: Array<Framework>;
12+
benchmarks: Array<Benchmark>;
13+
results: ResultLookup;
14+
currentSortKey: string;
15+
sortBy: (name: string) => void;
16+
cpuDurationMode: CpuDurationMode;
17+
}
18+
19+
const BoxPlotTableRows = ({
20+
frameworks,
21+
benchmarks,
22+
results,
23+
currentSortKey,
24+
sortBy,
25+
cpuDurationMode,
26+
}: Props) => {
27+
return (
28+
<>
29+
{benchmarks.map((benchmark) => (
30+
<BoxPlotTableRow
31+
key={benchmark.id}
32+
frameworks={frameworks}
33+
benchmark={benchmark}
34+
results={results}
35+
currentSortKey={currentSortKey}
36+
sortBy={sortBy}
37+
cpuDurationMode={cpuDurationMode}
38+
/>
39+
))}
40+
</>
41+
);
42+
};
43+
44+
export default BoxPlotTableRows;
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import React from "react";
2+
import {
3+
SORT_BY_NAME,
4+
Benchmark,
5+
Framework,
6+
ResultLookup,
7+
CpuDurationMode,
8+
} from "../../Common";
9+
import BoxPlotTableRows from "./BoxPlotTableRows";
10+
11+
interface Props {
12+
frameworks: Array<Framework>;
13+
benchmarks: Array<Benchmark>;
14+
results: ResultLookup;
15+
currentSortKey: string;
16+
sortBy: (name: string) => void;
17+
cpuDurationMode: CpuDurationMode;
18+
}
19+
20+
const BoxPlotTable = ({
21+
frameworks,
22+
benchmarks,
23+
results,
24+
currentSortKey,
25+
sortBy,
26+
cpuDurationMode,
27+
}: Props) => {
28+
const handleSortByName = (event: React.MouseEvent) => {
29+
event.preventDefault();
30+
sortBy(SORT_BY_NAME);
31+
};
32+
33+
return (
34+
<div>
35+
<h3>Duration in milliseconds</h3>
36+
<table className="results">
37+
<thead>
38+
<tr>
39+
<th className="benchname">
40+
<button
41+
className={
42+
currentSortKey === SORT_BY_NAME
43+
? "sortKey textButton"
44+
: "textButton"
45+
}
46+
aria-label="Sort frameworks in ascending order (asc)"
47+
onClick={handleSortByName}
48+
>
49+
Name
50+
</button>
51+
</th>
52+
<th style={{ width: frameworks.length * 70 + 100 }}></th>
53+
</tr>
54+
</thead>
55+
<tbody>
56+
<BoxPlotTableRows
57+
results={results}
58+
frameworks={frameworks}
59+
benchmarks={benchmarks}
60+
currentSortKey={currentSortKey}
61+
sortBy={sortBy}
62+
cpuDurationMode={cpuDurationMode}
63+
/>
64+
</tbody>
65+
</table>
66+
</div>
67+
);
68+
};
69+
70+
export default BoxPlotTable;
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import React from "react";
2+
3+
interface Props {
4+
children: Array<JSX.Element>;
5+
selectNone: (event: React.SyntheticEvent) => void;
6+
selectAll: (event: React.SyntheticEvent) => void;
7+
isNoneSelected: boolean;
8+
areAllSelected: boolean;
9+
grid?: boolean;
10+
}
11+
12+
const DropDownContents = ({
13+
selectAll,
14+
selectNone,
15+
isNoneSelected,
16+
areAllSelected,
17+
children,
18+
grid = false,
19+
}: Props) => {
20+
const handleSelectNone = (event: React.MouseEvent) => {
21+
!isNoneSelected && selectNone(event);
22+
};
23+
24+
const handleSelectAll = (event: React.MouseEvent) => {
25+
!areAllSelected && selectAll(event);
26+
};
27+
28+
return (
29+
<div className="section">
30+
{children[0]}
31+
<div className="float-rt">
32+
<button
33+
className="textButton"
34+
onClick={handleSelectNone}
35+
disabled={isNoneSelected}
36+
aria-label="Select none"
37+
>
38+
None
39+
</button>
40+
&nbsp;
41+
<button
42+
className="textButton"
43+
onClick={handleSelectAll}
44+
disabled={areAllSelected}
45+
aria-label="Select all"
46+
>
47+
All
48+
</button>
49+
</div>
50+
<div className={grid ? "grid" : ""}>{children[1]}</div>
51+
</div>
52+
);
53+
};
54+
55+
export default DropDownContents;

webdriver-ts-results/src/selection/DropDown.tsx renamed to webdriver-ts-results/src/components/DropDown/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ interface Props {
66
width: string;
77
}
88

9-
const DropDown = ({ label, children, width }: Props): JSX.Element => {
9+
const DropDown = ({ label, children, width }: Props) => {
1010
const [open, setOpen] = useState(false);
1111
const toggle = useCallback(
1212
(event: React.SyntheticEvent<HTMLElement>) => {

0 commit comments

Comments
 (0)