Skip to content

Commit 5aa7bd5

Browse files
authored
Merge pull request #98 from Gossamer-React/fix-layering
fixed tree position and highlighted buttons on click.
2 parents dcc04ea + 22d7e50 commit 5aa7bd5

File tree

5 files changed

+104
-64
lines changed

5 files changed

+104
-64
lines changed

build/webpack-bundle.js

Lines changed: 0 additions & 38 deletions
Large diffs are not rendered by default.

build/webpack-bundle.js.map

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/app.css

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,69 @@ body{
88
background: linear-gradient(to right, #eef2f3, #8e9eab); W3C, IE 10+/ Edge, Firefox 16+, Chrome 26+, Opera 12+, Safari 7+; */
99
}
1010

11+
@media screen and (max-width: 600px) {
12+
.reactTab {
13+
display: grid;
14+
grid-template-rows: 1fr 1fr 1fr;
15+
grid-template-columns: 1fr;
16+
grid-template-areas:
17+
'sp-box'
18+
'diff'
19+
'tree';
20+
}
21+
.state-prop-display {
22+
grid-area: sp-box;
23+
background-color: #333;
24+
color: white;
25+
overflow-y: scroll;
26+
border: 1px solid black;
27+
border-radius: 5px;
28+
padding: 5px 5px;
29+
margin-right: 10px;
30+
}
31+
32+
#treeWrapper{
33+
grid-area: tree;
34+
background-color: rgba(214, 214, 214, 0.4);
35+
border: 1px solid rgba(0, 0, 0, 0.3);
36+
border-radius: 5px;
37+
padding: 10px;
38+
margin-left: 10px;
39+
}
40+
41+
#stateDiff-container {
42+
grid-area: diff;
43+
overflow-y: scroll;
44+
background-color: rgba(214, 214, 214, 0.4);
45+
border: 1px solid rgba(0, 0, 0, 0.3);
46+
border-radius: 5px;
47+
padding: 10px;
48+
margin-top: 10px;
49+
margin-right: 10px;
50+
}
51+
52+
#state-header{
53+
display: flex;
54+
/* justify-content: space-between; */
55+
margin-bottom: 5px;
56+
}
57+
58+
.stateDiff-div {
59+
overflow-x: scroll;
60+
padding: 15px;
61+
background:rgba(255,255,255,0.5);
62+
margin: 8px 0px;
63+
}
64+
65+
.state-span{
66+
margin: 6px;
67+
font-size: 1.2em;
68+
font-weight: 500;
69+
letter-spacing: 0.8px;
70+
line-height: 15px;
71+
}
72+
}
73+
1174
#app-container{
1275
display: flex;
1376
padding: 10px 25px;
@@ -40,6 +103,7 @@ body{
40103
margin-right: 10px;
41104
}
42105

106+
43107
#treeWrapper{
44108
grid-area: tree;
45109
height: 700px;
@@ -66,6 +130,10 @@ body{
66130
justify-content: center;
67131
}
68132

133+
.toggleOn {
134+
background-color: rgba(214, 214, 214, 0.8);
135+
color: white;
136+
}
69137

70138
/* For window */
71139
#window{

src/components/TreeDiagram.jsx

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ class TreeDiagram extends React.Component {
99
this.state = {
1010
transition: null,
1111
orientation: 'vertical',
12-
foreignObjectWrapper: {y: -5, x: 10},
13-
nodeSize: {x: 75, y: 75},
12+
foreignObjectWrapper: {x: 8, y: 4},
13+
nodeSize: {x: 95, y: 85},
1414
};
1515
this.handleFlip = this.handleFlip.bind(this);
1616
}
@@ -29,17 +29,27 @@ class TreeDiagram extends React.Component {
2929
}
3030

3131
handleFlip() {
32+
const dimensions = this.treeContainer.getBoundingClientRect();
3233
if(this.state.orientation === 'vertical') {
3334
this.setState({
3435
orientation: 'horizontal',
35-
foreignObjectWrapper: {y: 10, x: 10},
36-
nodeSize:{y:85, x:90}
36+
foreignObjectWrapper: {x: 5, y: 8},
37+
nodeSize: {x: 110, y:110},
38+
translate: {
39+
x: dimensions.width / 8,
40+
y: dimensions.height / 2
41+
}
3742
})
3843
} else {
3944
this.setState({
4045
orientation: 'vertical',
41-
foreignObjectWrapper: {y: -5, x: 10}
42-
})
46+
foreignObjectWrapper: {x: 8, y: 4},
47+
nodeSize: {x: 85, y: 85},
48+
translate: {
49+
x: dimensions.width / 2,
50+
y: dimensions.height / 8
51+
}
52+
});
4353
}
4454
}
4555

