-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathcodegate-status-polling-control.tsx
54 lines (49 loc) · 1.51 KB
/
codegate-status-polling-control.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
import { Dispatch, SetStateAction } from "react";
import {
Label,
Select,
SelectButton,
TDropdownItemOrSection,
} from "@stacklok/ui-kit";
// NOTE: We don't poll more than once per minute, as the server depends on
// Github's public API, which is rate limited to 60reqs per hour.
export const POLLING_INTERVAl = {
"1_MIN": { value: 60_000, name: "1 minute" },
"5_MIN": { value: 300_000, name: "5 minutes" },
"10_MIN": { value: 600_000, name: "10 minutes" },
} as const;
export const INTERVAL_SELECT_ITEMS: TDropdownItemOrSection[] = Object.entries(
POLLING_INTERVAl,
).map(([key, { name }]) => {
return { textValue: name, id: key };
});
export const DEFAULT_INTERVAL: PollingInterval = "5_MIN";
export type PollingInterval = keyof typeof POLLING_INTERVAl;
export function PollIntervalControl({
className,
pollingInterval,
setPollingInterval,
}: {
className?: string;
pollingInterval: PollingInterval;
setPollingInterval: Dispatch<SetStateAction<PollingInterval>>;
}) {
return (
<Select
className={className}
onSelectionChange={(v) =>
setPollingInterval(v.toString() as PollingInterval)
}
items={INTERVAL_SELECT_ITEMS}
defaultSelectedKey={pollingInterval}
>
<Label className="w-full text-right font-semibold text-secondary -mb-1">
Check for updates
</Label>
<SelectButton
isBorderless
className="h-7 max-w-36 pr-0 [&>span>span]:text-right [&>span>span]:justify-end !gap-0 text-secondary"
/>
</Select>
);
}