diff --git a/CHANGELOG.md b/CHANGELOG.md index 30caf76152a..36165ceb87a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ **Bug fixes** +- Fixed `EuiDataGrid` breaking if invalid schema passed ([#2955](https://github.com/elastic/eui/pull/2955)) - Fixed `EuiTitle` not rendering child classes ([#2925](https://github.com/elastic/eui/pull/2925)) - Extended `div` element in `EuiFlyout` type ([#2914](https://github.com/elastic/eui/pull/2914)) - Fixed popover positioning service to be more lenient when positioning 0-width or 0-height content ([#2948](https://github.com/elastic/eui/pull/2948)) diff --git a/src/components/datagrid/column_sorting.tsx b/src/components/datagrid/column_sorting.tsx index 8f9724194c6..87db96c9b7b 100644 --- a/src/components/datagrid/column_sorting.tsx +++ b/src/components/datagrid/column_sorting.tsx @@ -96,10 +96,22 @@ export const useColumnSorting = ( const numberOfSortedFields = sorting.columns.length; - const inactiveSortableColumns = inactiveColumns.filter(({ id, isSortable }) => + const schemaDetails = (id: string | number) => schema.hasOwnProperty(id) && schema[id].columnType != null - ? getDetailsForSchema(schemaDetectors, schema[id].columnType).isSortable - : isSortable !== false + ? getDetailsForSchema(schemaDetectors, schema[id].columnType) + : null; + + const inactiveSortableColumns = inactiveColumns.filter( + ({ id, isSortable }) => { + const schemaDetail = schemaDetails(id); + let sortable = true; + if (isSortable != null) { + sortable = isSortable; + } else if (schemaDetail != null) { + sortable = schemaDetail.isSortable; + } + return sortable; + } ); const columnSorting = ( @@ -221,8 +233,7 @@ export const useColumnSorting = ( = ({ id, direction, index, sorting, schema, schemaDetectors, ...rest }) => { + const schemaDetails = + schema.hasOwnProperty(id) && schema[id].columnType != null + ? getDetailsForSchema(schemaDetectors, schema[id].columnType) + : null; + const textSortAsc = - schema.hasOwnProperty(id) && schema[id].columnType != null ? ( - getDetailsForSchema(schemaDetectors, schema[id].columnType).sortTextAsc + schemaDetails != null ? ( + schemaDetails.sortTextAsc ) : ( ); const textSortDesc = - schema.hasOwnProperty(id) && schema[id].columnType != null ? ( - getDetailsForSchema(schemaDetectors, schema[id].columnType).sortTextDesc + schemaDetails != null ? ( + schemaDetails.sortTextDesc ) : (