[Persistability] Various checks in actions (Edit Properties, ImportFromJSON) (#4587)

Co-authored-by: Joshi <simplyrender@gmail.com>
This commit is contained in:
Jamie V 2021-12-21 14:30:31 -08:00 committed by GitHub
parent 8e3947e48d
commit e634e09e32
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 3 deletions

View File

@ -37,9 +37,11 @@ export default class EditPropertiesAction extends PropertiesAction {
} }
appliesTo(objectPath) { appliesTo(objectPath) {
const definition = this._getTypeDefinition(objectPath[0].type); const object = objectPath[0];
const definition = this._getTypeDefinition(object.type);
const persistable = this.openmct.objects.isPersistable(object.identifier);
return definition && definition.creatable; return persistable && definition && definition.creatable;
} }
invoke(objectPath) { invoke(objectPath) {

View File

@ -43,7 +43,13 @@ export default class ImportAsJSONAction {
*/ */
appliesTo(objectPath) { appliesTo(objectPath) {
const domainObject = objectPath[0]; const domainObject = objectPath[0];
if (domainObject && domainObject.locked) { const locked = domainObject && domainObject.locked;
const persistable = this.openmct.objects.isPersistable(domainObject.identifier);
const TypeDefinition = this.openmct.types.get(domainObject.type);
const definition = TypeDefinition.definition;
const creatable = definition && definition.creatable;
if (locked || !persistable || !creatable) {
return false; return false;
} }

View File

@ -97,6 +97,7 @@ describe("The import JSON action", function () {
domainObject domainObject
]; ];
spyOn(openmct.types, 'get').and.returnValue({});
spyOn(openmct.composition, 'get').and.returnValue(false); spyOn(openmct.composition, 'get').and.returnValue(false);
expect(importFromJSONAction.appliesTo(objectPath)).toBe(false); expect(importFromJSONAction.appliesTo(objectPath)).toBe(false);