Skip to content

Commit 765cd2d

Browse files
committed
on the process of convert to typescript
1 parent a94612f commit 765cd2d

File tree

5 files changed

+36
-34
lines changed

5 files changed

+36
-34
lines changed

src/app/components/Action.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ interface ActionProps {
1818

1919
/* // gabi and nate :: index and delta props were removed from Action.jsx */
2020
// viewIndex and handleonkeyDown added to props
21-
const Action: React.SFC = (props: ActionProps) => {
21+
const Action = (props: ActionProps) => {
2222
const {
2323
selected, last, index, sliderIndex, dispatch, displayName, componentName, componentData, state, viewIndex, handleOnkeyDown,
2424
} = props;
@@ -28,8 +28,8 @@ const Action: React.SFC = (props: ActionProps) => {
2828
if (!componentData.actualDuration) {
2929
return 'NO TIME';
3030
}
31-
let seconds;
32-
let miliseconds = componentData.actualDuration;
31+
let seconds:any ;
32+
let miliseconds:any = componentData.actualDuration;
3333
if (Math.floor(componentData.actualDuration) > 60) {
3434
seconds = Math.floor(componentData.actualDuration / 60);
3535
seconds = JSON.stringify(seconds);

src/app/components/App.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import MainContainer from '../containers/MainContainer.tsx';
33
import { StoreContext } from '../store.tsx';
44
import mainReducer from '../reducers/mainReducer.ts';
55

6-
const initialState = {
6+
const initialState:object = {
77
port: null,
88
currentTab: null,
99
tabs: {},

src/app/components/Chart.tsx

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,15 @@ import React, { Component } from 'react';
1515
import * as d3 from 'd3';
1616

1717
const colors = ['#95B6B7', '#475485', '#519331', '#AA5039', '#8B2F5F', '#C5B738', '#858DFF', '#FF8D02', '#FFCD51', '#ACDAE6', '#FC997E', '#CF93AD', '#AA3939', '#AA6C39', '#226666', '#2C4870'];
18+
interface ChartProps {
19+
chartRef:any;
20+
maked3Tree: any;
21+
removed3Tree: any;
22+
}
1823

1924
let root = {};
2025
class Chart extends Component {
21-
constructor(props) {
26+
constructor(props:ChartProps) {
2227
super(props);
2328
this.chartRef = React.createRef();
2429
this.maked3Tree = this.maked3Tree.bind(this);
@@ -76,7 +81,7 @@ class Chart extends Component {
7681
// .size([2 * Math.PI, radius / 1.3])
7782
.nodeSize([width / 10, height / 10])
7883
// .separation(function (a, b) { return (a.parent == b.parent ? 1 : 2) / a.depth; });
79-
.separation(function (a, b) { return (a.parent == b.parent ? 2 : 2); });
84+
.separation(function (a:{parent:object}, b:{parent:object}) { return (a.parent == b.parent ? 2 : 2); });
8085

8186
const d3root = tree(hierarchy);
8287

@@ -90,15 +95,15 @@ class Chart extends Component {
9095
.append('path')
9196
.attr('class', 'link')
9297
.attr('d', d3.linkRadial()
93-
.angle(d => d.x)
94-
.radius(d => d.y));
98+
.angle((d:{x:number}) => d.x)
99+
.radius((d:{y:number}) => d.y));
95100

96101
const node = g.selectAll('.node')
97102
// root.descendants gets an array of of all nodes
98103
.data(d3root.descendants())
99104
.enter()
100105
.append('g')
101-
.style('fill', function (d) {
106+
.style('fill', function (d:{data:{branch:number}}) {
102107
if (d.data.branch < colors.length) {
103108
return colors[d.data.branch];
104109
}
@@ -114,13 +119,13 @@ class Chart extends Component {
114119
// .attr('class', function (d) {
115120
// return 'node' + (d.children ? ' node--internal' : ' node--leaf');
116121
// })
117-
.attr('transform', function (d) {
122+
.attr('transform', function (d:{x:number, y:number}) {
118123
return 'translate(' + reinfeldTidierAlgo(d.x, d.y) + ')';
119124
});
120125

121126
node.append('circle')
122127
.attr('r', 15)
123-
.on('mouseover', function (d) {
128+
.on('mouseover', function (d:any) {
124129
d3.select(this)
125130
.transition(100)
126131
.duration(20)
@@ -135,7 +140,7 @@ class Chart extends Component {
135140
.style('top', (d3.event.pageY - 65) + 'px');
136141
})
137142
// eslint-disable-next-line no-unused-vars
138-
.on('mouseout', function (d) {
143+
.on('mouseout', function (d:any) {
139144
d3.select(this)
140145
.transition()
141146
.duration(300)
@@ -149,16 +154,16 @@ class Chart extends Component {
149154
.append('text')
150155
// adjusts the y coordinates for the node text
151156
.attr('dy', '0.5em')
152-
.attr('x', function (d) {
157+
.attr('x', function (d:{x:number; children?:[]}) {
153158
// this positions how far the text is from leaf nodes (ones without children)
154159
// negative number before the colon moves the text of rightside nodes,
155160
// positive number moves the text for the leftside nodes
156161
return d.x < Math.PI === !d.children ? 0 : 0;
157162
})
158163
.attr('text-anchor', 'middle')
159164
// this arranges the angle of the text
160-
.attr('transform', function (d) { return 'rotate(' + (d.x < Math.PI ? d.x - Math.PI / 2 : d.x + Math.PI / 2) * 1 / Math.PI + ')'; })
161-
.text(function (d) {
165+
.attr('transform', function (d:{x:number, y:number}) { return 'rotate(' + (d.x < Math.PI ? d.x - Math.PI / 2 : d.x + Math.PI / 2) * 1 / Math.PI + ')'; })
166+
.text(function (d:{data:{name:number, branch:number}}) {
162167
// gabi and nate :: display the name of of specific patch
163168
return `${d.data.name}.${d.data.branch}`;
164169
});
@@ -179,7 +184,7 @@ class Chart extends Component {
179184
g.attr('cursor', 'grabbing');
180185
}
181186

182-
function dragged(d) {
187+
function dragged(d:{x:number, y:number}) {
183188
d3.select(this).attr('dx', d.x = d3.event.x).attr('dy', d.y = d3.event.y);
184189
}
185190

@@ -196,7 +201,7 @@ class Chart extends Component {
196201
.attr('class', 'tooltip')
197202
.style('opacity', 0);
198203

199-
function reinfeldTidierAlgo(x, y) {
204+
function reinfeldTidierAlgo(x:number, y:number) {
200205
return [(y = +y) * Math.cos(x -= Math.PI / 2), y * Math.sin(x)];
201206
}
202207
}

src/app/components/Diff.tsx

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,13 @@ import ReactHtmlParser from 'react-html-parser';
55

66
import { useStoreContext } from '../store.tsx';
77

8-
function Diff({ snapshot, show }) {
8+
interface DiffProps {
9+
snapshot: object;
10+
show?: boolean;
11+
}
12+
13+
function Diff(props: DiffProps) {
14+
const { snapshot, show } = props
915
const [mainState] = useStoreContext();
1016
const { currentTab, tabs } = mainState; // Nate:: k/v pairs of mainstate store object being created
1117
const { snapshots, viewIndex, sliderIndex } = tabs[currentTab];
@@ -19,17 +25,14 @@ function Diff({ snapshot, show }) {
1925
}
2026

2127
// gabi :: cleanning preview from stateless data
22-
const statelessCleanning = obj => {
28+
const statelessCleanning = (obj:{name?:string; componentData?:object; state?: object | string;stateSnaphot?:object; children?:[]}) => {
2329
const newObj = { ...obj };
2430
if (newObj.name === 'nameless') {
2531
delete newObj.name;
2632
}
2733
if (newObj.componentData) {
2834
delete newObj.componentData;
2935
}
30-
if (newObj.parent || newObj.parent === null) {
31-
delete newObj.parent;
32-
}
3336
if (newObj.state === 'stateless') {
3437
delete newObj.state;
3538
}
@@ -39,7 +42,7 @@ function Diff({ snapshot, show }) {
3942
if (newObj.children) {
4043
newObj.children = [];
4144
if (obj.children.length > 0) {
42-
obj.children.forEach(element => {
45+
obj.children.forEach((element:{state?:object | string; children?:[]}) => {
4346
if (element.state !== 'stateless' || element.children.length > 0) {
4447
const clean = statelessCleanning(element);
4548
newObj.children.push(clean);

src/app/components/DiffRoute.tsx

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ import PropTypes from 'prop-types';
33
import {
44
MemoryRouter as Router, Route, NavLink, Switch,
55
} from 'react-router-dom';
6-
76
import Diff from './Diff.tsx';
87

9-
const DiffRoute = ({ snapshot }) => (
8+
9+
const DiffRoute = (props: {snapshot: {state: string | object; children?:[]}}) => (
10+
1011
<Router>
1112
<div className="navbar">
1213
<NavLink className="router-link" activeClassName="is-active" exact to="/">
@@ -17,17 +18,10 @@ const DiffRoute = ({ snapshot }) => (
1718
</NavLink>
1819
</div>
1920
<Switch>
20-
<Route path="/diffRaw" render={() => <Diff snapshot={snapshot} show />} />
21-
<Route path="/" render={() => <Diff snapshot={snapshot} show={false} />} />
21+
<Route path="/diffRaw" render={() => <Diff snapshot={props.snapshot} show />} />
22+
<Route path="/" render={() => <Diff snapshot={props.snapshot} show={false} />} />
2223
</Switch>
2324
</Router>
2425
);
2526

26-
DiffRoute.propTypes = {
27-
snapshot: PropTypes.shape({
28-
state: PropTypes.oneOfType([PropTypes.string, PropTypes.object]),
29-
children: PropTypes.arrayOf(PropTypes.object),
30-
}).isRequired,
31-
};
32-
3327
export default DiffRoute;

0 commit comments

Comments
 (0)