Skip to content

Commit 6bf8966

Browse files
committed
feat: replace one-level field lookup with full-depth traversal in condition builder
Signed-off-by: Dariy Miseldzhani <dariy.miseldzhani@hashgraph.com>
1 parent 8e682bf commit 6bf8966

3 files changed

Lines changed: 29 additions & 14 deletions

File tree

common/src/xlsx/models/schema-condition.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,4 +85,15 @@ export class XlsxSchemaConditions {
8585
this.condition.thenFields.push(field);
8686
}
8787
}
88+
89+
public addTarget(field: SchemaField, targetFieldPath: string[], invert: boolean) {
90+
const target = { field, fieldPath: targetFieldPath };
91+
if (invert) {
92+
if (!this.condition.elseTargets) { this.condition.elseTargets = []; }
93+
this.condition.elseTargets.push(target);
94+
} else {
95+
if (!this.condition.thenTargets) { this.condition.thenTargets = []; }
96+
this.condition.thenTargets.push(target);
97+
}
98+
}
8899
}

frontend/src/app/modules/schema-engine/schema-configuration/schema-configuration.component.ts

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,25 +1008,29 @@ export class SchemaConfigurationComponent implements OnInit {
10081008
(typeof r?.field === 'string' ? r.field : undefined);
10091009
};
10101010

1011+
const traverseFieldPath = (path: string[]): SchemaField | undefined => {
1012+
let current: SchemaField | undefined = fieldsBySchemaName.get(path[0]);
1013+
for (let i = 1; i < path.length; i++) {
1014+
if (!current?.fields) { return undefined; }
1015+
current = current.fields.find(f => f.name === path[i]);
1016+
}
1017+
return current;
1018+
};
1019+
10111020
const resolveIfField = (opt: ConditionFieldOption | undefined): { field: SchemaField; fieldPath?: string[] } | null => {
10121021
if (!opt?.fieldPath?.length) { return null; }
1013-
if (opt.fieldPath.length === 1) {
1014-
const sf = fieldsBySchemaName.get(opt.fieldPath[0]);
1015-
return sf ? { field: sf } : null;
1016-
}
1017-
const containerField = fieldsBySchemaName.get(opt.fieldPath[0]);
1018-
if (!containerField) { return null; }
1019-
const leafField = containerField.fields?.find(f => f.name === opt.fieldPath[opt.fieldPath.length - 1]);
1020-
return leafField ? { field: leafField, fieldPath: opt.fieldPath } : null;
1022+
const leaf = traverseFieldPath(opt.fieldPath);
1023+
if (!leaf) { return null; }
1024+
return opt.fieldPath.length === 1
1025+
? { field: leaf }
1026+
: { field: leaf, fieldPath: opt.fieldPath };
10211027
};
10221028

10231029
const buildCrossTargets = (targets: ConditionFieldOption[]): SchemaConditionTarget[] =>
10241030
targets.map(opt => {
1025-
const containerField = fieldsBySchemaName.get(opt.fieldPath[0]);
1026-
if (!containerField) { return null; }
1027-
const leafField = containerField.fields?.find(f => f.name === opt.fieldPath[opt.fieldPath.length - 1]);
1028-
if (!leafField) { return null; }
1029-
return { fieldPath: opt.fieldPath, field: leafField } as SchemaConditionTarget;
1031+
const leaf = traverseFieldPath(opt.fieldPath);
1032+
if (!leaf) { return null; }
1033+
return { fieldPath: opt.fieldPath, field: leaf } as SchemaConditionTarget;
10301034
}).filter(Boolean) as SchemaConditionTarget[];
10311035

10321036
const conditions: SchemaCondition[] = [];

guardian-service/src/analytics/compare/interfaces/raw-data.interface.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ export interface ISchemaDocument {
7777
* Properties
7878
*/
7979
properties?: {
80-
[x: string]: ISchemaDocument;
80+
[x: string]: ISchemaDocument | false;
8181
}
8282
/**
8383
* Required fields

0 commit comments

Comments
 (0)