Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Inspector Tabs] Make them more opinionated on where they show #7974

Closed
wants to merge 7 commits into from
21 changes: 21 additions & 0 deletions src/api/annotation/AnnotationAPI.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ export default class AnnotationAPI extends EventEmitter {
this.availableTags = {};
this.namespaceToSaveAnnotations = '';
this.#targetComparatorMap = new Map();
this.annotatableTypes = [];

this.ANNOTATION_TYPES = ANNOTATION_TYPES;
this.ANNOTATION_TYPE = ANNOTATION_TYPE;
Expand All @@ -115,6 +116,17 @@ export default class AnnotationAPI extends EventEmitter {
domainObject.annotationType = domainObject.annotationType || 'plotspatial';
}
});

this.openmct.on('start', () => {
const types = this.openmct.types.getTypes();
const typeKeys = Object.keys(types);

typeKeys.forEach((key) => {
if (types[key].definition.annotatable) {
this.annotatableTypes.push(key);
}
});
});
}
/**
* Creates an annotation on a given domain object (e.g., a plot) and a set of targets (e.g., telemetry objects)
Expand Down Expand Up @@ -582,4 +594,13 @@ export default class AnnotationAPI extends EventEmitter {
_.isEqual(targets, otherTargets)
);
}

/**
* Checks if the given type is annotatable
* @param {string} type The type to check
* @returns {boolean} Returns true if the type is annotatable
*/
isAnnotatableType(type) {
return this.annotatableTypes.some((annotatableType) => annotatableType === type);
}
}
27 changes: 27 additions & 0 deletions src/api/telemetry/TelemetryAPI.js
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,33 @@ export default class TelemetryAPI {
return value;
}

/**
* Determines whether a domain object has numeric telemetry data.
* A domain object has numeric telemetry if it:
* 1. Has a telemetry property
* 2. Has telemetry metadata with domain values (like timestamps)
* 3. Has range values (measurements) where at least one is numeric
*
* @method hasNumericTelemetry
* @param {import('openmct').DomainObject} domainObject The domain object to check
* @returns {boolean} True if the object has numeric telemetry, false otherwise
*/
hasNumericTelemetry(domainObject) {
if (!Object.prototype.hasOwnProperty.call(domainObject, 'telemetry')) {
return false;
}

const metadata = this.openmct.telemetry.getMetadata(domainObject);
const rangeValues = metadata.valuesForHints(['range']);
const domains = metadata.valuesForHints(['domain']);

return (
domains.length > 0 &&
rangeValues.length > 0 &&
!rangeValues.every((value) => value.format === 'string')
);
}

