Skip to content

Commit 4fd993d

Browse files
Jakob Vogelsangca-d
andauthored
refactor(editor/communication): move wizards to wizard library (openscd#489)
* refactor(wizards/subnetwork): move wizards * refactor(editors/communication/subnetwork-editor): minor changes/doc * refactor(editors/communication/subnetwork-editor): use action-pane * refactor(editors/communication): minor code improvements * refactor(editors/foundation): remove selectors * refactor(editors/communication/subnetwork-editor): fail save selector * refactor(wizards/subnetwork): update edit wizard * refactor(wizards/subnetwork): create wizard and its tests * refactor(editors/communication/subnetwork-editor): minor improvements * refactor(editors/communication/subnetwork-editor): remove code duplication * style(editors/communication/subnetwork-editor): adjust CSS * refactor: resolve review comments Co-authored-by: cad <[email protected]>
1 parent 600166a commit 4fd993d

File tree

13 files changed

+1057
-709
lines changed

13 files changed

+1057
-709
lines changed

src/editors/Communication.ts

Lines changed: 33 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,22 @@ import { translate, get } from 'lit-translate';
33

44
import '@material/mwc-fab';
55

6+
import './communication/subnetwork-editor.js';
67
import {
78
newWizardEvent,
89
newActionEvent,
910
createElement,
11+
isPublic,
1012
} from '../foundation.js';
11-
import { selectors, styles } from './communication/foundation.js';
12-
import './communication/subnetwork-editor.js';
13-
import { subNetworkWizard } from './communication/subnetwork-editor.js';
13+
import { createSubNetworkWizard } from '../wizards/subnetwork.js';
1414

1515
/** An editor [[`plugin`]] for editing the `Communication` section. */
1616
export default class CommunicationPlugin extends LitElement {
1717
/** The document being edited as provided to plugins by [[`OpenSCD`]]. */
1818
@property()
1919
doc!: XMLDocument;
2020

21-
createCommunication(): void {
21+
private createCommunication(): void {
2222
this.dispatchEvent(
2323
newActionEvent({
2424
new: {
@@ -30,21 +30,15 @@ export default class CommunicationPlugin extends LitElement {
3030
}
3131

3232
/** Opens a [[`WizardDialog`]] for creating a new `SubNetwork` element. */
33-
openCreateSubNetworkWizard(): void {
34-
if (!this.doc.querySelector(selectors.Communication))
35-
this.createCommunication();
33+
private openCreateSubNetworkWizard(): void {
34+
const parent = this.doc.querySelector(':root > Communication');
35+
if (!parent) this.createCommunication();
3636

37-
this.dispatchEvent(
38-
newWizardEvent(
39-
subNetworkWizard({
40-
parent: this.doc.querySelector('Communication')!,
41-
})
42-
)
43-
);
37+
this.dispatchEvent(newWizardEvent(createSubNetworkWizard(parent!)));
4438
}
4539

4640
render(): TemplateResult {
47-
if (!this.doc?.querySelector(selectors.SubNetwork))
41+
if (!this.doc?.querySelector(':root > Communication >SubNetwork'))
4842
return html`<h1>
4943
<span style="color: var(--base1)"
5044
>${translate('communication.missing')}</span
@@ -55,29 +49,43 @@ export default class CommunicationPlugin extends LitElement {
5549
@click=${() => this.openCreateSubNetworkWizard()}
5650
></mwc-fab>
5751
</h1>`;
52+
5853
return html`<mwc-fab
5954
extended
6055
icon="add"
6156
label="${get('subnetwork.wizard.title.add')}"
6257
@click=${() => this.openCreateSubNetworkWizard()}
63-
></mwc-fab
64-
>${Array.from(this.doc.querySelectorAll(selectors.SubNetwork) ?? []).map(
65-
subnetwork =>
66-
html`<subnetwork-editor .element=${subnetwork}></subnetwork-editor>`
67-
)}`;
58+
></mwc-fab>
59+
<section>
60+
${Array.from(this.doc.querySelectorAll('SubNetwork') ?? [])
61+
.filter(isPublic)
62+
.map(
63+
subnetwork =>
64+
html`<subnetwork-editor
65+
.element=${subnetwork}
66+
></subnetwork-editor>`
67+
)}
68+
</section> `;
6869
}
6970

7071
static styles = css`
71-
${styles}
72+
:host {
73+
width: 100vw;
74+
}
75+
76+
section {
77+
outline: none;
78+
padding: 8px 12px 16px;
79+
}
80+
81+
subnetwork-editor {
82+
margin: 8px 12px 16px;
83+
}
7284
7385
mwc-fab {
7486
position: fixed;
7587
bottom: 32px;
7688
right: 32px;
7789
}
78-
79-
:host {
80-
width: 100vw;
81-
}
8290
`;
8391
}

src/editors/communication/foundation.ts

Lines changed: 0 additions & 105 deletions
This file was deleted.

0 commit comments

Comments
 (0)