Skip to content
New issue

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

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

Already on GitHub? # to your account

do not store state in singleton action #7121

Merged
merged 3 commits into from
Oct 10, 2023
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
19 changes: 10 additions & 9 deletions src/plugins/importFromJSONAction/ImportFromJSONAction.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
this.cssClass = 'icon-import';
this.group = 'import';
this.priority = 2;
this.newObjects = [];

this.openmct = openmct;
}
Expand Down Expand Up @@ -83,9 +82,10 @@
* @param {object} parent
* @param {object} tree
* @param {object} seen
* @param {Array} objectsToCreate tracks objects from import json that will need to be created
*/
_deepInstantiate(parent, tree, seen) {
let objectIdentifiers = this._getObjectReferenceIds(parent);
_deepInstantiate(parent, tree, seen, objectsToCreate) {
const objectIdentifiers = this._getObjectReferenceIds(parent);

if (objectIdentifiers.length) {
const parentId = this.openmct.objects.makeKeyString(parent.identifier);
Expand All @@ -100,15 +100,16 @@
const newModel = tree[keystring];
delete newModel.persisted;

this.newObjects.push(newModel);
objectsToCreate.push(newModel);

Check warning on line 103 in src/plugins/importFromJSONAction/ImportFromJSONAction.js

View check run for this annotation

Codecov / codecov/patch

src/plugins/importFromJSONAction/ImportFromJSONAction.js#L103

Added line #L103 was not covered by tests

// make sure there weren't any errors saving
if (newModel) {
this._deepInstantiate(newModel, tree, seen);
this._deepInstantiate(newModel, tree, seen, objectsToCreate);

Check warning on line 107 in src/plugins/importFromJSONAction/ImportFromJSONAction.js

View check run for this annotation

Codecov / codecov/patch

src/plugins/importFromJSONAction/ImportFromJSONAction.js#L107

Added line #L107 was not covered by tests
}
}
}
}

/**
* @private
* @param {object} parent
Expand Down Expand Up @@ -170,19 +171,19 @@
* @param {object} objTree
*/
async _importObjectTree(domainObject, objTree) {
const objectsToCreate = [];
const namespace = domainObject.identifier.namespace;
const tree = this._generateNewIdentifiers(objTree, namespace);
const rootId = tree.rootId;

const rootObj = tree.openmct[rootId];
delete rootObj.persisted;
this.newObjects.push(rootObj);

objectsToCreate.push(rootObj);
if (this.openmct.composition.checkPolicy(domainObject, rootObj)) {
this._deepInstantiate(rootObj, tree.openmct, []);
this._deepInstantiate(rootObj, tree.openmct, [], objectsToCreate);

try {
await Promise.all(this.newObjects.map(this._instantiate, this));
await Promise.all(objectsToCreate.map(this._instantiate, this));
} catch (error) {
this.openmct.notifications.error('Error saving objects');

Expand Down
Loading