Skip to content

Commit

Permalink
Updating so new documents don't remove entities
Browse files Browse the repository at this point in the history
  • Loading branch information
tomsmoker committed Nov 4, 2024
1 parent 0d53cf1 commit a093f7f
Showing 1 changed file with 35 additions and 25 deletions.
60 changes: 35 additions & 25 deletions frontend/src/config/store/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -315,35 +315,45 @@ export const useStore = create<Store>()(

// Create a Set of cell keys being rerun for easy lookup
const rerunCellKeys = new Set(
cells.map(cell => `${cell.rowId}-${cell.columnId}`)
cells.map(cell => getCellKey(cell.rowId, cell.columnId))
);

// Only clear resolvedEntities for the specific cells being rerun
editTable(activeTableId, {
columns: columns.map(col => ({
...col,
resolvedEntities: (col.resolvedEntities || []).filter(entity => {
// Keep entities that aren't from the cells being rerun
const cellKey = `${entity.source.type === 'column' ? cells.find(cell =>
cell.columnId === entity.source.id
)?.rowId : ''}-${entity.source.id}`;
return !rerunCellKeys.has(cellKey);
})
})),
globalRules: globalRules.map(rule => ({
...rule,
resolvedEntities: (rule.resolvedEntities || []).filter(entity => {
if (entity.source.type === 'global') {
const affectedRows = cells.filter(cell =>
rerunColumnIds.has(cell.columnId)
).map(cell => cell.rowId);
return !affectedRows.some(rowId => rerunRowIds.has(rowId));
}
return true;
})
}))
// Don't clear resolved entities if we're processing new rows
const isNewRow = cells.some(cell => {
const row = rowMap[cell.rowId];
return row && Object.keys(row.cells).length === 0;
});

if (!isNewRow) {
editTable(activeTableId, {
columns: columns.map(col => ({
...col,
resolvedEntities: (col.resolvedEntities || []).filter(entity => {
if (entity.source.type === 'column') {
const cellKey = getCellKey(
cells.find(cell => cell.columnId === entity.source.id)?.rowId || '',
entity.source.id
);
return !rerunCellKeys.has(cellKey);
}
return true;
})
})),
globalRules: globalRules.map(rule => ({
...rule,
resolvedEntities: (rule.resolvedEntities || []).filter(entity => {
if (entity.source.type === 'global') {
const affectedRows = cells.filter(cell =>
rerunColumnIds.has(cell.columnId)
).map(cell => cell.rowId);
return !affectedRows.some(rowId => rerunRowIds.has(rowId));
}
return true;
})
}))
});
}

const batch = compact(
cells.map(({ rowId, columnId }) => {
const key = getCellKey(rowId, columnId);
Expand Down

0 comments on commit a093f7f

Please sign in to comment.