Skip to content

Commit 2aad51e

Browse files
committed
diffing tab at top right with text
1 parent f0380bd commit 2aad51e

File tree

7 files changed

+155
-110
lines changed

7 files changed

+155
-110
lines changed

package-lock.json

Lines changed: 10 additions & 70 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,12 @@
5050
"dependencies": {
5151
"d3": "^3.5.17",
5252
"jsondiffpatch": "^0.3.11",
53-
"jsondiffpatch-for-react": "^1.0.3",
5453
"prop-types": "^15.7.2",
5554
"rc-slider": "^8.6.13",
5655
"rc-tooltip": "^3.7.3",
5756
"react": "^16.8.6",
5857
"react-dom": "^16.8.6",
58+
"react-html-parser": "^2.0.2",
5959
"react-json-tree": "^0.11.2",
6060
"react-router-dom": "^5.0.1",
6161
"react-select": "^3.0.4",

src/app/components/Diff.jsx

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import React from 'react';
22
import PropTypes from 'prop-types';
3-
import { diff, reverse, formatters } from "jsondiffpatch";
3+
import { diff, formatters } from 'jsondiffpatch';
4+
import ReactHtmlParser from 'react-html-parser';
45
import './diff.css';
56

67
import { useStoreContext } from '../store';
78

8-
function Diff({ snapshot }) {
9+
function Diff({ snapshot, show }) {
910
const [mainState] = useStoreContext();
1011
const { snapshots, viewIndex } = mainState;
1112

@@ -21,20 +22,13 @@ function Diff({ snapshot }) {
2122
} else {
2223
[previous] = snapshots;
2324
}
24-
const delta = diff(previous,snapshot)
25-
console.log('delta',delta);
25+
26+
const delta = diff(previous, snapshot);
2627
const html = formatters.html.format(delta, previous);
27-
console.log('format', formatters.html.format(delta, previous));
28-
if (previous === undefined) {
29-
return (
30-
<div>
31-
states are equal
32-
</div>
33-
);
34-
}
28+
show ? formatters.html.showUnchanged() : formatters.html.hideUnchanged();
29+
3530
return (
36-
<div dangerouslySetInnerHTML={{__html: html}}>
37-
</div>
31+
previous ? <div> { ReactHtmlParser(html) } </div> : <div>states are equal</div>
3832
);
3933
}
4034

@@ -43,6 +37,7 @@ Diff.propTypes = {
4337
state: PropTypes.oneOfType([PropTypes.string, PropTypes.object]),
4438
children: PropTypes.arrayOf(PropTypes.object),
4539
}).isRequired,
40+
// show: PropTypes.boolean,
4641
};
4742

4843
export default Diff;

src/app/components/DiffRoute.jsx

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import React from 'react';
2+
import PropTypes from 'prop-types';
3+
import {
4+
MemoryRouter as Router, Route, NavLink, Switch,
5+
} from 'react-router-dom';
6+
7+
import Diff from './Diff';
8+
9+
const DiffRoute = ({ snapshot }) => (
10+
<Router>
11+
<div className="navbar">
12+
<NavLink className="router-link" activeClassName="is-active" exact to="/">
13+
Tree
14+
</NavLink>
15+
<NavLink className="router-link" activeClassName="is-active" to="/diffRaw">
16+
Raw
17+
</NavLink>
18+
</div>
19+
<Switch>
20+
<Route path="/diffRaw" render={() => <Diff snapshot={snapshot} show />} />
21+
<Route path="/" render={() => <Diff snapshot={snapshot} show={false} />} />
22+
</Switch>
23+
</Router>
24+
);
25+
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+
33+
export default DiffRoute;

src/app/components/StateRoute.jsx

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import React from 'react';
2+
import PropTypes from 'prop-types';
3+
import {
4+
MemoryRouter as Router, Route, NavLink, Switch,
5+
} from 'react-router-dom';
6+
7+
import Chart from './Chart';
8+
import Tree from './Tree';
9+
10+
const StateRoute = ({ snapshot }) => (
11+
<Router>
12+
<div className="navbar">
13+
<NavLink className="router-link" activeClassName="is-active" exact to="/">
14+
Tree
15+
</NavLink>
16+
<NavLink className="router-link" activeClassName="is-active" to="/chart">
17+
Chart
18+
</NavLink>
19+
</div>
20+
<Switch>
21+
<Route path="/chart" render={() => <Chart snapshot={snapshot} />} />
22+
<Route path="/" render={() => <Tree snapshot={snapshot} />} />
23+
</Switch>
24+
</Router>
25+
);
26+
27+
StateRoute.propTypes = {
28+
snapshot: PropTypes.shape({
29+
state: PropTypes.oneOfType([PropTypes.string, PropTypes.object]),
30+
children: PropTypes.arrayOf(PropTypes.object),
31+
}).isRequired,
32+
};
33+
34+
export default StateRoute;

