Skip to content

Commit 8db97c3

Browse files
fix(AnalyticalTable): Always respect Cell option (#359)
Closes #358
1 parent d19c256 commit 8db97c3

File tree

7 files changed

+25
-9
lines changed

7 files changed

+25
-9
lines changed

packages/main/src/components/AnalyticalTable/defaults/Column/Aggregated.tsx

Lines changed: 0 additions & 3 deletions
This file was deleted.

packages/main/src/components/AnalyticalTable/defaults/Column/Cell.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Text } from '@ui5/webcomponents-react/lib/Text';
22
import React from 'react';
33

44
export const Cell = ({ cell: { value = '', isGrouped }, row }) => {
5-
let cellContent = `${value}`;
5+
let cellContent = `${value ?? ''}`;
66
if (isGrouped) {
77
cellContent += ` (${row.subRows.length})`;
88
}

packages/main/src/components/AnalyticalTable/defaults/Column/Expandable.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ export const Expandable = (props) => {
6868
) : (
6969
<span style={{ paddingLeft }} />
7070
)}
71-
{cell.value && cell.render('Cell')}
71+
{cell.render('Cell')}
7272
</>
7373
);
7474
};

packages/main/src/components/AnalyticalTable/defaults/Column/index.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { VerticalAlign } from '@ui5/webcomponents-react/lib/VerticalAlign';
22
import { DefaultFilterComponent } from '../FilterComponent';
3-
import { Aggregated } from './Aggregated';
43
import { Cell } from './Cell';
54
import { Expandable } from './Expandable';
65
import { Grouped } from './Grouped';
@@ -18,7 +17,6 @@ export const DefaultColumn = {
1817
canReorder: true,
1918
minWidth: DEFAULT_COLUMN_WIDTH,
2019
vAlign: VerticalAlign.Middle,
21-
Aggregated: Aggregated,
2220
defaultFilter: defaultFilterMethod,
2321
Grouped: Grouped,
2422
Cell: Cell,

packages/main/src/components/AnalyticalTable/hooks/useRowSelectionColumn.tsx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ export const useRowSelectionColumn: PluginHook<{}> = (hooks) => {
6161
// to the render a checkbox
6262
// eslint-disable-next-line react/prop-types,react/display-name
6363
Cell: ({ row }) => {
64+
if (row.isGrouped && selectionMode === TableSelectionMode.SINGLE_SELECT) {
65+
return null;
66+
}
6467
if (selectionMode === TableSelectionMode.SINGLE_SELECT) {
6568
// eslint-disable-next-line react/prop-types
6669
return <div style={divStyle} onClick={row.toggleRowSelected} />;
@@ -72,5 +75,23 @@ export const useRowSelectionColumn: PluginHook<{}> = (hooks) => {
7275
...columns
7376
];
7477
});
78+
79+
hooks.visibleColumnsDeps.push((deps, { instance }) => [
80+
...deps,
81+
instance.webComponentsReactProperties.noSelectionColumn,
82+
instance.webComponentsReactProperties.selectionMode
83+
]);
84+
85+
hooks.visibleColumns.push((columns, { instance: { webComponentsReactProperties } }) => {
86+
if (
87+
webComponentsReactProperties.noSelectionColumn ||
88+
webComponentsReactProperties.selectionMode === TableSelectionMode.NONE
89+
) {
90+
return columns;
91+
}
92+
93+
const selectionColumn = columns.find(({ id }) => id === '__ui5wcr__internal_selection_column');
94+
return [selectionColumn, ...columns.filter(({ id }) => id !== '__ui5wcr__internal_selection_column')];
95+
});
7596
};
7697
useRowSelectionColumn.pluginName = 'useRowSelectionColumn';

packages/main/src/components/AnalyticalTable/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,6 @@ const AnalyticalTable: FC<TableProps> = forwardRef((props: TableProps, ref: Ref<
215215
},
216216
...reactTableOptions
217217
},
218-
useRowSelectionColumn,
219218
useAbsoluteLayout,
220219
useFilters,
221220
useGroupBy,
@@ -232,6 +231,7 @@ const AnalyticalTable: FC<TableProps> = forwardRef((props: TableProps, ref: Ref<
232231
useColumnsDependencies,
233232
useTableCellStyling,
234233
useToggleRowExpand,
234+
useRowSelectionColumn,
235235
...tableHooks
236236
);
237237

packages/main/src/components/AnalyticalTable/virtualization/VirtualTableRow.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export const VirtualTableRow = (props) => {
2525
contentToRender = 'Expandable';
2626
} else if (cell.isGrouped) {
2727
contentToRender = 'Grouped';
28-
} else if (row.isGrouped) {
28+
} else if (cell.isAggregated) {
2929
contentToRender = 'Aggregated';
3030
} else if (cell.isPlaceholder || cell.column.isGrouped) {
3131
contentToRender = 'RepeatedValue';

0 commit comments

Comments
 (0)