forked from sqlpad/sqlpad
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQueryTableOnly.js
More file actions
83 lines (72 loc) · 2.24 KB
/
Copy pathQueryTableOnly.js
File metadata and controls
83 lines (72 loc) · 2.24 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
import PropTypes from 'prop-types';
import React, { useEffect, useState } from 'react';
import ExportButton from './common/ExportButton.js';
import IncompleteDataNotification from './common/IncompleteDataNotification';
import QueryResultContainer from './common/QueryResultContainer.js';
import fetchJson from './utilities/fetch-json.js';
function QueryTableOnly({ 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) {
console.error(queryJson.error);
}
setQuery(queryJson.query);
const queryResultJson = await fetchJson(
'GET',
'/api/query-result/' + queryId
);
setIsRunning(false);
setQueryError(queryResultJson.error);
setQueryResult(queryResultJson.queryResult);
};
useEffect(() => {
document.title = 'SQLPad';
runQuery(queryId);
}, [queryId]);
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} />
</div>
</div>
<div style={{ display: 'flex', flexGrow: 1, height: '100%' }}>
<div
style={{
position: 'relative',
width: '100%',
height: '100%',
border: '1px solid #CCC'
}}
>
<QueryResultContainer
isRunning={isRunning}
queryResult={queryResult}
queryError={queryError}
/>
</div>
</div>
</div>
);
}
QueryTableOnly.propTypes = {
queryId: PropTypes.string.isRequired
};
export default QueryTableOnly;