From c92bd64be600912d50bb1cc61484459b9679d8d7 Mon Sep 17 00:00:00 2001 From: Meghea Iulian Date: Wed, 20 Sep 2023 14:23:23 +0300 Subject: [PATCH] fix(lib/use-dom-columns): fallback sortOn, groupOn on valuePath Uses valuePath that fallbacks to name for sortOn & groupOn. --- lib/use-dom-columns.js | 154 +++++++++++++++++++++-------------------- 1 file changed, 79 insertions(+), 75 deletions(-) diff --git a/lib/use-dom-columns.js b/lib/use-dom-columns.js index 218b0bcd..0ca63d2b 100644 --- a/lib/use-dom-columns.js +++ b/lib/use-dom-columns.js @@ -14,7 +14,7 @@ const columnSymbol = Symbol('column'), // eslint-disable-next-line no-console console.error( 'The name attribute needs to be set on all columns! Missing on column', - column + column, ); }); @@ -29,7 +29,7 @@ const columnSymbol = Symbol('column'), // eslint-disable-next-line no-console console.error( 'The name attribute needs to be unique among all columns! Not unique on column', - column + column, ); }); return ok; @@ -50,79 +50,83 @@ const columnSymbol = Symbol('column'), : domColumns.filter((column) => !column.disabled); // eslint-disable-next-line max-lines-per-function - return columns.map((column) => ({ - name: column.name, - title: column.title, - - valuePath: column.valuePath ?? column.name, - groupOn: column.groupOn ?? column.valuePath, - sortOn: column.sortOn ?? column.valuePath, - - minWidth: column.minWidth, - width: column.width, - flex: column.flex, - priority: column.priority, - - getString: column.getString, - getComparableValue: column.getComparableValue, - serializeFilter: column.serializeFilter, - deserializeFilter: column.deserializeFilter, - toXlsxValue: column.toXlsxValue, - - renderHeader: column.renderHeader, - renderCell: column.renderCell, - renderEditCell: column.renderEditCell, - renderGroup: column.renderGroup, - cellTitleFn: column.cellTitleFn, - getFilterFn: column.getFilterFn, - headerCellClass: column.headerCellClass, - cellClass: column.cellClass, - - editable: column.editable, - - values: column.values, - source: memooize(column.computeSource), - - noLocalFilter: column.noLocalFilter, - - // @deprecated - loading: column.loading, - externalValues: column.externalValues, - computeSource: column.computeSource, - - // boolean columns - trueLabel: column.trueLabel, - falseLabel: column.falseLabel, - - // list columns - valueProperty: column.valueProperty, - textProperty: column.textProperty, - emptyLabel: column.emptyLabel, - emptyValue: column.emptyValue, - - // range columns - min: column.min, - max: column.max, - locale: column.locale, - autoupdate: column.autoupdate, - - // number columns - maximumFractionDigits: column.maximumFractionDigits, - minimumFractionDigits: column.minimumFractionDigits, - - // amount columns - currency: column.currency, - rates: column.rates, - autodetect: column.autodetect, - - // treenode columns - ownerTree: column.ownerTree, - keyProperty: column.keyProperty, - - ...column.getConfig?.(column), - - [columnSymbol]: column, - })); + return columns.map((column) => { + const valuePath = column.valuePath ?? column.name; + + return { + name: column.name, + title: column.title, + + valuePath, + groupOn: column.groupOn ?? valuePath, + sortOn: column.sortOn ?? valuePath, + + minWidth: column.minWidth, + width: column.width, + flex: column.flex, + priority: column.priority, + + getString: column.getString, + getComparableValue: column.getComparableValue, + serializeFilter: column.serializeFilter, + deserializeFilter: column.deserializeFilter, + toXlsxValue: column.toXlsxValue, + + renderHeader: column.renderHeader, + renderCell: column.renderCell, + renderEditCell: column.renderEditCell, + renderGroup: column.renderGroup, + cellTitleFn: column.cellTitleFn, + getFilterFn: column.getFilterFn, + headerCellClass: column.headerCellClass, + cellClass: column.cellClass, + + editable: column.editable, + + values: column.values, + source: memooize(column.computeSource), + + noLocalFilter: column.noLocalFilter, + + // @deprecated + loading: column.loading, + externalValues: column.externalValues, + computeSource: column.computeSource, + + // boolean columns + trueLabel: column.trueLabel, + falseLabel: column.falseLabel, + + // list columns + valueProperty: column.valueProperty, + textProperty: column.textProperty, + emptyLabel: column.emptyLabel, + emptyValue: column.emptyValue, + + // range columns + min: column.min, + max: column.max, + locale: column.locale, + autoupdate: column.autoupdate, + + // number columns + maximumFractionDigits: column.maximumFractionDigits, + minimumFractionDigits: column.minimumFractionDigits, + + // amount columns + currency: column.currency, + rates: column.rates, + autodetect: column.autodetect, + + // treenode columns + ownerTree: column.ownerTree, + keyProperty: column.keyProperty, + + ...column.getConfig?.(column), + + [columnSymbol]: column, + }; + }); }, useDOMColumns = (host, { enabledColumns }) => { const [columns, setColumns] = useState([]);