Skip to content

Commit 451e2bf

Browse files
committed
feat(schemas): improve condition UX
Signed-off-by: Dariy Miseldzhani <dariy.miseldzhani@hashgraph.com>
1 parent 7c022df commit 451e2bf

1 file changed

Lines changed: 17 additions & 17 deletions

File tree

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

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1490,21 +1490,23 @@ export class SchemaConfigurationComponent implements OnInit {
14901490
return result;
14911491
}
14921492

1493-
private collectNestedFieldOptions(
1493+
private collectNestedFieldGroups(
14941494
fields: SchemaField[],
14951495
prefix: string[],
14961496
labelPrefix: string,
14971497
alreadySelected?: Set<string>,
14981498
maxDepth: number = 12,
1499-
): ConditionFieldOption[] {
1499+
): ConditionFieldGroup[] {
15001500
if (prefix.length > maxDepth) { return []; }
1501-
const result: ConditionFieldOption[] = [];
1501+
const groups: ConditionFieldGroup[] = [];
1502+
const directItems: ConditionFieldOption[] = [];
1503+
15021504
for (const f of fields) {
15031505
if (f.readOnly) { continue; }
15041506
if (f.isRef) {
15051507
const nestedSchema = this.subSchemas?.find(s => s.iri === f.type);
15061508
if (!nestedSchema?.fields?.length) { continue; }
1507-
result.push(...this.collectNestedFieldOptions(
1509+
groups.push(...this.collectNestedFieldGroups(
15081510
nestedSchema.fields,
15091511
[...prefix, f.name],
15101512
`${labelPrefix} > ${f.title || f.name}`,
@@ -1516,17 +1518,21 @@ export class SchemaConfigurationComponent implements OnInit {
15161518
if (!leafTypeKey || !this.schemaTypeMap[leafTypeKey]) { continue; }
15171519
const path = [...prefix, f.name];
15181520
if (alreadySelected?.has(path.join('.'))) { continue; }
1519-
result.push({
1521+
directItems.push({
15201522
key: path.join('.'),
1521-
label: `${labelPrefix} > ${f.title || f.name}`,
1523+
label: f.title || f.name,
15221524
shortLabel: f.title || f.name,
15231525
fieldPath: path,
15241526
typeKey: leafTypeKey,
15251527
required: f.required,
15261528
});
15271529
}
15281530
}
1529-
return result;
1531+
1532+
if (directItems.length) {
1533+
groups.unshift({ label: labelPrefix, items: directItems });
1534+
}
1535+
return groups;
15301536
}
15311537

15321538
public getFieldOptionGroupsForCondition(condition: ConditionControl): ConditionFieldGroup[] {
@@ -1566,14 +1572,11 @@ export class SchemaConfigurationComponent implements OnInit {
15661572
const subSchema = this.subSchemas?.find(s => s.iri === type.type);
15671573
if (!subSchema?.fields?.length) { continue; }
15681574
const groupLabel = fc.controlTitle.value || fc.controlKey.value;
1569-
const nestedItems = this.collectNestedFieldOptions(
1575+
groups.push(...this.collectNestedFieldGroups(
15701576
subSchema.fields,
15711577
[fc.controlKey.value],
15721578
groupLabel,
1573-
);
1574-
if (nestedItems.length) {
1575-
groups.push({ label: groupLabel, items: nestedItems });
1576-
}
1579+
));
15771580
}
15781581

15791582
return groups;
@@ -1592,15 +1595,12 @@ export class SchemaConfigurationComponent implements OnInit {
15921595
const subSchema = this.subSchemas?.find(s => s.iri === schemaType.type);
15931596
if (!subSchema?.fields?.length) { continue; }
15941597
const groupLabel = fc.controlTitle.value || fc.controlKey.value;
1595-
const items = this.collectNestedFieldOptions(
1598+
groups.push(...this.collectNestedFieldGroups(
15961599
subSchema.fields,
15971600
[fc.controlKey.value],
15981601
groupLabel,
15991602
alreadySelected,
1600-
);
1601-
if (items.length) {
1602-
groups.push({ label: groupLabel, items });
1603-
}
1603+
));
16041604
}
16051605
return groups;
16061606
}

0 commit comments

Comments
 (0)