Skip to content

Commit 9385506

Browse files
author
Rob Tjalma
authored
feat(editors/ied): Add toggle for LDevice child elements (openscd#484)
1 parent 15abe5c commit 9385506

File tree

4 files changed

+65
-9
lines changed

4 files changed

+65
-9
lines changed

src/editors/ied/ldevice-container.ts

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,24 @@ import {
44
html,
55
LitElement,
66
property,
7+
query,
78
TemplateResult,
89
} from 'lit-element';
910

1011
import '../../action-pane.js';
1112
import './ln-container.js'
1213
import { nothing } from 'lit-html';
1314
import { getDescriptionAttribute, getInstanceAttribute, getNameAttribute } from '../../foundation.js';
15+
import { IconButtonToggle } from '@material/mwc-icon-button-toggle';
16+
import { translate } from 'lit-translate';
1417

1518
/** [[`IED`]] plugin subeditor for editing `LDevice` element. */
1619
@customElement('ldevice-container')
1720
export class LDeviceContainer extends LitElement {
1821
@property({ attribute: false })
1922
element!: Element;
23+
24+
@query('#toggleButton') toggleButton!: IconButtonToggle | undefined;
2025

2126
private header(): TemplateResult {
2227
const nameOrInst = getNameAttribute(this.element) ?? getInstanceAttribute(this.element);
@@ -25,14 +30,29 @@ export class LDeviceContainer extends LitElement {
2530
return html`${nameOrInst}${desc ? html` — ${desc}` : nothing}`;
2631
}
2732

33+
protected firstUpdated(): void {
34+
this.requestUpdate();
35+
}
36+
2837
render(): TemplateResult {
38+
const lnElements = Array.from(this.element.querySelectorAll(':scope > LN,LN0'));
39+
2940
return html`<action-pane .label="${this.header()}">
30-
<div id="lnContainer">
31-
${Array.from(this.element.querySelectorAll(':scope > LN,LN0')).map(
32-
server => html`<ln-container
33-
.element=${server}
34-
></ln-container>`)}
35-
</div>
41+
${lnElements.length > 0 ? html`<abbr slot="action" title="${translate('iededitor.toggleChildElements')}">
42+
<mwc-icon-button-toggle
43+
on
44+
id="toggleButton"
45+
onIcon="keyboard_arrow_up"
46+
offIcon="keyboard_arrow_down"
47+
@click=${() => this.requestUpdate()}
48+
></mwc-icon-button-toggle>
49+
</abbr>` : nothing}
50+
<div id="lnContainer">
51+
${this.toggleButton?.on ? lnElements.map(server => html`<ln-container
52+
.element=${server}
53+
></ln-container>
54+
`) : nothing}
55+
</div>
3656
</action-pane>`;
3757
}
3858

test/testfiles/valid2007B4withIEDModifications.scd

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,8 @@
211211
</DOI>
212212
</LN>
213213
</LDevice>
214+
<LDevice inst="EmptyLDevice">
215+
</LDevice>
214216
</Server>
215217
</AccessPoint>
216218
<KDC iedName="IED1" apName="P1"/>

test/unit/editors/ied/__snapshots__/ldevice-container.test.snap.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,18 @@ export const snapshots = {};
33

44
snapshots["ldevice-container looks like the latest snapshot"] =
55
`<action-pane tabindex="0">
6+
<abbr
7+
slot="action"
8+
title="[iededitor.toggleChildElements]"
9+
>
10+
<mwc-icon-button-toggle
11+
id="toggleButton"
12+
officon="keyboard_arrow_down"
13+
on=""
14+
onicon="keyboard_arrow_up"
15+
>
16+
</mwc-icon-button-toggle>
17+
</abbr>
618
<div id="lnContainer">
719
<ln-container>
820
</ln-container>
@@ -14,8 +26,24 @@ snapshots["ldevice-container looks like the latest snapshot"] =
1426
</ln-container>
1527
<ln-container>
1628
</ln-container>
29+
<ln-container>
30+
</ln-container>
31+
<ln-container>
32+
</ln-container>
33+
<ln-container>
34+
</ln-container>
35+
<ln-container>
36+
</ln-container>
1737
</div>
1838
</action-pane>
1939
`;
2040
/* end snapshot ldevice-container looks like the latest snapshot */
2141

42+
snapshots["ldevice-container looks like the latest snapshot with a LDevice without LN elements"] =
43+
`<action-pane tabindex="0">
44+
<div id="lnContainer">
45+
</div>
46+
</action-pane>
47+
`;
48+
/* end snapshot ldevice-container looks like the latest snapshot with a LDevice without LN elements */
49+

test/unit/editors/ied/ldevice-container.test.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,22 @@ describe('ldevice-container', () => {
88
let validSCL: XMLDocument;
99

1010
beforeEach(async () => {
11-
validSCL = await fetch('/test/testfiles/valid2007B4.scd')
11+
validSCL = await fetch('/test/testfiles/valid2007B4withIEDModifications.scd')
1212
.then(response => response.text())
1313
.then(str => new DOMParser().parseFromString(str, 'application/xml'));
14+
});
1415

16+
it('looks like the latest snapshot', async () => {
1517
element = await fixture(html`<ldevice-container
16-
.element=${validSCL.querySelector('LDevice')}
18+
.element=${validSCL.querySelector('LDevice[inst="Disconnectors"]')}
1719
></ldevice-container>`);
20+
await expect(element).shadowDom.to.equalSnapshot();
1821
});
1922

20-
it('looks like the latest snapshot', async () => {
23+
it('looks like the latest snapshot with a LDevice without LN elements', async () => {
24+
element = await fixture(html`<ldevice-container
25+
.element=${validSCL.querySelector('LDevice[inst="EmptyLDevice"]')}
26+
></ldevice-container>`);
2127
await expect(element).shadowDom.to.equalSnapshot();
2228
});
2329
});

0 commit comments

Comments
 (0)