fix: remove redundant request on FaultManagement mount (#6502)

* fix: remove redundant update request

* fix: handle case where request returns no faults

* test: fix fault management tests

* docs: clean up FaultManagement API types

---------

Co-authored-by: Jamie V <jamie.j.vigliotta@nasa.gov>
This commit is contained in:
Jesse Mazzella 2023-03-30 11:43:55 -07:00 committed by GitHub
parent b0a0b4bb58
commit 767fb6c5fd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 70 additions and 48 deletions

View File

@ -22,6 +22,7 @@
const { test, expect } = require('../../../../pluginFixtures'); const { test, expect } = require('../../../../pluginFixtures');
const utils = require('../../../../helper/faultUtils'); const utils = require('../../../../helper/faultUtils');
const { selectInspectorTab } = require('../../../../appActions');
test.describe('The Fault Management Plugin using example faults', () => { test.describe('The Fault Management Plugin using example faults', () => {
test.beforeEach(async ({ page }) => { test.beforeEach(async ({ page }) => {
@ -38,6 +39,7 @@ test.describe('The Fault Management Plugin using example faults', () => {
test('When selecting a fault, it has an "is-selected" class and it\'s information shows in the inspector @unstable', async ({ page }) => { test('When selecting a fault, it has an "is-selected" class and it\'s information shows in the inspector @unstable', async ({ page }) => {
await utils.selectFaultItem(page, 1); await utils.selectFaultItem(page, 1);
await selectInspectorTab(page, 'Fault Management Configuration');
const selectedFaultName = await page.locator('.c-fault-mgmt__list.is-selected .c-fault-mgmt__list-faultname').textContent(); const selectedFaultName = await page.locator('.c-fault-mgmt__list.is-selected .c-fault-mgmt__list-faultname').textContent();
const inspectorFaultNameCount = await page.locator(`.c-inspector__properties >> :text("${selectedFaultName}")`).count(); const inspectorFaultNameCount = await page.locator(`.c-inspector__properties >> :text("${selectedFaultName}")`).count();
@ -52,6 +54,7 @@ test.describe('The Fault Management Plugin using example faults', () => {
const selectedRows = page.locator('.c-fault-mgmt__list.is-selected .c-fault-mgmt__list-faultname'); const selectedRows = page.locator('.c-fault-mgmt__list.is-selected .c-fault-mgmt__list-faultname');
expect.soft(await selectedRows.count()).toEqual(2); expect.soft(await selectedRows.count()).toEqual(2);
await selectInspectorTab(page, 'Fault Management Configuration');
const firstSelectedFaultName = await selectedRows.nth(0).textContent(); const firstSelectedFaultName = await selectedRows.nth(0).textContent();
const secondSelectedFaultName = await selectedRows.nth(1).textContent(); const secondSelectedFaultName = await selectedRows.nth(1).textContent();
const firstNameInInspectorCount = await page.locator(`.c-inspector__properties >> :text("${firstSelectedFaultName}")`).count(); const firstNameInInspectorCount = await page.locator(`.c-inspector__properties >> :text("${firstSelectedFaultName}")`).count();

View File

@ -33,6 +33,8 @@ export default function (staticFaults = false) {
return Promise.resolve(faultsData); return Promise.resolve(faultsData);
}, },
subscribe(domainObject, callback) { subscribe(domainObject, callback) {
callback({ type: 'global-alarm-status' });
return () => {}; return () => {};
}, },
supportsRequest(domainObject) { supportsRequest(domainObject) {

View File

@ -21,18 +21,31 @@
*****************************************************************************/ *****************************************************************************/
export default class FaultManagementAPI { export default class FaultManagementAPI {
/**
* @param {import("openmct").OpenMCT} openmct
*/
constructor(openmct) { constructor(openmct) {
this.openmct = openmct; this.openmct = openmct;
} }
/**
* @param {*} provider
*/
addProvider(provider) { addProvider(provider) {
this.provider = provider; this.provider = provider;
} }
/**
* @returns {boolean}
*/
supportsActions() { supportsActions() {
return this.provider?.acknowledgeFault !== undefined && this.provider?.shelveFault !== undefined; return this.provider?.acknowledgeFault !== undefined && this.provider?.shelveFault !== undefined;
} }
/**
* @param {import("../objects/ObjectAPI").DomainObject} domainObject
* @returns {Promise.<FaultAPIResponse[]>}
*/
request(domainObject) { request(domainObject) {
if (!this.provider?.supportsRequest(domainObject)) { if (!this.provider?.supportsRequest(domainObject)) {
return Promise.reject(); return Promise.reject();
@ -41,6 +54,11 @@ export default class FaultManagementAPI {
return this.provider.request(domainObject); return this.provider.request(domainObject);
} }
/**
* @param {import("../objects/ObjectAPI").DomainObject} domainObject
* @param {Function} callback
* @returns {Function} unsubscribe
*/
subscribe(domainObject, callback) { subscribe(domainObject, callback) {
if (!this.provider?.supportsSubscribe(domainObject)) { if (!this.provider?.supportsSubscribe(domainObject)) {
return Promise.reject(); return Promise.reject();
@ -49,58 +67,55 @@ export default class FaultManagementAPI {
return this.provider.subscribe(domainObject, callback); return this.provider.subscribe(domainObject, callback);
} }
/**
* @param {Fault} fault
* @param {*} ackData
*/
acknowledgeFault(fault, ackData) { acknowledgeFault(fault, ackData) {
return this.provider.acknowledgeFault(fault, ackData); return this.provider.acknowledgeFault(fault, ackData);
} }
/**
* @param {Fault} fault
* @param {*} shelveData
* @returns {Promise.<T>}
*/
shelveFault(fault, shelveData) { shelveFault(fault, shelveData) {
return this.provider.shelveFault(fault, shelveData); return this.provider.shelveFault(fault, shelveData);
} }
} }
/** @typedef {object} Fault /**
* @property {string} type * @typedef {object} TriggerValueInfo
* @property {object} fault * @property {number} value
* @property {boolean} fault.acknowledged * @property {string} rangeCondition
* @property {object} fault.currentValueInfo * @property {string} monitoringResult
* @property {number} fault.currentValueInfo.value */
* @property {string} fault.currentValueInfo.rangeCondition
* @property {string} fault.currentValueInfo.monitoringResult /**
* @property {string} fault.id * @typedef {object} CurrentValueInfo
* @property {string} fault.name * @property {number} value
* @property {string} fault.namespace * @property {string} rangeCondition
* @property {number} fault.seqNum * @property {string} monitoringResult
* @property {string} fault.severity */
* @property {boolean} fault.shelved
* @property {string} fault.shortDescription /**
* @property {string} fault.triggerTime * @typedef {object} Fault
* @property {object} fault.triggerValueInfo * @property {boolean} acknowledged
* @property {number} fault.triggerValueInfo.value * @property {CurrentValueInfo} currentValueInfo
* @property {string} fault.triggerValueInfo.rangeCondition * @property {string} id
* @property {string} fault.triggerValueInfo.monitoringResult * @property {string} name
* @example * @property {string} namespace
* { * @property {number} seqNum
* "type": "", * @property {string} severity
* "fault": { * @property {boolean} shelved
* "acknowledged": true, * @property {string} shortDescription
* "currentValueInfo": { * @property {string} triggerTime
* "value": 0, * @property {TriggerValueInfo} triggerValueInfo
* "rangeCondition": "", */
* "monitoringResult": ""
* }, /**
* "id": "", * @typedef {object} FaultAPIResponse
* "name": "", * @property {string} type
* "namespace": "", * @property {Fault} fault
* "seqNum": 0,
* "severity": "",
* "shelved": true,
* "shortDescription": "",
* "triggerTime": "",
* "triggerValueInfo": {
* "value": 0,
* "rangeCondition": "",
* "monitoringResult": ""
* }
* }
* }
*/ */

View File

@ -42,8 +42,6 @@ export default {
}; };
}, },
mounted() { mounted() {
this.updateFaultList();
this.unsubscribe = this.openmct.faults this.unsubscribe = this.openmct.faults
.subscribe(this.domainObject, this.updateFault); .subscribe(this.domainObject, this.updateFault);
}, },
@ -68,7 +66,11 @@ export default {
this.openmct.faults this.openmct.faults
.request(this.domainObject) .request(this.domainObject)
.then(faultsData => { .then(faultsData => {
this.faultsList = faultsData.map(fd => fd.fault); if (faultsData?.length > 0) {
this.faultsList = faultsData.map(fd => fd.fault);
} else {
this.faultsList = [];
}
}); });
} }
} }