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

983 remove line #1209

Merged
merged 11 commits into from
Apr 18, 2023
38 changes: 37 additions & 1 deletion src/editors/substation/line-editor.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
css,
customElement,
html,
LitElement,
Expand All @@ -16,7 +17,13 @@ import './conducting-equipment-editor.js';
import './function-editor.js';
import './general-equipment-editor.js';
import './l-node-editor.js';
import { getChildElementsByTagName, newWizardEvent } from '../../foundation.js';

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

@customElement('line-editor')
Expand Down Expand Up @@ -87,6 +94,17 @@ export class LineEditor extends LitElement {
></function-editor>`
)}`;
}
remove(): void {
if (this.element.parentElement)
this.dispatchEvent(
newActionEvent({
old: {
parent: this.element.parentElement,
element: this.element,
},
})
);
}

private renderLNodes(): TemplateResult {
if (!this.showfunctions) return html``;
Expand All @@ -111,8 +129,26 @@ export class LineEditor extends LitElement {
<mwc-icon-button
icon="edit"
@click=${() => this.openEditWizard()}
></mwc-icon-button>
</abbr>
<abbr slot="action" title="${translate('remove')}">
<mwc-icon-button
icon="delete"
@click=${() => this.remove()}
></mwc-icon-button> </abbr
>${this.renderConductingEquipments()}${this.renderGeneralEquipments()}${this.renderFunctions()}${this.renderLNodes()}
</action-pane>`;
}
static styles = css`
${styles}

:host(.moving) {
opacity: 0.3;
}

abbr {
text-decoration: none;
border-bottom: none;
}
`;
}
1 change: 0 additions & 1 deletion src/editors/substation/tapchanger-editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ export class TapChangerEditor extends LitElement {
if (this.addMenu && this.addButton)
this.addMenu.anchor = <HTMLElement>this.addButton;
}

remove(): void {
if (this.element.parentElement)
this.dispatchEvent(
Expand Down
12 changes: 5 additions & 7 deletions src/editors/substation/zeroline-pane.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ export class ZerolinePane extends LitElement {
renderSubstation(): TemplateResult {
return this.doc?.querySelector(':root > Substation')
? html`<section>
${Array.from(this.doc.querySelectorAll(':root >Substation') ?? [])
${Array.from(this.doc.querySelectorAll('Substation') ?? [])
.filter(isPublic)
.map(
substation =>
Expand All @@ -157,13 +157,15 @@ export class ZerolinePane extends LitElement {
renderLines(): TemplateResult {
return this.doc?.querySelector(':root > Line')
? html`<section>
${Array.from(this.doc.querySelectorAll(':root >Line') ?? [])
${Array.from(this.doc.querySelectorAll('Line') ?? [])
.filter(isPublic)
.map(
line =>
html`<line-editor
.doc=${this.doc}
.element=${line}
.getAttachedIeds=${this.getAttachedIeds}
?readonly=${this.readonly}
?showfunctions=${shouldShowFunctions()}
></line-editor>`
)}
Expand Down Expand Up @@ -200,7 +202,7 @@ export class ZerolinePane extends LitElement {
@click=${() => (this.addMenu.open = true)}
></mwc-icon-button
><mwc-menu
corner="BOTTOM_LEFT"
corner="BOTTOM_RIGHT"
@action=${(e: Event) => {
const tagName = (<ListItem>(<Menu>e.target).selected).value;
this.openCreateWizard(tagName);
Expand Down Expand Up @@ -297,9 +299,5 @@ export class ZerolinePane extends LitElement {
box-sizing: border-box;
grid-template-columns: repeat(auto-fit, minmax(128px, auto));
}
:host {
display: block;
position: relative;
}
`;
}
2 changes: 2 additions & 0 deletions src/wizards/line.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import {
const initial = {
nomFreq: '50',
numPhases: '3',
Voltage: '110',
multiplier: 'k',
};

function render(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,5 +106,21 @@ describe('line-editor wizarding editing integration', () => {
doc.querySelector('Line[name="Berlin"]')?.getAttribute('numPhases')
).to.equal('3');
});
describe('has a delete icon button that', () => {
let deleteButton: HTMLElement;

beforeEach(async () => {
deleteButton = <HTMLElement>(
element?.shadowRoot?.querySelector('mwc-icon-button[icon="delete"]')
);
await parent.updateComplete;
});

it('removes the Line element from the document', async () => {
expect(doc.querySelector('Line[name="Berlin"]')).to.exist;
await deleteButton.click();
expect(doc.querySelector('Line[name="Berlin"]')).to.not.exist;
});
});
});
});
6 changes: 2 additions & 4 deletions test/integration/editors/substation/zeroline-pane.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@ import { expect, fixture, html } from '@open-wc/testing';
import '../../../mock-wizard-editor.js';
import { MockWizardEditor } from '../../../mock-wizard-editor.js';

import { IconButton } from '@material/mwc-icon-button';

import '../../../../src/editors/substation/zeroline-pane.js';
import { FilteredList } from '../../../../src/filtered-list.js';
import { ZerolinePane } from '../../../../src/editors/substation/zeroline-pane.js';
import { WizardTextField } from '../../../../src/wizard-textfield.js';
import { ListItem } from '@material/mwc-list/mwc-list-item.js';
import { IconButton } from '@material/mwc-icon-button';
import { ListItem } from '@material/mwc-list/mwc-list-item';

describe('zeroline-pane wizarding editing integration', () => {
let doc: XMLDocument;
Expand Down Expand Up @@ -71,7 +70,6 @@ describe('zeroline-pane wizarding editing integration', () => {
doc.querySelectorAll('ReportControl').length
);
});

it('add Substation element with add button', async () => {
expect(doc.querySelector('Substation[name="newSubstation"]')).to.not.exist;
zeroline.addButton.click();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ snapshots["web component rendering Line element rendering LNode and Function chi
<mwc-icon-button icon="edit">
</mwc-icon-button>
</abbr>
<abbr
slot="action"
title="[remove]"
>
<mwc-icon-button icon="delete">
</mwc-icon-button>
</abbr>
<conducting-equipment-editor showfunctions="">
</conducting-equipment-editor>
<function-editor showfunctions="">
Expand All @@ -37,6 +44,13 @@ snapshots["web component rendering Line element rendering ConductingEquipment lo
<mwc-icon-button icon="edit">
</mwc-icon-button>
</abbr>
<abbr
slot="action"
title="[remove]"
>
<mwc-icon-button icon="delete">
</mwc-icon-button>
</abbr>
<conducting-equipment-editor showfunctions="">
</conducting-equipment-editor>
<function-editor showfunctions="">
Expand All @@ -61,6 +75,13 @@ snapshots["web component rendering Line element rendering GeneralEquipment looks
<mwc-icon-button icon="edit">
</mwc-icon-button>
</abbr>
<abbr
slot="action"
title="[remove]"
>
<mwc-icon-button icon="delete">
</mwc-icon-button>
</abbr>
<conducting-equipment-editor showfunctions="">
</conducting-equipment-editor>
<general-equipment-editor showfunctions="">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ snapshots["zeroline-pane per default looks like the latest snapshot"] =
>
<mwc-icon-button icon="playlist_add">
</mwc-icon-button>
<mwc-menu corner="BOTTOM_LEFT">
<mwc-menu corner="BOTTOM_RIGHT">
<mwc-list-item
aria-disabled="false"
mwc-list-item=""
Expand Down Expand Up @@ -92,7 +92,7 @@ snapshots["zeroline-pane showieds looks like the latest snapshot"] =
>
<mwc-icon-button icon="playlist_add">
</mwc-icon-button>
<mwc-menu corner="BOTTOM_LEFT">
<mwc-menu corner="BOTTOM_RIGHT">
<mwc-list-item
aria-disabled="false"
mwc-list-item=""
Expand Down