src/app/containers/StateContainer.jsx

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,38 @@
1-
import React from 'react';
1+
import React, { useState } from 'react';
22
import PropTypes from 'prop-types';
33
import {
44
MemoryRouter as Router, Route, NavLink, Switch,
55
} from 'react-router-dom';
6-
import Tree from '../components/Tree';
7-
import Chart from '../components/Chart';
8-
import Diff from '../components/Diff';
6+
import StateRoute from '../components/StateRoute';
7+
import DiffRoute from '../components/DiffRoute';
98

10-
const StateContainer = ({ snapshot }) => (
11-
<Router>
12-
<div className="state-container">
13-
<div className="navbar">
14-
<NavLink className="router-link" activeClassName="is-active" exact to="/">
15-
Tree
16-
</NavLink>
17-
<NavLink className="router-link" activeClassName="is-active" to="/chart">
18-
Chart
19-
</NavLink>
20-
<NavLink className="router-link" activeClassName="is-active" to="/diff">
21-
Diff
22-
</NavLink>
9+
10+
const StateContainer = ({ snapshot }) => {
11+
const [Text, setText] = useState('State');
12+
return (
13+
<Router>
14+
<div className="state-container">
15+
<div className="main-navbar-container">
16+
<div className="main-navbar-text">
17+
{Text}
18+
</div>
19+
<div className="main-navbar">
20+
<NavLink className="main-router-link" activeClassName="is-active" exact to="/">
21+
State
22+
</NavLink>
23+
<NavLink className="main-router-link" activeClassName="is-active" to="/diff">
24+
Diff
25+
</NavLink>
26+
</div>
27+
</div>
28+
<Switch>
29+
<Route path="/diff" render={() => { setText('Diff'); return <DiffRoute snapshot={snapshot} />; }} />
30+
<Route path="/" render={() => { setText('State'); return <StateRoute snapshot={snapshot} />; }} />
31+
</Switch>
2332
</div>
24-
<Switch>
25-
<Route path="/chart" render={() => <Chart snapshot={snapshot} />} />
26-
<Route path="/diff" render={() => <Diff snapshot={snapshot} />} />
27-
<Route path="/" render={() => <Tree snapshot={snapshot} />} />
28-
</Switch>
29-
</div>
30-
</Router>
31-
);
33+
</Router>
34+
);
35+
};
3236

3337
StateContainer.propTypes = {
3438
snapshot: PropTypes.shape({

src/app/styles/layout/_stateContainer.scss

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,24 @@
1313
height: 30px;
1414
}
1515

16+
.state-container .main-navbar{
17+
background-color: #565A61;
18+
display: flex;
19+
flex-direction: row;
20+
align-items: center;
21+
height: 40px;
22+
margin: 6px;
23+
}
24+
25+
.state-container .main-navbar-container{
26+
background-color: #565A61;
27+
display: flex;
28+
flex-direction: row;
29+
justify-content: space-between;
30+
align-items: center;
31+
height: 40px;
32+
}
33+
1634
.navbar {
1735
// prevent navbar from scrolling with state/tree display
1836
position: sticky;
@@ -23,6 +41,27 @@
2341
}
2442

2543
.state-container {
44+
.main-navbar-text {
45+
margin: 6px;
46+
}
47+
.main-router-link {
48+
height: 80%;
49+
width: 80px;
50+
display: flex;
51+
justify-content: center;
52+
align-items: center;
53+
background-color: $navbar-color;
54+
text-decoration: none;
55+
color: $text-color;
56+
}
57+
.main-router-link:hover {
58+
background-color: $light-grey-three;
59+
}
60+
61+
.main-router-link.is-active {
62+
background-color: $brand-color;
63+
}
64+
2665
.router-link {
2766
height: 100%;
2867
width: 80px;

0 commit comments

Comments
 (0)