Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: scope editor-container and zweroline-pane #377

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/editor-container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ function childTags(element: Element | null | undefined): SCLTag[] {
* A responsive container for nested elements with header and
* create new child functionality.
*/
@customElement('editor-container')
export class EditorContainer extends LitElement {
/** The visualized `Element`. */
@property()
Expand Down
27 changes: 14 additions & 13 deletions src/editors/Substation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import { get } from 'lit-translate';

import { html, newWizardEvent } from '../foundation.js';
import { wizards } from '../wizards/wizard-library.js';

import '../zeroline-pane.js';
import { ZerolinePane } from '../zeroline-pane.js';

/** An editor [[`plugin`]] for editing the `Substation` section. */
export default class SubstationPlugin extends LitElement {
Expand All @@ -19,17 +18,19 @@ export default class SubstationPlugin extends LitElement {
}

render(): TemplateResult {
return html` <zeroline-pane .doc=${this.doc}></zeroline-pane>
${!this.doc?.querySelector(':root > Substation')
? html`<h1>
<mwc-fab
extended
icon="add"
label="${get('substation.wizard.title.add')}"
@click=${() => this.openCreateSubstationWizard()}
></mwc-fab>
</h1>`
: html``}`;
return html` <${ZerolinePane} .doc=${this.doc}></${ZerolinePane}>
${
!this.doc?.querySelector(':root > Substation')
? html`<h1>
<mwc-fab
extended
icon="add"
label="${get('substation.wizard.title.add')}"
@click=${() => this.openCreateSubstationWizard()}
></mwc-fab>
</h1>`
: html``
}`;
}

static styles = css`
Expand Down
1 change: 0 additions & 1 deletion src/zeroline-pane.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ function setShowIEDs(value: Settings['showieds']) {
}

/** [[`Zeroline`]] pane for displaying `Substation` and/or `IED` sections. */
@customElement('zeroline-pane')
export class ZerolinePane extends LitElement {
/** The document being edited as provided to editor by [[`Zeroline`]]. */
@property({ attribute: false })
Expand Down
10 changes: 7 additions & 3 deletions src/zeroline/bay-editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import { wizards } from '../wizards/wizard-library.js';

import { VoltageLevelEditor } from './voltage-level-editor.js';
import './conducting-equipment-editor.js';
import { EditorContainer } from '../editor-container.js';
import { IedEditor } from './ied-editor.js';

/** [[`SubstationEditor`]] subeditor for a `Bay` element. */
@customElement('bay-editor')
Expand Down Expand Up @@ -61,13 +63,15 @@ export class BayEditor extends LitElement {
const ieds = this.getAttachedIeds?.(this.element) ?? [];
return ieds?.length
? html`<div id="iedcontainer">
${ieds.map(ied => html`<ied-editor .element=${ied}></ied-editor>`)}
${ieds.map(
ied => html`<${IedEditor} .element=${ied}></${IedEditor}>`
)}
</div>`
: html``;
}

render(): TemplateResult {
return html`<editor-container .element=${this.element} nomargin>
return html`<${EditorContainer} .element=${this.element} nomargin>
<abbr slot="header" title="${translate('lnode.tooltip')}">
<mwc-icon-button
icon="account_tree"
Expand Down Expand Up @@ -110,7 +114,7 @@ export class BayEditor extends LitElement {
></conducting-equipment-editor>`
)}
</div>
</editor-container> `;
</${EditorContainer}> `;
}

