-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathInfo.tsx
94 lines (90 loc) · 1.99 KB
/
Info.tsx
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
import React, { useState, useEffect, useCallback } from "react";
import {
EuiFlexGroup,
EuiFlexItem,
} from "@elastic/eui";
import moment from "moment";
export interface IProps {
/**
* Format of date to be displayed
*/
dateFormat?: string;
/**
* Interval for the buckets of the recent request
*/
bucketInterval?: {
scaled?: boolean;
description?: string;
scale?: number;
timeFieldName: string;
};
/**
* Range of dates to be displayed
*/
timeRange?: {
from: string;
to: string;
};
/**
* selected interval
*/
stateInterval: string;
total: number;
took?: number;
}
export default ({
bucketInterval,
dateFormat,
timeRange,
stateInterval,
total,
took,
}: IProps) => {
const [interval, setInterval] = useState(stateInterval);
const toMoment = useCallback(
(datetime: string) => {
if (!datetime) {
return "";
}
if (!dateFormat) {
return datetime;
}
return moment(datetime).format(dateFormat);
},
[dateFormat]
);
useEffect(() => {
setInterval(stateInterval);
}, [stateInterval]);
return (
<EuiFlexGroup
gutterSize="s"
responsive
justifyContent="center"
alignItems="center"
>
<EuiFlexItem grow={false}>
<div style={{ fontSize: 12}}>
Found <span style={{fontWeight: "bold" }}>{total}</span>{" "}
records {took && (
<span style={{marginLeft: 5 }}>
({took} milliscond)
</span>
)}
{timeRange && (
<span style={{marginLeft: 5 }}>
{`between ${toMoment(timeRange.from)} and ${toMoment(
timeRange.to
)} ${
interval !== "auto" ? "" : "" //per
}`}
</span>
)}
{bucketInterval && (
<span>{`(${bucketInterval.timeFieldName} per ${bucketInterval.description})`}</span>
)}
</div>
</EuiFlexItem>
</EuiFlexGroup>
);
}