Skip to content

Commit 78f9d11

Browse files
yuanjackie1jasnoo
authored andcommitted
Full TS implementation on ComponentMap.tsx
1 parent 3a3e297 commit 78f9d11

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

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

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import getLinkComponent from './getLinkComponent';
2020
import { toggleExpanded, setCurrentTabInApp } from '../../../actions/actions';
2121
import { useStoreContext } from '../../../store';
2222

23-
const defaultMargin = {
23+
const defaultMargin: {} = {
2424
top: 30,
2525
left: 30,
2626
right: 55,
@@ -95,7 +95,7 @@ export default function ComponentMap({
9595
scroll: true,
9696
});
9797

98-
const tooltipStyles = {
98+
const tooltipStyles: {} = {
9999
...defaultStyles,
100100
minWidth: 60,
101101
maxWidth: 300,
@@ -108,7 +108,7 @@ export default function ComponentMap({
108108
pointerEvents: 'all !important',
109109
};
110110

111-
const scrollStyle = {
111+
const scrollStyle: {} = {
112112
minWidth: '60',
113113
maxWidth: '300',
114114
minHeight: '20px',
@@ -117,13 +117,13 @@ export default function ComponentMap({
117117
overflowWrap: 'break-word',
118118
};
119119

120-
const formatRenderTime = (time: number): string => {
120+
const formatRenderTime: string = (time: number): string => {
121121
const renderTime = time.toFixed(3);
122122
return `${renderTime} ms `;
123123
};
124124

125-
const formatData = (data, type) => {
126-
const contextFormat = [];
125+
const formatData: [] = (data, type) => {
126+
const contextFormat: string[] = [];
127127
for (const key in data) {
128128
// Suggestion: update the front end to display as a list if we have object
129129
let inputData = data[key];
@@ -135,15 +135,15 @@ export default function ComponentMap({
135135
return contextFormat;
136136
};
137137

138-
const formatState = (state) => {
138+
const formatState: string[] = (state) => {
139139
if (state === 'stateless') return ['stateless'];
140140
return ['stateful'];
141141
};
142142

143143
// places all nodes into a flat array
144-
const nodeList = [];
144+
const nodeList: [] = [];
145145

146-
const collectNodes = (node) => {
146+
const collectNodes: void = (node) => {
147147
nodeList.splice(0, nodeList.length);
148148
nodeList.push(node);
149149
for (let i = 0; i < nodeList.length; i += 1) {
@@ -170,7 +170,7 @@ export default function ComponentMap({
170170
findSelectedNode();
171171

172172
// controls for the map
173-
const LinkComponent = getLinkComponent({ layout, linkType, orientation });
173+
const LinkComponent: React.ComponentType<unknown> = getLinkComponent({ layout, linkType, orientation });
174174
return totalWidth < 10 ? null : (
175175
<div>
176176
<LinkControls
@@ -218,14 +218,14 @@ export default function ComponentMap({
218218
))}
219219

220220
{tree.descendants().map((node, key) => {
221-
const widthFunc = (name) => {
221+
const widthFunc:number = (name) => {
222222
const nodeLength = name.length;
223223
if (nodeLength < 5) return nodeLength + 40;
224224
if (nodeLength < 10) return nodeLength + 60;
225225
return nodeLength + 70;
226226
};
227-
const width = widthFunc(node.data.name);
228-
const height = 25;
227+
const width:number = widthFunc(node.data.name);
228+
const height:number = 25;
229229

230230
let top: number;
231231
let left: number;
@@ -242,7 +242,7 @@ export default function ComponentMap({
242242
}
243243

244244
// mousing controls & Tooltip display logic
245-
const handleMouseAndClickOver = (event) => {
245+
const handleMouseAndClickOver: void = (event) => {
246246
const coords = localPoint(event.target.ownerSVGElement, event);
247247
const tooltipObj = { ...node.data };
248248

0 commit comments

Comments
 (0)