From 0375c3ef9e366cf9fa19e15cda5706ff3e4c94fd Mon Sep 17 00:00:00 2001 From: Jean Dessane Date: Thu, 20 May 2021 17:52:29 +0200 Subject: [PATCH] Fix groupBy import --- src/imex/import/useImportTable.columns.tsx | 6 +++++- src/imex/import/useImportTable.tsx | 2 +- src/imex/import/useImportTable.utils.ts | 2 +- src/plugin/useExpandAll/useExpandAll.tsx | 8 +++++--- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/imex/import/useImportTable.columns.tsx b/src/imex/import/useImportTable.columns.tsx index dcad7134..c06be353 100644 --- a/src/imex/import/useImportTable.columns.tsx +++ b/src/imex/import/useImportTable.columns.tsx @@ -27,6 +27,7 @@ export const getCompareColumnsFromImexColumns = ( .accessor as ReactTable.Accessor const columnModified = rows.reduce( (sum, row) => + row.original && !Object.values(row.original._rowMeta.errors).length && accessor(row.original, row.index, { subRows: [], @@ -122,12 +123,15 @@ export const getCompareColumnsFromImexColumns = ( }) as ReactTable.Renderer>>, })) // Status column - compareColumns.unshift({ + compareColumns.push({ Header: '', maxWidth: 40, id: 'status', Footer: '', Cell: (({ row }) => { + if (!row.original) { + return null + } const rowMeta = row.original._rowMeta if (Object.values(rowMeta.errors).length) { diff --git a/src/imex/import/useImportTable.tsx b/src/imex/import/useImportTable.tsx index 3536259c..de1da16d 100644 --- a/src/imex/import/useImportTable.tsx +++ b/src/imex/import/useImportTable.tsx @@ -67,7 +67,7 @@ export const useImportTable = ( return await parseRawData( { data: rawData, originalData, columns: imexColumns }, - options + mergedOptions ) } diff --git a/src/imex/import/useImportTable.utils.ts b/src/imex/import/useImportTable.utils.ts index 341b97fa..e8d1c818 100644 --- a/src/imex/import/useImportTable.utils.ts +++ b/src/imex/import/useImportTable.utils.ts @@ -263,7 +263,7 @@ export const parseRawData = async ( for (const rowGroup in groupedParsedData) { if ( groupedParsedData[rowGroup].some( - (row) => row._rowMeta.hasDiff && options.filterRows?.(row) + (row) => row._rowMeta.hasDiff || options.filterRows?.(row) ) ) { filteredGroupedParsedData.push(groupedParsedData[rowGroup]) diff --git a/src/plugin/useExpandAll/useExpandAll.tsx b/src/plugin/useExpandAll/useExpandAll.tsx index c6fbed9e..f59fa67a 100644 --- a/src/plugin/useExpandAll/useExpandAll.tsx +++ b/src/plugin/useExpandAll/useExpandAll.tsx @@ -5,11 +5,13 @@ import { ensurePluginOrder } from 'react-table' import { TableInstance } from '../../types/Table' const useInstance = (instance: TableInstance) => { - const { data, toggleAllRowsExpanded, plugins } = instance + const { data, expandedRows, toggleRowExpanded, plugins } = instance React.useLayoutEffect(() => { - toggleAllRowsExpanded() - }, [data]) // eslint-disable-line + expandedRows.map(({ id }) => { + return toggleRowExpanded(id as any, true) + }) + }, [ data, toggleRowExpanded]) // eslint-disable-line ensurePluginOrder(plugins, ['useExpanded'], 'useExpandAll') }