forked from gaearon/react-devtools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQueryViewer.js
More file actions
118 lines (109 loc) · 3.13 KB
/
QueryViewer.js
File metadata and controls
118 lines (109 loc) · 3.13 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
112
113
114
115
116
117
118
/**
* 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';
import type {Map} from 'immutable';
import DataView from '../../frontend/DataView/DataView';
import DetailPane from '../../frontend/detail_pane/DetailPane';
import DetailPaneSection from '../../frontend/detail_pane/DetailPaneSection';
import React from 'react';
import decorate from '../../frontend/decorate';
import tidyGraphQL from './tidyGraphQL';
class QueryViewer extends React.Component {
props: {
data: Map,
inspect: (path: Array<string>, cb: () => void) => void,
};
render() {
var data = this.props.data;
var status = data.get('status');
var resultBlock = null;
if (status === 'success') {
resultBlock =
<DetailPaneSection title="Response">
<DataView
data={data.get('response')}
readOnly={true}
showMenu={false}
inspect={this.props.inspect}
path={['response']}
/>
</DetailPaneSection>;
} else if (status === 'failure') {
resultBlock =
<DetailPaneSection title="Error">
<DataView
data={data.get('error')}
readOnly={true}
showMenu={false}
inspect={this.props.inspect}
path={['error']}
/>
</DetailPaneSection>;
}
const start = data.get('start');
const end = data.get('end');
return (
<DetailPane header={data.get('type') + ': ' + data.get('name')}>
<DetailPaneSection title="Start">
<div>
{Math.round(start) / 1000}s since page load
</div>
</DetailPaneSection>
<DetailPaneSection title="Status">
<div>
{status}
</div>
</DetailPaneSection>
<DetailPaneSection title="Duration">
<div>
{Math.round(end - start)}ms
</div>
</DetailPaneSection>
<DetailPaneSection title="Query">
<div style={styles.query}>
{tidyGraphQL(data.get('text'))}
</div>
</DetailPaneSection>
<DetailPaneSection title="Variables">
<DataView
data={data.get('variables')}
readOnly={true}
showMenu={false}
inspect={this.props.inspect}
path={['variables']}
/>
</DetailPaneSection>
{resultBlock}
</DetailPane>
);
}
}
var styles = {
query: {
cursor: 'text',
fontFamily: 'monospace',
userSelect: 'text',
MozUserSelect: 'text',
WebkitUserSelect: 'text',
whiteSpace: 'pre',
wordWrap: 'break-word',
},
};
module.exports = decorate({
store: 'relayStore',
listeners: (props, store) => ['selectedQuery', store.selectedQuery],
props(store) {
return {
data: store.queries.get(store.selectedQuery),
inspect: store.inspect.bind(store, store.selectedQuery),
};
},
}, QueryViewer);