Skip to content

Commit bf345c8

Browse files
authored
Merge pull request #11 from oslabs-beta/louis/new-feature
Modularized code using a typescript file to import and refactoring code using engineering best practices
2 parents d1113a0 + 33ca0d4 commit bf345c8

File tree

5 files changed

+110
-137
lines changed

5 files changed

+110
-137
lines changed

src/app/components/FrontendTypes.ts

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import { SeriesPoint } from '@visx/shape/lib/types';
2+
3+
// PerformanceVisx types
4+
5+
export interface Series {
6+
data: {
7+
barStack: ActionObj[],
8+
}
9+
name: string
10+
}
11+
12+
interface ActionObj {
13+
name: string,
14+
seriesName: string,
15+
}
16+
17+
export interface PerfData {
18+
barStack: BarStackProp[],
19+
componentData?: Record<string, unknown>,
20+
maxTotalRender: number,
21+
}
22+
23+
interface BarStackProp {
24+
snapshotId: string,
25+
route: string,
26+
currentTab?: string,
27+
}
28+
29+
// On-hover data for BarGraph/BarGraphComparison.tsx
30+
export interface TooltipData {
31+
bar: SeriesPoint<snapshot>;
32+
key: string;
33+
index: number;
34+
height: number;
35+
width: number;
36+
x: number;
37+
y: number;
38+
color: string;
39+
}
40+
41+
export interface snapshot {
42+
snapshotId?: string;
43+
children: [];
44+
componentData: { actualDuration: number } | undefined;
45+
name: string;
46+
state: string;
47+
}
48+
49+
export interface margin {
50+
top: number;
51+
right: number;
52+
bottom: number;
53+
left: number;
54+
}
55+
56+
interface BarGraphBase {
57+
width: number,
58+
height: number,
59+
data: PerfData,
60+
comparison: string | Series | [],
61+
}
62+
63+
export interface BarGraphComparisonProps extends BarGraphBase {
64+
setSeries: () => void,
65+
series: number,
66+
setAction: () => void,
67+
}
68+
69+
export interface BarGraphProps extends BarGraphBase{
70+
setRoute: () => void,
71+
allRoutes: unknown,
72+
filteredSnapshots: unknown,
73+
snapshot: unknown,
74+
setSnapshot: () => void
75+
}

src/app/components/StateRoute/PerformanceVisx/BarGraph.tsx

Lines changed: 2 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// @ts-nocheck
22
import React, { useEffect, useState } from 'react';
33
import { BarStack } from '@visx/shape';
4-
import { SeriesPoint } from '@visx/shape/lib/types';
54
import { Group } from '@visx/group';
65
import { Grid } from '@visx/grid';
76
import { AxisBottom, AxisLeft } from '@visx/axis';
@@ -11,46 +10,7 @@ import { Text } from '@visx/text';
1110
import { schemeSet3 } from 'd3-scale-chromatic';
1211
import { onHover, onHoverExit, save } from '../../../actions/actions';
1312
import { useStoreContext } from '../../../store';
14-
15-
/* TYPESCRIPT */
16-
17-
interface margin {
18-
top: number;
19-
right: number;
20-
bottom: number;
21-
left: number;
22-
}
23-
24-
interface snapshot {
25-
snapshotId?: string;
26-
children: [];
27-
componentData: any;
28-
name: string;
29-
state: string;
30-
}
31-
32-
interface TooltipData {
33-
bar: SeriesPoint<snapshot>;
34-
key: string;
35-
index: number;
36-
height: number;
37-
width: number;
38-
x: number;
39-
y: number;
40-
color: string;
41-
}
42-
43-
interface BarGraphProps {
44-
width: number,
45-
height: number,
46-
data: Record<string, unknown>,
47-
comparison: unknown,
48-
setRoute: () => void,
49-
allRoutes: unknown,
50-
filteredSnapshots: unknown,
51-
snapshot: unknown,
52-
setSnapshot: () => void
53-
}
13+
import { snapshot, TooltipData, margin, BarGraphProps } from '../../FrontendTypes';
5414

