Skip to content

Commit 27ee4e1

Browse files
authored
Merge pull request #4 from oslabs-beta/reactime19.0-Jackie
Final TypeScript inclusions and cleanup
2 parents 374736e + 457cd73 commit 27ee4e1

File tree

14 files changed

+44
-115
lines changed

14 files changed

+44
-115
lines changed

src/app/components/Action.tsx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import React from 'react';
66
import ReactHover, { Trigger, Hover } from 'react-hover';
77
import { changeView, changeSlider } from '../actions/actions';
8-
import { ActionProps } from '../components/FrontendTypes';
8+
import { ActionProps, OptionsCursorTrueWithMargin } from '../components/FrontendTypes';
99

1010
/**
1111
* @function Action
@@ -41,12 +41,12 @@ const Action = (props: ActionProps): JSX.Element => {
4141
* @function cleanTime: Displays render times for state changes
4242
* @returns render display time in seconds in milliseconds
4343
*/
44-
const cleanTime = ():string => {
44+
const cleanTime = (): string => {
4545
if (!componentData || !componentData.actualDuration) {
4646
return 'NO TIME';
4747
}
4848
let seconds: number | string;
49-
let milliseconds: any = componentData.actualDuration;
49+
let milliseconds: any = componentData.actualDuration;
5050
if (Math.floor(componentData.actualDuration) > 60) {
5151
seconds = Math.floor(componentData.actualDuration / 60);
5252
seconds = JSON.stringify(seconds);
@@ -57,8 +57,8 @@ const Action = (props: ActionProps): JSX.Element => {
5757
} else {
5858
seconds = '00';
5959
}
60-
milliseconds = Number.parseFloat(milliseconds).toFixed(2);
61-
const arrayMilliseconds = milliseconds.split('.');
60+
milliseconds = Number.parseFloat(milliseconds as string).toFixed(2);
61+
const arrayMilliseconds: string | number = milliseconds.split('.');
6262
if (arrayMilliseconds[0].length < 2) {
6363
arrayMilliseconds[0] = '0'.concat(arrayMilliseconds[0]);
6464
}
@@ -69,7 +69,7 @@ const Action = (props: ActionProps): JSX.Element => {
6969
};
7070
const displayTime: string = cleanTime();
7171

72-
const optionsCursorTrueWithMargin: {} = {
72+
const optionsCursorTrueWithMargin: OptionsCursorTrueWithMargin = {
7373
followCursor: true,
7474
shiftX: 20,
7575
shiftY: 0,
@@ -79,7 +79,7 @@ const Action = (props: ActionProps): JSX.Element => {
7979
<div className='individual-action'>
8080
<div
8181
// Invoking keyboard functionality; functionality is in ActionContainer;
82-
onKeyDown={(e) => handleOnkeyDown(e, viewIndex)}
82+
onKeyDown={(e):void => handleOnkeyDown(e, viewIndex)}
8383
className={selected || last ? 'action-component selected' : 'action-component'}
8484
onClick={() => {
8585
dispatch(changeView(index));
@@ -112,7 +112,7 @@ const Action = (props: ActionProps): JSX.Element => {
112112
) : (
113113
<button
114114
className='jump-button'
115-
onClick={(e: any): void => {
115+
onClick={(e): void => {
116116
e.stopPropagation();
117117
dispatch(changeSlider(index));
118118
dispatch(changeView(index));

src/app/components/StateRoute/ComponentMap/ComponentMap.tsx

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,15 @@ import LinkControls from './LinkControls';
1919
import getLinkComponent from './getLinkComponent';
2020
import { toggleExpanded, setCurrentTabInApp } from '../../../actions/actions';
2121
import { useStoreContext } from '../../../store';
22+
import { LinkTypesProps, DefaultMargin, ToolTipStyles } from '../../../components/FrontendTypes'
2223

23-
const defaultMargin: {} = {
24+
const defaultMargin: DefaultMargin = {
2425
top: 30,
2526
left: 30,
2627
right: 55,
2728
bottom: 70,
2829
};
2930

30-
export type LinkTypesProps = {
31-
width: number;
32-
height: number;
33-
margin?: { top: number; right: number; bottom: number; left: number };
34-
snapshots: Record<string, unknown>;
35-
currentSnapshot?: Record<string, unknown>;
36-
};
3731

3832
export default function ComponentMap({
3933
// imported props to be used to display the dendrogram
@@ -95,7 +89,7 @@ export default function ComponentMap({
9589
scroll: true,
9690
});
9791

98-
const tooltipStyles: {} = {
92+
const tooltipStyles: ToolTipStyles = {
9993
...defaultStyles,
10094
minWidth: 60,
10195
maxWidth: 300,

src/app/components/StateRoute/ComponentMap/LinkControls.tsx

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
/* eslint-disable jsx-a11y/label-has-associated-control */
22
import React from 'react';
3+
import { LinkControlProps, ControlStyles, DropDownStyle, Node } from '../../../components/FrontendTypes'
34
// Font size of the Controls label and Dropdowns
4-
const controlStyles = {
5+
const controlStyles: ControlStyles = {
56
fontSize: '12px',
67
padding: '10px',
78
};
8-
9-
const dropDownStyle = {
9+
10+
const dropDownStyle: DropDownStyle = {
1011
margin: '0.5em',
1112
fontSize: '12px',
1213
fontFamily: 'Roboto, sans-serif',
@@ -18,24 +19,10 @@ const dropDownStyle = {
1819
padding: '2px',
1920
};
2021

21-
type Props = {
22-
layout: string;
23-
orientation: string;
24-
linkType: string;
25-
stepPercent: number;
26-
selectedNode: string;
27-
setLayout: (layout: string) => void;
28-
setOrientation: (orientation: string) => void;
29-
setLinkType: (linkType: string) => void;
30-
setStepPercent: (percent: number) => void;
31-
setSelectedNode: (selectedNode: string) => void;
32-
snapShots: Record<string, unknown>;
33-
};
34-
3522
// use BFS to put all the nodes under snapShots(which is the tree node) into an array
36-
const nodeList = [];
23+
const nodeList: Node[] = [];
3724

38-
const collectNodes = (node): void => {
25+
const collectNodes = (node: Node): void => {
3926
nodeList.splice(0, nodeList.length);
4027
/* We used the .splice method here to ensure that nodeList
4128
did not accumulate with page refreshes */
@@ -58,7 +45,7 @@ export default function LinkControls({
5845
setStepPercent,
5946
setSelectedNode,
6047
snapShots,
61-
}: Props): JSX.Element {
48+
}: LinkControlProps): JSX.Element {
6249
collectNodes(snapShots);
6350

6451
return (

src/app/components/StateRoute/ComponentMap/getLinkComponent.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,13 @@ import {
1212
LinkVerticalLine,
1313
LinkRadialLine,
1414
} from '@visx/shape';
15+
import { LinkComponent } from '../../../components/FrontendTypes'
1516

1617
export default function getLinkComponent({
1718
layout,
1819
linkType,
1920
orientation,
20-
}: {
21-
layout: string;
22-
linkType: string;
23-
orientation: string;
24-
}): React.ComponentType<unknown> {
21+
}: LinkComponent): React.ComponentType<unknown> {
2522
let LinkComponent: React.ComponentType<unknown>;
2623

2724
if (layout === 'polar') {

src/app/components/StateRoute/History.tsx

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,11 @@ import React, { useEffect } from 'react';
55
// formatting findDiff return data to show the changes with colors, aligns with actions.tsx
66
import { diff, formatters } from 'jsondiffpatch';
77
import * as d3 from 'd3';
8-
8+
import { DefaultMargin } from '../../components/FrontendTypes';
99
import { changeView, changeSlider, setCurrentTabInApp } from '../../actions/actions';
1010
import { useStoreContext } from '../../store';
1111

12-
interface defaultMargin {
13-
top: number;
14-
left: number;
15-
right: number;
16-
bottom: number;
17-
}
18-
19-
const defaultMargin: defaultMargin = {
12+
const defaultMargin: DefaultMargin = {
2013
top: 30,
2114
left: 30,
2215
right: 55,

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

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,7 @@ import BarGraphComparison from './BarGraphComparison';
1010
import BarGraphComparisonActions from './BarGraphComparisonActions';
1111
import { useStoreContext } from '../../../store';
1212
import { setCurrentTabInApp } from '../../../actions/actions';
13-
import { PerfData, Series } from '../../FrontendTypes';
14-
15-
interface PerformanceVisxProps {
16-
width: number;
17-
height: number;
18-
snapshots: [];
19-
hierarchy: any;
20-
}
13+
import { PerfData, Series, PerformanceVisxProps } from '../../FrontendTypes';
2114

2215
const collectNodes = (snaps, componentName) => {
2316
const componentsResult = [];

src/app/components/StateRoute/StateRoute.tsx

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,12 @@ import { changeView, changeSlider } from '../../actions/actions';
1414
import { useStoreContext } from '../../store';
1515
import PerformanceVisx from './PerformanceVisx/PerformanceVisx';
1616
import WebMetrics from '../WebMetrics';
17+
import { StateRouteProps } from '../../components/FrontendTypes'
1718

1819
const History = require('./History').default;
1920

2021
const NO_STATE_MSG = 'No state change detected. Trigger an event to change state';
2122

22-
export interface StateRouteProps {
23-
snapshot: {
24-
name?: string;
25-
componentData?: object;
26-
state?: string | object;
27-
stateSnaphot?: object;
28-
children?: any[];
29-
};
30-
hierarchy: any;
31-
snapshots: [];
32-
viewIndex: number;
33-
webMetrics: object;
34-
currLocation: object;
35-
}
3623

3724
const StateRoute = (props: StateRouteProps) => {
3825
const { snapshot, hierarchy, snapshots, viewIndex, webMetrics, currLocation } = props;
@@ -63,7 +50,7 @@ const StateRoute = (props: StateRouteProps) => {
6350
// if true, we invoke the D3 render chart with hierarchy
6451
// by invoking History component, and passing in all the props required to render D3 elements and perform timeJump from clicking of node
6552
// otherwise we send an alert to the user that no state was found.
66-
const renderHistory = () => {
53+
const renderHistory:JSX.Element = () => {
6754
if (hierarchy) {
6855
return (
6956
<ParentSize>

src/app/components/StateRoute/Tree.tsx

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import JSONTree from 'react-json-tree';
33

44
import { setCurrentTabInApp } from '../../actions/actions';
55
import { useStoreContext } from '../../store';
6+
import { TreeProps } from '../../components/FrontendTypes'
67

78
const colors = {
89
scheme: 'paraiso',
@@ -32,15 +33,6 @@ const getItemString = (type, data: { state?: object | string; name: string; chil
3233
return <span />;
3334
};
3435

35-
interface TreeProps {
36-
snapshot: {
37-
name?: string;
38-
componentData?: object;
39-
state?: string | object;
40-
stateSnaphot?: object;
41-
children?: any[];
42-
};
43-
}
4436

4537
const Tree = (props: TreeProps) => {
4638
const { snapshot } = props;

src/app/components/SwitchApp.tsx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,23 @@ import Select from 'react-select';
33
import { useStoreContext } from '../store';
44
import { setTab } from '../actions/actions';
55

6-
const SwitchAppDropdown = () => {
6+
const SwitchAppDropdown = (): JSX.Element => {
77
const [{ currentTab, tabs }, dispatch] = useStoreContext();
88

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

14-
const currTab = {
14+
const currTab: {} = {
1515
value: currentTab,
1616
label: tabs[currentTab].title,
1717
};
1818

19-
const customStyles = {
20-
menu: (provided, state) => {
21-
const outline = state.isSelected ? 'transparent' : 'transparent';
22-
const margin = 0;
19+
const customStyles: {} = {
20+
menu: (provided, state):{} => {
21+
const outline: string = state.isSelected ? 'transparent' : 'transparent';
22+
const margin: number = 0;
2323

2424
return { ...provided, outline, margin };
2525
},
@@ -31,7 +31,7 @@ const SwitchAppDropdown = () => {
3131
classNamePrefix='tab-select'
3232
value={currTab}
3333
styles={customStyles}
34-
onChange={(e) => {
34+
onChange={(e): void => {
3535
dispatch(setTab(parseInt(e.value, 10)));
3636
}}
3737
options={tabsArray}

src/app/components/Tutorial.tsx

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,15 @@ import 'intro.js/introjs.css';
88
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
99
import { faQuestion } from '@fortawesome/free-solid-svg-icons';
1010
import { tutorialSaveSeriesToggle, setCurrentTabInApp } from '../actions/actions';
11+
import { TutorialProps, TutorialState, StepsObj } from '../components/FrontendTypes';
1112

1213
//Must be required in. This enables compatibility with TS. If imported in, throws ts error of not rendering steps as a class component correctly.
1314
const { Steps } = require('intro.js-react');
1415

15-
interface tutorialProps {
16-
dispatch: (object) => void;
17-
currentTabInApp: string;
18-
}
19-
20-
interface tutorialState {
21-
stepsEnabled: boolean;
22-
}
23-
2416
// This is the tutorial displayed when the "How to use" button is clicked
2517
// This needs to be a class component to be compatible with updateStepElement from intro.js
26-
export default class Tutorial extends React.Component<tutorialProps, tutorialState> {
27-
constructor(props: tutorialProps) {
18+
export default class Tutorial extends Component<TutorialProps, TutorialState> {
19+
constructor(props: TutorialProps) {
2820
super(props);
2921
this.state = {
3022
stepsEnabled: false,
@@ -82,14 +74,8 @@ export default class Tutorial extends React.Component<tutorialProps, tutorialSta
8274
this.setState({ stepsEnabled: true });
8375
};
8476

85-
interface stepsObj {
86-
title: string;
87-
element?: string;
88-
intro: string;
89-
position: string;
90-
}
9177

92-
let steps: stepsObj[] = [];
78+
let steps: StepsObj[] = [];
9379

9480
switch (currentTabInApp) {
9581
case 'map':

0 commit comments

Comments
 (0)