feat: sort interceptors by priority, ensure myItemsInterceptor
runs first (#5965)
* feat: sort interceptors by priority * fix(#5914): high priority for MyItemsInterceptor * fix: create myItems if object is falsy * test(e2e): update snapshots Co-authored-by: Scott Bell <scott@traclabs.com>
Before Width: | Height: | Size: 16 KiB After Width: | Height: | Size: 18 KiB |
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 18 KiB |
Before Width: | Height: | Size: 18 KiB After Width: | Height: | Size: 21 KiB |
Before Width: | Height: | Size: 18 KiB After Width: | Height: | Size: 21 KiB |
@ -19,6 +19,7 @@
|
|||||||
* this source code distribution or the Licensing information page available
|
* this source code distribution or the Licensing information page available
|
||||||
* at runtime from the About dialog for additional information.
|
* at runtime from the About dialog for additional information.
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
|
const DEFAULT_INTERCEPTOR_PRIORITY = 0;
|
||||||
export default class InterceptorRegistry {
|
export default class InterceptorRegistry {
|
||||||
/**
|
/**
|
||||||
* A InterceptorRegistry maintains the definitions for different interceptors that may be invoked on domain objects.
|
* A InterceptorRegistry maintains the definitions for different interceptors that may be invoked on domain objects.
|
||||||
@ -45,7 +46,6 @@ export default class InterceptorRegistry {
|
|||||||
* @memberof module:openmct.InterceptorRegistry#
|
* @memberof module:openmct.InterceptorRegistry#
|
||||||
*/
|
*/
|
||||||
addInterceptor(interceptorDef) {
|
addInterceptor(interceptorDef) {
|
||||||
//TODO: sort by priority
|
|
||||||
this.interceptors.push(interceptorDef);
|
this.interceptors.push(interceptorDef);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -56,10 +56,18 @@ export default class InterceptorRegistry {
|
|||||||
* @memberof module:openmct.InterceptorRegistry#
|
* @memberof module:openmct.InterceptorRegistry#
|
||||||
*/
|
*/
|
||||||
getInterceptors(identifier, object) {
|
getInterceptors(identifier, object) {
|
||||||
|
|
||||||
|
function byPriority(interceptorA, interceptorB) {
|
||||||
|
let priorityA = interceptorA.priority ?? DEFAULT_INTERCEPTOR_PRIORITY;
|
||||||
|
let priorityB = interceptorB.priority ?? DEFAULT_INTERCEPTOR_PRIORITY;
|
||||||
|
|
||||||
|
return priorityB - priorityA;
|
||||||
|
}
|
||||||
|
|
||||||
return this.interceptors.filter(interceptor => {
|
return this.interceptors.filter(interceptor => {
|
||||||
return typeof interceptor.appliesTo === 'function'
|
return typeof interceptor.appliesTo === 'function'
|
||||||
&& interceptor.appliesTo(identifier, object);
|
&& interceptor.appliesTo(identifier, object);
|
||||||
});
|
}).sort(byPriority);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -37,14 +37,15 @@ function myItemsInterceptor(openmct, identifierObject, name) {
|
|||||||
return identifier.key === MY_ITEMS_KEY;
|
return identifier.key === MY_ITEMS_KEY;
|
||||||
},
|
},
|
||||||
invoke: (identifier, object) => {
|
invoke: (identifier, object) => {
|
||||||
if (openmct.objects.isMissing(object)) {
|
if (!object || openmct.objects.isMissing(object)) {
|
||||||
openmct.objects.save(myItemsModel);
|
openmct.objects.save(myItemsModel);
|
||||||
|
|
||||||
return myItemsModel;
|
return myItemsModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
return object;
|
return object;
|
||||||
}
|
},
|
||||||
|
priority: openmct.priority.HIGH
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|