Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

4.50.5 #1524

Merged
merged 13 commits into from
Aug 19, 2023
Prev Previous commit
Next Next commit
Fixed nested arrays settings #2 (#1510)
* Fixed nested arrays;
Fixed lint;

* Removed console.log()
  • Loading branch information
Artem Kononenko authored Jul 19, 2023
commit 9dae60b5f3b969cf947bc4e2890ac441e3f87d21
28 changes: 16 additions & 12 deletions ui/src/app/core/directives/json-schema-form-patch.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@ export class JsonSchemaFormPatchDirective {
constructor(
@Host() @Self() @Optional() public jsonSchemaForm: JsonSchemaFormComponent) {

let buildLayout_original = jsonSchemaForm.jsf.buildLayout.bind(jsonSchemaForm.jsf)
const buildLayoutOriginal = jsonSchemaForm.jsf.buildLayout.bind(jsonSchemaForm.jsf);

jsonSchemaForm.jsf.buildLayout = (widgetLibrary: any) => {

buildLayout_original(widgetLibrary);
buildLayoutOriginal(widgetLibrary);
if (jsonSchemaForm.jsf.formValues && this.jsfPatch) {
return this.fixNestedArrayLayout(
jsonSchemaForm.jsf.layout,
jsonSchemaForm.jsf.formValues
jsonSchemaForm.jsf.formValues,
);
}
}
};

}

Expand All @@ -34,9 +34,9 @@ export class JsonSchemaFormPatchDirective {
private fixArray(items: any | any[], formData: any, refPointer: string) {

if (Array.isArray(items)) {
items.filter(x => x.name !== "_bridge" && (x.dataType == "array" || x.arrayItem)).forEach(item => {
items.filter(x => x.name !== '_bridge' && (x.dataType === 'array' || x.arrayItem)).forEach(item => {
this.fixNestedArray(item, formData, refPointer);
})
});
} else {
this.fixNestedArray(items, formData, refPointer);
}
Expand All @@ -45,9 +45,9 @@ export class JsonSchemaFormPatchDirective {
private fixNestedArray(item: any, formData: any, refPointer: string) {
if (item.items && Array.isArray(item.items)) {

const ref = item.items.find(x => x.type === "$ref");
const ref = item.items.find(x => x.type === '$ref');
if (ref) {
const dataItems = item.items.filter(x => x.type === "section");
const dataItems = item.items.filter(x => x.type === 'section');
const template = dataItems.length > 0
? dataItems.reduce((a, b) => a.id > b.id ? a : b)
: this.getItemTemplateFromRef(ref);
Expand All @@ -58,7 +58,7 @@ export class JsonSchemaFormPatchDirective {
// add missing items
while (item.items.length - 1 < data.length) {
const newItem = cloneDeep(template);
newItem._id = uniqueId("new_");
newItem._id = uniqueId('new_');

item.items.unshift(newItem);
}
Expand All @@ -72,6 +72,10 @@ export class JsonSchemaFormPatchDirective {
} else {
this.fixArray(item.items, formData, refPointer);
}

item.items.filter(i => i.items && Array.isArray(i.items)).forEach(i => {
this.fixArray(i.items, formData, refPointer);
});
}
}

Expand All @@ -85,9 +89,9 @@ export class JsonSchemaFormPatchDirective {
}

private getItemTemplateFromRef(ref: any) {
const templateNode = {
"type": "section",
"items": []
const templateNode: { type: string; items: any[] } = {
type: 'section',
items: [],
};

const item = cloneDeep(ref);
Expand Down