Skip to content

Commit

Permalink
moving to canView, since that is where the logic should be
Browse files Browse the repository at this point in the history
  • Loading branch information
jvigliotta committed Dec 31, 2024
1 parent 3cba87d commit cc99f19
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 35 deletions.
28 changes: 11 additions & 17 deletions src/plugins/inspectorViews/annotations/AnnotationsViewProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
},
Expand Down
32 changes: 14 additions & 18 deletions src/plugins/inspectorViews/styles/StylesInspectorViewProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Check warning on line 39 in src/plugins/inspectorViews/styles/StylesInspectorViewProvider.js

View check run for this annotation

Codecov / codecov/patch

src/plugins/inspectorViews/styles/StylesInspectorViewProvider.js#L39

Added line #L39 was not covered by tests
}

export default function StylesInspectorViewProvider(openmct) {
Expand All @@ -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) {
Expand Down Expand Up @@ -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;
},
Expand Down

0 comments on commit cc99f19

Please sign in to comment.