From 216f4475782d44329ced54a399c3a5ab7c71e0e4 Mon Sep 17 00:00:00 2001 From: Deep Tailor Date: Mon, 10 Jun 2019 15:17:43 -0700 Subject: [PATCH] Show error message when user tries to import an invalid object into another object (#2417) * check composition policy before importing into parent * use alert icon and improve message * add a but in message * change alert message to a more generic sentence: * add a period --- .../src/actions/ImportAsJSONAction.js | 28 +++++++++++++++---- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/platform/import-export/src/actions/ImportAsJSONAction.js b/platform/import-export/src/actions/ImportAsJSONAction.js index 8b253af155..0a0195002a 100644 --- a/platform/import-export/src/actions/ImportAsJSONAction.js +++ b/platform/import-export/src/actions/ImportAsJSONAction.js @@ -64,12 +64,30 @@ define(['zepto'], function ($) { var tree = this.generateNewIdentifiers(objTree); var rootId = tree.rootId; var rootObj = this.instantiate(tree.openmct[rootId], rootId); + var newStyleParent = parent.useCapability('adapter'); + var newStyleRootObj = rootObj.useCapability('adapter'); - // Instantiate all objects in tree with their newly genereated ids, - // adding each to its rightful parent's composition - rootObj.getCapability("location").setPrimaryLocation(parent.getId()); - this.deepInstantiate(rootObj, tree.openmct, []); - parent.getCapability("composition").add(rootObj); + if (this.openmct.composition.checkPolicy(newStyleParent, newStyleRootObj)) { + // Instantiate all objects in tree with their newly generated ids, + // adding each to its rightful parent's composition + rootObj.getCapability("location").setPrimaryLocation(parent.getId()); + this.deepInstantiate(rootObj, tree.openmct, []); + parent.getCapability("composition").add(rootObj); + } else { + var dialog = this.openmct.overlays.dialog({ + iconClass: 'alert', + message: "We're sorry, but you cannot import that object type into this object.", + buttons: [ + { + label: "Ok", + emphasis: true, + callback: function () { + dialog.dismiss(); + } + } + ] + }); + } }; ImportAsJSONAction.prototype.deepInstantiate = function (parent, tree, seen) {