mirror of
https://github.com/nasa/openmct.git
synced 2025-05-02 16:53:24 +00:00
[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:
parent
55829dcf05
commit
d80c0eef8e
@ -89,7 +89,7 @@ export default class DuplicateAction {
|
||||
{
|
||||
key: "name",
|
||||
control: "textfield",
|
||||
name: "Folder Name",
|
||||
name: "Name",
|
||||
pattern: "\\S+",
|
||||
required: true,
|
||||
cssClass: "l-input-lg"
|
||||
|
@ -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
|
||||
* once complete.
|
||||
*/
|
||||
async duplicate(domainObject, parent, filter) {
|
||||
this.domainObject = domainObject;
|
||||
this.parent = parent;
|
||||
this.namespace = parent.identifier.namespace;
|
||||
this.filter = filter || this.isCreatable;
|
||||
|
||||
await this.buildDuplicationPlan();
|
||||
@ -96,13 +97,14 @@ export default class DuplicateTask {
|
||||
let initialCount = this.clones.length;
|
||||
let dialog = this.openmct.overlays.progressDialog({
|
||||
progressPerc: 0,
|
||||
message: `Duplicating ${initialCount} files.`,
|
||||
message: `Duplicating ${initialCount} objects.`,
|
||||
iconClass: 'info',
|
||||
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 message = `Duplicating ${initialCount - this.persisted} files.`;
|
||||
let message = `Duplicating ${initialCount - this.persisted} objects.`;
|
||||
|
||||
dialog.updateProgress(percentPersisted, message);
|
||||
|
||||
@ -110,6 +112,7 @@ export default class DuplicateTask {
|
||||
}));
|
||||
|
||||
await clonesDone;
|
||||
|
||||
dialog.dismiss();
|
||||
this.openmct.notifications.info(`Duplicated ${this.persisted} objects.`);
|
||||
|
||||
@ -141,10 +144,7 @@ export default class DuplicateTask {
|
||||
async duplicateObject(originalObject) {
|
||||
// Check if the creatable (or other passed in filter).
|
||||
if (this.filter(originalObject)) {
|
||||
// Clone original object
|
||||
let clone = this.cloneObjectModel(originalObject);
|
||||
|
||||
// Get children, if any
|
||||
let composeesCollection = this.openmct.composition.get(originalObject);
|
||||
let composees;
|
||||
|
||||
@ -152,7 +152,6 @@ export default class DuplicateTask {
|
||||
composees = await composeesCollection.load();
|
||||
}
|
||||
|
||||
// Recursively duplicate children
|
||||
return this.duplicateComposees(clone, composees);
|
||||
}
|
||||
|
||||
@ -198,12 +197,11 @@ export default class DuplicateTask {
|
||||
*/
|
||||
async duplicateComposees(clonedParent, composees = []) {
|
||||
let idMap = {};
|
||||
|
||||
let allComposeesDuplicated = composees.reduce(async (previousPromise, nextComposee) => {
|
||||
await previousPromise;
|
||||
let clonedComposee = await this.duplicateObject(nextComposee);
|
||||
idMap[this.getId(nextComposee)] = this.getId(clonedComposee);
|
||||
await this.composeChild(clonedComposee, clonedParent, clonedComposee !== nextComposee);
|
||||
this.composeChild(clonedComposee, clonedParent, clonedComposee !== nextComposee);
|
||||
|
||||
return;
|
||||
}, Promise.resolve());
|
||||
@ -216,11 +214,9 @@ export default class DuplicateTask {
|
||||
return clonedParent;
|
||||
}
|
||||
|
||||
async composeChild(child, parent, setLocation) {
|
||||
const PERSIST_BOOL = false;
|
||||
let parentComposition = this.openmct.composition.get(parent);
|
||||
await parentComposition.load();
|
||||
parentComposition.add(child, PERSIST_BOOL);
|
||||
composeChild(child, parent, setLocation) {
|
||||
let childKeyString = this.openmct.objects.makeKeyString(child.identifier);
|
||||
parent.composition.push(childKeyString);
|
||||
|
||||
//If a location is not specified, set it.
|
||||
if (setLocation && child.location === undefined) {
|
||||
@ -239,7 +235,7 @@ export default class DuplicateTask {
|
||||
let clone = JSON.parse(JSON.stringify(domainObject));
|
||||
let identifier = {
|
||||
key: uuid(),
|
||||
namespace: domainObject.identifier.namespace
|
||||
namespace: this.namespace // set to NEW parent's namespace
|
||||
};
|
||||
|
||||
if (clone.modified || clone.persisted || clone.location) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user