From cc99f19318e813cc85c89f0133c5688c8ef52bf8 Mon Sep 17 00:00:00 2001 From: Jamie V Date: Mon, 30 Dec 2024 16:13:42 -0800 Subject: [PATCH] moving to canView, since that is where the logic should be --- .../annotations/AnnotationsViewProvider.js | 28 +++++++--------- .../styles/StylesInspectorViewProvider.js | 32 ++++++++----------- 2 files changed, 25 insertions(+), 35 deletions(-) diff --git a/src/plugins/inspectorViews/annotations/AnnotationsViewProvider.js b/src/plugins/inspectorViews/annotations/AnnotationsViewProvider.js index bbfc9b98b1..50cb6381f4 100644 --- a/src/plugins/inspectorViews/annotations/AnnotationsViewProvider.js +++ b/src/plugins/inspectorViews/annotations/AnnotationsViewProvider.js @@ -30,19 +30,25 @@ export default function AnnotationsViewProvider(openmct) { name: 'Annotations', canView: function (selection) { const availableTags = openmct.annotation.getAvailableTags(); + const selectionContext = selection?.[0]?.[0]?.context; + const domainObject = selectionContext?.item; + const isLayoutItem = selectionContext?.layoutItem; - if (availableTags.length < 1) { + if (availableTags.length < 1 || isLayoutItem || !domainObject) { return false; } - return selection.length; + const isAnnotatableType = openmct.annotation.isAnnotatableType(domainObject.type); + const metadata = openmct.telemetry.getMetadata(domainObject); + const hasImagery = metadata?.valuesForHints(['image']).length > 0; + const hasNumericTelemetry = openmct.telemetry.hasNumericTelemetry(domainObject); + + return isAnnotatableType || hasImagery || hasNumericTelemetry; }, view: function (selection) { let _destroy = null; - const selectionContext = selection?.[0]?.[0]?.context; - const domainObject = selectionContext?.item; - const isLayoutItem = selectionContext?.layoutItem; + const domainObject = selection?.[0]?.[0]?.context?.item; return { show: function (element) { @@ -65,18 +71,6 @@ export default function AnnotationsViewProvider(openmct) { ); _destroy = destroy; }, - showTab: function () { - if (isLayoutItem) { - return false; - } - - const isAnnotatableType = openmct.annotation.isAnnotatableType(domainObject.type); - const metadata = openmct.telemetry.getMetadata(domainObject); - const hasImagery = metadata?.valuesForHints(['image']).length > 0; - const hasNumericTelemetry = openmct.telemetry.hasNumericTelemetry(domainObject); - - return isAnnotatableType || hasImagery || hasNumericTelemetry; - }, priority: function () { return openmct.priority.DEFAULT; }, diff --git a/src/plugins/inspectorViews/styles/StylesInspectorViewProvider.js b/src/plugins/inspectorViews/styles/StylesInspectorViewProvider.js index 8abc1acdc1..2984b34ac7 100644 --- a/src/plugins/inspectorViews/styles/StylesInspectorViewProvider.js +++ b/src/plugins/inspectorViews/styles/StylesInspectorViewProvider.js @@ -35,8 +35,8 @@ function isLayoutObject(selection, objectType) { ); } -function isCreatableObject(object, type) { - return NON_STYLABLE_TYPES.indexOf(object.type) < 0 && type.definition.creatable; +function isCreatableObject(object, typeObject) { + return NON_STYLABLE_TYPES.indexOf(object.type) < 0 && typeObject.definition.creatable; } export default function StylesInspectorViewProvider(openmct) { @@ -47,23 +47,28 @@ export default function StylesInspectorViewProvider(openmct) { canView: function (selection) { const objectSelection = selection?.[0]; const objectContext = objectSelection?.[0]?.context; - const layoutItem = objectContext?.layoutItem; const domainObject = objectContext?.item; - const isFlexibleLayoutContainer = - domainObject?.type === 'flexible-layout' && objectContext.type === 'container'; + const hasStyles = domainObject?.configuration?.objectStyles; + const isFlexibleLayoutContainer = ['flexible-layout', 'fixed-layout'].includes( + domainObject?.type + ); + const isLayoutItem = objectContext?.layoutItem; - if (layoutItem) { + if (isLayoutItem) { return true; } - if (!domainObject || isFlexibleLayoutContainer) { + if (!domainObject || isFlexibleLayoutContainer || !hasStyles) { return false; } - const type = openmct.types.get(domainObject.type); + const typeObject = openmct.types.get(domainObject.type); return ( - isLayoutObject(objectSelection, domainObject.type) || isCreatableObject(domainObject, type) + hasStyles || + isLayoutItem || + isLayoutObject(objectSelection, domainObject.type) || + isCreatableObject(domainObject, typeObject) ); }, view: function (selection) { @@ -91,15 +96,6 @@ export default function StylesInspectorViewProvider(openmct) { ); _destroy = destroy; }, - showTab: function () { - const objectSelection = selection?.[0]; - const objectContext = objectSelection?.[0]?.context; - const layoutItem = objectContext?.layoutItem; - const domainObject = objectContext?.item; - const hasStyles = domainObject?.configuration?.objectStyles; - - return layoutItem || hasStyles; - }, priority: function () { return openmct.priority.DEFAULT; },