Skip to content

Commit

Permalink
Fix adding properties in view (#816)
Browse files Browse the repository at this point in the history
  • Loading branch information
PrographerMan authored Mar 30, 2023
1 parent 7b5a583 commit 81e0de4
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion addon/components/fd-editing-panels/fd-create-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,26 @@ export default Component.extend(FdReadonlyModeMixin, {
return propertyName;
},

/**
Get index of selected property in definitions
@method getIndexOfSelectedProperty
@return {Number} index
*/
getIndexOfSelectedProperty: function() {
const selectedProperty = this.get('selectedProperty');
const definitionArray = this.get('view.definitionArray');
let index = -1;

if (isNone(selectedProperty)) {
return index;
}

index = definitionArray.findIndex((definitionProperty) => definitionProperty.get('name') === selectedProperty.name);

return index;
},

actions: {

/**
Expand All @@ -271,6 +291,7 @@ export default Component.extend(FdReadonlyModeMixin, {
*/
addNodeInDefinition() {
let node = this.get('selectedNode');

if (isNone(node)) {
return;
}
Expand All @@ -279,6 +300,7 @@ export default Component.extend(FdReadonlyModeMixin, {

// Create propertyName
let propertyName = this.createPropertyName(node, this.get('treeObject').jstree(true));

if (view.findBy('name', propertyName)) {
return;
}
Expand Down Expand Up @@ -308,7 +330,14 @@ export default Component.extend(FdReadonlyModeMixin, {
}
}

view.pushObject(newDefinition);
let indexOfSelectedProperty = this.getIndexOfSelectedProperty();

if (indexOfSelectedProperty >= 0) {
view.insertAt(indexOfSelectedProperty + 1, newDefinition);
} else {
view.pushObject(newDefinition);
}

},

/**
Expand Down

0 comments on commit 81e0de4

Please sign in to comment.