refactor: Remove manual cleanup buttons from Data Retention Settings

- The three manual cleanup buttons have been removed from the dashboard.
- The data retention service now automatically runs once per day, cleaning up older data based on the configured retention settings.
This commit is contained in:
Tola Leng
2025-09-13 02:28:52 +07:00
parent 0b04034141
commit 9b0b2663ec
@@ -52,7 +52,6 @@ const DataRetentionSettings = () => {
setLastCleanup(result.lastCleanup); setLastCleanup(result.lastCleanup);
} }
} catch (error) { } catch (error) {
console.error("Error loading retention settings:", error);
toast({ toast({
title: "Error", title: "Error",
description: "Failed to load retention settings", description: "Failed to load retention settings",
@@ -72,7 +71,6 @@ const DataRetentionSettings = () => {
description: "Data retention settings have been updated", description: "Data retention settings have been updated",
}); });
} catch (error) { } catch (error) {
console.error("Error saving retention settings:", error);
toast({ toast({
title: "Error", title: "Error",
description: "Failed to save retention settings", description: "Failed to save retention settings",
@@ -96,7 +94,6 @@ const DataRetentionSettings = () => {
// Reload settings to get updated last cleanup time // Reload settings to get updated last cleanup time
await loadSettings(); await loadSettings();
} catch (error) { } catch (error) {
console.error("Error during uptime cleanup:", error);
toast({ toast({
title: "Error", title: "Error",
description: "Failed to perform uptime data cleanup", description: "Failed to perform uptime data cleanup",
@@ -120,7 +117,6 @@ const DataRetentionSettings = () => {
// Reload settings to get updated last cleanup time // Reload settings to get updated last cleanup time
await loadSettings(); await loadSettings();
} catch (error) { } catch (error) {
console.error("Error during server cleanup:", error);
toast({ toast({
title: "Error", title: "Error",
description: "Failed to perform server data cleanup", description: "Failed to perform server data cleanup",
@@ -144,7 +140,6 @@ const DataRetentionSettings = () => {
// Reload settings to get updated last cleanup time // Reload settings to get updated last cleanup time
await loadSettings(); await loadSettings();
} catch (error) { } catch (error) {
console.error("Error during manual cleanup:", error);
toast({ toast({
title: "Error", title: "Error",
description: "Failed to perform database cleanup", description: "Failed to perform database cleanup",
@@ -170,7 +165,7 @@ const DataRetentionSettings = () => {
<Alert className="border-blue-200 bg-blue-50 dark:bg-blue-950 dark:border-blue-800"> <Alert className="border-blue-200 bg-blue-50 dark:bg-blue-950 dark:border-blue-800">
<AlertTriangle className="h-5 w-5 text-blue-600 dark:text-blue-400" /> <AlertTriangle className="h-5 w-5 text-blue-600 dark:text-blue-400" />
<AlertDescription className="text-blue-700 dark:text-blue-300"> <AlertDescription className="text-blue-700 dark:text-blue-300">
<span className="font-medium">{t("permissionNotice")}</span> As an admin user, you do not have access to data retention settings. These settings can only be accessed and modified by Super Admins. <span className="font-medium">Permission Notice:</span> As an admin user, you do not have access to data retention settings. These settings can only be accessed and modified by Super Admins.
</AlertDescription> </AlertDescription>
</Alert> </Alert>
</CardContent> </CardContent>
@@ -210,10 +205,16 @@ const DataRetentionSettings = () => {
min="1" min="1"
max="365" max="365"
value={settings.uptimeRetentionDays} value={settings.uptimeRetentionDays}
onChange={(e) => setSettings(prev => ({ onChange={(e) => {
...prev, const value = e.target.value;
uptimeRetentionDays: parseInt(e.target.value) || 30 if (value === '' || isNaN(Number(value))) {
}))} return;
}
setSettings(prev => ({
...prev,
uptimeRetentionDays: Number(value)
}));
}}
className="mt-1" className="mt-1"
/> />
<p className="text-sm text-muted-foreground mt-1"> <p className="text-sm text-muted-foreground mt-1">
@@ -229,10 +230,16 @@ const DataRetentionSettings = () => {
min="1" min="1"
max="365" max="365"
value={settings.serverRetentionDays} value={settings.serverRetentionDays}
onChange={(e) => setSettings(prev => ({ onChange={(e) => {
...prev, const value = e.target.value;
serverRetentionDays: parseInt(e.target.value) || 30 if (value === '' || isNaN(Number(value))) {
}))} return;
}
setSettings(prev => ({
...prev,
serverRetentionDays: Number(value)
}));
}}
className="mt-1" className="mt-1"
/> />
<p className="text-sm text-muted-foreground mt-1"> <p className="text-sm text-muted-foreground mt-1">
@@ -250,63 +257,17 @@ const DataRetentionSettings = () => {
</Alert> </Alert>
)} )}
</CardContent> </CardContent>
<CardFooter className="flex flex-col gap-4"> <CardFooter className="flex justify-end">
<div className="flex flex-wrap gap-2 w-full"> <Button
<Button onClick={handleSave}
variant="outline" disabled={isSaving}
onClick={handleUptimeShrink} className="flex items-center gap-2"
disabled={isUptimeShrinking} >
className="flex items-center gap-2" {isSaving ? (
> <Loader2 className="h-4 w-4 animate-spin" />
{isUptimeShrinking ? ( ) : null}
<Loader2 className="h-4 w-4 animate-spin" /> Save Changes
) : ( </Button>
<Globe className="h-4 w-4" />
)}
Shrink Uptime Data
</Button>
<Button
variant="outline"
onClick={handleServerShrink}
disabled={isServerShrinking}
className="flex items-center gap-2"
>
{isServerShrinking ? (
<Loader2 className="h-4 w-4 animate-spin" />
) : (
<Server className="h-4 w-4" />
)}
Shrink Server Data
</Button>
<Button
variant="outline"
onClick={handleFullShrink}
disabled={isFullShrinking}
className="flex items-center gap-2"
>
{isFullShrinking ? (
<Loader2 className="h-4 w-4 animate-spin" />
) : (
<Trash2 className="h-4 w-4" />
)}
Full Database Shrink
</Button>
</div>
<div className="flex justify-end w-full">
<Button
onClick={handleSave}
disabled={isSaving}
className="flex items-center gap-2"
>
{isSaving ? (
<Loader2 className="h-4 w-4 animate-spin" />
) : null}
Save Changes
</Button>
</div>
</CardFooter> </CardFooter>
</Card> </Card>
</div> </div>