From 4486697ca5b9fed281ec782a5a4a18dfacc79433 Mon Sep 17 00:00:00 2001 From: Noste <83548733+Noooste@users.noreply.github.com> Date: Sat, 7 Mar 2026 11:18:14 +0100 Subject: [PATCH] refactor: simplify access key loading in BucketSettingsDialog and enhance last modified tooltip in ObjectsTable Signed-off-by: Noste <83548733+Noooste@users.noreply.github.com> --- .../buckets/BucketSettingsDialog.tsx | 16 +--- .../src/components/buckets/ObjectsTable.tsx | 90 ++++++++++--------- 2 files changed, 50 insertions(+), 56 deletions(-) diff --git a/frontend/src/components/buckets/BucketSettingsDialog.tsx b/frontend/src/components/buckets/BucketSettingsDialog.tsx index 7712313..5426551 100644 --- a/frontend/src/components/buckets/BucketSettingsDialog.tsx +++ b/frontend/src/components/buckets/BucketSettingsDialog.tsx @@ -10,8 +10,8 @@ import { DialogHeader, DialogTitle, } from '@/components/ui/dialog'; -import { accessApi } from '@/lib/api'; -import type { AccessKey, Bucket } from '@/types'; +import { useAccessKeys } from '@/hooks/useApi'; +import type { Bucket } from '@/types'; import { toast } from 'sonner'; interface BucketSettingsDialogProps { @@ -22,7 +22,7 @@ interface BucketSettingsDialogProps { } export function BucketSettingsDialog({ open, onOpenChange, bucket, onGrantPermission }: BucketSettingsDialogProps) { - const [availableKeys, setAvailableKeys] = useState([]); + const { data: availableKeys = [] } = useAccessKeys(); const [selectedAccessKey, setSelectedAccessKey] = useState(''); const [permissionRead, setPermissionRead] = useState(false); const [permissionWrite, setPermissionWrite] = useState(false); @@ -30,20 +30,10 @@ export function BucketSettingsDialog({ open, onOpenChange, bucket, onGrantPermis useEffect(() => { if (open && bucket) { - loadAccessKeys(); resetForm(); } }, [open, bucket]); - const loadAccessKeys = async () => { - try { - const keys = await accessApi.listKeys(); - setAvailableKeys(keys); - } catch (error) { - console.error('Failed to load access keys:', error); - } - }; - const resetForm = () => { setSelectedAccessKey(''); setPermissionRead(false); diff --git a/frontend/src/components/buckets/ObjectsTable.tsx b/frontend/src/components/buckets/ObjectsTable.tsx index cf13a0c..457f654 100644 --- a/frontend/src/components/buckets/ObjectsTable.tsx +++ b/frontend/src/components/buckets/ObjectsTable.tsx @@ -301,56 +301,60 @@ export function ObjectsTable({ {obj.isFolder ? null : formatBytes(obj.size)} - {obj.lastModified ? - - - -
- {new Date(obj.lastModified).toLocaleDateString('en-GB', { - day: '2-digit', - month: 'short', - year: 'numeric', - })} {new Date(obj.lastModified).toLocaleTimeString('en-GB', { - hour: '2-digit', - minute: '2-digit', - second: '2-digit', - hour12: false, - })} CET -
-
- -
-
- UTC - - {new Date(obj.lastModified).toLocaleString('en-GB', { + {obj.lastModified ? (() => { + const d = new Date(obj.lastModified); + return ( + + + +
+ {d.toLocaleDateString('en-GB', { day: '2-digit', month: 'short', year: 'numeric', + })} {d.toLocaleTimeString('en-GB', { hour: '2-digit', minute: '2-digit', second: '2-digit', hour12: false, - timeZone: 'UTC', - })} UTC - -
-
- Relative - - {formatRelativeTime(new Date(obj.lastModified))} - -
-
- Timestamp - - {new Date(obj.lastModified).toISOString()} - -
-
- - - : null} + })} CET +
+ + +
+
+ UTC + + {d.toLocaleString('en-GB', { + day: '2-digit', + month: 'short', + year: 'numeric', + hour: '2-digit', + minute: '2-digit', + second: '2-digit', + hour12: false, + timeZone: 'UTC', + })} UTC + +
+
+ Relative + + {formatRelativeTime(d)} + +
+
+ Timestamp + + {d.toISOString()} + +
+
+
+
+
+ ); + })() : null}
{!obj.isFolder && (