Skip to content

Commit 88b2820

Browse files
committed
design improvements to variable-aware editor
1 parent da31c97 commit 88b2820

File tree

2 files changed

+29
-27
lines changed

2 files changed

+29
-27
lines changed

site/_core/MiniGraphiQL.js

+19-17
Original file line numberDiff line numberDiff line change
@@ -19,42 +19,42 @@ module.exports = class MiniGraphiQL extends React.Component {
1919
constructor(props) {
2020
super();
2121

22+
const query = props.query.replace(/^\s+/, '').replace(/\s+$/, '');
23+
2224
// Initialize state
2325
this.state = {
24-
query: props.query.replace(/^\s+/, '').replace(/\s+$/, ''),
26+
query: query,
2527
variables: props.variables,
2628
response: null,
27-
variableToType: null,
29+
variableToType: getVariableToType(props.schema, query)
2830
};
2931

3032
this._editorQueryID = 0;
3133
}
3234

3335
render() {
36+
const editor =
37+
<QueryEditor
38+
key="query-editor"
39+
schema={this.props.schema}
40+
value={this.state.query}
41+
onEdit={this._handleEditQuery.bind(this)}
42+
runQuery={this._runQueryFromEditor.bind(this)}
43+
/>;
44+
3445
return (
3546
<div className="miniGraphiQL">
36-
{this.state.variables ?
47+
{Object.keys(this.state.variableToType).length > 0 ?
3748
<div className="hasVariables">
38-
<QueryEditor
39-
schema={this.props.schema}
40-
value={this.state.query}
41-
onEdit={this._handleEditQuery.bind(this)}
42-
runQuery={this._runQueryFromEditor.bind(this)}
43-
/>
49+
{editor}
4450
<VariableEditor
4551
value={this.state.variables}
4652
variableToType={this.state.variableToType}
4753
onEdit={this._handleEditVariables.bind(this)}
4854
onRunQuery={this._runQuery.bind(this)}
4955
/>
5056
</div>
51-
:
52-
<QueryEditor
53-
schema={this.props.schema}
54-
value={this.state.query}
55-
onEdit={this._handleEditQuery.bind(this)}
56-
runQuery={this._runQueryFromEditor.bind(this)}
57-
/>
57+
: editor
5858
}
5959
<ResultViewer value={this.state.response} />
6060
</div>
@@ -556,7 +556,7 @@ function onHasCompletion(cm, data, onHintInformationRender) {
556556

557557
function getVariableToType(schema, documentStr) {
558558
if (!documentStr || !schema) {
559-
return;
559+
return {};
560560
}
561561

562562
try {
@@ -579,4 +579,6 @@ function getVariableToType(schema, documentStr) {
579579
} catch (e) {
580580
// ignore
581581
}
582+
583+
return {};
582584
}

site/_css/codemirror.less

+10-10
Original file line numberDiff line numberDiff line change
@@ -694,16 +694,13 @@ div.CodeMirror span.CodeMirror-nonmatchingbracket {
694694
.miniGraphiQL {
695695
margin: 28px 0;
696696
color: #333;
697-
/*background: #faf9f9;*/
698-
/*border-left: 4px solid @rhodamine-color;*/
699697
width: 100%;
700698
display: -webkit-flex;
701699
display: flex;
702700
-webkit-flex-direction: row;
703701
flex-direction: row;
704702
position: relative;
705703

706-
padding: 3px; /*7px 14px;*/
707704
background: white;
708705
box-shadow: inset 0 0 0 1px #EEE, inset 4px 0 0 #EEE;
709706
border-radius: 3px;
@@ -713,8 +710,8 @@ div.CodeMirror span.CodeMirror-nonmatchingbracket {
713710
.query-editor .CodeMirror {
714711
height: auto;
715712
min-height: 100px;
716-
margin: 0px 7px 28px;
717-
/*background: #faf9f9;*/
713+
margin: 0px 7px 35px;
714+
background: none;
718715
}
719716

720717
.query-editor {
@@ -724,14 +721,19 @@ div.CodeMirror span.CodeMirror-nonmatchingbracket {
724721
.hasVariables {
725722
width: 50%;
726723

727-
& > .query-editor {
724+
.query-editor {
728725
width: auto;
729726
}
730727

728+
.query-editor .CodeMirror {
729+
margin-bottom: 21px;
730+
}
731+
731732
.variable-editor .CodeMirror {
732733
height: auto;
733734
min-height: 30px;
734735
margin: 0 7px;
736+
background: none;
735737
}
736738

737739
.variable-editor::before {
@@ -764,10 +766,8 @@ div.CodeMirror span.CodeMirror-nonmatchingbracket {
764766
}
765767

766768
.result-window .CodeMirror {
767-
/*background: #fbfafa;*/
768-
background: transparent;
769+
background: none;
769770
height: 100%;
770771
margin: 0 7px;
771-
-webkit-box-sizing: border-box;
772-
box-sizing: border-box;
772+
box-sizing: border-box;
773773
}

0 commit comments

Comments
 (0)