Skip to content

Commit 4497967

Browse files
committed
Updating to reflect changes with global rules
1 parent b630891 commit 4497967

File tree

2 files changed

+46
-11
lines changed

2 files changed

+46
-11
lines changed

frontend/src/components/kt/kt-controls/kt-global-rules.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ export function KTGlobalRules(props: BoxProps) {
126126
<br />
127127
max_length,3,
128128
<br />
129-
resolve_entity,"blue,ultramarine,sapphire",Color
129+
resolve_entity,"blue:ultramarine,red:crimson",Color
130130
</Code>
131131
</Box>
132132
</Group>

frontend/src/config/store/store.ts

Lines changed: 45 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,16 @@ export const useStore = create<Store>()(
332332
})),
333333
globalRules: globalRules.map(rule => ({
334334
...rule,
335-
resolvedEntities: rule.resolvedEntities || []
335+
resolvedEntities: (rule.resolvedEntities || []).filter(entity => {
336+
// Keep entities that aren't from the rows being rerun
337+
if (entity.source.type === 'global') {
338+
const affectedRows = cells.filter(cell =>
339+
rerunColumnIds.has(cell.columnId)
340+
).map(cell => cell.rowId);
341+
return !affectedRows.some(rowId => rerunRowIds.has(rowId));
342+
}
343+
return true;
344+
})
336345
}))
337346
});
338347

@@ -391,6 +400,16 @@ export const useStore = create<Store>()(
391400
// Get current state
392401
const currentTable = getTable(activeTableId);
393402

403+
// Helper to check if an entity matches any global rule patterns
404+
const isGlobalEntity = (entity: { original: string; resolved: string }) => {
405+
return globalRules.some(rule =>
406+
rule.type === 'resolve_entity' &&
407+
rule.options?.some(pattern =>
408+
entity.original.toLowerCase().includes(pattern.toLowerCase())
409+
)
410+
);
411+
};
412+
394413
editTable(activeTableId, {
395414
chunks: { ...currentTable.chunks, [key]: chunks },
396415
loadingCells: omit(currentTable.loadingCells, key),
@@ -399,20 +418,36 @@ export const useStore = create<Store>()(
399418
resolvedEntities: col.id === column.id
400419
? [
401420
...(col.resolvedEntities || []),
402-
...(resolvedEntities || []).map(entity => ({
403-
...entity,
404-
entityType: column.entityType,
405-
source: {
406-
type: 'column' as const,
407-
id: column.id
408-
}
409-
})) as ResolvedEntity[]
421+
...(resolvedEntities || [])
422+
.filter(entity => !isGlobalEntity(entity))
423+
.map(entity => ({
424+
...entity,
425+
entityType: column.entityType,
426+
source: {
427+
type: 'column' as const,
428+
id: column.id
429+
}
430+
})) as ResolvedEntity[]
410431
]
411432
: (col.resolvedEntities || [])
412433
})),
413434
globalRules: currentTable.globalRules.map(rule => ({
414435
...rule,
415-
resolvedEntities: rule.resolvedEntities || []
436+
resolvedEntities: rule.type === 'resolve_entity'
437+
? [
438+
...(rule.resolvedEntities || []),
439+
...(resolvedEntities || [])
440+
.filter(entity => isGlobalEntity(entity))
441+
.map(entity => ({
442+
...entity,
443+
entityType: 'global',
444+
source: {
445+
type: 'global' as const,
446+
id: rule.id
447+
}
448+
})) as ResolvedEntity[]
449+
]
450+
: (rule.resolvedEntities || [])
416451
}))
417452
});
418453
});

0 commit comments

Comments
 (0)