clear-stats

This commit is contained in:
Alex Holliday committed 2026-02-19 17:28:00 +00:00
1 parent b5f2a7b26c
commit a3a25b2add
2 files changed
+62 -2

No files matched your search

+37 -1
View File
@@ -1,5 +1,5 @@
import { BasePage, ConfigBox } from "@/Components/v2/design-elements";
import { Autocomplete, Select } from "@/Components/v2/inputs";
import { Autocomplete, Select, Dialog } from "@/Components/v2/inputs";
import { Stack, useTheme, MenuItem, type SelectChangeEvent } from "@mui/material";
import { useEffect } from "react";
import { useForm } from "react-hook-form";
@@ -15,6 +15,7 @@ import { useState } from "react";
import { Controller } from "react-hook-form";
import { TextField, Button, FieldLabel } from "@/Components/v2/inputs";
import { Box } from "@mui/material";
import { useDelete } from "@/Hooks/UseApi";
import {
setTimezone,
@@ -54,6 +55,9 @@ export const SettingsPage = () => {
fetchedSettings?.pagespeedKeySet ?? false
);
const [apiKeyHasBeenReset, setApiKeyHasBeenReset] = useState(false);
// Local state for clear stats dialog
const [isStatsDialogOpen, setIsStatsDialogOpen] = useState(false);
const { deleteFn: deleteStats, loading: isDeletingStats } = useDelete();
// Initialize form with schema and defaults
const { schema, defaults } = useSettingsForm({ data: fetchedSettings?.settings });
@@ -113,6 +117,11 @@ export const SettingsPage = () => {
setApiKeyHasBeenReset(true);
};
const handleClearStats = async () => {
await deleteStats("/checks/team");
setIsStatsDialogOpen(false);
};
const onSubmit = async (data: SettingsFormData) => {
// Don't send pagespeedApiKey if it's already set and user hasn't clicked reset
const dataToSend = { ...data };
@@ -306,8 +315,35 @@ export const SettingsPage = () => {
/>
}
/>
{/* Clear All Stats */}
{isAdmin && (
<ConfigBox
title={t("pages.settings.form.stats.title")}
subtitle={t("pages.settings.form.stats.description")}
rightContent={
<Button
variant="contained"
color="error"
onClick={() => setIsStatsDialogOpen(true)}
>
{t("common.buttons.clear")}
</Button>
}
/>
)}
</Stack>
{/* Clear Stats Confirmation Dialog */}
<Dialog
open={isStatsDialogOpen}
title={t("pages.settings.form.stats.dialog.title")}
content={t("pages.settings.form.stats.dialog.description")}
onCancel={() => setIsStatsDialogOpen(false)}
onConfirm={handleClearStats}
loading={isDeletingStats}
/>
{/* Sticky Save Button */}
<Stack
direction="row"
+25 -1
View File
@@ -39,7 +39,8 @@
"flushQueue": "Flush queue",
"notFound": "Go to the main dashboard",
"resetPassword": "Reset password",
"reset": "Reset"
"reset": "Reset",
"clear": "Clear"
},
"charts": {
"labels": {
@@ -555,6 +556,16 @@
"disabled": "Disabled"
}
}
},
"stats": {
"title": "Monitor history",
"description": "Clear all monitoring history and statistics for your team. This action is irreversible.",
"buttonText": "Clear all stats",
"dialog": {
"title": "Clear all monitoring history?",
"description": "This will permanently delete all monitoring history, statistics, and check data for your team. This action cannot be undone.",
"confirm": "Yes, clear all stats"
}
}
}
},
@@ -970,6 +981,19 @@
"disabled": "Disabled"
}
}
},
"stats": {
"title": "Monitor history",
"description": "Define how long you want to retain historical data. You can also clear all existing data.",
"option": {
"clear": {
"label": "Clear all stats. This is irreversible."
}
},
"dialog": {
"title": "Clear all monitoring history?",
"description": "This cannot be undone"
}
}
}
},