static styles = css`
Expand Down
1 change: 0 additions & 1 deletion src/zeroline/ied-editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import { selectGseControlWizard } from '../wizards/gsecontrol.js';
import { gooseIcon } from '../icons.js';

/** [[`SubstationEditor`]] subeditor for a `ConductingEquipment` element. */
@customElement('ied-editor')
export class IedEditor extends LitElement {
@property({ type: Element })
element!: Element;
Expand Down
11 changes: 7 additions & 4 deletions src/zeroline/substation-editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ import {
import { wizards } from '../wizards/wizard-library.js';

import './voltage-level-editor.js';
import '../editor-container.js';
import { EditorContainer } from '../editor-container.js';
import { IedEditor } from './ied-editor.js';

/** [[`Substation`]] plugin subeditor for editing `Substation` sections. */
@customElement('substation-editor')
Expand Down Expand Up @@ -63,13 +64,15 @@ export class SubstationEditor extends LitElement {
const ieds = this.getAttachedIeds?.(this.element) ?? [];
return ieds?.length
? html`<div id="iedcontainer">
${ieds.map(ied => html`<ied-editor .element=${ied}></ied-editor>`)}
${ieds.map(
ied => html`<${IedEditor} .element=${ied}></${IedEditor}>`
)}
</div>`
: html``;
}

render(): TemplateResult {
return html`<editor-container .element=${this.element}>
return html`<${EditorContainer} .element=${this.element}>
<abbr slot="header" title="${translate('lnode.tooltip')}">
<mwc-icon-button
icon="account_tree"
Expand Down Expand Up @@ -108,7 +111,7 @@ export class SubstationEditor extends LitElement {
.getAttachedIeds=${this.getAttachedIeds}
?readonly=${this.readonly}
></voltage-level-editor>`
)}</editor-container
)}</${EditorContainer}
>`;
}

Expand Down
10 changes: 7 additions & 3 deletions src/zeroline/voltage-level-editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import { SubstationEditor } from './substation-editor.js';
import { wizards } from '../wizards/wizard-library.js';

import './bay-editor.js';
import { EditorContainer } from '../editor-container.js';
import { IedEditor } from './ied-editor.js';

/** [[`Substation`]] subeditor for a `VoltageLevel` element. */
@customElement('voltage-level-editor')
Expand Down Expand Up @@ -79,13 +81,15 @@ export class VoltageLevelEditor extends LitElement {
const ieds = this.getAttachedIeds?.(this.element) ?? [];
return ieds?.length
? html`<div id="iedcontainer">
${ieds.map(ied => html`<ied-editor .element=${ied}></ied-editor>`)}
${ieds.map(
ied => html`<${IedEditor} .element=${ied}></${IedEditor}>`
)}
</div>`
: html``;
}

render(): TemplateResult {
return html`<editor-container
return html`<${EditorContainer}
.element=${this.element}
header="${this.header}"
>
Expand Down Expand Up @@ -129,7 +133,7 @@ export class VoltageLevelEditor extends LitElement {
></bay-editor>`
)}
</div>
</editor-container>`;
</${EditorContainer}>`;
}

static styles = css`
Expand Down
8 changes: 3 additions & 5 deletions test/integration/zeroline-pane.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,10 @@ describe('zeroline-pane wizarding editing integration', () => {
.then(response => response.text())
.then(str => new DOMParser().parseFromString(str, 'application/xml'));

parent = <MockWizardEditor>(
await fixture(
html`<mock-wizard-editor
><zeroline-pane .doc=${doc}></zeroline-pane
parent = <MockWizardEditor>await fixture(
html`<mock-wizard-editor
><${ZerolinePane} .doc=${doc}></${ZerolinePane}
></mock-wizard-editor>`
)
);
zeroline = <ZerolinePane>parent.querySelector('zeroline-pane');
await parent.updateComplete;
Expand Down
10 changes: 4 additions & 6 deletions test/unit/editor-container.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { expect, fixture } from '@open-wc/testing';
import sinon, { SinonSpy } from 'sinon';

import '../../src/editor-container.js';
import { EditorContainer } from '../../src/editor-container.js';
import { html } from '../../src/foundation.js';
import { BayEditor } from '../../src/zeroline/bay-editor.js';

