diff --git a/src/wizards/reportcontrol.ts b/src/wizards/reportcontrol.ts index 651c1fa8b0..289c1880b7 100644 --- a/src/wizards/reportcontrol.ts +++ b/src/wizards/reportcontrol.ts @@ -19,14 +19,55 @@ import { identity, isPublic, newSubWizardEvent, + newWizardEvent, + newActionEvent, selector, SimpleAction, Wizard, WizardActor, WizardInput, + Delete, } from '../foundation.js'; import { maxLength, patterns } from './foundation/limits.js'; +export function removeReportControlAction(element: Element): Delete[] { + if (!element.parentElement) return []; + + const dataSet = element.parentElement.querySelector( + `DataSet[name="${element.getAttribute('datSet')}"]` + ); + + const isDataSetUsedByThisControlBlockOnly = + Array.from( + element.parentElement.querySelectorAll( + 'ReportControl, GSEControl, SampledValueControl' + ) + ).filter( + controlblock => + controlblock.getAttribute('datSet') === dataSet?.getAttribute('name') + ).length <= 1; + + const actions: Delete[] = []; + actions.push({ + old: { + parent: element.parentElement!, + element, + reference: element.nextSibling, + }, + }); + + if (dataSet && isDataSetUsedByThisControlBlockOnly) + actions.push({ + old: { + parent: element.parentElement!, + element: dataSet, + reference: element.nextSibling, + }, + }); + + return actions; +} + function getRptEnabledAction( olRptEnabled: Element | null, max: string | null, @@ -220,6 +261,17 @@ export function editReportControlWizard(element: Element): Wizard { bufTime, intgPd, }), + html` { + const deleteActions = removeReportControlAction(element); + deleteActions.forEach(deleteAction => + e.target?.dispatchEvent(newActionEvent(deleteAction)) + ); + e.target?.dispatchEvent(newWizardEvent()); + }} + >`, ], }, ]; diff --git a/test/integration/wizards/reportcontrol-wizarding-editing.test.ts b/test/integration/wizards/reportcontrol-wizarding-editing.test.ts index 32dd3a8faf..915adca60f 100644 --- a/test/integration/wizards/reportcontrol-wizarding-editing.test.ts +++ b/test/integration/wizards/reportcontrol-wizarding-editing.test.ts @@ -3,6 +3,7 @@ import { expect, fixture, html } from '@open-wc/testing'; import '../../mock-wizard-editor.js'; import { MockWizardEditor } from '../../mock-wizard-editor.js'; +import { Button } from '@material/mwc-button'; import { ListItemBase } from '@material/mwc-list/mwc-list-item-base'; import { FilteredList } from '../../../src/filtered-list.js'; @@ -85,7 +86,7 @@ describe('Wizards for SCL element ReportControl', () => { const report = ( (element.wizardUI.dialog?.querySelector('filtered-list')) - .items[0] + .items[1] ); report.click(); await new Promise(resolve => setTimeout(resolve, 20)); // await animation @@ -108,7 +109,7 @@ describe('Wizards for SCL element ReportControl', () => { it('rejects name attribute starting with decimals', async () => { expect( - parentIED.querySelector('ReportControl')?.getAttribute('name') + parentIED.querySelectorAll('ReportControl')[1]?.getAttribute('name') ).to.not.equal('4adsasd'); nameField.value = '4adsasd'; @@ -116,13 +117,13 @@ describe('Wizards for SCL element ReportControl', () => { primaryAction.click(); expect( - parentIED.querySelector('ReportControl')?.getAttribute('name') + parentIED.querySelectorAll('ReportControl')[1]?.getAttribute('name') ).to.not.equal('4adsasd'); }); it('edits name attribute on primary action', async () => { expect( - parentIED.querySelector('ReportControl')?.getAttribute('name') + parentIED.querySelectorAll('ReportControl')[1]?.getAttribute('name') ).to.not.equal('myNewName'); nameField.value = 'myNewName'; @@ -130,7 +131,7 @@ describe('Wizards for SCL element ReportControl', () => { primaryAction.click(); expect( - parentIED.querySelector('ReportControl')?.getAttribute('name') + parentIED.querySelectorAll('ReportControl')[1]?.getAttribute('name') ).to.equal('myNewName'); }); @@ -142,7 +143,7 @@ describe('Wizards for SCL element ReportControl', () => { const report = ( (element.wizardUI.dialog?.querySelector('filtered-list')) - .items[0] + .items[1] ); expect(report.innerHTML).to.contain('myNewName'); @@ -160,5 +161,33 @@ describe('Wizards for SCL element ReportControl', () => { expect(report.innerHTML).to.contain('ReportCb'); }); + + it('removes the ReportControl element and its referenced elements on remove button click', async () => { + expect( + doc.querySelector( + 'IED[name="IED2"] LN[lnClass="XSWI"] ReportControl[name="ReportCb2"]' + ) + ).to.exist; + expect( + doc.querySelector( + 'IED[name="IED2"] LN[lnClass="XSWI"][inst="1"] DataSet[name="dataSet"]' + ) + ).to.exist; + const deleteButton =