[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
* context.
*/
PropertiesAction.appliesTo = function (context) {
PropertiesAction.appliesTo = function (context, view, openmct) {
var domainObject = (context || {}).domainObject,
type = domainObject && domainObject.getCapability('type'),
creatable = type && type.hasFeature('creation');
let domainObject = (context || {}).domainObject;
if (domainObject && domainObject.model && domainObject.model.locked) {
if (!domainObject || (domainObject.model && domainObject.model.locked)) {
return false;
}
// Only allow creatable types to be edited
return domainObject && creatable;
return openmct.objects.isPersistable(domainObject.id);
};
return PropertiesAction;

View File

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