mirror of
https://github.com/nasa/openmct.git
synced 2024-12-18 20:57:53 +00:00
Have in-memory search indexer use composition API (#5578)
* need to remove tags and objects on composition removal * had to separate out emits from load as it was causing memory indexer to loop upon itself
This commit is contained in:
parent
1a44652470
commit
7cf11e177c
@ -63,6 +63,8 @@ class InMemorySearchProvider {
|
||||
this.localSearchForTags = this.localSearchForTags.bind(this);
|
||||
this.localSearchForNotebookAnnotations = this.localSearchForNotebookAnnotations.bind(this);
|
||||
this.onAnnotationCreation = this.onAnnotationCreation.bind(this);
|
||||
this.onCompositionAdded = this.onCompositionAdded.bind(this);
|
||||
this.onCompositionRemoved = this.onCompositionRemoved.bind(this);
|
||||
this.onerror = this.onWorkerError.bind(this);
|
||||
this.startIndexing = this.startIndexing.bind(this);
|
||||
|
||||
@ -75,6 +77,12 @@ class InMemorySearchProvider {
|
||||
this.worker.port.close();
|
||||
}
|
||||
|
||||
Object.keys(this.indexedCompositions).forEach(keyString => {
|
||||
const composition = this.indexedCompositions[keyString];
|
||||
composition.off('add', this.onCompositionAdded);
|
||||
composition.off('remove', this.onCompositionRemoved);
|
||||
});
|
||||
|
||||
this.destroyObservers(this.indexedIds);
|
||||
this.destroyObservers(this.indexedCompositions);
|
||||
});
|
||||
@ -281,17 +289,25 @@ class InMemorySearchProvider {
|
||||
provider.index(domainObject);
|
||||
}
|
||||
|
||||
onCompositionMutation(domainObject, composition) {
|
||||
onCompositionAdded(newDomainObjectToIndex) {
|
||||
const provider = this;
|
||||
const indexedComposition = domainObject.composition;
|
||||
const identifiersToIndex = composition
|
||||
.filter(identifier => !indexedComposition
|
||||
.some(indexedIdentifier => this.openmct.objects
|
||||
.areIdsEqual([identifier, indexedIdentifier])));
|
||||
provider.index(newDomainObjectToIndex);
|
||||
}
|
||||
|
||||
identifiersToIndex.forEach(identifier => {
|
||||
this.openmct.objects.get(identifier).then(objectToIndex => provider.index(objectToIndex));
|
||||
});
|
||||
onCompositionRemoved(domainObjectToRemoveIdentifier) {
|
||||
const keyString = this.openmct.objects.makeKeyString(domainObjectToRemoveIdentifier);
|
||||
if (this.indexedIds[keyString]) {
|
||||
// we store the unobserve function in the indexedId map
|
||||
this.indexedIds[keyString]();
|
||||
delete this.indexedIds[keyString];
|
||||
}
|
||||
|
||||
const composition = this.indexedCompositions[keyString];
|
||||
if (composition) {
|
||||
composition.off('add', this.onCompositionAdded);
|
||||
composition.off('remove', this.onCompositionRemoved);
|
||||
delete this.indexedCompositions[keyString];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -305,6 +321,7 @@ class InMemorySearchProvider {
|
||||
async index(domainObject) {
|
||||
const provider = this;
|
||||
const keyString = this.openmct.objects.makeKeyString(domainObject.identifier);
|
||||
const composition = this.openmct.composition.get(domainObject);
|
||||
|
||||
if (!this.indexedIds[keyString]) {
|
||||
this.indexedIds[keyString] = this.openmct.objects.observe(
|
||||
@ -312,11 +329,12 @@ class InMemorySearchProvider {
|
||||
'name',
|
||||
this.onNameMutation.bind(this, domainObject)
|
||||
);
|
||||
this.indexedCompositions[keyString] = this.openmct.objects.observe(
|
||||
domainObject,
|
||||
'composition',
|
||||
this.onCompositionMutation.bind(this, domainObject)
|
||||
);
|
||||
if (composition) {
|
||||
composition.on('add', this.onCompositionAdded);
|
||||
composition.on('remove', this.onCompositionRemoved);
|
||||
this.indexedCompositions[keyString] = composition;
|
||||
}
|
||||
|
||||
if (domainObject.type === 'annotation') {
|
||||
this.indexedTags[keyString] = this.openmct.objects.observe(
|
||||
domainObject,
|
||||
@ -338,8 +356,6 @@ class InMemorySearchProvider {
|
||||
}
|
||||
}
|
||||
|
||||
const composition = this.openmct.composition.get(domainObject);
|
||||
|
||||
if (composition !== undefined) {
|
||||
const children = await composition.load();
|
||||
|
||||
|
@ -95,14 +95,12 @@ describe('the plugin', function () {
|
||||
originalRouterPath = openmct.router.path;
|
||||
|
||||
mockComposition = new EventEmitter();
|
||||
mockComposition.load = () => {
|
||||
mockComposition.emit('add', planObject);
|
||||
|
||||
return Promise.resolve([planObject]);
|
||||
// eslint-disable-next-line require-await
|
||||
mockComposition.load = async () => {
|
||||
return [planObject];
|
||||
};
|
||||
|
||||
spyOn(openmct.composition, 'get').and.returnValue(mockComposition);
|
||||
|
||||
openmct.on('start', done);
|
||||
openmct.start(appHolder);
|
||||
});
|
||||
@ -268,6 +266,8 @@ describe('the plugin', function () {
|
||||
});
|
||||
|
||||
it('loads the plan from composition', () => {
|
||||
mockComposition.emit('add', planObject);
|
||||
|
||||
return Vue.nextTick(() => {
|
||||
const items = element.querySelectorAll(LIST_ITEM_CLASS);
|
||||
expect(items.length).toEqual(2);
|
||||
@ -319,6 +319,8 @@ describe('the plugin', function () {
|
||||
});
|
||||
|
||||
it('activities', () => {
|
||||
mockComposition.emit('add', planObject);
|
||||
|
||||
return Vue.nextTick(() => {
|
||||
const items = element.querySelectorAll(LIST_ITEM_CLASS);
|
||||
expect(items.length).toEqual(1);
|
||||
@ -370,6 +372,8 @@ describe('the plugin', function () {
|
||||
});
|
||||
|
||||
it('hides past events', () => {
|
||||
mockComposition.emit('add', planObject);
|
||||
|
||||
return Vue.nextTick(() => {
|
||||
const items = element.querySelectorAll(LIST_ITEM_CLASS);
|
||||
expect(items.length).toEqual(1);
|
||||
|
Loading…
Reference in New Issue
Block a user