From 3a7f23f75e0fb500ee35af54706d8b2a6e1bd087 Mon Sep 17 00:00:00 2001 From: ManishMadan2882 Date: Thu, 6 Mar 2025 01:56:38 +0530 Subject: [PATCH] (feat:logs) ui --- frontend/src/settings/Logs.tsx | 91 ++++++++++++++++++++++++++-------- frontend/tailwind.config.cjs | 6 +++ 2 files changed, 75 insertions(+), 22 deletions(-) diff --git a/frontend/src/settings/Logs.tsx b/frontend/src/settings/Logs.tsx index 49a2e7a5..173e0461 100644 --- a/frontend/src/settings/Logs.tsx +++ b/frontend/src/settings/Logs.tsx @@ -104,6 +104,7 @@ export default function Logs() { } rounded="3xl" border="border" + darkBorderColor="dim-gray" /> )} @@ -121,46 +122,82 @@ type LogsTableProps = { setPage: React.Dispatch>; loading: boolean; }; - function LogsTable({ logs, setPage, loading }: LogsTableProps) { const { t } = useTranslation(); - const observerRef = useRef(); - const firstObserver = useCallback((node: HTMLDivElement) => { - if (observerRef.current) { - observerRef.current = new IntersectionObserver((entries) => { - if (entries[0].isIntersecting) setPage((prev) => prev + 1); - }); + const observerRef = useRef(null); + const [openLogId, setOpenLogId] = useState(null); + + const handleLogToggle = (logId: string) => { + if (openLogId && openLogId !== logId) { + // If a different log is being opened, close the current one + const currentOpenLog = document.getElementById( + openLogId, + ) as HTMLDetailsElement; + if (currentOpenLog) { + currentOpenLog.open = false; + } } - if (node && observerRef.current) observerRef.current.observe(node); + setOpenLogId(logId); + }; + + const firstObserver = useCallback((node: HTMLDivElement | null) => { + // Cleanup previous observer + if (observerRef.current) { + observerRef.current.disconnect(); + } + + // If node is null, just cleanup and return + if (!node) return; + + // Create new observer + observerRef.current = new IntersectionObserver((entries) => { + if (entries[0].isIntersecting) { + setPage((prev) => prev + 1); + } + }); + + observerRef.current.observe(node); + }, []); + + // Cleanup observer on component unmount + useEffect(() => { + return () => { + if (observerRef.current) { + observerRef.current.disconnect(); + } + }; }, []); return ( -
-
+
+

{t('settings.logs.tableHeader')}

-
+
{logs?.map((log, index) => { if (index === logs.length - 1) { return (
- +
); - } else return ; + } else + return ; })} {loading && }
); } - -function Log({ log }: { log: LogData }) { +function Log({ + log, + onToggle, +}: { + log: LogData; + onToggle: (id: string) => void; +}) { const { t } = useTranslation(); const logLevelColor = { info: 'text-green-500', @@ -168,9 +205,18 @@ function Log({ log }: { log: LogData }) { warning: 'text-yellow-500', }; const { id, action, timestamp, ...filteredLog } = log; + return ( -
- +
{ + if ((e.target as HTMLDetailsElement).open) { + onToggle(log.id); + } + }} + > + Expand log entry -
+

{JSON.stringify(filteredLog, null, 2)}

-
+
diff --git a/frontend/tailwind.config.cjs b/frontend/tailwind.config.cjs index 6930c453..baff4501 100644 --- a/frontend/tailwind.config.cjs +++ b/frontend/tailwind.config.cjs @@ -76,6 +76,12 @@ module.exports = { 'apple-green': '#4CAF50', 'medium-purple': '#8d66dd', 'slate-blue': '#6f5fca', + 'old-silver': '#848484', + 'arsenic': '#4D4E58', + 'light-gainsboro': '#d7D7D7', + 'raisin-black-light': '#18181B', + 'gunmetal': '#32333B', + 'sonic-silver-light': '#7f7f82' }, }, },