From 9385506d3f5356bf0523eb3678c13d6b38c17ba9 Mon Sep 17 00:00:00 2001 From: Rob Tjalma Date: Sat, 15 Jan 2022 22:50:05 +0100 Subject: [PATCH] feat(editors/ied): Add toggle for LDevice child elements (#484) --- src/editors/ied/ldevice-container.ts | 32 +++++++++++++++---- .../valid2007B4withIEDModifications.scd | 2 ++ .../ldevice-container.test.snap.js | 28 ++++++++++++++++ .../editors/ied/ldevice-container.test.ts | 12 +++++-- 4 files changed, 65 insertions(+), 9 deletions(-) diff --git a/src/editors/ied/ldevice-container.ts b/src/editors/ied/ldevice-container.ts index 4f537850df..e3207ee139 100644 --- a/src/editors/ied/ldevice-container.ts +++ b/src/editors/ied/ldevice-container.ts @@ -4,6 +4,7 @@ import { html, LitElement, property, + query, TemplateResult, } from 'lit-element'; @@ -11,12 +12,16 @@ import '../../action-pane.js'; import './ln-container.js' import { nothing } from 'lit-html'; import { getDescriptionAttribute, getInstanceAttribute, getNameAttribute } from '../../foundation.js'; +import { IconButtonToggle } from '@material/mwc-icon-button-toggle'; +import { translate } from 'lit-translate'; /** [[`IED`]] plugin subeditor for editing `LDevice` element. */ @customElement('ldevice-container') export class LDeviceContainer extends LitElement { @property({ attribute: false }) element!: Element; + + @query('#toggleButton') toggleButton!: IconButtonToggle | undefined; private header(): TemplateResult { const nameOrInst = getNameAttribute(this.element) ?? getInstanceAttribute(this.element); @@ -25,14 +30,29 @@ export class LDeviceContainer extends LitElement { return html`${nameOrInst}${desc ? html` — ${desc}` : nothing}`; } + protected firstUpdated(): void { + this.requestUpdate(); + } + render(): TemplateResult { + const lnElements = Array.from(this.element.querySelectorAll(':scope > LN,LN0')); + return html` -
- ${Array.from(this.element.querySelectorAll(':scope > LN,LN0')).map( - server => html``)} -
+ ${lnElements.length > 0 ? html` + this.requestUpdate()} + > + ` : nothing} +
+ ${this.toggleButton?.on ? lnElements.map(server => html` + `) : nothing} +
`; } diff --git a/test/testfiles/valid2007B4withIEDModifications.scd b/test/testfiles/valid2007B4withIEDModifications.scd index 39e9ce1f5b..41574b493c 100644 --- a/test/testfiles/valid2007B4withIEDModifications.scd +++ b/test/testfiles/valid2007B4withIEDModifications.scd @@ -211,6 +211,8 @@ + + diff --git a/test/unit/editors/ied/__snapshots__/ldevice-container.test.snap.js b/test/unit/editors/ied/__snapshots__/ldevice-container.test.snap.js index e807fb7feb..a91f766cdd 100644 --- a/test/unit/editors/ied/__snapshots__/ldevice-container.test.snap.js +++ b/test/unit/editors/ied/__snapshots__/ldevice-container.test.snap.js @@ -3,6 +3,18 @@ export const snapshots = {}; snapshots["ldevice-container looks like the latest snapshot"] = ` + + + +
@@ -14,8 +26,24 @@ snapshots["ldevice-container looks like the latest snapshot"] = + + + + + + + +
`; /* end snapshot ldevice-container looks like the latest snapshot */ +snapshots["ldevice-container looks like the latest snapshot with a LDevice without LN elements"] = +` +
+
+
+`; +/* end snapshot ldevice-container looks like the latest snapshot with a LDevice without LN elements */ + diff --git a/test/unit/editors/ied/ldevice-container.test.ts b/test/unit/editors/ied/ldevice-container.test.ts index de1f4d3e7d..3411be10e8 100644 --- a/test/unit/editors/ied/ldevice-container.test.ts +++ b/test/unit/editors/ied/ldevice-container.test.ts @@ -8,16 +8,22 @@ describe('ldevice-container', () => { let validSCL: XMLDocument; beforeEach(async () => { - validSCL = await fetch('/test/testfiles/valid2007B4.scd') + validSCL = await fetch('/test/testfiles/valid2007B4withIEDModifications.scd') .then(response => response.text()) .then(str => new DOMParser().parseFromString(str, 'application/xml')); + }); + it('looks like the latest snapshot', async () => { element = await fixture(html``); + await expect(element).shadowDom.to.equalSnapshot(); }); - it('looks like the latest snapshot', async () => { + it('looks like the latest snapshot with a LDevice without LN elements', async () => { + element = await fixture(html``); await expect(element).shadowDom.to.equalSnapshot(); }); });