Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 35 additions & 23 deletions src/lib/artie-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,33 +93,45 @@ const _nestedInputsHandler = (parent, inputId, inputName, blocks) => {

// 1- Searches for the input element in the block array
const tmpElement = blocks.find(block => block.id === inputId);
const inputElement = _blockHandler(tmpElement, blocks);

// 2.1- If the input element is a nested element
if (inputName.includes('SUBSTACK') && !_inputElementsValues.includes(tmpElement.opcode)){

// 2.1.1- Adds the parent element, without its next, nested, previous and parent to avoid large objects
inputElement.parent = {id: parent.id, elementName: parent.elementName, elementFamily: parent.elementFamily, next: null, inputs: null, nested: [], previous: null, parent: null}
if (tmpElement !== undefined) {

const inputElement = _blockHandler(tmpElement, blocks);

// 2.1- If the input element is a nested element
if (inputName.includes('SUBSTACK') && !_inputElementsValues.includes(tmpElement.opcode)) {

// 2.1.1- Adds the parent element, without its next, nested, previous and parent to avoid large objects
inputElement.parent = {
id: parent.id,
elementName: parent.elementName,
elementFamily: parent.elementFamily,
next: null,
inputs: null,
nested: [],
previous: null,
parent: null
}

// 2.1.2- Pushes the input element into the artie parent nested array
artieParent.nested.push(inputElement);
}
// 2.2- If the input element is an input
else {
// Gets all the fields from the different subInputs of the element
let tempFields = [];
if (inputElement.inputs !== undefined && inputElement.inputs !== null && inputElement.inputs.length > 0){
Object.values(inputElement.inputs).forEach((input) => {
tempFields = tempFields.concat(input.fields);
});
// 2.1.2- Pushes the input element into the artie parent nested array
artieParent.nested.push(inputElement);
}
// 2.2- If the input element is an input
else {
// Gets all the fields from the different subInputs of the element
let tempFields = [];
if (inputElement.inputs !== undefined && inputElement.inputs !== null && inputElement.inputs.length > 0) {
Object.values(inputElement.inputs).forEach((input) => {
tempFields = tempFields.concat(input.fields);
});
}

const tempInput = {opcode: inputElement.elementName, name: inputName, fields: tempFields};
Object.values(tmpElement.fields).forEach((field) => {
tempInput.fields.push({opcode: field.elementName, name: field.name, value: field.value});
});
const tempInput = {opcode: inputElement.elementName, name: inputName, fields: tempFields};
Object.values(tmpElement.fields).forEach((field) => {
tempInput.fields.push({opcode: field.elementName, name: field.name, value: field.value});
});

artieParent.inputs.push(tempInput);
artieParent.inputs.push(tempInput);
}
}

return artieParent;
Expand Down
Loading