From 77fc03485c93ce2d9ee9fd11d428a2666199c0cc Mon Sep 17 00:00:00 2001 From: Ashik Meerankutty Date: Sun, 1 Mar 2020 14:45:09 +0530 Subject: [PATCH 1/3] Fixed data grid break on invalid schema --- src/components/datagrid/column_sorting.tsx | 20 ++++++++----- .../datagrid/column_sorting_draggable.tsx | 29 +++++++------------ 2 files changed, 24 insertions(+), 25 deletions(-) diff --git a/src/components/datagrid/column_sorting.tsx b/src/components/datagrid/column_sorting.tsx index 8f9724194c6..e1f68ec7942 100644 --- a/src/components/datagrid/column_sorting.tsx +++ b/src/components/datagrid/column_sorting.tsx @@ -96,10 +96,18 @@ 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); + const sortable = + schemaDetail != null ? schemaDetail.isSortable : isSortable !== false; + return sortable; + } ); const columnSorting = ( @@ -221,8 +229,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 ) : ( From 56f53b6587836bb5c38f43070a6d6eff5f12dec9 Mon Sep 17 00:00:00 2001 From: Ashik Meerankutty Date: Sun, 1 Mar 2020 14:56:13 +0530 Subject: [PATCH 2/3] Added changes to changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) 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)) From 0e40f81ef6eb7863ff7756aebcc100afd6ceeb00 Mon Sep 17 00:00:00 2001 From: Ashik Meerankutty Date: Sun, 1 Mar 2020 23:24:19 +0530 Subject: [PATCH 3/3] Fixed order of isSortable and schemaDetail --- src/components/datagrid/column_sorting.tsx | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/components/datagrid/column_sorting.tsx b/src/components/datagrid/column_sorting.tsx index e1f68ec7942..87db96c9b7b 100644 --- a/src/components/datagrid/column_sorting.tsx +++ b/src/components/datagrid/column_sorting.tsx @@ -104,8 +104,12 @@ export const useColumnSorting = ( const inactiveSortableColumns = inactiveColumns.filter( ({ id, isSortable }) => { const schemaDetail = schemaDetails(id); - const sortable = - schemaDetail != null ? schemaDetail.isSortable : isSortable !== false; + let sortable = true; + if (isSortable != null) { + sortable = isSortable; + } else if (schemaDetail != null) { + sortable = schemaDetail.isSortable; + } return sortable; } );