[Actions] Update to use isPersistable API Method (#4432)

* added persistance check to edit properties action
* adding persistence check in browse bar as well as reverting passing in openmct in bundle and now passing it in through appliesTo method
* adding other actions that need to be persistable
* adding persistance check to set primary location action

Co-authored-by: Andrew Henry <akhenry@gmail.com>
This commit is contained in:
Jamie V
2021-12-06 12:42:22 -08:00
committed by GitHub
parent 420edb75f8
commit 7b53cad2c5
10 changed files with 83 additions and 31 deletions

View File

@ -80,18 +80,15 @@ define(
* This will ensure that a domain object is present in the * This will ensure that a domain object is present in the
* context. * context.
*/ */
PropertiesAction.appliesTo = function (context) { PropertiesAction.appliesTo = function (context, view, openmct) {
var domainObject = (context || {}).domainObject, let domainObject = (context || {}).domainObject;
type = domainObject && domainObject.getCapability('type'),
creatable = type && type.hasFeature('creation');
if (domainObject && domainObject.model && domainObject.model.locked) { if (!domainObject || (domainObject.model && domainObject.model.locked)) {
return false; return false;
} }
// Only allow creatable types to be edited return openmct.objects.isPersistable(domainObject.id);
return domainObject && creatable;
}; };
return PropertiesAction; return PropertiesAction;

View File

@ -25,7 +25,7 @@ define(
function (PropertiesAction) { function (PropertiesAction) {
describe("Properties action", function () { describe("Properties action", function () {
var capabilities, model, object, context, input, dialogService, action; var capabilities, model, object, context, input, dialogService, action, openmct;
function mockPromise(value) { function mockPromise(value) {
return { return {
@ -36,6 +36,11 @@ define(
} }
beforeEach(function () { beforeEach(function () {
openmct = {
objects: {
isPersistable: jasmine.createSpy('isPersistable')
}
};
capabilities = { capabilities = {
type: { type: {
getProperties: function () { getProperties: function () {
@ -77,6 +82,8 @@ define(
capabilities.type.hasFeature.and.returnValue(true); capabilities.type.hasFeature.and.returnValue(true);
capabilities.mutation.and.returnValue(true); capabilities.mutation.and.returnValue(true);
openmct.objects.isPersistable.and.returnValue(true);
action = new PropertiesAction(dialogService, context); action = new PropertiesAction(dialogService, context);
}); });
@ -93,11 +100,11 @@ define(
}); });
it("is only applicable when a domain object is in context", function () { it("is only applicable when a domain object is in context", function () {
expect(PropertiesAction.appliesTo(context)).toBeTruthy(); expect(PropertiesAction.appliesTo(context, undefined, openmct)).toBeTruthy();
expect(PropertiesAction.appliesTo({})).toBeFalsy(); expect(PropertiesAction.appliesTo({}, undefined, openmct)).toBeFalsy();
// Make sure it checked for creatability expect(openmct.objects.isPersistable).toHaveBeenCalled();
expect(capabilities.type.hasFeature).toHaveBeenCalledWith('creation');
}); });
}); });
} }
); );

View File

@ -47,10 +47,16 @@ define(
); );
}; };
SetPrimaryLocationAction.appliesTo = function (context) { SetPrimaryLocationAction.appliesTo = function (context, view, openmct) {
var domainObject = context.domainObject; let domainObject = (context || {}).domainObject;
return domainObject && domainObject.hasCapability("location") if (!domainObject || (domainObject.model && domainObject.model.locked)) {
return false;
}
let isPersistable = openmct.objects.isPersistable(domainObject.id);
return isPersistable && domainObject.hasCapability("location")
&& (domainObject.getModel().location === undefined); && (domainObject.getModel().location === undefined);
}; };

View File

@ -31,9 +31,15 @@ define(
var testContext, var testContext,
testModel, testModel,
testId, testId,
mockLocationCapability; mockLocationCapability,
openmct;
beforeEach(function () { beforeEach(function () {
openmct = {
objects: {
isPersistable: jasmine.createSpy('isPersistable')
}
};
testId = "some-id"; testId = "some-id";
testModel = { name: "some name" }; testModel = { name: "some name" };
@ -42,6 +48,7 @@ define(
['setPrimaryLocation', 'getContextualLocation'] ['setPrimaryLocation', 'getContextualLocation']
); );
openmct.objects.isPersistable.and.returnValue(true);
mockLocationCapability.getContextualLocation.and.returnValue(testId); mockLocationCapability.getContextualLocation.and.returnValue(testId);
testContext = { testContext = {
@ -55,16 +62,21 @@ define(
}); });
it("is applicable to objects with no location specified", function () { it("is applicable to objects with no location specified", function () {
expect(SetPrimaryLocation.appliesTo(testContext)) expect(SetPrimaryLocation.appliesTo(testContext, undefined, openmct))
.toBe(true); .toBe(true);
testContext.domainObject.getModel.and.returnValue({ testContext.domainObject.getModel.and.returnValue({
location: "something", location: "something",
name: "some name" name: "some name"
}); });
expect(SetPrimaryLocation.appliesTo(testContext)) expect(SetPrimaryLocation.appliesTo(testContext, undefined, openmct))
.toBe(false); .toBe(false);
}); });
it("checks object persistability", function () {
SetPrimaryLocation.appliesTo(testContext, undefined, openmct);
expect(openmct.objects.isPersistable).toHaveBeenCalled();
});
it("sets the location contextually when performed", function () { it("sets the location contextually when performed", function () {
new SetPrimaryLocation(testContext).perform(); new SetPrimaryLocation(testContext).perform();
expect(mockLocationCapability.setPrimaryLocation) expect(mockLocationCapability.setPrimaryLocation)

View File

@ -221,15 +221,17 @@ define(['zepto', 'objectUtils'], function ($, objectUtils) {
dialog = this.dialogService.showBlockingMessage(model); dialog = this.dialogService.showBlockingMessage(model);
}; };
ImportAsJSONAction.appliesTo = function (context) { ImportAsJSONAction.appliesTo = function (context, view, openmct) {
let domainObject = context.domainObject; let domainObject = (context || {}).domainObject;
if (domainObject && domainObject.model.locked) { if (!domainObject || (domainObject.model && domainObject.model.locked)) {
return false; return false;
} }
return domainObject !== undefined let isPersistable = openmct.objects.isPersistable(domainObject.id);
&& domainObject.hasCapability("composition"); let hasComposition = domainObject.hasCapability('composition');
return hasComposition && isPersistable;
}; };
return ImportAsJSONAction; return ImportAsJSONAction;

View File

@ -42,7 +42,6 @@ define(
newObjects; newObjects;
beforeEach(function () { beforeEach(function () {
uniqueId = 0; uniqueId = 0;
newObjects = []; newObjects = [];
openmct = { openmct = {
@ -50,9 +49,11 @@ define(
objects: { objects: {
makeKeyString: function (identifier) { makeKeyString: function (identifier) {
return identifier.key; return identifier.key;
} },
isPersistable: jasmine.createSpy('isPersistable')
} }
}; };
openmct.objects.isPersistable.and.returnValue(true);
mockInstantiate = jasmine.createSpy('instantiate').and.callFake( mockInstantiate = jasmine.createSpy('instantiate').and.callFake(
function (model, id) { function (model, id) {
var config = { var config = {
@ -121,9 +122,22 @@ define(
var noCompDomainObject = domainObjectFactory(); var noCompDomainObject = domainObjectFactory();
context.domainObject = compDomainObject; context.domainObject = compDomainObject;
expect(ImportAsJSONAction.appliesTo(context)).toBe(true); expect(ImportAsJSONAction.appliesTo(context, undefined, openmct)).toBe(true);
context.domainObject = noCompDomainObject; context.domainObject = noCompDomainObject;
expect(ImportAsJSONAction.appliesTo(context)).toBe(false); expect(ImportAsJSONAction.appliesTo(context, undefined, openmct)).toBe(false);
});
it("checks object persistability", function () {
var compDomainObject = domainObjectFactory({
name: 'compObject',
model: { name: 'compObject'},
capabilities: {"composition": compositionCapability}
});
context.domainObject = compDomainObject;
ImportAsJSONAction.appliesTo(context, undefined, openmct);
expect(openmct.objects.isPersistable).toHaveBeenCalled();
}); });
it("displays error dialog on invalid file choice", function () { it("displays error dialog on invalid file choice", function () {

View File

@ -60,9 +60,10 @@ export default class LegacyContextMenuAction {
appliesTo(objectPath) { appliesTo(objectPath) {
let legacyObject = this.openmct.legacyObject(objectPath); let legacyObject = this.openmct.legacyObject(objectPath);
let view;
return (this.LegacyAction.appliesTo === undefined return (this.LegacyAction.appliesTo === undefined
|| this.LegacyAction.appliesTo({domainObject: legacyObject})) || this.LegacyAction.appliesTo({domainObject: legacyObject}, view, this.openmct))
&& !this.isBlacklisted(objectPath); && !this.isBlacklisted(objectPath);
} }

View File

@ -83,7 +83,8 @@ export default class NewFolderAction {
} }
appliesTo(objectPath) { appliesTo(objectPath) {
let domainObject = objectPath[0]; let domainObject = objectPath[0];
let isPersistable = this._openmct.objects.isPersistable(domainObject.identifier);
return domainObject.type === 'folder'; return domainObject.type === 'folder' && isPersistable;
} }
} }

View File

@ -78,6 +78,7 @@ describe("the plugin", () => {
spyOn(openmct.$injector, 'get').and.returnValue(mockDialogService); spyOn(openmct.$injector, 'get').and.returnValue(mockDialogService);
spyOn(compositionAPI, 'get').and.returnValue(mockComposition); spyOn(compositionAPI, 'get').and.returnValue(mockComposition);
spyOn(openmct.objects, 'save').and.returnValue(Promise.resolve(true)); spyOn(openmct.objects, 'save').and.returnValue(Promise.resolve(true));
spyOn(openmct.objects, 'isPersistable').and.returnValue(true);
return newFolderAction.invoke(mockObjectPath); return newFolderAction.invoke(mockObjectPath);
}); });
@ -93,5 +94,11 @@ describe("the plugin", () => {
it('adds new folder object to parent composition', () => { it('adds new folder object to parent composition', () => {
expect(mockComposition.add).toHaveBeenCalled(); expect(mockComposition.add).toHaveBeenCalled();
}); });
it('checks if the domainObject is persistable', () => {
newFolderAction.appliesTo(mockObjectPath);
expect(openmct.objects.isPersistable).toHaveBeenCalled();
});
}); });
}); });

View File

@ -20,8 +20,8 @@
</div> </div>
<span <span
class="l-browse-bar__object-name c-object-label__name" class="l-browse-bar__object-name c-object-label__name"
:class="{ 'c-input-inline' : type.creatable}" :class="{ 'c-input-inline' : isPersistable}"
:contenteditable="type.creatable" :contenteditable="isPersistable"
@blur="updateName" @blur="updateName"
@keydown.enter.prevent @keydown.enter.prevent
@keyup.enter.prevent="updateNameOnEnterKeyPress" @keyup.enter.prevent="updateNameOnEnterKeyPress"
@ -194,6 +194,11 @@ export default {
return objectType.definition; return objectType.definition;
}, },
isPersistable() {
let persistable = this.openmct.objects.isPersistable(this.domainObject.identifier);
return persistable;
},
isViewEditable() { isViewEditable() {
let currentViewKey = this.currentView.key; let currentViewKey = this.currentView.key;
if (currentViewKey !== undefined) { if (currentViewKey !== undefined) {