Plot view policy fix (#3995)

* deny plot view for non-numeric telemetry

* revert plot type for backwards compatibility
This commit is contained in:
David Tsay 2021-07-14 18:12:26 -07:00 committed by GitHub
parent 10da314a4a
commit 4a7ebe326c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 55 additions and 9 deletions

View File

@ -24,19 +24,23 @@ import Plot from './Plot.vue';
import Vue from 'vue';
export default function PlotViewProvider(openmct) {
function hasTelemetry(domainObject) {
function hasNumericTelemetry(domainObject) {
if (!Object.prototype.hasOwnProperty.call(domainObject, 'telemetry')) {
return false;
}
let metadata = openmct.telemetry.getMetadata(domainObject);
return metadata.values().length > 0 && hasDomainAndRange(metadata);
return metadata.values().length > 0 && hasDomainAndNumericRange(metadata);
}
function hasDomainAndRange(metadata) {
return (metadata.valuesForHints(['range']).length > 0
&& metadata.valuesForHints(['domain']).length > 0);
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) {
@ -44,11 +48,11 @@ export default function PlotViewProvider(openmct) {
}
return {
key: 'plot-simple',
key: 'plot-single',
name: 'Plot',
cssClass: 'icon-telemetry',
canView(domainObject, objectPath) {
return hasTelemetry(domainObject, openmct);
return hasNumericTelemetry(domainObject);
},
view: function (domainObject, objectPath) {

View File

@ -201,15 +201,57 @@ describe("the plugin", function () {
hints: {
range: 1
}
},
{
key: "yet-another-key",
format: "string",
hints: {
range: 2
}
}]
}
};
const applicableViews = openmct.objectViews.get(testTelemetryObject, mockObjectPath);
let plotView = applicableViews.find((viewProvider) => viewProvider.key === "plot-simple");
const plotView = applicableViews.find((viewProvider) => viewProvider.key === "plot-single");
expect(plotView).toBeDefined();
});
it("does not provide a plot view if the telemetry is entirely non numeric", () => {
const testTelemetryObject = {
id: "test-object",
type: "test-object",
telemetry: {
values: [{
key: "some-key",
hints: {
domain: 1
}
},
{
key: "other-key",
format: "string",
hints: {
range: 1
}
},
{
key: "yet-another-key",
format: "string",
hints: {
range: 1
}
}]
}
};
const applicableViews = openmct.objectViews.get(testTelemetryObject, mockObjectPath);
const plotView = applicableViews.find((viewProvider) => viewProvider.key === "plot-single");
expect(plotView).toBeUndefined();
});
it("provides an overlay plot view for objects with telemetry", () => {
const testTelemetryObject = {
id: "test-object",
@ -323,7 +365,7 @@ describe("the plugin", function () {
};
applicableViews = openmct.objectViews.get(testTelemetryObject, mockObjectPath);
plotViewProvider = applicableViews.find((viewProvider) => viewProvider.key === "plot-simple");
plotViewProvider = applicableViews.find((viewProvider) => viewProvider.key === "plot-single");
plotView = plotViewProvider.view(testTelemetryObject, [testTelemetryObject]);
plotView.show(child, true);