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

Gauge fixes for NaN and composition policy #5608

Merged
merged 24 commits into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
3986a12
Closes #5536, #5538
charlesh88 Aug 4, 2022
40597ff
Merge remote-tracking branch 'origin' into fix-gauge-5538
charlesh88 Aug 4, 2022
06058c4
Closes #5536, #5538
charlesh88 Aug 4, 2022
0c6e385
Merge branch 'master' into fix-gauge-5538
akhenry Sep 12, 2022
e8b4b8f
Closes #5538
charlesh88 Oct 24, 2023
3b6dc26
Merge branch 'master' into fix-gauge-5538
davetsay Oct 26, 2023
f19c0c3
Closes #5538
charlesh88 Oct 26, 2023
69ca440
Merge branch 'master' into fix-gauge-5538
charlesh88 Oct 30, 2023
665ac24
Merge branch 'master' into fix-gauge-5538
ozyx Nov 6, 2023
26f1916
Merge branch 'fix-gauge-5538' of github.com:nasa/openmct into fix-gau…
charlesh88 Nov 6, 2023
300100a
Closes #5538
charlesh88 Nov 6, 2023
8979ed3
Closes #5538
charlesh88 Nov 7, 2023
cf40952
Closes #5538
charlesh88 Nov 7, 2023
fb49b0b
Closes #5538
charlesh88 Nov 7, 2023
f0a0faf
Merge branch 'master' into fix-gauge-5538
charlesh88 Nov 7, 2023
7682062
Closes #5538
charlesh88 Nov 7, 2023
5ddbdaf
Closes #5538
charlesh88 Nov 7, 2023
9b051ca
Merge branch 'master' into fix-gauge-5538
charlesh88 Nov 8, 2023
f19a06d
Merge remote-tracking branch 'origin' into fix-gauge-5538
charlesh88 Nov 8, 2023
5bf67b8
Merge branch 'fix-gauge-5538' of github.com:nasa/openmct into fix-gau…
charlesh88 Nov 8, 2023
1f58050
Update e2e/tests/functional/plugins/gauge/gauge.e2e.spec.js
charlesh88 Nov 16, 2023
ac1a105
chore: lint:fix
ozyx Nov 16, 2023
b596f32
Merge branch 'master' into fix-gauge-5538
ozyx Nov 16, 2023
2c48b0d
Merge branch 'master' into fix-gauge-5538
ozyx Nov 16, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions e2e/tests/functional/plugins/gauge/gauge.e2e.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,4 +133,50 @@ test.describe('Gauge', () => {

// TODO: Verify changes in the UI
});

test('Gauge does not display NaN when data not available', async ({ page }) => {
// Create a Gauge
await createDomainObjectWithDefaults(page, {
type: 'Gauge',
name: 'Unnamed Gauge'
});

// Create a Sine Wave Generator in the Gauge with a loading delay
await page.getByRole('button', { name: ' Create ' }).click();
await page.getByRole('menuitem', { name: ' Sine Wave Generator' }).click();
await page
.getByRole('dialog')
.locator('div')
.filter({ hasText: 'Loading Delay (ms)' })
.nth(3)
.click();
await page.getByLabel('Loading Delay (ms)').fill('5000');
await page.locator('[aria-label="Save"]').click();
await page.getByLabel('Expand My Items folder').click();
await page
.getByRole('treeitem', { name: 'Expand Unnamed Gauge gauge  Unnamed Gauge' })
.locator('a')
.click();
const gaugeNoDataText = await page.locator('.js-dial-current-value tspan').textContent();
expect(gaugeNoDataText).toBe('--');
});

test('Gauge enforces composition policy', async ({ page }) => {
// Create a Gauge
await createDomainObjectWithDefaults(page, {
type: 'Gauge',
name: 'Unnamed Gauge'
});

// Try to create a Folder into the Gauge. Should be disallowed.
await page.getByRole('button', { name: ' Create ' }).click();
await page.getByRole('menuitem', { name: ' Folder' }).click();
await expect(page.locator('[aria-label="Save"]')).toBeDisabled();
await page.getByLabel('Cancel').click();

// Try to create a Display Layout into the Gauge. Should be disallowed.
await page.getByRole('button', { name: ' Create ' }).click();
await page.getByRole('menuitem', { name: ' Display Layout' }).click();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same thing here

await expect(page.locator('[aria-label="Save"]')).toBeDisabled();
});
});
29 changes: 29 additions & 0 deletions src/plugins/gauge/GaugeCompositionPolicy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
export default function GaugeCompositionPolicy(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 === 'gauge') {
return hasNumericTelemetry(child);
}

return true;
}
};
}
5 changes: 4 additions & 1 deletion src/plugins/gauge/GaugePlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import mount from 'utils/mount';

import GaugeFormController from './components/GaugeFormController.vue';
import GaugeCompositionPolicy from './GaugeCompositionPolicy';
import GaugeViewProvider from './GaugeViewProvider';

export const GAUGE_TYPES = [
Expand Down Expand Up @@ -165,6 +166,7 @@ export default function () {
}
]
});
openmct.composition.addPolicy(new GaugeCompositionPolicy(openmct).allow);
};

function getGaugeFormController(openmct) {
Expand All @@ -187,7 +189,8 @@ export default function () {
onChange
};
},
template: `<GaugeFormController :model="model" @on-change="onChange"></GaugeFormController>`
template: `
<GaugeFormController :model="model" @on-change="onChange"></GaugeFormController>`
},
{
app: openmct.app,
Expand Down
8 changes: 4 additions & 4 deletions src/plugins/gauge/components/GaugeComponent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -402,10 +402,10 @@ export default {
const CHAR_THRESHOLD = 3;
const START_PERC = 8.5;
const REDUCE_PERC = 0.8;
const RANGE_CHARS_MAX = Math.max(
this.rangeLow.toString().length,
this.rangeHigh.toString().length
);
const RANGE_CHARS_MAX =
this.rangeLow && this.rangeHigh
? Math.max(this.rangeLow.toString().length, this.rangeHigh.toString().length)
: CHAR_THRESHOLD;

return this.fontSizeFromChars(RANGE_CHARS_MAX, CHAR_THRESHOLD, START_PERC, REDUCE_PERC);
},
Expand Down