@@ -73,18 +83,18 @@ class TreeDiagram extends React.Component {
7383
}
7484
};
7585

86+
7687
return (
7788
<div id="treeWrapper" ref={tc => (this.treeContainer = tc)}>
7889
<button onClick={() => {this.handleFlip()}}> {this.state.orientation[0].toUpperCase() + this.state.orientation.slice(1)} </button>
79-
<button onClick={() => { this.props.handleFilter(filterComponents.reduxComponents) }}>Filter Redux</button>
80-
<button onClick={() => { this.props.handleFilter(filterComponents.reactRouterComponents) }}>Filter React-Router</button>
81-
<button onClick={() => { this.props.handleFilter(filterComponents.apolloComponents) }}>Filter Apollo-GraphQL</button>
90+
<button onClick={(e) => { this.props.handleFilter(e, filterComponents.reduxComponents) }}>Filter Redux</button>
91+
<button onClick={(e) => { this.props.handleFilter(e, filterComponents.reactRouterComponents) }}>Filter React-Router</button>
92+
<button onClick={(e) => { this.props.handleFilter(e, filterComponents.apolloComponents) }}>Filter Apollo-GraphQL</button>
8293

83-
{/* when appState has a length we populate tree */}
8494
{this.props.appState.length !== 0 ? (
8595
<Tree
8696
data={this.props.appState}
87-
nodeSize={{ x: 75, y: 75 }}
97+
nodeSize={this.state.nodeSize}
8898
orientation={this.state.orientation}
8999
styles={styles}
90100
translate={this.state.translate}

src/devtools.js

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,7 @@ class App extends Component {
2626
componentsToFilter: [],
2727
};
2828

29-
this.handleMouseOver = this.handleMouseOver.bind(this);
30-
31-
chrome.devtools.panels.create('Lucid', null, 'devtools.html');
29+
chrome.devtools.panels.create("Lucid", null, "devtools.html");
3230
}
3331

3432
componentDidMount() {
@@ -55,10 +53,9 @@ class App extends Component {
5553
let diff = recurseDiff(oldstate, this.state.appReactDOM);
5654
appState.setState({ stateDiff: diff });
5755
}
58-
56+
5957
//if there is an active setTimeout, clear it
6058
clearTimeout(timeout);
61-
6259
timeout = setTimeout(() => {
6360
appState.setState({ appState: req.msg });
6461
}, 1000);
@@ -100,14 +97,14 @@ class App extends Component {
10097
headers: { 'Content-Type': 'application/json' },
10198
body: JSON.stringify({ query: introspectionQuery })
10299
})
103-
.then(res => res.json())
104-
.then(json =>
105-
this.setState({
106-
schema: JSON.stringify(json.data)
107-
})
100+
.then(res => res.json())
101+
.then(json =>
102+
this.setState({
103+
schema: JSON.stringify(json.data)
104+
})
108105
);
106+
}
109107
}
110-
}
111108

112109
//* invoke schema fetch only after a log object from a previous response is available
113110
componentDidUpdate(prevProps, prevState) {
@@ -124,7 +121,6 @@ class App extends Component {
124121
}
125122
}
126123

127-
128124
// * Handles the tab click for tree and req/res window
129125
handleWindowChange(target) {
130126
console.log(target);
@@ -140,7 +136,12 @@ class App extends Component {
140136
}
141137

142138
// * Handles the filter for the component tree
143-
handleFilter(arr) {
139+
handleFilter(e, arr) {
140+
if(e.target.classList.contains('toggleOn')) {
141+
e.target.classList.remove('toggleOn')
142+
} else {
143+
e.target.classList.add('toggleOn');
144+
}
144145
let result = [];
145146
if (!this.state.componentsToFilter.includes(arr[0])) {
146147
let componentsArr = this.state.componentsToFilter.concat(arr);
@@ -222,7 +223,7 @@ class App extends Component {
222223
) : (
223224
<div class='reactTab'>
224225
<StateContainer clearLog={this.handleClearLog.bind(this)} stateDiffs={this.state.stateDiff} />
225-
<TreeDiagram appState={this.state.appFilteredDOM.length === 0 ? this.state.appState : this.state.appFilteredDOM} handleMouseOver={this.handleMouseOver} handleFilter={this.handleFilter.bind(this)} />
226+
<TreeDiagram appState={this.state.appFilteredDOM.length === 0 ? this.state.appState : this.state.appFilteredDOM} handleMouseOver={this.handleMouseOver.bind(this)} handleFilter={this.handleFilter.bind(this)} />
226227
<StatePropsBox nodeData={this.state.nodeData} />
227228
</div>
228229
)}

0 commit comments

Comments
 (0)