forked from sqlpad/sqlpad
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQueryResultHeader.js
More file actions
112 lines (100 loc) · 2.76 KB
/
Copy pathQueryResultHeader.js
File metadata and controls
112 lines (100 loc) · 2.76 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
import React from 'react';
import PropTypes from 'prop-types';
import Typography from 'antd/lib/typography';
import { Link } from 'react-router-dom';
import IncompleteDataNotification from '../common/IncompleteDataNotification';
import SecondsTimer from '../common/SecondsTimer.js';
import { connect } from 'unistore/react';
import { actions } from '../stores/unistoreStore';
const { Text } = Typography;
const barStyle = {
height: '30px',
borderBottom: '1px solid #ccc',
backgroundColor: '#f4f4f4',
lineHeight: '30px',
paddingLeft: 4
};
const headerItemStyle = {
paddingLeft: 4,
paddingRight: 48
};
function QueryResultHeader({
cacheKey,
config,
isRunning,
queryResult,
runQueryStartTime
}) {
if (isRunning || !queryResult) {
return (
<div style={barStyle}>
{isRunning ? (
<span style={headerItemStyle}>
<Text type="secondary">Query time: </Text>
<SecondsTimer startTime={runQueryStartTime} /> sec.
</span>
) : null}
</div>
);
}
const serverSec = queryResult
? queryResult.queryRunTime / 1000 + ' sec.'
: '';
const rowCount =
queryResult && queryResult.rows ? queryResult.rows.length : '';
const incomplete = queryResult ? queryResult.incomplete : false;
const csvDownloadLink = `/download-results/${cacheKey}.csv`;
const xlsxDownloadLink = `/download-results/${cacheKey}.xlsx`;
return (
<div style={barStyle}>
<span style={headerItemStyle}>
<Text type="secondary">Query time: </Text>
{serverSec}
</span>
<span style={headerItemStyle}>
<Text type="secondary">Rows: </Text>
{rowCount}
</span>
<span style={headerItemStyle}>
{config.allowCsvDownload && (
<span>
<Text type="secondary">Download: </Text>
<Link
style={{ marginLeft: 16 }}
target="_blank"
rel="noopener noreferrer"
to={csvDownloadLink}
>
.csv
</Link>
<Link
style={{ marginLeft: 16 }}
target="_blank"
rel="noopener noreferrer"
to={xlsxDownloadLink}
>
.xlsx
</Link>
</span>
)}
</span>
{incomplete && <IncompleteDataNotification />}
</div>
);
}
QueryResultHeader.propTypes = {
cacheKey: PropTypes.string,
config: PropTypes.object,
isRunning: PropTypes.bool,
queryResult: PropTypes.object,
runQueryStartTime: PropTypes.instanceOf(Date)
};
QueryResultHeader.defaultProps = {
cacheKey: '',
config: {},
isRunning: false
};
export default connect(
['cacheKey', 'config', 'isRunning', 'queryResult', 'runQueryStartTime'],
actions
)(React.memo(QueryResultHeader));