From 8894c66cf1a9bb76e2d404c269d0fb909bf8879b Mon Sep 17 00:00:00 2001 From: Nicolas Van Labeke Date: Fri, 10 Jan 2025 13:25:27 +0000 Subject: [PATCH] fix(28974): fix the magic code --- .../EventLog/components/table/EventLogTable.tsx | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/hivemq-edge/src/frontend/src/modules/EventLog/components/table/EventLogTable.tsx b/hivemq-edge/src/frontend/src/modules/EventLog/components/table/EventLogTable.tsx index d299dccac..b569c7a26 100644 --- a/hivemq-edge/src/frontend/src/modules/EventLog/components/table/EventLogTable.tsx +++ b/hivemq-edge/src/frontend/src/modules/EventLog/components/table/EventLogTable.tsx @@ -49,7 +49,7 @@ const EventLogTable: FC = ({ return data.items }, [data, globalSourceFilter, maxEvents]) - const columns = useMemo[]>(() => { + const allColumns = useMemo[]>(() => { return [ { accessorKey: 'identifier.identifier', @@ -119,6 +119,13 @@ const EventLogTable: FC = ({ ] }, [isLoading, onOpen, t]) + const displayColumns = useMemo(() => { + const [, createdColumn, severityColumn, idColumn, messageColumn] = allColumns + if (variant === 'full') return allColumns + if (isSingleSource) return [createdColumn, severityColumn, messageColumn] + else return [createdColumn, idColumn, severityColumn, messageColumn] + }, [allColumns, isSingleSource, variant]) + if (error) { return ( @@ -130,9 +137,6 @@ const EventLogTable: FC = ({ ) } - // TODO[NVL] Not the best approach; destructure within memo - const [, a, b, d, c] = columns - return ( <> {variant === 'full' && ( @@ -152,7 +156,7 @@ const EventLogTable: FC = ({ aria-label={t('eventLog.title')} data={safeData} - columns={variant === 'full' ? columns : isSingleSource ? [a, b, c] : [a, d, b, c]} + columns={displayColumns} enablePaginationGoTo={variant === 'full'} enablePaginationSizes={variant === 'full'} enableColumnFilters={variant === 'full'}