/
DetailsComponent.js
262 lines (249 loc) · 8.8 KB
/
DetailsComponent.js
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
import React from 'react';
import { connect } from 'react-redux';
import {
ExpansionPanel,
ExpansionPanelSummary,
Typography,
ExpansionPanelDetails,
List,
ListItem,
ListItemText,
TextField,
Fab,
IconButton,
Grid,
Table,
TableBody,
TableRow,
TableCell,
FormControlLabel,
Switch
} from '@material-ui/core';
import ExpandMoreIcon from '@material-ui/icons/ExpandMore';
import AddIcon from '@material-ui/icons/Add';
import DeleteIcon from '@material-ui/icons/Delete';
import RefreshIcon from '@material-ui/icons/Refresh';
import ArrowBackIcon from '@material-ui/icons/ArrowBack';
import ArrowForwardIcon from '@material-ui/icons/ArrowForward';
import _ from 'lodash';
import { JsonToTable } from 'react-json-to-table';
import { ACTIONS, COMMON_GREMLIN_ERROR, QUERY_ENDPOINT } from '../../constants';
import axios from "axios";
import { onFetchQuery} from '../../logics/actionHelper';
class Details extends React.Component {
onAddNodeLabel() {
this.props.dispatch({ type: ACTIONS.ADD_NODE_LABEL });
}
onEditNodeLabel(index, nodeLabel) {
this.props.dispatch({ type: ACTIONS.EDIT_NODE_LABEL, payload: { id: index, nodeLabel } });
}
onRemoveNodeLabel(index) {
this.props.dispatch({ type: ACTIONS.REMOVE_NODE_LABEL, payload: index });
}
onRefresh() {
this.props.dispatch({ type: ACTIONS.REFRESH_NODE_LABELS, payload: this.props.nodeLabels });
}
onTraverse(nodeId, direction) {
const query = `g.V('${nodeId}').${direction}()`;
axios.post(
QUERY_ENDPOINT,
{ host: this.props.host, port: this.props.port, query: query },
{ headers: { 'Content-Type': 'application/json' } }
).then((response) => {
onFetchQuery(response, query, this.props.nodeLabels, this.props.dispatch);
}).catch((error) => {
this.props.dispatch({ type: ACTIONS.SET_ERROR, payload: COMMON_GREMLIN_ERROR });
});
}
onTogglePhysics(enabled){
this.props.dispatch({ type: ACTIONS.SET_IS_PHYSICS_ENABLED, payload: enabled });
if (this.props.network) {
const edges = {
smooth: {
type: enabled ? 'dynamic' : 'continuous'
}
};
this.props.network.setOptions( { physics: enabled, edges } );
}
}
generateList(list) {
let key = 0;
return list.map(value => {
key = key+1;
return React.cloneElement((
<ListItem>
<ListItemText
primary={value}
/>
</ListItem>
), {
key
})
});
}
generateNodeLabelList(nodeLabels) {
let index = -1;
return nodeLabels.map( nodeLabel => {
index = index+1;
nodeLabel.index = index;
return React.cloneElement((
<ListItem>
<TextField id="standard-basic" label="Node Type" InputLabelProps={{ shrink: true }} value={nodeLabel.type} onChange={event => {
const type = event.target.value;
const field = nodeLabel.field;
this.onEditNodeLabel(nodeLabel.index, { type, field })
}}
/>
<TextField id="standard-basic" label="Label Field" InputLabelProps={{ shrink: true }} value={nodeLabel.field} onChange={event => {
const field = event.target.value;
const type = nodeLabel.type;
this.onEditNodeLabel(nodeLabel.index, { type, field })
}}/>
<IconButton aria-label="delete" size="small" onClick={() => this.onRemoveNodeLabel(nodeLabel.index)}>
<DeleteIcon fontSize="small" />
</IconButton>
</ListItem>
), {
key: index
})
});
}
render(){
let hasSelected = false;
let selectedType = null;
let selectedId = null ;
let selectedProperties = null;
let selectedHeader = null;
if (!_.isEmpty(this.props.selectedNode)) {
hasSelected = true;
selectedType = _.get(this.props.selectedNode, 'type');
selectedId = _.get(this.props.selectedNode, 'id');
selectedProperties = _.get(this.props.selectedNode, 'properties');
selectedHeader = 'Node';
} else if (!_.isEmpty(this.props.selectedEdge)) {
hasSelected = true;
selectedType = _.get(this.props.selectedEdge, 'type');
selectedId = _.get(this.props.selectedEdge, 'id');
selectedProperties = _.get(this.props.selectedEdge, 'properties');
selectedHeader = 'Edge';
}
return (
<div className={'details'}>
<Grid container spacing={2}>
<Grid item xs={12} sm={12} md={12}>
<ExpansionPanel>
<ExpansionPanelSummary
expandIcon={<ExpandMoreIcon />}
aria-controls="panel1a-content"
id="panel1a-header"
>
<Typography>Query History</Typography>
</ExpansionPanelSummary>
<ExpansionPanelDetails>
<List dense={true}>
{this.generateList(this.props.queryHistory)}
</List>
</ExpansionPanelDetails>
</ExpansionPanel>
<ExpansionPanel>
<ExpansionPanelSummary
expandIcon={<ExpandMoreIcon />}
aria-controls="panel1a-content"
id="panel1a-header"
>
<Typography>Settings</Typography>
</ExpansionPanelSummary>
<ExpansionPanelDetails>
<Grid container spacing={2}>
<Grid item xs={12} sm={12} md={12}>
<FormControlLabel
control={
<Switch
checked={this.props.isPhysicsEnabled}
onChange={() => { this.onTogglePhysics(!this.props.isPhysicsEnabled); }}
value="physics"
color="primary"
/>
}
label="Enable Physics"
/>
</Grid>
<Grid item xs={12} sm={12} md={12}>
<Typography>Node Labels</Typography>
</Grid>
<Grid item xs={12} sm={12} md={12}>
<List dense={true}>
{this.generateNodeLabelList(this.props.nodeLabels)}
</List>
</Grid>
<Grid item xs={12} sm={12} md={12}>
<Fab variant="extended" color="primary" size="small" onClick={this.onRefresh.bind(this)}>
<RefreshIcon />
Refresh
</Fab>
<Fab variant="extended" size="small" onClick={this.onAddNodeLabel.bind(this)}>
<AddIcon />
Add Node Label
</Fab>
</Grid>
</Grid>
</ExpansionPanelDetails>
</ExpansionPanel>
</Grid>
{hasSelected &&
<Grid item xs={12} sm={12} md={12}>
<h2>Information: {selectedHeader}</h2>
{selectedHeader === 'Node' &&
<Grid item xs={12} sm={12} md={12}>
<Grid container spacing={2}>
<Grid item xs={6} sm={6} md={6}>
<Fab variant="extended" size="small" onClick={() => this.onTraverse(selectedId, 'out')}>
Traverse Out Edges
<ArrowForwardIcon/>
</Fab>
</Grid>
<Grid item xs={6} sm={6} md={6}>
<Fab variant="extended" size="small" onClick={() => this.onTraverse(selectedId, 'in')}>
Traverse In Edges
<ArrowBackIcon/>
</Fab>
</Grid>
</Grid>
</Grid>
}
<Grid item xs={12} sm={12} md={12}>
<Grid container>
<Table aria-label="simple table">
<TableBody>
<TableRow key={'type'}>
<TableCell scope="row">Type</TableCell>
<TableCell align="left">{String(selectedType)}</TableCell>
</TableRow>
<TableRow key={'id'}>
<TableCell scope="row">ID</TableCell>
<TableCell align="left">{String(selectedId)}</TableCell>
</TableRow>
</TableBody>
</Table>
<JsonToTable json={selectedProperties}/>
</Grid>
</Grid>
</Grid>
}
</Grid>
</div>
);
}
}
export const DetailsComponent = connect((state)=>{
return {
host: state.gremlin.host,
port: state.gremlin.port,
network: state.graph.network,
selectedNode: state.graph.selectedNode,
selectedEdge: state.graph.selectedEdge,
queryHistory: state.options.queryHistory,
nodeLabels: state.options.nodeLabels,
isPhysicsEnabled: state.options.isPhysicsEnabled
};
})(Details);