Compare commits

...

3 Commits

Author SHA1 Message Date
b7cb18c494 add priority to time conductor boundsChanged event listeners 2024-11-14 10:50:32 -08:00
860bd06c8f add PriorityEventEmitter
use PriorityEventEmitter for time api event handling
2024-11-14 10:49:34 -08:00
ea9947cab5 Use the disabled attribute on a valid element - the button. (#7914)
* Use the disabled attribute on a valid tag - the button.

* Add e2e test to check for add criteria button being enabled

* Improve test

* Check for add criteria button to have attribute disabled

* Remove focused test
2024-11-05 20:53:28 +00:00
7 changed files with 72 additions and 7 deletions

View File

@ -287,6 +287,41 @@ test.describe('Basic Condition Set Use', () => {
description: 'https://github.com/nasa/openmct/issues/7484'
});
});
test('ConditionSet has add criteria button enabled/disabled when composition is and is not available', async ({
page
}) => {
const exampleTelemetry = await createExampleTelemetryObject(page);
await page.getByLabel('Show selected item in tree').click();
await page.goto(conditionSet.url);
// Change the object to edit mode
await page.getByLabel('Edit Object').click();
// Create a condition
await page.locator('#addCondition').click();
await page.locator('#conditionCollection').getByRole('textbox').nth(0).fill('First Condition');
// Validate that the add criteria button is disabled
await expect(page.getByLabel('Add Criteria - Disabled')).toHaveAttribute('disabled');
// Add Telemetry to ConditionSet
const sineWaveGeneratorTreeItem = page
.getByRole('tree', {
name: 'Main Tree'
})
.getByRole('treeitem', {
name: exampleTelemetry.name
});
const conditionCollection = page.locator('#conditionCollection');
await sineWaveGeneratorTreeItem.dragTo(conditionCollection);
// Validate that the add criteria button is enabled and adds a new criterion
await expect(page.getByLabel('Add Criteria - Enabled')).not.toHaveAttribute('disabled');
await page.getByLabel('Add Criteria - Enabled').click();
const numOfUnnamedCriteria = await page.getByLabel('Criterion Telemetry Selection').count();
expect(numOfUnnamedCriteria).toEqual(2);
});
});
test.describe('Condition Set Composition', () => {

View File

@ -20,7 +20,7 @@
* at runtime from the About dialog for additional information.
*****************************************************************************/
import { EventEmitter } from 'eventemitter3';
import PriorityEventEmitter from 'utils/PriorityEventEmitter.js';
import { FIXED_MODE_KEY, MODES, REALTIME_MODE_KEY, TIME_CONTEXT_EVENTS } from './constants.js';
@ -66,9 +66,9 @@ import { FIXED_MODE_KEY, MODES, REALTIME_MODE_KEY, TIME_CONTEXT_EVENTS } from '.
/**
* @class TimeContext
* @extends EventEmitter
* @extends PriorityEventEmitter
*/
class TimeContext extends EventEmitter {
class TimeContext extends PriorityEventEmitter {
constructor() {
super();

View File

@ -160,8 +160,10 @@
</div>
</template>
<div class="c-cdef__separator c-row-separator"></div>
<div class="c-cdef__controls" :disabled="!telemetry.length">
<div class="c-cdef__controls">
<button
:disabled="!telemetry.length"
:aria-label="`Add Criteria - ${!telemetry.length ? 'Disabled' : 'Enabled'}`"
class="c-cdef__add-criteria-button c-button c-button--labeled icon-plus"
@click="addCriteria"
>

View File

@ -156,7 +156,11 @@ export default {
this.setTimeSystem(this.copy(this.openmct.time.getTimeSystem()));
this.openmct.time.on(TIME_CONTEXT_EVENTS.boundsChanged, _.throttle(this.handleNewBounds, 300));
this.openmct.time.on(
TIME_CONTEXT_EVENTS.boundsChanged,
_.throttle(this.handleNewBounds, 300),
this.openmct.priority.HIGH
);
this.openmct.time.on(TIME_CONTEXT_EVENTS.timeSystemChanged, this.setTimeSystem);
this.openmct.time.on(TIME_CONTEXT_EVENTS.modeChanged, this.setMode);
},

View File

@ -173,7 +173,7 @@ export default {
this.setViewFromOffsets(offsets);
if (this.timeContext) {
this.timeContext.on(TIME_CONTEXT_EVENTS.boundsChanged, this.handleNewBounds);
this.timeContext.on(TIME_CONTEXT_EVENTS.boundsChanged, this.handleNewBounds, this.openmct.priority.HIGH);
this.timeContext.on(TIME_CONTEXT_EVENTS.clockOffsetsChanged, this.setViewFromOffsets);
} else {
this.openmct.time.on(TIME_CONTEXT_EVENTS.boundsChanged, this.handleNewBounds);

View File

@ -205,7 +205,7 @@ export default {
this.timeContext = this.openmct.time.getContextForView(this.objectPath);
this.timeContext.on(TIME_CONTEXT_EVENTS.clockChanged, this.setViewFromClock);
this.timeContext.on(TIME_CONTEXT_EVENTS.boundsChanged, this.setBounds);
this.timeContext.on(TIME_CONTEXT_EVENTS.boundsChanged, this.setBounds, this.openmct.priority.HIGH);
this.setViewFromClock(this.timeContext.getClock());
this.setBounds(this.timeContext.getBounds());

View File

@ -0,0 +1,24 @@
import { EventEmitter } from 'eventemitter3';
export default class PriorityEventEmitter extends EventEmitter {
constructor() {
super();
this.listeners = {};
}
on(event, listener, priority = 0) {
if (!this.listeners[event]) {
this.listeners[event] = [];
}
this.listeners[event].push({ listener, priority });
this.listeners[event].sort((a, b) => b.priority - a.priority);
super.on(event, listener);
}
emit(event, ...args) {
this.listeners[event]?.forEach(({ listener }) => listener(...args));
}
}