Skip to content

Commit 06ccdcc

Browse files
[BUGFIX] - Table remove duplication of columnSetting (#489)
* fixes duplication of columnSettings Signed-off-by: christophrichtersap <[email protected]> * fixes linting Signed-off-by: christophrichtersap <[email protected]> * removed conditioonal check Signed-off-by: christophrichtersap <[email protected]> * removed conditioonal check Signed-off-by: christophrichtersap <[email protected]> --------- Signed-off-by: christophrichtersap <[email protected]>
1 parent 5cb5f0e commit 06ccdcc

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

table/src/components/TablePanel.tsx

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -262,26 +262,30 @@ export function TablePanel({ contentDimensions, spec, queryResults }: TableProps
262262
return uniqueValues;
263263
}, [data, keys]);
264264

265+
// Generate columns and map each column accessor to its settings index and data key
265266
const columns: Array<TableColumnConfig<unknown>> = useMemo(() => {
266267
const columns: Array<TableColumnConfig<unknown>> = [];
268+
const customizedColumns = new Set<string>();
267269

268-
// Taking the customized columns first for the ordering of the columns in the table
269-
const customizedColumns =
270-
spec.columnSettings?.map((column) => column.name).filter((name) => keys.includes(name)) ?? [];
271-
const defaultColumns = keys.filter((key) => !customizedColumns.includes(key));
270+
// Process columnSettings if they exist
271+
for (const columnSetting of spec.columnSettings ?? []) {
272+
if (customizedColumns.has(columnSetting.name)) continue; // Skip duplicates
272273

273-
for (const key of customizedColumns) {
274-
const columnConfig = generateColumnConfig(key, spec.columnSettings ?? []);
274+
const columnConfig = generateColumnConfig(columnSetting.name, spec.columnSettings ?? []);
275275
if (columnConfig !== undefined) {
276276
columns.push(columnConfig);
277+
customizedColumns.add(columnSetting.name);
277278
}
278279
}
279280

281+
// Add remaining columns if defaultColumnHidden is false
280282
if (!spec.defaultColumnHidden) {
281-
for (const key of defaultColumns) {
282-
const columnConfig = generateColumnConfig(key, spec.columnSettings ?? []);
283-
if (columnConfig !== undefined) {
284-
columns.push(columnConfig);
283+
for (const key of keys) {
284+
if (!customizedColumns.has(key)) {
285+
const columnConfig = generateColumnConfig(key, spec.columnSettings ?? []);
286+
if (columnConfig !== undefined) {
287+
columns.push(columnConfig);
288+
}
285289
}
286290
}
287291
}
@@ -315,11 +319,12 @@ export function TablePanel({ contentDimensions, spec, queryResults }: TableProps
315319
...row,
316320
};
317321

322+
// Generate cellConfigs for each column (including duplicates with different headers)
318323
for (const [key, value] of Object.entries(extendRow)) {
319324
// First, try to get cell config from global cell settings
320325
let cellConfig = evaluateConditionalFormatting(value, spec.cellSettings ?? []);
321326

322-
// Then, try to get cell config from column-specific cell settings if conditional formatting is enabled
327+
// Then, try to get cell config from column-specific cell settings
323328
const columnSetting = spec.columnSettings?.find((col) => col.name === key);
324329
if (columnSetting?.cellSettings?.length) {
325330
const columnCellConfig = evaluateConditionalFormatting(value, columnSetting.cellSettings);

0 commit comments

Comments
 (0)