From f00dd17213d2e82bbe3cd8de3211c271b079d1d3 Mon Sep 17 00:00:00 2001 From: Radek Podrazky Date: Wed, 9 Oct 2024 16:35:09 +0200 Subject: [PATCH] fix(DatatableV2): fix Rendered fewer hooks than expected issue Ref AFE-209 --- src/components/DatatableV2/buttons/ExpandAllButton.tsx | 6 ++++-- src/components/DatatableV2/buttons/ExpandButton.tsx | 2 +- src/components/DatatableV2/header/HeaderCell.tsx | 2 +- src/components/DatatableV2/hooks/useDisplayColumns.tsx | 7 ++----- 4 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/components/DatatableV2/buttons/ExpandAllButton.tsx b/src/components/DatatableV2/buttons/ExpandAllButton.tsx index 6780c8200..405e1a379 100644 --- a/src/components/DatatableV2/buttons/ExpandAllButton.tsx +++ b/src/components/DatatableV2/buttons/ExpandAllButton.tsx @@ -3,16 +3,18 @@ import IconButton from '../../ButtonV2/IconButton'; import { useSafeTranslation } from '../../../hooks/useSafeTranslation'; const ExpandAllButton = ({ table }: { table: DatatableInstance }) => { + const { t } = useSafeTranslation(); const { getIsSomeRowsExpanded, getState, - options: { renderDetailPanel }, + options: { renderDetailPanel, enableExpandAll }, toggleAllRowsExpanded, } = table; const { isLoading } = getState(); const areSomeRowsExpanded = getIsSomeRowsExpanded(); - const { t } = useSafeTranslation(); + + if (!enableExpandAll) return null; return ( ({ table: DatatableInstance; row: DatatableRow; }) => { + const { t } = useSafeTranslation(); const { options: { renderDetailPanel }, } = table; @@ -16,7 +17,6 @@ const ExpandButton = ({ const canExpand = getCanExpand(); const isExpanded = getIsExpanded(); - const { t } = useSafeTranslation(); return ( ({ )} - ) : Object.values(displayColumnIds).indexOf(columnDef.id) > 0 ? ( + ) : Object.values(displayColumnIds).includes(columnDef.id) ? ( {headerElement} diff --git a/src/components/DatatableV2/hooks/useDisplayColumns.tsx b/src/components/DatatableV2/hooks/useDisplayColumns.tsx index ea3d887f9..d58a32b4e 100644 --- a/src/components/DatatableV2/hooks/useDisplayColumns.tsx +++ b/src/components/DatatableV2/hooks/useDisplayColumns.tsx @@ -21,10 +21,8 @@ export const useDisplayColumns = ( tableOptions.enableExpanding && { id: displayColumnIds.expand, header: '', - headerComponent: tableOptions.enableExpandAll - ? ExpandAllButton - : null, - cell: ExpandButton, + headerComponent: (props) => , + cell: (props) => , size: 56, ...tableOptions.defaultDisplayColumn, }, @@ -59,7 +57,6 @@ export const useDisplayColumns = ( ).filter(Boolean), [ tableOptions.enableExpanding, - tableOptions.enableExpandAll, tableOptions.enableRowSelection, tableOptions.enableSelectAll, tableOptions.enableMultiRowSelection,