Skip to content

Commit f082d20

Browse files
authored
fix(communication): display changes to ConnectedAPs in SubNetworks (openscd#819)
* fix(foundation): make sCLSelector more robust * fix(wizards): p-types throws for orphaned element * fix(communication/subnetwork): reactively monitor doc changes
1 parent f510446 commit f082d20

File tree

9 files changed

+424
-21
lines changed

9 files changed

+424
-21
lines changed

src/editors/Communication.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ export default class CommunicationPlugin extends LitElement {
6262
.map(
6363
subnetwork =>
6464
html`<subnetwork-editor
65+
.doc=${this.doc}
6566
.element=${subnetwork}
6667
></subnetwork-editor>`
6768
)}

src/editors/communication/subnetwork-editor.ts

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,32 +22,34 @@ import { wizards } from '../../wizards/wizard-library.js';
2222
/** [[`Communication`]] subeditor for a `SubNetwork` element. */
2323
@customElement('subnetwork-editor')
2424
export class SubNetworkEditor extends LitElement {
25+
@property({ attribute: false })
26+
doc!: XMLDocument;
2527
/** SCL element SubNetwork */
2628
@property({ attribute: false })
2729
element!: Element;
2830
/** SubNetwork attribute name */
29-
@property()
31+
@property({ type: String })
3032
get name(): string {
3133
return this.element.getAttribute('name') ?? 'UNDEFINED';
3234
}
3335
/** SubNetwork attribute desc */
34-
@property()
36+
@property({ type: String })
3537
get desc(): string | null {
3638
return this.element.getAttribute('desc') ?? null;
3739
}
3840
/** SubNetwork attribute type */
39-
@property()
41+
@property({ type: String })
4042
get type(): string | null {
4143
return this.element.getAttribute('type') ?? null;
4244
}
4345
/** SubNetwork child elements BitRate label */
44-
@property()
46+
@property({ type: String })
4547
get bitrate(): string | null {
4648
const bitRate = this.element.querySelector('BitRate');
4749
if (bitRate === null) return null;
4850
const bitRateValue = bitRate.textContent ?? '';
4951
const m = bitRate.getAttribute('multiplier');
50-
const unit = m === null ? 'b/s' : ' ' + m + 'b/s';
52+
const unit = ` ${m ?? ''}b/s`;
5153
return bitRateValue ? bitRateValue + unit : null;
5254
}
5355

@@ -73,7 +75,7 @@ export class SubNetworkEditor extends LitElement {
7375
);
7476
}
7577

76-
private renderIedContainer(): TemplateResult[] {
78+
private renderIEDs(): TemplateResult[] {
7779
return Array.from(this.element.querySelectorAll(':scope > ConnectedAP'))
7880
.map(connAP => connAP.getAttribute('iedName')!)
7981
.filter((v, i, a) => a.indexOf(v) === i)
@@ -106,7 +108,7 @@ export class SubNetworkEditor extends LitElement {
106108
}
107109

108110
private header(): string {
109-
return ` ${this.name} ${this.desc === null ? '' : `— ${this.desc}`}
111+
return `${this.name} ${this.desc === null ? '' : `— ${this.desc}`}
110112
${this.subNetworkSpecs()}`;
111113
}
112114

@@ -122,14 +124,15 @@ export class SubNetworkEditor extends LitElement {
122124
<mwc-icon-button
123125
icon="delete"
124126
@click=${() => this.remove()}
125-
></mwc-icon-button> </abbr
126-
><abbr slot="action" title="${translate('add')}">
127+
></mwc-icon-button>
128+
</abbr>
129+
<abbr slot="action" title="${translate('add')}">
127130
<mwc-icon-button
128131
icon="playlist_add"
129132
@click="${() => this.openConnectedAPwizard()}"
130133
></mwc-icon-button>
131134
</abbr>
132-
<div id="iedContainer">${this.renderIedContainer()}</div>
135+
<div id="iedContainer">${this.renderIEDs()}</div>
133136
</action-pane> `;
134137
}
135138

src/foundation.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1323,7 +1323,7 @@ function sCLIdentity(): string {
13231323
}
13241324

13251325
function sCLSelector(): string {
1326-
return 'SCL';
1326+
return ':root';
13271327
}
13281328

13291329
function namingIdentity(e: Element): string {

src/wizards/foundation/p-types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
* Supported Editions are 1 (2003), 2 (2007B) and 2.1 (2007B4)
33
*/
44
export function getTypes(element: Element): string[] {
5-
if (!element.ownerDocument) return [];
5+
if (!element.ownerDocument.documentElement) return [];
66

7-
const scl: Element = element.ownerDocument.querySelector(':root')!;
7+
const scl: Element = element.ownerDocument.documentElement;
88

99
const type =
1010
(scl.getAttribute('version') ?? '2003') +

0 commit comments

Comments
 (0)