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

fix(overlay plot): legend updates correctly when removing element via remove action #7531

Merged
merged 4 commits into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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();
Copy link
Member Author

Choose a reason for hiding this comment

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

remove duplicate code

},
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 @@
isMissing: false,
colorAsHexString: '',
nameWithUnit: '',
seriesName: '',
formattedYValue: '',
formattedXValue: '',
mctLimitStateClass: '',
Expand Down Expand Up @@ -206,6 +206,9 @@
const seriesIndexToRemove = this.seriesModels.findIndex(
(series) => series.keyString === seriesToRemove.keyString
);
if (seriesIndexToRemove === -1) {
return;
}

Check warning on line 211 in src/plugins/plot/legend/PlotLegendItemCollapsed.vue

View check run for this annotation

Codecov / codecov/patch

src/plugins/plot/legend/PlotLegendItemCollapsed.vue#L209-L211

Added lines #L209 - L211 were not covered by tests
Comment on lines +209 to +211
Copy link
Member Author

Choose a reason for hiding this comment

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

don't remove a seriesModel if we don't find one in the list

Copy link
Contributor

Choose a reason for hiding this comment

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

haha, that ... makes sense

this.seriesModels.splice(seriesIndexToRemove, 1);
},
getSeries(keyStringToFind) {
Expand All @@ -220,6 +223,7 @@

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
Loading