describe('editor-container', () => {
let element: EditorContainer;
Expand All @@ -16,7 +14,7 @@ describe('editor-container', () => {
);
beforeEach(async () => {
element = await fixture(
html`<editor-container header="test header"></editor-container>`
html`<${EditorContainer} header="test header"></${EditorContainer}>`
);
await element.updateComplete;
});
Expand Down Expand Up @@ -185,7 +183,7 @@ describe('editor-container', () => {
);
beforeEach(async () => {
parent = await fixture(
`<editor-container header="parent header"><bay-editor .element=${bay}></bay-editor></editor-container>`
html`<${EditorContainer} header="parent header"><bay-editor .element=${bay}></bay-editor></${EditorContainer}>`
);

element = parent
Expand Down Expand Up @@ -218,7 +216,7 @@ describe('editor-container', () => {

it('negated the set contrasted property of the parent', async () => {
parent = await fixture(
`<editor-container contrasted header="parent header"><bay-editor .element=${bay}></bay-editor></editor-container>`
html`<${EditorContainer} contrasted header="parent header"><bay-editor .element=${bay}></bay-editor></${EditorContainer}>`
);

element = parent
Expand All @@ -231,7 +229,7 @@ describe('editor-container', () => {

it('makes sure maximum level is 6', async () => {
parent = await fixture(
`<editor-container level="6" header="parent header"><bay-editor .element=${bay}></bay-editor></editor-container>`
html`<${EditorContainer} level="6" header="parent header"><bay-editor .element=${bay}></bay-editor></${EditorContainer}>`
);

element = parent
Expand Down
2 changes: 1 addition & 1 deletion test/unit/wizards/clientln.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe('clientln wizards', () => {

parent = await fixture(
html`<mock-wizard-editor
><zeroline-pane .doc=${doc}></zeroline-pane
><${ZerolinePane} .doc=${doc}></${ZerolinePane}
></mock-wizard-editor>`
);

Expand Down
2 changes: 1 addition & 1 deletion test/unit/wizards/commmap.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe('communication mapping wizard', () => {

parent = await fixture(
html`<mock-wizard
><zeroline-pane .doc=${doc}></zeroline-pane
><${ZerolinePane} .doc=${doc}></${ZerolinePane}
></mock-wizard>`
);

Expand Down
2 changes: 1 addition & 1 deletion test/unit/wizards/controlwithiedname.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe('selectExtRefWizard', () => {

parent = await fixture(
html`<mock-wizard-editor
><zeroline-pane .doc=${doc}></zeroline-pane
><${ZerolinePane} .doc=${doc}></${ZerolinePane}
></mock-wizard-editor>`
);

Expand Down
13 changes: 7 additions & 6 deletions test/unit/zeroline-pane.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { expect, fixture } from '@open-wc/testing';
import { html } from '../../src/foundation.js';
import { ZerolinePane } from '../../src/zeroline-pane.js';
import {
attachedIeds,
getAttachedIeds,
Expand Down Expand Up @@ -38,10 +39,10 @@ describe('zeroline-pane', () => {

it('per default looks like the latest snapshot', async () => {
const element = await fixture(
html`<zeroline-pane
html`<${ZerolinePane}
.doc=${doc}
.getAttachedIeds="${undefined}"
></zeroline-pane>`
></${ZerolinePane}>`
);

await new Promise(resolve => setTimeout(resolve, 2000)); // await animation
Expand All @@ -51,11 +52,11 @@ describe('zeroline-pane', () => {

it('readonly looks like the latest snapshot', async () => {
const element = await fixture(
html`<zeroline-pane
html`<${ZerolinePane}
.doc=${doc}
.readonly=${true}
.getAttachedIeds="${undefined}"
></zeroline-pane>`
></${ZerolinePane}>`
);

await new Promise(resolve => setTimeout(resolve, 2000)); // await animation
Expand All @@ -65,10 +66,10 @@ describe('zeroline-pane', () => {

it('showieds looks like the latest snapshot', async () => {
const element = await fixture(
html`<zeroline-pane
html`<${ZerolinePane}
.doc=${doc}
.getAttachedIeds=${getAttachedIeds(doc)}
></zeroline-pane>`
></${ZerolinePane}>`
);

await new Promise(resolve => setTimeout(resolve, 2000)); // await animation
Expand Down