Skip to content

Commit

Permalink
fix(DatatableV2): fix Rendered fewer hooks than expected issue
Browse files Browse the repository at this point in the history
Ref AFE-209
  • Loading branch information
ajkl2533 committed Oct 9, 2024
1 parent 0af3cdc commit f00dd17
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 9 deletions.
6 changes: 4 additions & 2 deletions src/components/DatatableV2/buttons/ExpandAllButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,18 @@ import IconButton from '../../ButtonV2/IconButton';
import { useSafeTranslation } from '../../../hooks/useSafeTranslation';

const ExpandAllButton = <D,>({ table }: { table: DatatableInstance<D> }) => {
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 (
<IconButton
Expand Down
2 changes: 1 addition & 1 deletion src/components/DatatableV2/buttons/ExpandButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ const ExpandButton = <D,>({
table: DatatableInstance<D>;
row: DatatableRow<D>;
}) => {
const { t } = useSafeTranslation();
const {
options: { renderDetailPanel },
} = table;
const { getIsExpanded, getCanExpand, toggleExpanded } = row;

const canExpand = getCanExpand();
const isExpanded = getIsExpanded();
const { t } = useSafeTranslation();

return (
<IconButton
Expand Down
2 changes: 1 addition & 1 deletion src/components/DatatableV2/header/HeaderCell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ const HeaderCell = <D,>({
<HeaderCellResizeHandler header={header} table={table} />
)}
</Inline>
) : Object.values(displayColumnIds).indexOf(columnDef.id) > 0 ? (
) : Object.values(displayColumnIds).includes(columnDef.id) ? (
<Inline align="center" justify="center">
{headerElement}
</Inline>
Expand Down
7 changes: 2 additions & 5 deletions src/components/DatatableV2/hooks/useDisplayColumns.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,8 @@ export const useDisplayColumns = <D,>(
tableOptions.enableExpanding && {
id: displayColumnIds.expand,
header: '',
headerComponent: tableOptions.enableExpandAll
? ExpandAllButton
: null,
cell: ExpandButton,
headerComponent: (props) => <ExpandAllButton {...props} />,
cell: (props) => <ExpandButton {...props} />,
size: 56,
...tableOptions.defaultDisplayColumn,
},
Expand Down Expand Up @@ -59,7 +57,6 @@ export const useDisplayColumns = <D,>(
).filter(Boolean),
[
tableOptions.enableExpanding,
tableOptions.enableExpandAll,
tableOptions.enableRowSelection,
tableOptions.enableSelectAll,
tableOptions.enableMultiRowSelection,
Expand Down

0 comments on commit f00dd17

Please sign in to comment.