@@ -315,35 +315,45 @@ export const useStore = create<Store>()(
315315
316316 // Create a Set of cell keys being rerun for easy lookup
317317 const rerunCellKeys = new Set (
318- cells . map ( cell => ` ${ cell . rowId } - ${ cell . columnId } ` )
318+ cells . map ( cell => getCellKey ( cell . rowId , cell . columnId ) )
319319 ) ;
320320
321- // Only clear resolvedEntities for the specific cells being rerun
322- editTable ( activeTableId , {
323- columns : columns . map ( col => ( {
324- ...col ,
325- resolvedEntities : ( col . resolvedEntities || [ ] ) . filter ( entity => {
326- // Keep entities that aren't from the cells being rerun
327- const cellKey = `${ entity . source . type === 'column' ? cells . find ( cell =>
328- cell . columnId === entity . source . id
329- ) ?. rowId : '' } -${ entity . source . id } `;
330- return ! rerunCellKeys . has ( cellKey ) ;
331- } )
332- } ) ) ,
333- globalRules : globalRules . map ( rule => ( {
334- ...rule ,
335- resolvedEntities : ( rule . resolvedEntities || [ ] ) . filter ( entity => {
336- if ( entity . source . type === 'global' ) {
337- const affectedRows = cells . filter ( cell =>
338- rerunColumnIds . has ( cell . columnId )
339- ) . map ( cell => cell . rowId ) ;
340- return ! affectedRows . some ( rowId => rerunRowIds . has ( rowId ) ) ;
341- }
342- return true ;
343- } )
344- } ) )
321+ // Don't clear resolved entities if we're processing new rows
322+ const isNewRow = cells . some ( cell => {
323+ const row = rowMap [ cell . rowId ] ;
324+ return row && Object . keys ( row . cells ) . length === 0 ;
345325 } ) ;
346326
327+ if ( ! isNewRow ) {
328+ editTable ( activeTableId , {
329+ columns : columns . map ( col => ( {
330+ ...col ,
331+ resolvedEntities : ( col . resolvedEntities || [ ] ) . filter ( entity => {
332+ if ( entity . source . type === 'column' ) {
333+ const cellKey = getCellKey (
334+ cells . find ( cell => cell . columnId === entity . source . id ) ?. rowId || '' ,
335+ entity . source . id
336+ ) ;
337+ return ! rerunCellKeys . has ( cellKey ) ;
338+ }
339+ return true ;
340+ } )
341+ } ) ) ,
342+ globalRules : globalRules . map ( rule => ( {
343+ ...rule ,
344+ resolvedEntities : ( rule . resolvedEntities || [ ] ) . filter ( entity => {
345+ if ( entity . source . type === 'global' ) {
346+ const affectedRows = cells . filter ( cell =>
347+ rerunColumnIds . has ( cell . columnId )
348+ ) . map ( cell => cell . rowId ) ;
349+ return ! affectedRows . some ( rowId => rerunRowIds . has ( rowId ) ) ;
350+ }
351+ return true ;
352+ } )
353+ } ) )
354+ } ) ;
355+ }
356+
347357 const batch = compact (
348358 cells . map ( ( { rowId, columnId } ) => {
349359 const key = getCellKey ( rowId , columnId ) ;
0 commit comments