diff options
author | Jesse Mazzella <ozyx@users.noreply.github.com> | 2022-11-10 19:00:29 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-10 19:00:29 +0300 |
commit | 8b5daad65c802d8c70cfe18ae2ccecde2107d38a (patch) | |
tree | e1b6f00dae881fcb099afe481ffc815b89a6fb8e | |
parent | fabfecdb3ebb790cb606a15636fad63840a7c645 (diff) |
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>
-rw-r--r-- | e2e/tests/functional/plugins/plot/autoscale.e2e.spec.js-snapshots/autoscale-canvas-panned-chrome-darwin | bin | 16185 -> 18966 bytes | |||
-rw-r--r-- | e2e/tests/functional/plugins/plot/autoscale.e2e.spec.js-snapshots/autoscale-canvas-panned-chrome-linux.png | bin | 15796 -> 18535 bytes | |||
-rw-r--r-- | e2e/tests/functional/plugins/plot/autoscale.e2e.spec.js-snapshots/autoscale-canvas-prepan-chrome-darwin | bin | 18393 -> 21738 bytes | |||
-rw-r--r-- | e2e/tests/functional/plugins/plot/autoscale.e2e.spec.js-snapshots/autoscale-canvas-prepan-chrome-linux.png | bin | 18089 -> 21380 bytes | |||
-rw-r--r-- | src/api/objects/InterceptorRegistry.js | 12 | ||||
-rw-r--r-- | src/plugins/myItems/myItemsInterceptor.js | 5 |
6 files changed, 13 insertions, 4 deletions
diff --git a/e2e/tests/functional/plugins/plot/autoscale.e2e.spec.js-snapshots/autoscale-canvas-panned-chrome-darwin b/e2e/tests/functional/plugins/plot/autoscale.e2e.spec.js-snapshots/autoscale-canvas-panned-chrome-darwin Binary files differindex d6d4dd21e..072218f3f 100644 --- a/e2e/tests/functional/plugins/plot/autoscale.e2e.spec.js-snapshots/autoscale-canvas-panned-chrome-darwin +++ b/e2e/tests/functional/plugins/plot/autoscale.e2e.spec.js-snapshots/autoscale-canvas-panned-chrome-darwin diff --git a/e2e/tests/functional/plugins/plot/autoscale.e2e.spec.js-snapshots/autoscale-canvas-panned-chrome-linux.png b/e2e/tests/functional/plugins/plot/autoscale.e2e.spec.js-snapshots/autoscale-canvas-panned-chrome-linux.png Binary files differindex 4a882660e..145d4e54c 100644 --- a/e2e/tests/functional/plugins/plot/autoscale.e2e.spec.js-snapshots/autoscale-canvas-panned-chrome-linux.png +++ b/e2e/tests/functional/plugins/plot/autoscale.e2e.spec.js-snapshots/autoscale-canvas-panned-chrome-linux.png diff --git a/e2e/tests/functional/plugins/plot/autoscale.e2e.spec.js-snapshots/autoscale-canvas-prepan-chrome-darwin b/e2e/tests/functional/plugins/plot/autoscale.e2e.spec.js-snapshots/autoscale-canvas-prepan-chrome-darwin Binary files differindex ef5455e5c..b6c7ba2fc 100644 --- a/e2e/tests/functional/plugins/plot/autoscale.e2e.spec.js-snapshots/autoscale-canvas-prepan-chrome-darwin +++ b/e2e/tests/functional/plugins/plot/autoscale.e2e.spec.js-snapshots/autoscale-canvas-prepan-chrome-darwin diff --git a/e2e/tests/functional/plugins/plot/autoscale.e2e.spec.js-snapshots/autoscale-canvas-prepan-chrome-linux.png b/e2e/tests/functional/plugins/plot/autoscale.e2e.spec.js-snapshots/autoscale-canvas-prepan-chrome-linux.png Binary files differindex ffdedffd2..3b1a664ad 100644 --- a/e2e/tests/functional/plugins/plot/autoscale.e2e.spec.js-snapshots/autoscale-canvas-prepan-chrome-linux.png +++ b/e2e/tests/functional/plugins/plot/autoscale.e2e.spec.js-snapshots/autoscale-canvas-prepan-chrome-linux.png diff --git a/src/api/objects/InterceptorRegistry.js b/src/api/objects/InterceptorRegistry.js index 80f83cc71..bc51f98e1 100644 --- a/src/api/objects/InterceptorRegistry.js +++ b/src/api/objects/InterceptorRegistry.js @@ -19,6 +19,7 @@ * this source code distribution or the Licensing information page available * at runtime from the About dialog for additional information. *****************************************************************************/ +const DEFAULT_INTERCEPTOR_PRIORITY = 0; export default class InterceptorRegistry { /** * 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# */ addInterceptor(interceptorDef) { - //TODO: sort by priority this.interceptors.push(interceptorDef); } @@ -56,10 +56,18 @@ export default class InterceptorRegistry { * @memberof module:openmct.InterceptorRegistry# */ 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 typeof interceptor.appliesTo === 'function' && interceptor.appliesTo(identifier, object); - }); + }).sort(byPriority); } } diff --git a/src/plugins/myItems/myItemsInterceptor.js b/src/plugins/myItems/myItemsInterceptor.js index 375ee88e4..6a1953f8a 100644 --- a/src/plugins/myItems/myItemsInterceptor.js +++ b/src/plugins/myItems/myItemsInterceptor.js @@ -37,14 +37,15 @@ function myItemsInterceptor(openmct, identifierObject, name) { return identifier.key === MY_ITEMS_KEY; }, invoke: (identifier, object) => { - if (openmct.objects.isMissing(object)) { + if (!object || openmct.objects.isMissing(object)) { openmct.objects.save(myItemsModel); return myItemsModel; } return object; - } + }, + priority: openmct.priority.HIGH }; } |