Skip to content

Commit 0d53cf1

Browse files
committed
Wokring replacement for resolutions applied to lists of strings
1 parent 29b14b0 commit 0d53cf1

File tree

2 files changed

+27
-19
lines changed

2 files changed

+27
-19
lines changed

frontend/src/components/kt/kt-controls/kt-resolved-entities.tsx

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,16 @@ export function KtResolvedEntities(props: BoxProps) {
2626
const globalEntities = table.globalRules.flatMap(rule => rule.resolvedEntities || []);
2727
const columnEntities = table.columns.flatMap(column => column.resolvedEntities || []);
2828
const entities = [...globalEntities, ...columnEntities];
29-
return entities;
29+
30+
// Only show entities where a transformation was actually applied
31+
return entities.filter(entity => {
32+
// For arrays, compare stringified versions
33+
if (Array.isArray(entity.original) && Array.isArray(entity.resolved)) {
34+
return JSON.stringify(entity.original) !== JSON.stringify(entity.resolved);
35+
}
36+
// For strings, direct comparison
37+
return entity.original !== entity.resolved;
38+
});
3039
}, [table.globalRules, table.columns]);
3140

3241
const handleUndoTransformation = (entity: ResolvedEntity) => {
@@ -39,22 +48,16 @@ export function KtResolvedEntities(props: BoxProps) {
3948
return [columnId, cellValue];
4049
}
4150

42-
if (typeof cellValue === 'string') {
43-
// Replace resolved with original in string values
44-
return [columnId, cellValue.includes(entity.resolved)
45-
? cellValue.replace(entity.resolved, entity.original)
46-
: cellValue];
47-
} else if (Array.isArray(cellValue)) {
48-
// Replace resolved with original in array values
49-
return [
50-
columnId,
51-
cellValue.map(item =>
52-
typeof item === 'string' && item.includes(entity.resolved)
53-
? item.replace(entity.resolved, entity.original)
54-
: item
55-
)
56-
];
51+
// Check if values match (either both arrays or both strings)
52+
const valuesMatch = Array.isArray(cellValue) && Array.isArray(entity.resolved)
53+
? JSON.stringify(cellValue) === JSON.stringify(entity.resolved)
54+
: cellValue === entity.resolved;
55+
56+
// If they match, replace with original value
57+
if (valuesMatch) {
58+
return [columnId, entity.original];
5759
}
60+
5861
return [columnId, cellValue];
5962
})
6063
)
@@ -84,7 +87,12 @@ export function KtResolvedEntities(props: BoxProps) {
8487

8588
return (
8689
<Group gap={8} {...props}>
87-
<Button leftSection={<IconReplace size={16} />} onClick={handlers.open}>
90+
<Button
91+
leftSection={<IconReplace size={16} />}
92+
onClick={handlers.open}
93+
disabled={allResolvedEntities.length === 0}
94+
variant="light" // Always light variant
95+
>
8896
Resolved entities
8997
</Button>
9098

frontend/src/config/store/store.types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ export interface Store {
5555
}
5656

5757
export interface ResolvedEntity {
58-
original: string;
59-
resolved: string;
58+
original: string | string[]; // Allow both string and array of strings
59+
resolved: string | string[]; // Allow both string and array of strings
6060
fullAnswer: string;
6161
entityType: string;
6262
source: {

0 commit comments

Comments
 (0)