forked from facebook/react-devtools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathElementPanel.js
More file actions
111 lines (106 loc) · 2.59 KB
/
ElementPanel.js
File metadata and controls
111 lines (106 loc) · 2.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @flow
*/
'use strict';
var React = require('react');
var decorate = require('../../frontend/decorate');
class ElementPanel extends React.Component {
props: {
dataIDs: Array<{id: string, queries: Array<Map>}>,
jumpToData: (id: string) => void,
jumpToQuery: (queryID: string) => void,
};
render() {
if (!this.props.dataIDs.length) {
return <span/>;
}
return (
<div>
Relay Nodes
<ul style={styles.dataIDs}>
{this.props.dataIDs.map(({id, queries}) => (
<li style={styles.dataNode}>
<div style={styles.dataID} onClick={() => this.props.jumpToData(id)}>
ID: {id}
</div>
<ul style={styles.queries}>
{queries.map(query => (
<li style={styles.queryID} onClick={() => {
var queryID = query.get('id');
if (queryID) {
this.props.jumpToQuery(queryID);
}
}}>
{query.get('name')}
</li>
))}
{!queries.length && <li style={styles.noQueries}>No Queries</li>}
</ul>
</li>
))}
</ul>
</div>
);
}
}
var styles = {
dataNode: {
marginBottom: 5,
border: '1px solid #ccc',
},
dataIDs: {
listStyle: 'none',
padding: 0,
margin: 0,
},
queries: {
listStyle: 'none',
padding: 0,
margin: 0,
},
dataID: {
cursor: 'pointer',
padding: '2px 4px',
backgroundColor: '#ccc',
},
queryID: {
cursor: 'pointer',
padding: '2px 4px',
},
noQueries: {
color: '#999',
padding: '2px 4px',
},
};
module.exports = decorate({
store: 'relayStore',
listeners(props, store) {
return [props.id];
},
shouldUpdate(props, prevProps) {
return props.id !== prevProps.id;
},
props(store, props) {
var dataIDs = [];
if (store.nodesToDataIDs[props.id]) {
for (var id of store.nodesToDataIDs[props.id]) {
dataIDs.push({
id,
queries: (store.queriesByDataID[id] || []).map(qid => store.queries.get(qid)),
});
}
}
return {
dataIDs,
jumpToData: dataID => store.jumpToDataID(dataID),
jumpToQuery: queryID => store.jumpToQuery(queryID),
};
},
}, ElementPanel);