-
Notifications
You must be signed in to change notification settings - Fork 426
Expand file tree
/
Copy pathobservability-toolbar.tsx
More file actions
94 lines (86 loc) · 3.06 KB
/
Copy pathobservability-toolbar.tsx
File metadata and controls
94 lines (86 loc) · 3.06 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
/**
* Copyright 2026 Redpanda Data, Inc.
*
* Use of this software is governed by the Business Source License
* included in the file https://github.com/redpanda-data/redpanda/blob/dev/licenses/bsl.md
*
* As of the Change Date specified in that file, in accordance with
* the Business Source License, use of this software will be governed
* by the Apache License, Version 2.0
*/
import type { FC } from 'react';
import { useMemo } from 'react';
import type { TimeRange } from '../../../utils/time-range';
import { calculateTimeRange, getTimeRanges } from '../../../utils/time-range';
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '../../redpanda-ui/components/select';
const TIME_RANGES = getTimeRanges(12 * 60 * 60 * 1000); // Up to 12 hours
function formatTimeRangeDate(date: Date): string {
return date.toLocaleString('en-US', {
month: 'short',
day: 'numeric',
hour: '2-digit',
minute: '2-digit',
second: '2-digit',
timeZone: 'UTC',
});
}
type ObservabilityToolbarProps = {
selectedTimeRange: TimeRange;
onTimeRangeChange: (timeRange: TimeRange) => void;
refreshKey: number;
};
export const ObservabilityToolbar: FC<ObservabilityToolbarProps> = ({
selectedTimeRange,
onTimeRangeChange,
refreshKey,
}) => {
// biome-ignore lint/correctness/useExhaustiveDependencies: refreshKey triggers recalculation on refresh
const timeRange = useMemo(() => calculateTimeRange(selectedTimeRange), [selectedTimeRange, refreshKey]);
const timeRangeDisplay = useMemo(
() => ({
start: formatTimeRangeDate(timeRange.start),
end: formatTimeRangeDate(timeRange.end),
}),
[timeRange]
);
return (
<div className="rounded-md border border-gray-200 p-4 shadow-sm">
<div className="flex gap-6">
<div>
<div className="mb-1 text-gray-600 text-xs">TIME RANGE</div>
<Select
items={TIME_RANGES}
onValueChange={(value) => onTimeRangeChange(value as TimeRange)}
value={selectedTimeRange}
>
<SelectTrigger className="h-8 w-[145px] text-sm">
<SelectValue />
</SelectTrigger>
<SelectContent>
{TIME_RANGES.map((option) => (
<SelectItem key={option.value} value={option.value}>
{option.label}
</SelectItem>
))}
</SelectContent>
</Select>
</div>
<div className="w-px bg-gray-300" />
<div>
<div className="mb-1 text-gray-600 text-xs">FROM</div>
<div className="font-medium text-sm">{timeRangeDisplay.start}</div>
</div>
<div className="w-px bg-gray-300" />
<div>
<div className="mb-1 text-gray-600 text-xs">TO</div>
<div className="font-medium text-sm">{timeRangeDisplay.end}</div>
</div>
<div className="w-px bg-gray-300" />
<div>
<div className="mb-1 text-gray-600 text-xs">TIMEZONE</div>
<div className="font-medium text-sm">UTC</div>
</div>
</div>
</div>
);
};