mirror of
https://github.com/nasa/openmct.git
synced 2025-06-18 23:28:14 +00:00
[Conditionals] Ensure correct conditions are updated after reordering (#3336)
* Use id of condition instead of index to ensure
This commit is contained in:
@ -125,11 +125,17 @@ export default class ConditionManager extends EventEmitter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
updateCondition(conditionConfiguration, index) {
|
updateCondition(conditionConfiguration) {
|
||||||
let condition = this.conditions[index];
|
let condition = this.findConditionById(conditionConfiguration.id);
|
||||||
this.conditionSetDomainObject.configuration.conditionCollection[index] = conditionConfiguration;
|
if (condition) {
|
||||||
condition.update(conditionConfiguration);
|
condition.update(conditionConfiguration);
|
||||||
this.persistConditions();
|
}
|
||||||
|
|
||||||
|
let index = this.conditionSetDomainObject.configuration.conditionCollection.findIndex(item => item.id === conditionConfiguration.id);
|
||||||
|
if (index > -1) {
|
||||||
|
this.conditionSetDomainObject.configuration.conditionCollection[index] = conditionConfiguration;
|
||||||
|
this.persistConditions();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
updateConditionDescription(condition) {
|
updateConditionDescription(condition) {
|
||||||
@ -202,12 +208,18 @@ export default class ConditionManager extends EventEmitter {
|
|||||||
this.persistConditions();
|
this.persistConditions();
|
||||||
}
|
}
|
||||||
|
|
||||||
removeCondition(index) {
|
removeCondition(id) {
|
||||||
let condition = this.conditions[index];
|
let index = this.conditions.findIndex(item => item.id === id);
|
||||||
condition.destroy();
|
if (index > -1) {
|
||||||
this.conditions.splice(index, 1);
|
this.conditions[index].destroy();
|
||||||
this.conditionSetDomainObject.configuration.conditionCollection.splice(index, 1);
|
this.conditions.splice(index, 1);
|
||||||
this.persistConditions();
|
}
|
||||||
|
|
||||||
|
let conditionCollectionIndex = this.conditionSetDomainObject.configuration.conditionCollection.findIndex(item => item.id === id);
|
||||||
|
if (conditionCollectionIndex > -1) {
|
||||||
|
this.conditionSetDomainObject.configuration.conditionCollection.splice(conditionCollectionIndex, 1);
|
||||||
|
this.persistConditions();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
findConditionById(id) {
|
findConditionById(id) {
|
||||||
@ -220,8 +232,8 @@ export default class ConditionManager extends EventEmitter {
|
|||||||
reorderPlan.forEach((reorderEvent) => {
|
reorderPlan.forEach((reorderEvent) => {
|
||||||
let item = oldConditions[reorderEvent.oldIndex];
|
let item = oldConditions[reorderEvent.oldIndex];
|
||||||
newCollection.push(item);
|
newCollection.push(item);
|
||||||
this.conditionSetDomainObject.configuration.conditionCollection = newCollection;
|
|
||||||
});
|
});
|
||||||
|
this.conditionSetDomainObject.configuration.conditionCollection = newCollection;
|
||||||
this.persistConditions();
|
this.persistConditions();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,13 +27,32 @@ describe('ConditionManager', () => {
|
|||||||
let conditionMgr;
|
let conditionMgr;
|
||||||
let mockListener;
|
let mockListener;
|
||||||
let openmct = {};
|
let openmct = {};
|
||||||
let mockCondition = {
|
let mockDefaultCondition = {
|
||||||
isDefault: true,
|
isDefault: true,
|
||||||
id: '1234-5678',
|
id: '1234-5678',
|
||||||
configuration: {
|
configuration: {
|
||||||
criteria: []
|
criteria: []
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
let mockCondition1 = {
|
||||||
|
id: '2345-6789',
|
||||||
|
configuration: {
|
||||||
|
criteria: []
|
||||||
|
}
|
||||||
|
};
|
||||||
|
let updatedMockCondition1 = {
|
||||||
|
id: '2345-6789',
|
||||||
|
configuration: {
|
||||||
|
trigger: 'xor',
|
||||||
|
criteria: []
|
||||||
|
}
|
||||||
|
};
|
||||||
|
let mockCondition2 = {
|
||||||
|
id: '3456-7890',
|
||||||
|
configuration: {
|
||||||
|
criteria: []
|
||||||
|
}
|
||||||
|
};
|
||||||
let conditionSetDomainObject = {
|
let conditionSetDomainObject = {
|
||||||
identifier: {
|
identifier: {
|
||||||
namespace: "",
|
namespace: "",
|
||||||
@ -43,7 +62,9 @@ describe('ConditionManager', () => {
|
|||||||
location: "mine",
|
location: "mine",
|
||||||
configuration: {
|
configuration: {
|
||||||
conditionCollection: [
|
conditionCollection: [
|
||||||
mockCondition
|
mockCondition1,
|
||||||
|
mockCondition2,
|
||||||
|
mockDefaultCondition
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -59,7 +80,7 @@ describe('ConditionManager', () => {
|
|||||||
|
|
||||||
let mockDomainObject = {
|
let mockDomainObject = {
|
||||||
useCapability: function () {
|
useCapability: function () {
|
||||||
return mockCondition;
|
return mockDefaultCondition;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
mockInstantiate.and.callFake(function () {
|
mockInstantiate.and.callFake(function () {
|
||||||
@ -107,7 +128,11 @@ describe('ConditionManager', () => {
|
|||||||
openmct.objects.get.and.returnValues(new Promise(function (resolve, reject) {
|
openmct.objects.get.and.returnValues(new Promise(function (resolve, reject) {
|
||||||
resolve(conditionSetDomainObject);
|
resolve(conditionSetDomainObject);
|
||||||
}), new Promise(function (resolve, reject) {
|
}), new Promise(function (resolve, reject) {
|
||||||
resolve(mockCondition);
|
resolve(mockCondition1);
|
||||||
|
}), new Promise(function (resolve, reject) {
|
||||||
|
resolve(mockCondition2);
|
||||||
|
}), new Promise(function (resolve, reject) {
|
||||||
|
resolve(mockDefaultCondition);
|
||||||
}));
|
}));
|
||||||
openmct.objects.makeKeyString.and.returnValue(conditionSetDomainObject.identifier.key);
|
openmct.objects.makeKeyString.and.returnValue(conditionSetDomainObject.identifier.key);
|
||||||
openmct.objects.observe.and.returnValue(function () {});
|
openmct.objects.observe.and.returnValue(function () {});
|
||||||
@ -126,9 +151,65 @@ describe('ConditionManager', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('creates a conditionCollection with a default condition', function () {
|
it('creates a conditionCollection with a default condition', function () {
|
||||||
expect(conditionMgr.conditionSetDomainObject.configuration.conditionCollection.length).toEqual(1);
|
expect(conditionMgr.conditionSetDomainObject.configuration.conditionCollection.length).toEqual(3);
|
||||||
let defaultConditionId = conditionMgr.conditions[0].id;
|
let defaultConditionId = conditionMgr.conditions[2].id;
|
||||||
expect(defaultConditionId).toEqual(mockCondition.id);
|
expect(defaultConditionId).toEqual(mockDefaultCondition.id);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('reorders a conditionCollection', function () {
|
||||||
|
let reorderPlan = [{
|
||||||
|
oldIndex: 1,
|
||||||
|
newIndex: 0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
oldIndex: 0,
|
||||||
|
newIndex: 1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
oldIndex: 2,
|
||||||
|
newIndex: 2
|
||||||
|
}];
|
||||||
|
conditionMgr.reorderConditions(reorderPlan);
|
||||||
|
expect(conditionMgr.conditionSetDomainObject.configuration.conditionCollection.length).toEqual(3);
|
||||||
|
expect(conditionMgr.conditionSetDomainObject.configuration.conditionCollection[0].id).toEqual(mockCondition2.id);
|
||||||
|
expect(conditionMgr.conditionSetDomainObject.configuration.conditionCollection[1].id).toEqual(mockCondition1.id);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('updates the right condition after reorder', function () {
|
||||||
|
let reorderPlan = [{
|
||||||
|
oldIndex: 1,
|
||||||
|
newIndex: 0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
oldIndex: 0,
|
||||||
|
newIndex: 1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
oldIndex: 2,
|
||||||
|
newIndex: 2
|
||||||
|
}];
|
||||||
|
conditionMgr.reorderConditions(reorderPlan);
|
||||||
|
conditionMgr.updateCondition(updatedMockCondition1);
|
||||||
|
expect(conditionMgr.conditions[1].trigger).toEqual(updatedMockCondition1.configuration.trigger);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('removes the right condition after reorder', function () {
|
||||||
|
let reorderPlan = [{
|
||||||
|
oldIndex: 1,
|
||||||
|
newIndex: 0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
oldIndex: 0,
|
||||||
|
newIndex: 1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
oldIndex: 2,
|
||||||
|
newIndex: 2
|
||||||
|
}];
|
||||||
|
conditionMgr.reorderConditions(reorderPlan);
|
||||||
|
conditionMgr.removeCondition(mockCondition1.id);
|
||||||
|
expect(conditionMgr.conditions.length).toEqual(2);
|
||||||
|
expect(conditionMgr.conditionSetDomainObject.configuration.conditionCollection[0].id).toEqual(mockCondition2.id);
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@ -308,15 +308,15 @@ export default {
|
|||||||
};
|
};
|
||||||
this.condition.configuration.criteria.push(criteriaObject);
|
this.condition.configuration.criteria.push(criteriaObject);
|
||||||
},
|
},
|
||||||
dragStart(e) {
|
dragStart(event) {
|
||||||
e.dataTransfer.setData('dragging', e.target); // required for FF to initiate drag
|
event.dataTransfer.clearData();
|
||||||
e.dataTransfer.effectAllowed = "copyMove";
|
event.dataTransfer.setData('dragging', event.target); // required for FF to initiate drag
|
||||||
e.dataTransfer.setDragImage(e.target.closest('.c-condition-h'), 0, 0);
|
event.dataTransfer.effectAllowed = "copyMove";
|
||||||
|
event.dataTransfer.setDragImage(event.target.closest('.c-condition-h'), 0, 0);
|
||||||
this.$emit('setMoveIndex', this.conditionIndex);
|
this.$emit('setMoveIndex', this.conditionIndex);
|
||||||
},
|
},
|
||||||
dragEnd(event) {
|
dragEnd() {
|
||||||
this.dragStarted = false;
|
this.dragStarted = false;
|
||||||
event.dataTransfer.clearData();
|
|
||||||
this.$emit('dragComplete');
|
this.$emit('dragComplete');
|
||||||
},
|
},
|
||||||
dropCondition(event, targetIndex) {
|
dropCondition(event, targetIndex) {
|
||||||
@ -359,10 +359,10 @@ export default {
|
|||||||
},
|
},
|
||||||
destroy() {
|
destroy() {
|
||||||
},
|
},
|
||||||
removeCondition(ev) {
|
removeCondition() {
|
||||||
this.$emit('removeCondition', this.conditionIndex);
|
this.$emit('removeCondition', this.condition.id);
|
||||||
},
|
},
|
||||||
cloneCondition(ev) {
|
cloneCondition() {
|
||||||
this.$emit('cloneCondition', {
|
this.$emit('cloneCondition', {
|
||||||
condition: this.condition,
|
condition: this.condition,
|
||||||
index: this.conditionIndex
|
index: this.conditionIndex
|
||||||
@ -380,8 +380,7 @@ export default {
|
|||||||
},
|
},
|
||||||
persist() {
|
persist() {
|
||||||
this.$emit('updateCondition', {
|
this.$emit('updateCondition', {
|
||||||
condition: this.condition,
|
condition: this.condition
|
||||||
index: this.conditionIndex
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
initCap(str) {
|
initCap(str) {
|
||||||
|
@ -223,10 +223,10 @@ export default {
|
|||||||
this.conditionManager.addCondition();
|
this.conditionManager.addCondition();
|
||||||
},
|
},
|
||||||
updateCondition(data) {
|
updateCondition(data) {
|
||||||
this.conditionManager.updateCondition(data.condition, data.index);
|
this.conditionManager.updateCondition(data.condition);
|
||||||
},
|
},
|
||||||
removeCondition(index) {
|
removeCondition(id) {
|
||||||
this.conditionManager.removeCondition(index);
|
this.conditionManager.removeCondition(id);
|
||||||
},
|
},
|
||||||
reorder(reorderPlan) {
|
reorder(reorderPlan) {
|
||||||
this.conditionManager.reorderConditions(reorderPlan);
|
this.conditionManager.reorderConditions(reorderPlan);
|
||||||
|
Reference in New Issue
Block a user