Skip to content

Commit

Permalink
fix(overlay plot): legend updates correctly when removing element via…
Browse files Browse the repository at this point in the history
… remove action (#7531)

* fix: remove duplicate listeners
* fix: if no series found, don't splice
* test(e2e): update legend a11y and add test
  • Loading branch information
ozyx authored Mar 5, 2024
1 parent 0bdd096 commit 39ab81c
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 15 deletions.
21 changes: 21 additions & 0 deletions e2e/tests/functional/plugins/plot/overlayPlot.e2e.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,10 @@ test.describe('Overlay Plot', () => {
type: 'Sine Wave Generator',
parent: overlayPlot.uuid
});
const swgB = await createDomainObjectWithDefaults(page, {
type: 'Sine Wave Generator',
parent: overlayPlot.uuid
});

await page.goto(overlayPlot.url);
// Wait for plot series data to load and be drawn
Expand All @@ -370,6 +374,23 @@ test.describe('Overlay Plot', () => {
await page.getByRole('menuitem', { name: 'Remove' }).click();
await page.getByRole('button', { name: 'OK', exact: true }).click();
await expect(swgAElementsPoolItem).toBeHidden();

await page.getByRole('button', { name: 'Save' }).click();
await page.getByRole('listitem', { name: 'Save and Finish Editing' }).click();

test.info().annotations.push({
type: 'issue',
description: 'https://github.com/nasa/openmct/issues/7530'
});
await test.step('Verify that the legend is correct after removing a series', async () => {
await page.getByLabel('Plot Canvas').hover();
await page.mouse.move(50, 0, {
steps: 10
});
await expect(page.getByLabel('Plot Legend Item')).toHaveCount(1);
await expect(page.getByLabel(`Plot Legend Item for ${swgA.name}`)).toBeHidden();
await expect(page.getByLabel(`Plot Legend Item for ${swgB.name}`)).toBeVisible();
});
});
});

Expand Down
11 changes: 0 additions & 11 deletions src/plugins/plot/legend/PlotLegend.vue
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@ export default {
this.registerListeners(this.config);
}
this.listenTo(this.config.legend, 'change:expandByDefault', this.changeExpandDefault, this);
this.initialize();
},
mounted() {
this.loaded = true;
Expand All @@ -182,16 +181,6 @@ export default {
this.stopListening();
},
methods: {
initialize() {
if (this.domainObject.type === 'telemetry.plot.stacked') {
this.objectComposition = this.openmct.composition.get(this.domainObject);
this.objectComposition.on('add', this.addTelemetryObject);
this.objectComposition.on('remove', this.removeTelemetryObject);
this.objectComposition.load();
} else {
this.registerListeners(this.config);
}
},
changeExpandDefault() {
this.isLegendExpanded = this.config.legend.model.expandByDefault;
this.legend.set('expanded', this.isLegendExpanded);
Expand Down
12 changes: 8 additions & 4 deletions src/plugins/plot/legend/PlotLegendItemCollapsed.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<template>
<div
class="plot-legend-item"
:aria-label="`Plot Legend Item for ${domainObject?.name}`"
:aria-label="`Plot Legend Item for ${seriesName}`"
:class="{
'is-stale': isStale,
'is-status--missing': isMissing
Expand All @@ -36,9 +36,8 @@
@mouseover.ctrl="showToolTip"
@mouseleave="hideToolTip"
>
<span class="plot-series-color-swatch" :style="{ 'background-color': colorAsHexString }">
</span>
<span class="is-status__indicator" title="This item is missing or suspect"></span>
<span class="plot-series-color-swatch" :style="{ 'background-color': colorAsHexString }" />
<span class="is-status__indicator" title="This item is missing or suspect" />
<span class="plot-series-name">{{ nameWithUnit }}</span>
</div>
<div
Expand Down Expand Up @@ -89,6 +88,7 @@ export default {
isMissing: false,
colorAsHexString: '',
nameWithUnit: '',
seriesName: '',
formattedYValue: '',
formattedXValue: '',
mctLimitStateClass: '',
Expand Down Expand Up @@ -206,6 +206,9 @@ export default {
const seriesIndexToRemove = this.seriesModels.findIndex(
(series) => series.keyString === seriesToRemove.keyString
);
if (seriesIndexToRemove === -1) {
return;
}
this.seriesModels.splice(seriesIndexToRemove, 1);
},
getSeries(keyStringToFind) {
Expand All @@ -220,6 +223,7 @@ export default {

this.isMissing = seriesObject.domainObject.status === 'missing';
this.colorAsHexString = seriesObject.get('color').asHexString();
this.seriesName = seriesObject.domainObject.name;
this.nameWithUnit = seriesObject.nameWithUnit();

const closest = seriesObject.closest;
Expand Down

0 comments on commit 39ab81c

Please sign in to comment.