Skip to content

Commit 313e322

Browse files
committed
all components converted to typescript
1 parent 765cd2d commit 313e322

File tree

11 files changed

+80
-87
lines changed

11 files changed

+80
-87
lines changed

src/app/components/Action.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import React from 'react';
2-
import PropTypes from 'prop-types';
32
import { changeView, changeSlider } from '../actions/actions.ts';
43

54
interface ActionProps {
@@ -57,7 +56,7 @@ const Action = (props: ActionProps) => {
5756
// Edwin: invoking keyboard functionality; functionality is in ActionContainer;
5857
onKeyDown={(e: KeyboardEvent) => handleOnkeyDown(e, viewIndex)}
5958
className={selected || last ? 'action-component selected' : 'action-component'}
60-
onClick={() => {
59+
onClick={(e: MouseEvent) => {
6160
dispatch(changeView(index));
6261
}}
6362
role="presentation"

src/app/components/Diff.tsx

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
import React from 'react';
2-
import PropTypes from 'prop-types';
32
import { diff, formatters } from 'jsondiffpatch';
43
import ReactHtmlParser from 'react-html-parser';
5-
64
import { useStoreContext } from '../store.tsx';
75

86
interface DiffProps {
9-
snapshot: object;
7+
snapshot: {state:object | string};
108
show?: boolean;
119
}
1210

@@ -69,12 +67,4 @@ function Diff(props: DiffProps) {
6967
return <div>{ReactHtmlParser(html)}</div>;
7068
}
7169

72-
Diff.propTypes = {
73-
snapshot: PropTypes.shape({
74-
state: PropTypes.oneOfType([PropTypes.string, PropTypes.object]),
75-
children: PropTypes.arrayOf(PropTypes.object),
76-
}).isRequired,
77-
show: PropTypes.bool.isRequired,
78-
};
79-
8070
export default Diff;

src/app/components/DiffRoute.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import React from 'react';
2-
import PropTypes from 'prop-types';
32
import {
43
MemoryRouter as Router, Route, NavLink, Switch,
54
} from 'react-router-dom';

src/app/components/Dropdown.tsx

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
import React from 'react';
22
import Select from 'react-select';
3-
import PropTypes from 'prop-types';
43

5-
const Dropdown = props => {
4+
interface DropdownProps {
5+
selectedSpeed: { value: number; label: string },
6+
speeds: [];
7+
setSpeed: () => void;
8+
}
9+
10+
const Dropdown = (props: DropdownProps) => {
611
const { speeds, setSpeed, selectedSpeed } = props;
712
return (
813
<Select
@@ -16,10 +21,4 @@ const Dropdown = props => {
1621
);
1722
};
1823

19-
Dropdown.propTypes = {
20-
selectedSpeed: PropTypes.shape({ value: PropTypes.number, label: PropTypes.string }).isRequired,
21-
speeds: PropTypes.arrayOf(PropTypes.object).isRequired,
22-
setSpeed: PropTypes.func.isRequired,
23-
};
24-
2524
export default Dropdown;

src/app/components/ErrorHandler.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
import React from 'react';
22

3+
interface ErrorHandlerProps {
4+
state: { errorOccurred: boolean }
5+
}
6+
37
class ErrorHandler extends React.Component {
4-
constructor(props) {
8+
constructor(props:ErrorHandlerProps) {
59
super(props);
610
this.state = { errorOccurred: false };
711
}
812

9-
componentDidCatch(error, info) {
13+
componentDidCatch(error:string, info:string) {
1014
this.setState({ errorOccurred: true })
1115
console.log('Error occurred in React Component: ', error, info);
1216
}

src/app/components/MainSlider.tsx

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,18 @@
33
import React from 'react';
44
import Slider from 'rc-slider';
55
import Tooltip from 'rc-tooltip';
6-
import PropTypes from 'prop-types';
7-
86
import { changeSlider, pause } from '../actions/actions.ts';
97
import { useStoreContext } from '../store';
108

119
const { Handle } = Slider;
1210

13-
const handle = props => {
11+
interface handleProps {
12+
value: number,
13+
dragging: boolean,
14+
index: number
15+
};
16+
17+
const handle = (props: handleProps) => {
1418
const {
1519
value, dragging, index, ...restProps
1620
} = props;
@@ -28,7 +32,12 @@ const handle = props => {
2832
);
2933
};
3034

31-
function MainSlider({ snapshotsLength }) {
35+
interface MainSliderProps {
36+
snapshotsLength: number;
37+
};
38+
39+
function MainSlider(props: MainSliderProps) {
40+
const { snapshotsLength } = props
3241
const [{ tabs, currentTab }, dispatch] = useStoreContext();
3342
const { sliderIndex } = tabs[currentTab];
3443

@@ -37,7 +46,7 @@ function MainSlider({ snapshotsLength }) {
3746
min={0}
3847
max={snapshotsLength - 1}
3948
value={sliderIndex}
40-
onChange={index => {
49+
onChange={(index:any) => {
4150
const newIndex = index === -1 ? 0 : index;
4251
dispatch(changeSlider(newIndex));
4352
dispatch(pause());
@@ -47,8 +56,4 @@ function MainSlider({ snapshotsLength }) {
4756
);
4857
}
4958

50-
MainSlider.propTypes = {
51-
snapshotsLength: PropTypes.number.isRequired,
52-
};
53-
5459
export default MainSlider;

src/app/components/PerfView.tsx

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,19 @@ import { schemeSet1 as colorScheme } from 'd3';
2222

2323
// import { addNewSnapshots } from '../actions/actions.ts';
2424

25-
26-
const PerfView = ({ snapshots, viewIndex, width = 600, height = 600 }) => {
25+
interface PerfViewProps {
26+
snapshots:[];
27+
viewIndex:number;
28+
width: number;
29+
height: number;
30+
}
31+
32+
const PerfView = (props:PerfViewProps) => {
33+
const { snapshots, viewIndex, width = 600, height = 600 } = props
2734
const svgRef = useRef(null);
2835

2936
// Figure out which snapshot index to use
30-
let indexToDisplay = null;
37+
let indexToDisplay: number | null = null;
3138
if (viewIndex < 0) indexToDisplay = snapshots.length - 1;
3239
else indexToDisplay = viewIndex;
3340

@@ -39,13 +46,13 @@ const PerfView = ({ snapshots, viewIndex, width = 600, height = 600 }) => {
3946
.interpolate(d3.interpolateHcl);
4047

4148
// Set up circle-packing layout function
42-
const packFunc = useCallback(data => {
49+
const packFunc = useCallback((data:object) => {
4350
return d3.pack()
4451
.size([width, height])
4552
// .radius(d => { return d.r; })
4653
.padding(3)(d3.hierarchy(data)
47-
.sum(d => { return d.componentData.actualDuration || 0; })
48-
.sort((a, b) => { return b.value - a.value; }));
54+
.sum((d:{componentData?:{actualDuration?:number}}) => { return d.componentData.actualDuration || 0; })
55+
.sort((a:{value:number}, b:{value:number}) => { return b.value - a.value; }));
4956
}, [width, height]);
5057

5158
// If indexToDisplay changes, clear old tree nodes
@@ -81,21 +88,21 @@ const PerfView = ({ snapshots, viewIndex, width = 600, height = 600 }) => {
8188
.selectAll('circle')
8289
.data(packedRoot.descendants().slice(1))
8390
.enter().append('circle')
84-
.attr('fill', d => (d.children ? colorScale(d.depth) : 'white'))
85-
.attr('pointer-events', d => (!d.children ? 'none' : null))
91+
.attr('fill', (d:{children:[]; depth:number}) => (d.children ? colorScale(d.depth) : 'white'))
92+
.attr('pointer-events', (d?:{children:[]}) => (!d.children ? 'none' : null))
8693
.on('mouseover', function () { d3.select(this).attr('stroke', '#000'); })
8794
.on('mouseout', function () { d3.select(this).attr('stroke', null); })
88-
.on('click', d => curFocus !== d && (zoomToNode(d), d3.event.stopPropagation()));
95+
.on('click', (d:MouseEvent<HTMLButtonElement | HTMLAnchorElement>) => curFocus !== d && (zoomToNode(d), d3.event.stopPropagation()));
8996

9097
// Generate text labels. Set (only) root to visible initially
9198
const label = svg.append('g')
9299
.attr('class', 'perf-chart-labels')
93100
.selectAll('text')
94101
.data(packedRoot.descendants())
95102
.enter().append('text')
96-
.style('fill-opacity', d => (d.parent === packedRoot ? 1 : 0))
97-
.style('display', d => (d.parent === packedRoot ? 'inline' : 'none'))
98-
.text(d => `${d.data.name}: \
103+
.style('fill-opacity', (d:{parent:object}) => (d.parent === packedRoot ? 1 : 0))
104+
.style('display', (d:{parent?:object}) => (d.parent === packedRoot ? 'inline' : 'none'))
105+
.text((d:{data:{name:string, componentData?:{actualDuration:number}}}) => `${d.data.name}:
99106
${Number.parseFloat(d.data.componentData.actualDuration || 0).toFixed(2)}ms`);
100107

101108
// Remove any unused nodes
@@ -115,21 +122,21 @@ const PerfView = ({ snapshots, viewIndex, width = 600, height = 600 }) => {
115122
}
116123

117124
// Transition visibility of labels
118-
function zoomToNode(newFocus) {
125+
function zoomToNode(newFocus:{x:number; y:number; r:number}) {
119126
const transition = svg.transition()
120127
.duration(d3.event.altKey ? 7500 : 750)
121-
.tween('zoom', d => {
128+
.tween('zoom', (d:object)=> {
122129
const i = d3.interpolateZoom(view, [newFocus.x, newFocus.y, newFocus.r * 2]);
123130
return t => zoomViewArea(i(t));
124131
});
125132

126133
// Grab all nodes that were previously displayed, or who's parent is the new target newFocus
127134
// Transition their labels to visible or not
128-
label.filter(function (d) { return d.parent === newFocus || this.style.display === 'inline'; })
135+
label.filter(function (d:{parent:object}) { return d.parent === newFocus || this.style.display === 'inline'; })
129136
.transition(transition)
130-
.style('fill-opacity', d => (d.parent === newFocus ? 1 : 0))
131-
.on('start', function (d) { if (d.parent === newFocus) this.style.display = 'inline'; })
132-
.on('end', function (d) { if (d.parent !== newFocus) this.style.display = 'none'; });
137+
.style('fill-opacity', (d:{parent:object}) => (d.parent === newFocus ? 1 : 0))
138+
.on('start', function (d:{parent:object}) { if (d.parent === newFocus) this.style.display = 'inline'; })
139+
.on('end', function (d:{parent:object}) { if (d.parent !== newFocus) this.style.display = 'none'; });
133140

134141
curFocus = newFocus;
135142
}

src/app/components/StateRoute.tsx

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
/* eslint-disable max-len */
22
/* eslint-disable object-curly-newline */
33
import React from 'react';
4-
import PropTypes from 'prop-types';
54
import { MemoryRouter as Router, Route, NavLink, Switch } from 'react-router-dom';
65

76
import Chart from './Chart.tsx';
@@ -12,7 +11,16 @@ import ErrorHandler from './ErrorHandler.tsx';
1211
const NO_STATE_MSG = 'No state change detected. Trigger an event to change state';
1312
// eslint-disable-next-line react/prop-types
1413

15-
const StateRoute = ({ snapshot, hierarchy, snapshots, viewIndex }) => {
14+
15+
interface StateRouteProps {
16+
snapshot: {state?: object | string, children?: []};
17+
hierarchy: object;
18+
snapshots: [];
19+
viewIndex: number;
20+
}
21+
22+
const StateRoute = (props:StateRouteProps) => {
23+
const { snapshot, hierarchy, snapshots, viewIndex } = props
1624
// gabi :: the hierarchy get set on the first click in the page, when page in refreshed we don't have a hierarchy so we need to check if hierarchy was initialize involk render chart
1725
const renderChart = () => {
1826
if (hierarchy) {
@@ -62,17 +70,4 @@ const StateRoute = ({ snapshot, hierarchy, snapshots, viewIndex }) => {
6270
);
6371
};
6472

65-
StateRoute.propTypes = {
66-
snapshot: PropTypes.shape({
67-
state: PropTypes.oneOfType([PropTypes.string, PropTypes.object]),
68-
children: PropTypes.arrayOf(PropTypes.object),
69-
}).isRequired,
70-
};
71-
72-
export default StateRoute;
73-
74-
// <div>
75-
// <PerfView viewIndex={viewIndex} snapshots={snapshots} />
76-
// <div className="ancestorStatus">Test</div>
77-
// </div>
78-
// );
73+
export default StateRoute;

src/app/components/SwitchApp.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { setTab } from '../actions/actions.ts';
77
const SwitchAppDropdown = () => {
88
const [{ currentTab, tabs }, dispatch] = useStoreContext();
99

10-
const tabsArray = [];
10+
const tabsArray:[] = [];
1111
Object.keys(tabs).forEach(tab => {
1212
tabsArray.unshift({ value: tab, label: tabs[tab].title });
1313
});

src/app/components/Tree.tsx

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import React from 'react';
22
import JSONTree from 'react-json-tree';
3-
import PropTypes from 'prop-types';
43

54

6-
const getItemString = (type, data) => {
5+
const getItemString = (type, data:{state:object|string, name:string, children:[]}) => {
76
// check to make sure that we are on the tree node, not anything else
87
if (
98
Object.keys(data).length > 3
@@ -16,7 +15,11 @@ const getItemString = (type, data) => {
1615
return null;
1716
};
1817

19-
const Tree = props => {
18+
interface TreeProps {
19+
snapshot: {state?:object|string, children?:[]};
20+
}
21+
22+
const Tree = (props:TreeProps) => {
2023
const { snapshot } = props;
2124

2225
return (
@@ -27,19 +30,11 @@ const Tree = props => {
2730
theme={{ tree: () => ({ className: 'json-tree' }) }}
2831
shouldExpandNode={() => true}
2932
getItemString={getItemString}
30-
labelRenderer={raw => (typeof raw[0] !== 'number' ? <span>{raw[0]}</span> : null)}
33+
labelRenderer={(raw:[]) => (typeof raw[0] !== 'number' ? <span>{raw[0]}</span> : null)}
3134
/>
3235
)}
3336
</>
3437
);
3538
};
3639

37-
Tree.propTypes = {
38-
snapshot: PropTypes.shape({
39-
state: PropTypes.oneOfType([PropTypes.string, PropTypes.object]),
40-
children: PropTypes.arrayOf(PropTypes.object),
41-
name: PropTypes.string,
42-
}).isRequired,
43-
};
44-
4540
export default Tree;

0 commit comments

Comments
 (0)