/**
* Generates a numeric hash value for an options object. The hash is consistent
* for equivalent option objects regardless of property order.
Expand Down
11 changes: 11 additions & 0 deletions src/api/types/TypeRegistry.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,17 @@ export default class TypeRegistry {
get(typeKey) {
return this.types[typeKey] || UNKNOWN_TYPE;
}
/**
* List all registered types.
* @returns {Type[]} all registered types
*/
getTypes() {
return this.types;
}
/**
* Import legacy types.
* @param {TypeDefinition[]} types the types to import
*/
importLegacyTypes(types) {
types
.filter((t) => this.get(t.key) === UNKNOWN_TYPE)
Expand Down
20 changes: 1 addition & 19 deletions src/plugins/gauge/GaugeCompositionPolicy.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,28 +21,10 @@
*****************************************************************************/

export default function GaugeCompositionPolicy(openmct) {
function hasNumericTelemetry(domainObject) {
const hasTelemetry = openmct.telemetry.isTelemetryObject(domainObject);
if (!hasTelemetry) {
return false;
}

const metadata = openmct.telemetry.getMetadata(domainObject);

return metadata.values().length > 0 && hasDomainAndRange(metadata);
}

function hasDomainAndRange(metadata) {
return (
metadata.valuesForHints(['range']).length > 0 &&
metadata.valuesForHints(['domain']).length > 0
);
}

return {
allow: function (parent, child) {
if (parent.type === 'gauge') {
return hasNumericTelemetry(child);
return openmct.telemetry.hasNumericTelemetry(child);
}

return true;
Expand Down
12 changes: 10 additions & 2 deletions src/plugins/inspectorViews/annotations/AnnotationsViewProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,20 @@ 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;
Expand Down
23 changes: 14 additions & 9 deletions src/plugins/inspectorViews/styles/StylesInspectorViewProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
);
}

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 @@
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
1 change: 1 addition & 0 deletions src/plugins/notebook/NotebookType.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export default class NotebookType {
this.description = description;
this.cssClass = icon;
this.creatable = true;
this.annotatable = true;
this.form = [
{
key: 'defaultSort',
Expand Down
23 changes: 1 addition & 22 deletions src/plugins/plot/PlotViewProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,27 +25,6 @@ import mount from 'utils/mount';
import Plot from './PlotView.vue';

export default function PlotViewProvider(openmct) {
function hasNumericTelemetry(domainObject) {
if (!Object.prototype.hasOwnProperty.call(domainObject, 'telemetry')) {
return false;
}

let metadata = openmct.telemetry.getMetadata(domainObject);

return metadata.values().length > 0 && hasDomainAndNumericRange(metadata);
}

function hasDomainAndNumericRange(metadata) {
const rangeValues = metadata.valuesForHints(['range']);
const domains = metadata.valuesForHints(['domain']);

return (
domains.length > 0 &&
rangeValues.length > 0 &&
!rangeValues.every((value) => value.format === 'string')
);
}

function isCompactView(objectPath) {
let isChildOfTimeStrip = objectPath.find((object) => object.type === 'time-strip');

Expand All @@ -57,7 +36,7 @@ export default function PlotViewProvider(openmct) {
name: 'Plot',
cssClass: 'icon-telemetry',
canView(domainObject, objectPath) {
return hasNumericTelemetry(domainObject);
return openmct.telemetry.hasNumericTelemetry(domainObject);
},

view: function (domainObject, objectPath) {
Expand Down
23 changes: 4 additions & 19 deletions src/plugins/plot/overlayPlot/OverlayPlotCompositionPolicy.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,10 @@
export default function OverlayPlotCompositionPolicy(openmct) {
function hasNumericTelemetry(domainObject) {
const hasTelemetry = openmct.telemetry.isTelemetryObject(domainObject);
if (!hasTelemetry) {
return false;
}

let metadata = openmct.telemetry.getMetadata(domainObject);

return metadata.values().length > 0 && hasDomainAndRange(metadata);
}

function hasDomainAndRange(metadata) {
return (
metadata.valuesForHints(['range']).length > 0 &&
metadata.valuesForHints(['domain']).length > 0
);
}

return {
allow: function (parent, child) {
if (parent.type === 'telemetry.plot.overlay' && hasNumericTelemetry(child) === false) {
if (
parent.type === 'telemetry.plot.overlay' &&
!openmct.telemetry.hasNumericTelemetry(child)
) {
return false;
}

Expand Down
18 changes: 1 addition & 17 deletions src/plugins/timeline/TimelineCompositionPolicy.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,6 @@
const ALLOWED_TYPES = ['telemetry.plot.overlay', 'telemetry.plot.stacked', 'plan', 'gantt-chart'];
const DISALLOWED_TYPES = ['telemetry.plot.bar-graph', 'telemetry.plot.scatter-plot'];
export default function TimelineCompositionPolicy(openmct) {
function hasNumericTelemetry(domainObject, metadata) {
const hasTelemetry = openmct.telemetry.isTelemetryObject(domainObject);
if (!hasTelemetry || !metadata) {
return false;
}

return metadata.values().length > 0 && hasDomainAndRange(metadata);
}

function hasDomainAndRange(metadata) {
return (
metadata.valuesForHints(['range']).length > 0 &&
metadata.valuesForHints(['domain']).length > 0
);
}

function hasImageTelemetry(domainObject, metadata) {
if (!metadata) {
return false;
Expand All @@ -54,7 +38,7 @@ export default function TimelineCompositionPolicy(openmct) {

if (
!DISALLOWED_TYPES.includes(child.type) &&
(hasNumericTelemetry(child, metadata) ||
(openmct.telemetry.hasNumericTelemetry(child) ||
hasImageTelemetry(child, metadata) ||
ALLOWED_TYPES.includes(child.type))
) {
Expand Down
Loading