[Actions] Duplicate Action bug fixes (#3578)

* WIP: refactoring legacy dulicate action

* WIP: debugging duplicate duplicates...

* WIP: fixed duplicate duplicates issue

* added unit tests

* removing old legacy copyaction and renaming duplicate action

* removing fdescribe

* trying to see if a done callback fixes testing issues

* fixed tests

* testing autoflow tests on server

* tweaked autoflow tests to stop failing

* minor updates for new 3 dot menu

* WIP bug fixing

* WIP debugging

* WIP more debuggin

* WIP using parent namespace for all duped objs

* WIP

* WIP
;
;

* cleaning up debugging code

* fixed linting issues

Co-authored-by: Deep Tailor <deep.j.tailor@nasa.gov>
This commit is contained in:
Jamie V 2020-12-07 10:15:41 -08:00 committed by GitHub
parent 55829dcf05
commit d80c0eef8e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 17 deletions

View File

@ -89,7 +89,7 @@ export default class DuplicateAction {
{ {
key: "name", key: "name",
control: "textfield", control: "textfield",
name: "Folder Name", name: "Name",
pattern: "\\S+", pattern: "\\S+",
required: true, required: true,
cssClass: "l-input-lg" cssClass: "l-input-lg"

View File

@ -48,13 +48,14 @@ export default class DuplicateTask {
} }
/** /**
* Execute the duplicate/copy task with the objects provided in the constructor. * Execute the duplicate/copy task with the objects provided.
* @returns {promise} Which will resolve with a clone of the object * @returns {promise} Which will resolve with a clone of the object
* once complete. * once complete.
*/ */
async duplicate(domainObject, parent, filter) { async duplicate(domainObject, parent, filter) {
this.domainObject = domainObject; this.domainObject = domainObject;
this.parent = parent; this.parent = parent;
this.namespace = parent.identifier.namespace;
this.filter = filter || this.isCreatable; this.filter = filter || this.isCreatable;
await this.buildDuplicationPlan(); await this.buildDuplicationPlan();
@ -96,13 +97,14 @@ export default class DuplicateTask {
let initialCount = this.clones.length; let initialCount = this.clones.length;
let dialog = this.openmct.overlays.progressDialog({ let dialog = this.openmct.overlays.progressDialog({
progressPerc: 0, progressPerc: 0,
message: `Duplicating ${initialCount} files.`, message: `Duplicating ${initialCount} objects.`,
iconClass: 'info', iconClass: 'info',
title: 'Duplicating' title: 'Duplicating'
}); });
let clonesDone = Promise.all(this.clones.map(clone => {
let clonesDone = Promise.all(this.clones.map((clone) => {
let percentPersisted = Math.ceil(100 * (++this.persisted / initialCount)); let percentPersisted = Math.ceil(100 * (++this.persisted / initialCount));
let message = `Duplicating ${initialCount - this.persisted} files.`; let message = `Duplicating ${initialCount - this.persisted} objects.`;
dialog.updateProgress(percentPersisted, message); dialog.updateProgress(percentPersisted, message);
@ -110,6 +112,7 @@ export default class DuplicateTask {
})); }));
await clonesDone; await clonesDone;
dialog.dismiss(); dialog.dismiss();
this.openmct.notifications.info(`Duplicated ${this.persisted} objects.`); this.openmct.notifications.info(`Duplicated ${this.persisted} objects.`);
@ -141,10 +144,7 @@ export default class DuplicateTask {
async duplicateObject(originalObject) { async duplicateObject(originalObject) {
// Check if the creatable (or other passed in filter). // Check if the creatable (or other passed in filter).
if (this.filter(originalObject)) { if (this.filter(originalObject)) {
// Clone original object
let clone = this.cloneObjectModel(originalObject); let clone = this.cloneObjectModel(originalObject);
// Get children, if any
let composeesCollection = this.openmct.composition.get(originalObject); let composeesCollection = this.openmct.composition.get(originalObject);
let composees; let composees;
@ -152,7 +152,6 @@ export default class DuplicateTask {
composees = await composeesCollection.load(); composees = await composeesCollection.load();
} }
// Recursively duplicate children
return this.duplicateComposees(clone, composees); return this.duplicateComposees(clone, composees);
} }
@ -198,12 +197,11 @@ export default class DuplicateTask {
*/ */
async duplicateComposees(clonedParent, composees = []) { async duplicateComposees(clonedParent, composees = []) {
let idMap = {}; let idMap = {};
let allComposeesDuplicated = composees.reduce(async (previousPromise, nextComposee) => { let allComposeesDuplicated = composees.reduce(async (previousPromise, nextComposee) => {
await previousPromise; await previousPromise;
let clonedComposee = await this.duplicateObject(nextComposee); let clonedComposee = await this.duplicateObject(nextComposee);
idMap[this.getId(nextComposee)] = this.getId(clonedComposee); idMap[this.getId(nextComposee)] = this.getId(clonedComposee);
await this.composeChild(clonedComposee, clonedParent, clonedComposee !== nextComposee); this.composeChild(clonedComposee, clonedParent, clonedComposee !== nextComposee);
return; return;
}, Promise.resolve()); }, Promise.resolve());
@ -216,11 +214,9 @@ export default class DuplicateTask {
return clonedParent; return clonedParent;
} }
async composeChild(child, parent, setLocation) { composeChild(child, parent, setLocation) {
const PERSIST_BOOL = false; let childKeyString = this.openmct.objects.makeKeyString(child.identifier);
let parentComposition = this.openmct.composition.get(parent); parent.composition.push(childKeyString);
await parentComposition.load();
parentComposition.add(child, PERSIST_BOOL);
//If a location is not specified, set it. //If a location is not specified, set it.
if (setLocation && child.location === undefined) { if (setLocation && child.location === undefined) {
@ -239,7 +235,7 @@ export default class DuplicateTask {
let clone = JSON.parse(JSON.stringify(domainObject)); let clone = JSON.parse(JSON.stringify(domainObject));
let identifier = { let identifier = {
key: uuid(), key: uuid(),
namespace: domainObject.identifier.namespace namespace: this.namespace // set to NEW parent's namespace
}; };
if (clone.modified || clone.persisted || clone.location) { if (clone.modified || clone.persisted || clone.location) {