mirror of
https://github.com/nasa/openmct.git
synced 2024-12-18 20:57:53 +00:00
do not store state in singleton action (#7121)
Co-authored-by: Andrew Henry <akhenry@gmail.com>
This commit is contained in:
parent
97b2ebc0bb
commit
a16a1d35b6
@ -32,7 +32,6 @@ export default class ImportAsJSONAction {
|
|||||||
this.cssClass = 'icon-import';
|
this.cssClass = 'icon-import';
|
||||||
this.group = 'import';
|
this.group = 'import';
|
||||||
this.priority = 2;
|
this.priority = 2;
|
||||||
this.newObjects = [];
|
|
||||||
|
|
||||||
this.openmct = openmct;
|
this.openmct = openmct;
|
||||||
}
|
}
|
||||||
@ -83,9 +82,10 @@ export default class ImportAsJSONAction {
|
|||||||
* @param {object} parent
|
* @param {object} parent
|
||||||
* @param {object} tree
|
* @param {object} tree
|
||||||
* @param {object} seen
|
* @param {object} seen
|
||||||
|
* @param {Array} objectsToCreate tracks objects from import json that will need to be created
|
||||||
*/
|
*/
|
||||||
_deepInstantiate(parent, tree, seen) {
|
_deepInstantiate(parent, tree, seen, objectsToCreate) {
|
||||||
let objectIdentifiers = this._getObjectReferenceIds(parent);
|
const objectIdentifiers = this._getObjectReferenceIds(parent);
|
||||||
|
|
||||||
if (objectIdentifiers.length) {
|
if (objectIdentifiers.length) {
|
||||||
const parentId = this.openmct.objects.makeKeyString(parent.identifier);
|
const parentId = this.openmct.objects.makeKeyString(parent.identifier);
|
||||||
@ -100,15 +100,16 @@ export default class ImportAsJSONAction {
|
|||||||
const newModel = tree[keystring];
|
const newModel = tree[keystring];
|
||||||
delete newModel.persisted;
|
delete newModel.persisted;
|
||||||
|
|
||||||
this.newObjects.push(newModel);
|
objectsToCreate.push(newModel);
|
||||||
|
|
||||||
// make sure there weren't any errors saving
|
// make sure there weren't any errors saving
|
||||||
if (newModel) {
|
if (newModel) {
|
||||||
this._deepInstantiate(newModel, tree, seen);
|
this._deepInstantiate(newModel, tree, seen, objectsToCreate);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
* @param {object} parent
|
* @param {object} parent
|
||||||
@ -170,19 +171,19 @@ export default class ImportAsJSONAction {
|
|||||||
* @param {object} objTree
|
* @param {object} objTree
|
||||||
*/
|
*/
|
||||||
async _importObjectTree(domainObject, objTree) {
|
async _importObjectTree(domainObject, objTree) {
|
||||||
|
const objectsToCreate = [];
|
||||||
const namespace = domainObject.identifier.namespace;
|
const namespace = domainObject.identifier.namespace;
|
||||||
const tree = this._generateNewIdentifiers(objTree, namespace);
|
const tree = this._generateNewIdentifiers(objTree, namespace);
|
||||||
const rootId = tree.rootId;
|
const rootId = tree.rootId;
|
||||||
|
|
||||||
const rootObj = tree.openmct[rootId];
|
const rootObj = tree.openmct[rootId];
|
||||||
delete rootObj.persisted;
|
delete rootObj.persisted;
|
||||||
this.newObjects.push(rootObj);
|
objectsToCreate.push(rootObj);
|
||||||
|
|
||||||
if (this.openmct.composition.checkPolicy(domainObject, rootObj)) {
|
if (this.openmct.composition.checkPolicy(domainObject, rootObj)) {
|
||||||
this._deepInstantiate(rootObj, tree.openmct, []);
|
this._deepInstantiate(rootObj, tree.openmct, [], objectsToCreate);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await Promise.all(this.newObjects.map(this._instantiate, this));
|
await Promise.all(objectsToCreate.map(this._instantiate, this));
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.openmct.notifications.error('Error saving objects');
|
this.openmct.notifications.error('Error saving objects');
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user