forked from jordanlambrecht/tracker-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDataSection.tsx
More file actions
88 lines (81 loc) · 2.78 KB
/
Copy pathDataSection.tsx
File metadata and controls
88 lines (81 loc) · 2.78 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
// src/components/settings/DataSection.tsx
"use client"
import { H3, Paragraph } from "@typography"
import { useState } from "react"
import { DatabaseSizeChart } from "@/components/settings/DatabaseSizeChart"
import { SettingsSection } from "@/components/settings/SettingsSection"
import { Divider, SaveDiscardBar, Select } from "@/components/ui"
import { usePatchSettings } from "@/hooks/usePatchSettings"
export interface DataSectionProps {
initialPollInterval: number
}
export function DataSection({ initialPollInterval }: DataSectionProps) {
const [pollInterval, setPollInterval] = useState(initialPollInterval)
const [savedPollInterval, setSavedPollInterval] = useState(initialPollInterval)
const {
saving: savingPollInterval,
error: pollIntervalError,
success: pollIntervalSuccess,
patch,
clearSuccess,
} = usePatchSettings()
async function handleSavePollInterval() {
const result = await patch({ trackerPollIntervalMinutes: pollInterval })
if (result.ok) {
setSavedPollInterval(
(result.data as { trackerPollIntervalMinutes: number }).trackerPollIntervalMinutes
)
}
}
return (
<SettingsSection id="data" title="Data">
{/* Poll interval */}
<div className="flex flex-col gap-3">
<H3>Tracker Poll Interval</H3>
<Paragraph>
How often all trackers are polled for new stats. All trackers poll on the same schedule to
keep data points aligned.
</Paragraph>
<Select
value={String(pollInterval)}
onChange={(v) => {
setPollInterval(Number(v))
clearSuccess()
}}
ariaLabel="Poll interval"
label="Interval"
size="md"
className="max-w-48"
options={[
{ value: "15", label: "15 min" },
{ value: "30", label: "30 min" },
{ value: "60", label: "1 hour" },
{ value: "180", label: "3 hours" },
{ value: "360", label: "6 hours" },
{ value: "720", label: "12 hours" },
{ value: "1440", label: "24 hours" },
]}
/>
<SaveDiscardBar
dirty={pollInterval !== savedPollInterval}
saving={savingPollInterval}
onSave={handleSavePollInterval}
error={pollIntervalError}
success={pollIntervalSuccess ? "Poll interval saved." : null}
saveLabel="Save Interval"
justify="end"
showDivider={false}
/>
</div>
{/* Database Size */}
<Divider compact />
<div className="flex flex-col gap-3">
<H3>Storage</H3>
<Paragraph>
Database size over time. Dashed line shows projected growth at current rate.
</Paragraph>
<DatabaseSizeChart />
</div>
</SettingsSection>
)
}