mirror of
https://github.com/nasa/openmct.git
synced 2025-01-29 15:43:52 +00:00
Allow tags files to define namespace to save annotations (#6274)
* allow tags files to define namespace to save annotations * add tests * typo in test name * lint * change param to objects object and remove debug
This commit is contained in:
parent
10decda94e
commit
5a8f1d542e
@ -20,11 +20,23 @@
|
|||||||
* at runtime from the About dialog for additional information.
|
* at runtime from the About dialog for additional information.
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
import availableTags from './tags.json';
|
import availableTags from './tags.json';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@typedef {{
|
||||||
|
namespaceToSaveAnnotations: string
|
||||||
|
}} TagsPluginOptions
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {TagsPluginOptions} options
|
||||||
* @returns {function} The plugin install function
|
* @returns {function} The plugin install function
|
||||||
*/
|
*/
|
||||||
export default function exampleTagsPlugin() {
|
export default function exampleTagsPlugin(options) {
|
||||||
return function install(openmct) {
|
return function install(openmct) {
|
||||||
|
if (options?.namespaceToSaveAnnotations) {
|
||||||
|
openmct.annotation.setNamespaceToSaveAnnotations(options?.namespaceToSaveAnnotations);
|
||||||
|
}
|
||||||
|
|
||||||
Object.keys(availableTags.tags).forEach(tagKey => {
|
Object.keys(availableTags.tags).forEach(tagKey => {
|
||||||
const tagDefinition = availableTags.tags[tagKey];
|
const tagDefinition = availableTags.tags[tagKey];
|
||||||
openmct.annotation.defineTag(tagKey, tagDefinition);
|
openmct.annotation.defineTag(tagKey, tagDefinition);
|
||||||
|
@ -84,6 +84,7 @@ export default class AnnotationAPI extends EventEmitter {
|
|||||||
super();
|
super();
|
||||||
this.openmct = openmct;
|
this.openmct = openmct;
|
||||||
this.availableTags = {};
|
this.availableTags = {};
|
||||||
|
this.namespaceToSaveAnnotations = '';
|
||||||
|
|
||||||
this.ANNOTATION_TYPES = ANNOTATION_TYPES;
|
this.ANNOTATION_TYPES = ANNOTATION_TYPES;
|
||||||
this.ANNOTATION_TYPE = ANNOTATION_TYPE;
|
this.ANNOTATION_TYPE = ANNOTATION_TYPE;
|
||||||
@ -139,7 +140,7 @@ export default class AnnotationAPI extends EventEmitter {
|
|||||||
const domainObjectKeyString = this.openmct.objects.makeKeyString(domainObject.identifier);
|
const domainObjectKeyString = this.openmct.objects.makeKeyString(domainObject.identifier);
|
||||||
const originalPathObjects = await this.openmct.objects.getOriginalPath(domainObjectKeyString);
|
const originalPathObjects = await this.openmct.objects.getOriginalPath(domainObjectKeyString);
|
||||||
const originalContextPath = this.openmct.objects.getRelativePath(originalPathObjects);
|
const originalContextPath = this.openmct.objects.getRelativePath(originalPathObjects);
|
||||||
const namespace = domainObject.identifier.namespace;
|
const namespace = this.namespaceToSaveAnnotations;
|
||||||
const type = 'annotation';
|
const type = 'annotation';
|
||||||
const typeDefinition = this.openmct.types.get(type);
|
const typeDefinition = this.openmct.types.get(type);
|
||||||
const definition = typeDefinition.definition;
|
const definition = typeDefinition.definition;
|
||||||
@ -198,6 +199,14 @@ export default class AnnotationAPI extends EventEmitter {
|
|||||||
this.availableTags[tagKey] = tagsDefinition;
|
this.availableTags[tagKey] = tagsDefinition;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @method setNamespaceToSaveAnnotations
|
||||||
|
* @param {String} namespace the namespace to save new annotations to
|
||||||
|
*/
|
||||||
|
setNamespaceToSaveAnnotations(namespace) {
|
||||||
|
this.namespaceToSaveAnnotations = namespace;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @method isAnnotation
|
* @method isAnnotation
|
||||||
* @param {DomainObject} domainObject the domainObject in question
|
* @param {DomainObject} domainObject the domainObject in question
|
||||||
|
@ -26,6 +26,7 @@ import ExampleTagsPlugin from "../../../example/exampleTags/plugin";
|
|||||||
describe("The Annotation API", () => {
|
describe("The Annotation API", () => {
|
||||||
let openmct;
|
let openmct;
|
||||||
let mockObjectProvider;
|
let mockObjectProvider;
|
||||||
|
let mockImmutableObjectProvider;
|
||||||
let mockDomainObject;
|
let mockDomainObject;
|
||||||
let mockFolderObject;
|
let mockFolderObject;
|
||||||
let mockAnnotationObject;
|
let mockAnnotationObject;
|
||||||
@ -89,6 +90,23 @@ describe("The Annotation API", () => {
|
|||||||
mockObjectProvider.create.and.returnValue(Promise.resolve(true));
|
mockObjectProvider.create.and.returnValue(Promise.resolve(true));
|
||||||
mockObjectProvider.update.and.returnValue(Promise.resolve(true));
|
mockObjectProvider.update.and.returnValue(Promise.resolve(true));
|
||||||
|
|
||||||
|
mockImmutableObjectProvider = jasmine.createSpyObj("mock immutable provider", [
|
||||||
|
"get"
|
||||||
|
]);
|
||||||
|
// eslint-disable-next-line require-await
|
||||||
|
mockImmutableObjectProvider.get = async (identifier) => {
|
||||||
|
if (identifier.key === mockDomainObject.identifier.key) {
|
||||||
|
return mockDomainObject;
|
||||||
|
} else if (identifier.key === mockAnnotationObject.identifier.key) {
|
||||||
|
return mockAnnotationObject;
|
||||||
|
} else if (identifier.key === mockFolderObject.identifier.key) {
|
||||||
|
return mockFolderObject;
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
openmct.objects.addProvider('immutableProvider', mockImmutableObjectProvider);
|
||||||
openmct.objects.addProvider('fooNameSpace', mockObjectProvider);
|
openmct.objects.addProvider('fooNameSpace', mockObjectProvider);
|
||||||
openmct.on('start', done);
|
openmct.on('start', done);
|
||||||
openmct.startHeadless();
|
openmct.startHeadless();
|
||||||
@ -115,6 +133,22 @@ describe("The Annotation API", () => {
|
|||||||
expect(annotationObject).toBeDefined();
|
expect(annotationObject).toBeDefined();
|
||||||
expect(annotationObject.type).toEqual('annotation');
|
expect(annotationObject.type).toEqual('annotation');
|
||||||
});
|
});
|
||||||
|
it("can create annotations if domain object is immutable", async () => {
|
||||||
|
mockDomainObject.identifier.namespace = 'immutableProvider';
|
||||||
|
const annotationCreationArguments = {
|
||||||
|
name: 'Test Annotation',
|
||||||
|
domainObject: mockDomainObject,
|
||||||
|
annotationType: openmct.annotation.ANNOTATION_TYPES.NOTEBOOK,
|
||||||
|
tags: ['sometag'],
|
||||||
|
contentText: "fooContext",
|
||||||
|
targetDomainObjects: [mockDomainObject],
|
||||||
|
targets: {'fooTarget': {}}
|
||||||
|
};
|
||||||
|
openmct.annotation.setNamespaceToSaveAnnotations('fooNameSpace');
|
||||||
|
const annotationObject = await openmct.annotation.create(annotationCreationArguments);
|
||||||
|
expect(annotationObject).toBeDefined();
|
||||||
|
expect(annotationObject.type).toEqual('annotation');
|
||||||
|
});
|
||||||
it("fails if annotation is an unknown type", async () => {
|
it("fails if annotation is an unknown type", async () => {
|
||||||
try {
|
try {
|
||||||
await openmct.annotation.create('Garbage Annotation', mockDomainObject, 'garbageAnnotation', ['sometag'], "fooContext", {'fooTarget': {}});
|
await openmct.annotation.create('Garbage Annotation', mockDomainObject, 'garbageAnnotation', ['sometag'], "fooContext", {'fooTarget': {}});
|
||||||
@ -122,6 +156,40 @@ describe("The Annotation API", () => {
|
|||||||
expect(error).toBeDefined();
|
expect(error).toBeDefined();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
it("fails if annotation if given an immutable namespace to save to", async () => {
|
||||||
|
try {
|
||||||
|
const annotationCreationArguments = {
|
||||||
|
name: 'Test Annotation',
|
||||||
|
domainObject: mockDomainObject,
|
||||||
|
annotationType: openmct.annotation.ANNOTATION_TYPES.NOTEBOOK,
|
||||||
|
tags: ['sometag'],
|
||||||
|
contentText: "fooContext",
|
||||||
|
targetDomainObjects: [mockDomainObject],
|
||||||
|
targets: {'fooTarget': {}}
|
||||||
|
};
|
||||||
|
openmct.annotation.setNamespaceToSaveAnnotations('nameespaceThatDoesNotExist');
|
||||||
|
await openmct.annotation.create(annotationCreationArguments);
|
||||||
|
} catch (error) {
|
||||||
|
expect(error).toBeDefined();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
it("fails if annotation if given an undefined namespace to save to", async () => {
|
||||||
|
try {
|
||||||
|
const annotationCreationArguments = {
|
||||||
|
name: 'Test Annotation',
|
||||||
|
domainObject: mockDomainObject,
|
||||||
|
annotationType: openmct.annotation.ANNOTATION_TYPES.NOTEBOOK,
|
||||||
|
tags: ['sometag'],
|
||||||
|
contentText: "fooContext",
|
||||||
|
targetDomainObjects: [mockDomainObject],
|
||||||
|
targets: {'fooTarget': {}}
|
||||||
|
};
|
||||||
|
openmct.annotation.setNamespaceToSaveAnnotations('immutableProvider');
|
||||||
|
await openmct.annotation.create(annotationCreationArguments);
|
||||||
|
} catch (error) {
|
||||||
|
expect(error).toBeDefined();
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("Tagging", () => {
|
describe("Tagging", () => {
|
||||||
|
@ -201,7 +201,6 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
async loadAnnotationForTargetObject(target) {
|
async loadAnnotationForTargetObject(target) {
|
||||||
console.debug(`📝 Loading annotations for target`, target);
|
|
||||||
const targetID = this.openmct.objects.makeKeyString(target.identifier);
|
const targetID = this.openmct.objects.makeKeyString(target.identifier);
|
||||||
const allAnnotationsForTarget = await this.openmct.annotation.getAnnotations(target.identifier);
|
const allAnnotationsForTarget = await this.openmct.annotation.getAnnotations(target.identifier);
|
||||||
const filteredAnnotationsForSelection = allAnnotationsForTarget.filter(annotation => {
|
const filteredAnnotationsForSelection = allAnnotationsForTarget.filter(annotation => {
|
||||||
|
@ -21,10 +21,9 @@ describe('Application router utility functions', () => {
|
|||||||
|
|
||||||
openmct.on('start', () => {
|
openmct.on('start', () => {
|
||||||
resolveFunction = () => {
|
resolveFunction = () => {
|
||||||
const success = window.location.hash !== null && window.location.hash !== '';
|
expect(window.location.hash).not.toBe(null);
|
||||||
if (success) {
|
expect(window.location.hash).not.toBe('');
|
||||||
done();
|
done();
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
openmct.router.on('change:hash', resolveFunction);
|
openmct.router.on('change:hash', resolveFunction);
|
||||||
@ -32,6 +31,7 @@ describe('Application router utility functions', () => {
|
|||||||
// the above resolve function sometimes doesn't fire due to a race condition.
|
// the above resolve function sometimes doesn't fire due to a race condition.
|
||||||
openmct.router.setHash.flush();
|
openmct.router.setHash.flush();
|
||||||
openmct.router.setLocationFromUrl();
|
openmct.router.setLocationFromUrl();
|
||||||
|
openmct.router.setHash.flush();
|
||||||
});
|
});
|
||||||
|
|
||||||
openmct.start(appHolder);
|
openmct.start(appHolder);
|
||||||
@ -47,8 +47,7 @@ describe('Application router utility functions', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('has initial hash when loaded', () => {
|
it('has initial hash when loaded', () => {
|
||||||
const success = window.location.hash !== null;
|
expect(window.location.hash).not.toBe(null);
|
||||||
expect(success).toBe(true);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('The setSearchParam function sets an individual search parameter in the window location hash', () => {
|
it('The setSearchParam function sets an individual search parameter in the window location hash', () => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user