From afd82a8e4573efe512ca9e3104bca5398f742310 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20G=C5=82ownia?= Date: Thu, 24 Mar 2022 14:52:33 +0100 Subject: [PATCH] Revert useApplyGridTransaction changes --- .../src/hooks/use-apply-grid-transaction.ts | 48 ++----------------- 1 file changed, 5 insertions(+), 43 deletions(-) diff --git a/libs/react-helpers/src/hooks/use-apply-grid-transaction.ts b/libs/react-helpers/src/hooks/use-apply-grid-transaction.ts index 082811bd9..007f891a7 100644 --- a/libs/react-helpers/src/hooks/use-apply-grid-transaction.ts +++ b/libs/react-helpers/src/hooks/use-apply-grid-transaction.ts @@ -1,48 +1,10 @@ import { GridApi } from 'ag-grid-community'; import { useEffect } from 'react'; import isEqual from 'lodash/isEqual'; -import { produce } from 'immer'; -export const updateCallback = - ( - gridApiRef: { current: GridApi | null }, - getRowNodeId: (row: T) => string - ) => - (data: T[]) => { - if (!gridApiRef.current) return; - - const update: T[] = []; - const add: T[] = []; - - // split into updates and adds - data.forEach((d) => { - if (!gridApiRef.current) return; - - const rowNode = gridApiRef.current.getRowNode(getRowNodeId(d)); - - if (rowNode) { - if ( - produce(rowNode.data, (draft: T) => Object.assign(draft, d)) !== - rowNode.data - ) { - update.push(d); - } - } else { - add.push(d); - } - }); - // async transaction for optimal handling of high grequency updates - gridApiRef.current.applyTransactionAsync({ - update, - add, - addIndex: 0, - }); - }; - -export const useApplyGridTransaction = ( +export const useApplyGridTransaction = ( data: T[], - gridApi: GridApi | null, - getRowNodeId: (row: T) => string + gridApi: GridApi | null ) => { useEffect(() => { if (!gridApi) return; @@ -54,7 +16,7 @@ export const useApplyGridTransaction = ( data.forEach((d) => { if (!gridApi) return; - const rowNode = gridApi.getRowNode(getRowNodeId(d)); + const rowNode = gridApi.getRowNode(d.id); if (rowNode) { if (!isEqual(rowNode.data, d)) { @@ -64,11 +26,11 @@ export const useApplyGridTransaction = ( add.push(d); } }); - // async transaction for optimal handling of high grequency updates + gridApi.applyTransaction({ update, add, addIndex: 0, }); - }, [data, gridApi, getRowNodeId]); + }, [data, gridApi]); };