5515
/* DEFAULTS */
5616
const margin = {
@@ -68,7 +28,7 @@ const tooltipStyles = {
6828
fontFamily: 'Roboto',
6929
};
7030

71-
const BarGraph = (props: BarGraphProps): unknown => {
31+
const BarGraph = (props: BarGraphProps): JSX.Element => {
7232
const [{ tabs, currentTab }, dispatch] = useStoreContext();
7333
const {
7434
width,

src/app/components/StateRoute/PerformanceVisx/BarGraphComparison.tsx

Lines changed: 12 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// @ts-nocheck
2+
/* eslint-disable no-param-reassign */
23
import React, { useEffect } from 'react';
34
import { BarStack } from '@visx/shape';
4-
import { SeriesPoint } from '@visx/shape/lib/types';
55
import { Group } from '@visx/group';
66
import { Grid } from '@visx/grid';
77
import { AxisBottom, AxisLeft } from '@visx/axis';
@@ -13,47 +13,13 @@ import { makeStyles } from '@material-ui/core/styles';
1313
import Select from '@material-ui/core/Select';
1414
import MenuItem from '@material-ui/core/MenuItem';
1515
import FormControl from '@material-ui/core/FormControl';
16-
import { onHover, onHoverExit, deleteSeries, setCurrentTabInApp } from '../../../actions/actions';
16+
import {
17+
onHover, onHoverExit, deleteSeries, setCurrentTabInApp,
18+
} from '../../../actions/actions';
1719
import { useStoreContext } from '../../../store';
18-
19-
/* TYPESCRIPT */
20-
21-
interface margin {
22-
top: number;
23-
right: number;
24-
bottom: number;
25-
left: number;
26-
}
27-
28-
interface snapshot {
29-
snapshotId?: string;
30-
children: [];
31-
componentData: any;
32-
name: string;
33-
state: string;
34-
}
35-
36-
// On-hover data.
37-
interface TooltipData {
38-
bar: SeriesPoint<snapshot>;
39-
key: string;
40-
index: number;
41-
height: number;
42-
width: number;
43-
x: number;
44-
y: number;
45-
color: string;
46-
}
47-
48-
interface BarGraphComparisonProps {
49-
width: number,
50-
height: number,
51-
data: Record<string, unknown>,
52-
comparison: string | [],
53-
setSeries: () => void,
54-
series: unknown,
55-
setAction: () => void,
56-
}
20+
import {
21+
snapshot, TooltipData, margin, BarGraphComparisonProps,
22+
} from '../../FrontendTypes';
5723

5824
/* DEFAULTS */
5925
const margin = {
@@ -71,7 +37,7 @@ const tooltipStyles = {
7137
fontFamily: 'Roboto',
7238
};
7339

74-
const BarGraphComparison = (props: BarGraphComparisonProps): unknown => {
40+
const BarGraphComparison = (props: BarGraphComparisonProps): JSX.Element => {
7541
const [{ tabs, currentTab }, dispatch] = useStoreContext();
7642
const {
7743
width, height, data, comparison, setSeries, series, setAction,
@@ -117,15 +83,15 @@ const BarGraphComparison = (props: BarGraphComparisonProps): unknown => {
11783
// We'll then use it in the renderingScale function and compare
11884
// with the render time of the current tab.
11985
// The max render time will determine the Y-axis's highest number.
120-
const calculateMaxTotalRender = serie => {
121-
const currentSeriesBarStacks = !comparison[serie]
86+
const calculateMaxTotalRender = (serie: number): number => {
87+
const currentSeriesBarStacks: number[] = !comparison[serie]
12288
? []
12389
: comparison[serie].data.barStack;
12490
if (currentSeriesBarStacks.length === 0) return 0;
12591
let currentMax = -Infinity;
12692
for (let i = 0; i < currentSeriesBarStacks.length; i += 1) {
127-
const renderTimes = Object.values(currentSeriesBarStacks[i]).slice(1);
128-
const renderTotal = renderTimes.reduce((acc, curr) => acc + curr);
93+
const renderTimes: number[] = Object.values(currentSeriesBarStacks[i]).slice(1);
94+
const renderTotal: number = renderTimes.reduce((acc, curr) => acc + curr);
12995
if (renderTotal > currentMax) currentMax = renderTotal;
13096
}
13197
return currentMax;

src/app/components/StateRoute/PerformanceVisx/BarGraphComparisonActions.tsx

Lines changed: 2 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// @ts-nocheck
22
import React, { useEffect } from 'react';
33
import { BarStack } from '@visx/shape';
4-
import { SeriesPoint } from '@visx/shape/lib/types';
54
import { Group } from '@visx/group';
65
import { Grid } from '@visx/grid';
76
import { AxisBottom, AxisLeft } from '@visx/axis';
@@ -15,35 +14,7 @@ import MenuItem from '@material-ui/core/MenuItem';
1514
import FormControl from '@material-ui/core/FormControl';
1615
import { deleteSeries, setCurrentTabInApp } from '../../../actions/actions';
1716
import { useStoreContext } from '../../../store';
18-
19-
/* TYPESCRIPT */
20-
21-
interface margin {
22-
top: number;
23-
right: number;
24-
bottom: number;
25-
left: number;
26-
}
27-
28-
interface snapshot {
29-
snapshotId?: string;
30-
children: [];
31-
componentData: any;
32-
name: string;
33-
state: string;
34-
}
35-
36-
// On-hover data.
37-
interface TooltipData {
38-
bar: SeriesPoint<snapshot>;
39-
key: string;
40-
index: number;
41-
height: number;
42-
width: number;
43-
x: number;
44-
y: number;
45-
color: string;
46-
}
17+
import { TooltipData, margin } from '../../FrontendTypes';
4718

4819
/* DEFAULTS */
4920
const margin = {
@@ -343,7 +314,7 @@ const BarGraphComparisonActions = props => {
343314
</div>
344315
<div>
345316
{
346-
`${tooltipData.bar.data[tooltipData.key]} ms`
317+
`${tooltipData.bar.data[tooltipData.key]} ms`
347318
}
348319
</div>
349320
<div>

0 commit comments

Comments
 (0)