forked from sqlpad/sqlpad
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQueryChartOnly.js
More file actions
82 lines (72 loc) · 2.35 KB
/
Copy pathQueryChartOnly.js
File metadata and controls
82 lines (72 loc) · 2.35 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
import PropTypes from 'prop-types';
import React, { useEffect, useState } from 'react';
import ExportButton from './common/ExportButton.js';
import IncompleteDataNotification from './common/IncompleteDataNotification';
import SqlpadTauChart from './common/SqlpadTauChart.js';
import { exportPng } from './common/tauChartRef';
import fetchJson from './utilities/fetch-json.js';
function QueryChartOnly({ queryId }) {
const [isRunning, setIsRunning] = useState(false);
const [queryResult, setQueryResult] = useState(null);
const [query, setQuery] = useState(null);
const [queryError, setQueryError] = useState(null);
const runQuery = async queryId => {
setIsRunning(true);
const queryJson = await fetchJson('GET', '/api/queries/' + queryId);
if (queryJson.error) {
setIsRunning(false);
setQueryError(queryJson.error);
return;
}
setQuery(queryJson.query);
const resultJson = await fetchJson('GET', '/api/query-result/' + queryId);
setIsRunning(false);
setQueryError(resultJson.error);
setQueryResult(resultJson.queryResult);
};
useEffect(() => {
document.title = 'SQLPad';
runQuery(queryId);
}, [queryId]);
const onSaveImageClick = () => {
exportPng(queryId, query && query.name);
};
const incomplete = queryResult ? queryResult.incomplete : false;
const cacheKey = queryResult ? queryResult.cacheKey : null;
return (
<div
style={{
display: 'flex',
height: '100vh',
width: '100%',
flexDirection: 'column',
padding: '16px'
}}
>
<div style={{ height: '50px' }}>
<span style={{ fontSize: '1.5rem' }}>{query ? query.name : ''}</span>
<div style={{ float: 'right' }}>
{incomplete && <IncompleteDataNotification />}
<ExportButton
cacheKey={cacheKey}
onSaveImageClick={onSaveImageClick}
/>
</div>
</div>
<div style={{ height: '100%', display: 'flex' }}>
<SqlpadTauChart
queryId={queryId}
queryName={query && query.name}
chartConfiguration={query && query.chartConfiguration}
queryResult={queryResult}
queryError={queryError}
isRunning={isRunning}
/>
</div>
</div>
);
}
QueryChartOnly.propTypes = {
queryId: PropTypes.string.isRequired
};
export default QueryChartOnly;