Skip to content

Commit

Permalink
fix(#7456): allow children of Overlay Plots to be removed (#7516)
Browse files Browse the repository at this point in the history
* fix(#7456): check if object is an identifier

* refactor: use v-show, remove unnecessary deep copy, set yAxes array to empty in a way that preserves reactivity

* refactor: use ESM exports

* refactor: use ESM imports

* test(e2e): add test for element item removal from overlay plot

* a11y: add accessible name for object labels

* refactor: move overlayPlot creation to beforeAll, use getByLabel
  • Loading branch information
ozyx authored Feb 22, 2024
1 parent 6393a77 commit 29d83e9
Show file tree
Hide file tree
Showing 24 changed files with 223 additions and 152 deletions.
45 changes: 25 additions & 20 deletions e2e/tests/functional/plugins/plot/overlayPlot.e2e.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ import {
import { expect, test } from '../../../../pluginFixtures.js';

test.describe('Overlay Plot', () => {
let overlayPlot;
test.beforeEach(async ({ page }) => {
await page.goto('./', { waitUntil: 'domcontentloaded' });
});

test('Plot legend color is in sync with plot series color', async ({ page }) => {
const overlayPlot = await createDomainObjectWithDefaults(page, {
overlayPlot = await createDomainObjectWithDefaults(page, {
type: 'Overlay Plot'
});
});

test('Plot legend color is in sync with plot series color', async ({ page }) => {
await createDomainObjectWithDefaults(page, {
type: 'Sine Wave Generator',
parent: overlayPlot.uuid
Expand All @@ -68,9 +68,6 @@ test.describe('Overlay Plot', () => {
type: 'issue',
description: 'https://github.com/nasa/openmct/issues/7403'
});
const overlayPlot = await createDomainObjectWithDefaults(page, {
type: 'Overlay Plot'
});

await createDomainObjectWithDefaults(page, {
type: 'Sine Wave Generator',
Expand Down Expand Up @@ -130,10 +127,6 @@ test.describe('Overlay Plot', () => {
type: 'issue',
description: 'https://github.com/nasa/openmct/issues/6338'
});
// Create an Overlay Plot with a default SWG
const overlayPlot = await createDomainObjectWithDefaults(page, {
type: 'Overlay Plot'
});

const swgA = await createDomainObjectWithDefaults(page, {
type: 'Sine Wave Generator',
Expand Down Expand Up @@ -199,10 +192,6 @@ test.describe('Overlay Plot', () => {
test('The elements pool supports dragging series into multiple y-axis buckets', async ({
page
}) => {
const overlayPlot = await createDomainObjectWithDefaults(page, {
type: 'Overlay Plot'
});

const swgA = await createDomainObjectWithDefaults(page, {
type: 'Sine Wave Generator',
parent: overlayPlot.uuid
Expand Down Expand Up @@ -292,10 +281,6 @@ test.describe('Overlay Plot', () => {
description: 'https://github.com/nasa/openmct/issues/7421'
});

const overlayPlot = await createDomainObjectWithDefaults(page, {
type: 'Overlay Plot'
});

const swgA = await createDomainObjectWithDefaults(page, {
type: 'Sine Wave Generator',
parent: overlayPlot.uuid
Expand All @@ -309,12 +294,32 @@ test.describe('Overlay Plot', () => {
await page.getByRole('tab', { name: 'Elements' }).click();

await page.locator(`#inspector-elements-tree >> text=${swgA.name}`).click();

const plotPixels = await getCanvasPixels(page, '.js-overlay canvas');
const plotPixelSize = plotPixels.length;
expect(plotPixelSize).toBeGreaterThan(0);
}
);

test('Can remove an item via the elements pool action menu', async ({ page }) => {
const swgA = 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
await waitForPlotsToRender(page);
await page.getByLabel('Edit Object').click();

await page.getByRole('tab', { name: 'Elements' }).click();

const swgAElementsPoolItem = page.getByLabel(`Preview ${swgA.name}`);
await expect(swgAElementsPoolItem).toBeVisible();
await swgAElementsPoolItem.click({ button: 'right' });
await page.getByRole('menuitem', { name: 'Remove' }).click();
await page.getByRole('button', { name: 'OK', exact: true }).click();
await expect(swgAElementsPoolItem).toBeHidden();
});
});

/**
Expand Down
12 changes: 6 additions & 6 deletions src/api/composition/CompositionProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*****************************************************************************/
import _ from 'lodash';

import objectUtils from '../objects/object-utils.js';
import { makeKeyString, parseKeyString } from '../objects/object-utils.js';

/**
* @typedef {import('../objects/ObjectAPI').DomainObject} DomainObject
Expand Down Expand Up @@ -223,18 +223,18 @@ export default class CompositionProvider {
* @param {DomainObject} oldDomainObject
*/
#onMutation(newDomainObject, oldDomainObject) {
const id = objectUtils.makeKeyString(oldDomainObject.identifier);
const id = makeKeyString(oldDomainObject.identifier);
const listeners = this.#listeningTo[id];

if (!listeners) {
return;
}

const oldComposition = oldDomainObject.composition.map(objectUtils.makeKeyString);
const newComposition = newDomainObject.composition.map(objectUtils.makeKeyString);
const oldComposition = oldDomainObject.composition.map(makeKeyString);
const newComposition = newDomainObject.composition.map(makeKeyString);

const added = _.difference(newComposition, oldComposition).map(objectUtils.parseKeyString);
const removed = _.difference(oldComposition, newComposition).map(objectUtils.parseKeyString);
const added = _.difference(newComposition, oldComposition).map(parseKeyString);
const removed = _.difference(oldComposition, newComposition).map(parseKeyString);

function notify(value) {
return function (listener) {
Expand Down
8 changes: 4 additions & 4 deletions src/api/composition/DefaultCompositionProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*****************************************************************************/
import { toRaw } from 'vue';

import objectUtils from '../objects/object-utils.js';
import { makeKeyString } from '../objects/object-utils.js';
import CompositionProvider from './CompositionProvider.js';

/**
Expand Down Expand Up @@ -91,7 +91,7 @@ export default class DefaultCompositionProvider extends CompositionProvider {
this.establishTopicListener();

/** @type {string} */
const keyString = objectUtils.makeKeyString(domainObject.identifier);
const keyString = makeKeyString(domainObject.identifier);
let objectListeners = this.listeningTo[keyString];

if (!objectListeners) {
Expand Down Expand Up @@ -120,7 +120,7 @@ export default class DefaultCompositionProvider extends CompositionProvider {
*/
off(domainObject, event, callback, context) {
/** @type {string} */
const keyString = objectUtils.makeKeyString(domainObject.identifier);
const keyString = makeKeyString(domainObject.identifier);
const objectListeners = this.listeningTo[keyString];

const index = objectListeners[event].findIndex((l) => {
Expand Down Expand Up @@ -228,7 +228,7 @@ export default class DefaultCompositionProvider extends CompositionProvider {
this.publicAPI.objects.mutate(domainObject, 'composition', newComposition);

/** @type {string} */
let id = objectUtils.makeKeyString(domainObject.identifier);
let id = makeKeyString(domainObject.identifier);
const listeners = this.listeningTo[id];

if (!listeners) {
Expand Down
6 changes: 3 additions & 3 deletions src/api/objects/MutableDomainObject.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import EventEmitter from 'EventEmitter';
import _ from 'lodash';

import utils from './object-utils.js';
import { makeKeyString, refresh } from './object-utils.js';

const ANY_OBJECT_EVENT = 'mutation';

Expand Down Expand Up @@ -152,7 +152,7 @@ class MutableDomainObject {

mutable.$observe('$_synchronize_model', (updatedObject) => {
let clone = JSON.parse(JSON.stringify(updatedObject));
utils.refresh(mutable, clone);
refresh(mutable, clone);
});

return mutable;
Expand All @@ -168,7 +168,7 @@ class MutableDomainObject {
}

function qualifiedEventName(object, eventName) {
let keystring = utils.makeKeyString(object.identifier);
let keystring = makeKeyString(object.identifier);

return [keystring, eventName].join(':');
}
Expand Down
Loading

0 comments on commit 29d83e9

Please sign in to comment.