Skip to content

Commit f4d9a5d

Browse files
authored
Merge pull request #132 from carlosms/issue-44-errors
Show error messages in main query box
2 parents b1e6499 + 99f9246 commit f4d9a5d

File tree

3 files changed

+61
-23
lines changed

3 files changed

+61
-23
lines changed

frontend/src/App.js

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class App extends Component {
4646
results: new Map(),
4747
schema: undefined,
4848
history: [],
49-
lastResultMeta: null,
49+
lastResult: null,
5050

5151
// modal
5252
showModal: false,
@@ -117,9 +117,10 @@ FROM ( SELECT MONTH(committer_when) as month,
117117
const historyIdx = history.findIndex(i => i.key === key);
118118
const { response } = result;
119119

120+
const status =
121+
typeof response !== 'undefined' ? STATUS_SUCCESS : STATUS_ERROR;
122+
120123
if (historyIdx >= 0) {
121-
const status =
122-
typeof response !== 'undefined' ? STATUS_SUCCESS : STATUS_ERROR;
123124
const newHistory = [
124125
...history.slice(0, historyIdx),
125126
{
@@ -140,11 +141,16 @@ FROM ( SELECT MONTH(committer_when) as month,
140141
}
141142

142143
const newResults = new Map(this.state.results);
143-
newResults.set(key, result);
144+
145+
if (status === STATUS_SUCCESS) {
146+
newResults.set(key, result);
147+
} else {
148+
newResults.delete(key);
149+
}
144150

145151
this.setState({
146152
results: newResults,
147-
lastResultMeta: response ? response.meta : null
153+
lastResult: result
148154
});
149155
}
150156

@@ -166,7 +172,8 @@ FROM ( SELECT MONTH(committer_when) as month,
166172
status: STATUS_LOADING
167173
},
168174
...history
169-
]
175+
],
176+
lastResult: null
170177
},
171178
() => this.handleSetActiveResult(key)
172179
);
@@ -360,7 +367,7 @@ FROM ( SELECT MONTH(committer_when) as month,
360367
<QueryBox
361368
sql={this.state.sql}
362369
schema={this.state.schema}
363-
resultMeta={this.state.lastResultMeta}
370+
result={this.state.lastResult}
364371
handleTextChange={this.handleTextChange}
365372
handleSubmit={this.handleSubmit}
366373
exportUrl={api.queryExport(this.state.sql)}

frontend/src/components/QueryBox.js

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,36 @@ import 'codemirror/addon/hint/sql-hint';
1313

1414
import './QueryBox.less';
1515
import SuccessIcon from '../icons/success-query.svg';
16+
import ErrorIcon from '../icons/error-query.svg';
17+
18+
function ResultInfo({ result }) {
19+
if (!result) {
20+
return null;
21+
}
22+
23+
if (result.response && result.response.meta) {
24+
return (
25+
<span className="meta meta-success">
26+
<SuccessIcon className="big-icon" />Showing rows (query took{' '}
27+
{result.response.meta.elapsedTime / 1000} seconds)
28+
</span>
29+
);
30+
}
31+
32+
if (result.errorMsg) {
33+
return (
34+
<span className="meta meta-error">
35+
<ErrorIcon className="big-icon" />Query Failed - {result.errorMsg}
36+
</span>
37+
);
38+
}
39+
40+
return null;
41+
}
42+
43+
ResultInfo.propTypes = {
44+
result: PropTypes.object
45+
};
1646

1747
class QueryBox extends Component {
1848
constructor(props) {
@@ -50,7 +80,7 @@ class QueryBox extends Component {
5080
}
5181

5282
render() {
53-
const { resultMeta } = this.props;
83+
const { result } = this.props;
5484
const { codeMirrorTables } = this.state;
5585

5686
const options = {
@@ -69,16 +99,6 @@ class QueryBox extends Component {
6999
}
70100
};
71101

72-
let meta = '';
73-
if (resultMeta) {
74-
meta = (
75-
<span className="meta">
76-
<SuccessIcon className="big-icon" />Showing rows (query took{' '}
77-
{resultMeta.elapsedTime / 1000} seconds)
78-
</span>
79-
);
80-
}
81-
82102
return (
83103
<div className="query-box-padding full-height full-width">
84104
<div className="query-box full-height full-width">
@@ -95,7 +115,7 @@ class QueryBox extends Component {
95115
</Row>
96116
<Row className="button-row">
97117
<Col xs={7} className="meta-wrapper no-spacing">
98-
{meta}
118+
<ResultInfo result={result} />
99119
</Col>
100120
<Col xs={5} className="buttons-wrapper no-spacing">
101121
<Button
@@ -135,7 +155,7 @@ QueryBox.propTypes = {
135155
).isRequired
136156
})
137157
),
138-
resultMeta: PropTypes.object,
158+
result: PropTypes.object,
139159
enabled: PropTypes.bool,
140160
handleTextChange: PropTypes.func.isRequired,
141161
handleSubmit: PropTypes.func.isRequired,

frontend/src/components/QueryBox.less

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,26 @@
3434
.meta {
3535
.big-icon {
3636
margin-right: 15px;
37-
path {
38-
fill: @success;
39-
}
4037
}
4138

4239
display: table-cell;
4340
vertical-align: middle;
4441

4542
font-size: 14px;
43+
44+
&.meta-success {
45+
svg path {
46+
fill: @success;
47+
}
48+
}
49+
50+
&.meta-error {
51+
color: @error-text;
52+
53+
svg path {
54+
fill: @error-text;
55+
}
56+
}
4657
}
4758
}
4859

0 commit comments

Comments
 (0)