Skip to content

Commit f1c71bb

Browse files
authored
Merge pull request #16 from oslabs-beta/brian/feature
Added Typescript to several event handler functions in BarGraphComparison.tsx
2 parents e7657cc + acdaee0 commit f1c71bb

File tree

5 files changed

+48
-27
lines changed

5 files changed

+48
-27
lines changed

src/app/components/FrontendTypes.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,20 @@ export interface Series {
99
name: string
1010
}
1111

12+
// interface Event {
13+
// target: EventTarget
14+
// }
15+
16+
// interface EventTarget {
17+
// x: WithParentSizeProvidedProps,
18+
// y: OptionalKeys,
19+
// value?: idk
20+
// }
21+
1222
export interface ActionObj {
1323
name: string,
14-
seriesName: string,
24+
seriesName: string,
25+
currentTab: string,
1526
}
1627

1728
export interface PerfData {
@@ -46,7 +57,7 @@ export interface snapshot {
4657
state: string;
4758
}
4859

49-
export interface margin {
60+
export interface Margin {
5061
top: number;
5162
right: number;
5263
bottom: number;
@@ -57,13 +68,13 @@ export interface BarGraphBase {
5768
width: number,
5869
height: number,
5970
data: PerfData,
60-
comparison: Series[] | string,
71+
comparison: Series[],
6172
}
6273

6374
export interface BarGraphComparisonProps extends BarGraphBase {
64-
setSeries: (e: boolean) => void,
75+
setSeries: (e: boolean | string) => void,
6576
series: number,
66-
setAction: () => void,
77+
setAction: (e: boolean | string) => void,
6778
}
6879

6980
export interface BarGraphProps extends BarGraphBase{

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { schemeSet3 } from 'd3-scale-chromatic';
1111
import { onHover, onHoverExit, save } from '../../../actions/actions';
1212
import { useStoreContext } from '../../../store';
1313
import {
14-
snapshot, TooltipData, margin, BarGraphProps,
14+
snapshot, TooltipData, Margin, BarGraphProps,
1515
} from '../../FrontendTypes';
1616

1717
/* DEFAULTS */

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

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// @ts-nocheck
2+
/// <reference lib="dom" />
23
/* eslint-disable no-param-reassign */
34
import React, { useEffect } from 'react';
45
import { BarStack } from '@visx/shape';
@@ -18,12 +19,12 @@ import {
1819
} from '../../../actions/actions';
1920
import { useStoreContext } from '../../../store';
2021
import {
21-
snapshot, TooltipData, margin, BarGraphComparisonProps, ActionObj,
22+
snapshot, TooltipData, Margin, BarGraphComparisonProps, ActionObj, Series,
2223
} from '../../FrontendTypes';
23-
import { BarStack } from '@visx/shape/lib/types';
24+
// import { BarStack as BarStacks } from '@visx/shape/lib/types';
2425

2526
/* DEFAULTS */
26-
const margin: margin = {
27+
const margin: Margin = {
2728
top: 30, right: 30, bottom: 0, left: 50,
2829
};
2930
const axisColor = '#62d6fb';
@@ -70,7 +71,7 @@ const BarGraphComparison = (props: BarGraphComparisonProps): JSX.Element => {
7071
const getSnapshotId = (d: snapshot) => d.snapshotId;
7172
const formatSnapshotId = (id: string): string => `Snapshot ID: ${id}`;
7273
const formatRenderTime = (time: string): string => `${time} ms `;
73-
const getCurrentTab = (storedSeries: Record<string, unknown>) => storedSeries.currentTab;
74+
const getCurrentTab = (storedSeries: ActionObj) => storedSeries.currentTab;
7475

7576
// create visualization SCALES with cleaned data
7677
// the domain array/xAxisPoints elements will place the bars along the x-axis
@@ -139,8 +140,11 @@ const BarGraphComparison = (props: BarGraphComparisonProps): JSX.Element => {
139140

140141
const handleSeriesChange = (event: Event) => {
141142
if (!event) return;
142-
setSeries(event.target.value);
143-
setAction(false);
143+
const target = event.target as HTMLInputElement;
144+
if (target) {
145+
setSeries(target.value);
146+
setAction(false);
147+
}
144148
};
145149

146150
const handleClose = () => {
@@ -152,9 +156,12 @@ const BarGraphComparison = (props: BarGraphComparisonProps): JSX.Element => {
152156
};
153157

154158
const handleActionChange = (event: Event) => {
155-
if (!event.target.value) return;
156-
setAction(event.target.value);
157-
setSeries(false);
159+
const target = event.target as HTMLInputElement;
160+
if (!target.value) return;
161+
if (target) {
162+
setAction(target.value);
163+
setSeries(false);
164+
}
158165
};
159166

160167
const picHandleClose = () => {
@@ -178,14 +185,18 @@ const BarGraphComparison = (props: BarGraphComparisonProps): JSX.Element => {
178185
});
179186
return data.barStack;
180187
}
188+
181189
const animateButton = (e: MouseEvent) => {
182190
e.preventDefault();
183-
e.target.classList.add('animate');
184-
e.target.innerHTML = 'Deleted!';
185-
setTimeout(() => {
186-
e.target.innerHTML = 'Clear All Series';
187-
e.target.classList.remove('animate');
188-
}, 1000);
191+
const target = (e.target as HTMLButtonElement);
192+
if (target) {
193+
target.classList.add('animate');
194+
target.innerHTML = 'Deleted!';
195+
setTimeout(() => {
196+
target.innerHTML = 'Clear All Series';
197+
target.classList.remove('animate');
198+
}, 1000);
199+
}
189200
};
190201
const classname = document.getElementsByClassName('delete-button');
191202
for (let i = 0; i < classname.length; i += 1) {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ import MenuItem from '@material-ui/core/MenuItem';
1414
import FormControl from '@material-ui/core/FormControl';
1515
import { deleteSeries, setCurrentTabInApp } from '../../../actions/actions';
1616
import { useStoreContext } from '../../../store';
17-
import { TooltipData, margin } from '../../FrontendTypes';
17+
import { TooltipData, Margin } from '../../FrontendTypes';
1818

1919
/* DEFAULTS */
20-
const margin = {
20+
const margin: Margin = {
2121
top: 30, right: 30, bottom: 0, left: 50,
2222
};
2323
const axisColor = '#62d6fb';

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
/* eslint-disable guard-for-in */
33
/* eslint-disable no-restricted-syntax */
44
/* eslint-disable max-len */
5-
65
import React, { useState, useEffect } from 'react';
76
import {
87
MemoryRouter as Router,
@@ -131,10 +130,10 @@ const traverse = (snapshot, data, snapshots, currTotalRender: currNum = 0): void
131130
};
132131

133132
// Retrieve snapshot series data from Chrome's local storage.
134-
const allStorage = () => {
133+
const allStorage = (): Series[] => {
135134
let values = localStorage.getItem('project');
136-
values = values === null ? [] : JSON.parse(values);
137-
return values;
135+
const newValues: Series[] = values === null ? [] : JSON.parse(values);
136+
return newValues;
138137
};
139138

140139
// Gets snapshot Ids for the regular bar graph view.

0 commit comments

Comments
 (0)