Skip to content

Commit 7966f0f

Browse files
feat(editor/substation/l-node-editor): add remove button (openscd#771)
* feat(editor/substation/l-node-editor): add remmove button * refactor(editors/substation/l-node-editor): better naming
1 parent 5368cf3 commit 7966f0f

File tree

3 files changed

+84
-8
lines changed

3 files changed

+84
-8
lines changed

src/editors/substation/l-node-editor.ts

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
} from 'lit-element';
99

1010
import '../../action-icon.js';
11-
import { identity } from '../../foundation.js';
11+
import { identity, newActionEvent } from '../../foundation.js';
1212
import {
1313
automationLogicalNode,
1414
controlLogicalNode,
@@ -75,15 +75,30 @@ export class LNodeEditor extends LitElement {
7575
return this.element.getAttribute('iedName') === 'None' ?? false;
7676
}
7777

78+
remove(): void {
79+
if (this.element)
80+
this.dispatchEvent(
81+
newActionEvent({
82+
old: {
83+
parent: this.element.parentElement!,
84+
element: this.element,
85+
},
86+
})
87+
);
88+
}
89+
7890
render(): TemplateResult {
7991
return html`<action-icon
8092
label="${this.header}"
8193
?secondary=${this.missingIedReference}
8294
?highlighted=${this.missingIedReference}
83-
hideActions
84-
><mwc-icon slot="icon"
85-
>${getLNodeIcon(this.element)}</mwc-icon
86-
></action-icon
87-
>`;
95+
><mwc-icon slot="icon">${getLNodeIcon(this.element)}</mwc-icon
96+
><mwc-fab
97+
slot="action"
98+
mini
99+
icon="delete"
100+
@click="${() => this.remove()}}"
101+
></mwc-fab
102+
></action-icon>`;
88103
}
89104
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import { fixture, html, expect } from '@open-wc/testing';
2+
3+
import '../../../mock-wizard-editor.js';
4+
import { MockWizardEditor } from '../../../mock-wizard-editor.js';
5+
6+
import '../../../../src/editors/substation/l-node-editor.js';
7+
import { LNodeEditor } from '../../../../src/editors/substation/l-node-editor.js';
8+
9+
describe('l-node-editor wizarding editing integration', () => {
10+
let doc: XMLDocument;
11+
let parent: MockWizardEditor;
12+
let element: LNodeEditor | null;
13+
14+
beforeEach(async () => {
15+
doc = await fetch('/test/testfiles/zeroline/functions.scd')
16+
.then(response => response.text())
17+
.then(str => new DOMParser().parseFromString(str, 'application/xml'));
18+
19+
parent = <MockWizardEditor>(
20+
await fixture(
21+
html`<mock-wizard-editor
22+
><l-node-editor
23+
.element=${doc.querySelector('Substation > LNode[lnClass="CSWI"]')}
24+
></l-node-editor
25+
></mock-wizard-editor>`
26+
)
27+
);
28+
29+
element = parent.querySelector('l-node-editor');
30+
});
31+
32+
describe('has a delete icon button that', () => {
33+
let deleteButton: HTMLElement;
34+
35+
beforeEach(async () => {
36+
deleteButton = <HTMLElement>(
37+
element?.shadowRoot?.querySelector('mwc-fab[icon="delete"]')
38+
);
39+
await parent.updateComplete;
40+
});
41+
42+
it('removes the attached LNode element from the document', async () => {
43+
expect(doc.querySelector('Substation > LNode[lnClass="CSWI"]')).to.exist;
44+
45+
await deleteButton.click();
46+
47+
expect(doc.querySelector('Substation > LNode[lnClass="CSWI"]')).to.not
48+
.exist;
49+
});
50+
});
51+
});

test/unit/editors/substation/__snapshots__/l-node-editor.test.snap.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,36 @@ export const snapshots = {};
33

44
snapshots["web component rendering LNode element as reference to a LN/LN0 within IED looks like the latest snapshot"] =
55
`<action-icon
6-
hideactions=""
76
label="IED1 CircuitBreaker_CB1/ XCBR 1"
87
tabindex="0"
98
>
109
<mwc-icon slot="icon">
1110
</mwc-icon>
11+
<mwc-fab
12+
icon="delete"
13+
mini=""
14+
slot="action"
15+
>
16+
</mwc-fab>
1217
</action-icon>
1318
`;
1419
/* end snapshot web component rendering LNode element as reference to a LN/LN0 within IED looks like the latest snapshot */
1520

1621
snapshots["web component rendering LNode element as instance of a LNodeType only looks like the latest snapshot"] =
1722
`<action-icon
18-
hideactions=""
1923
highlighted=""
2024
label="DC XSWI 1"
2125
secondary=""
2226
tabindex="0"
2327
>
2428
<mwc-icon slot="icon">
2529
</mwc-icon>
30+
<mwc-fab
31+
icon="delete"
32+
mini=""
33+
slot="action"
34+
>
35+
</mwc-fab>
2636
</action-icon>
2737
`;
2838
/* end snapshot web component rendering LNode element as instance of a LNodeType only looks like the latest snapshot */

0 commit comments

Comments
 (0)