moving to canView, since that is where the logic should be

This commit is contained in:
Jamie V 2024-12-30 16:13:42 -08:00
parent 3cba87d55b
commit cc99f19318
2 changed files with 25 additions and 35 deletions

View File

@ -30,19 +30,25 @@ export default function AnnotationsViewProvider(openmct) {
name: 'Annotations', name: 'Annotations',
canView: function (selection) { canView: function (selection) {
const availableTags = openmct.annotation.getAvailableTags(); 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 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) { view: function (selection) {
let _destroy = null; let _destroy = null;
const selectionContext = selection?.[0]?.[0]?.context; const domainObject = selection?.[0]?.[0]?.context?.item;
const domainObject = selectionContext?.item;
const isLayoutItem = selectionContext?.layoutItem;
return { return {
show: function (element) { show: function (element) {
@ -65,18 +71,6 @@ export default function AnnotationsViewProvider(openmct) {
); );
_destroy = destroy; _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 () { priority: function () {
return openmct.priority.DEFAULT; return openmct.priority.DEFAULT;
}, },

View File

@ -35,8 +35,8 @@ function isLayoutObject(selection, objectType) {
); );
} }
function isCreatableObject(object, type) { function isCreatableObject(object, typeObject) {
return NON_STYLABLE_TYPES.indexOf(object.type) < 0 && type.definition.creatable; return NON_STYLABLE_TYPES.indexOf(object.type) < 0 && typeObject.definition.creatable;
} }
export default function StylesInspectorViewProvider(openmct) { export default function StylesInspectorViewProvider(openmct) {
@ -47,23 +47,28 @@ export default function StylesInspectorViewProvider(openmct) {
canView: function (selection) { canView: function (selection) {
const objectSelection = selection?.[0]; const objectSelection = selection?.[0];
const objectContext = objectSelection?.[0]?.context; const objectContext = objectSelection?.[0]?.context;
const layoutItem = objectContext?.layoutItem;
const domainObject = objectContext?.item; const domainObject = objectContext?.item;
const isFlexibleLayoutContainer = const hasStyles = domainObject?.configuration?.objectStyles;
domainObject?.type === 'flexible-layout' && objectContext.type === 'container'; const isFlexibleLayoutContainer = ['flexible-layout', 'fixed-layout'].includes(
domainObject?.type
);
const isLayoutItem = objectContext?.layoutItem;
if (layoutItem) { if (isLayoutItem) {
return true; return true;
} }
if (!domainObject || isFlexibleLayoutContainer) { if (!domainObject || isFlexibleLayoutContainer || !hasStyles) {
return false; return false;
} }
const type = openmct.types.get(domainObject.type); const typeObject = openmct.types.get(domainObject.type);
return ( return (
isLayoutObject(objectSelection, domainObject.type) || isCreatableObject(domainObject, type) hasStyles ||
isLayoutItem ||
isLayoutObject(objectSelection, domainObject.type) ||
isCreatableObject(domainObject, typeObject)
); );
}, },
view: function (selection) { view: function (selection) {
@ -91,15 +96,6 @@ export default function StylesInspectorViewProvider(openmct) {
); );
_destroy = destroy; _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 () { priority: function () {
return openmct.priority.DEFAULT; return openmct.priority.DEFAULT;
}, },