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

986 edit wizard process #1215

Merged
merged 25 commits into from
Apr 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
230cee8
feat(line-editor.ts):unit_test_added
marcvanraalte Mar 7, 2023
68ad742
feat(line-editor):add_edit_wizard
marcvanraalte Mar 13, 2023
1d8a0fd
feat(line-editor-wizard-editing.test):part-of-test
marcvanraalte Mar 14, 2023
879d2fb
feat(line-editor_wizard_editing)_continue
marcvanraalte Mar 14, 2023
98702df
feat(line.test,etc):editing_and_testing
marcvanraalte Mar 15, 2023
1e22861
feat(line.ts):createLineWizard_added
marcvanraalte Mar 16, 2023
d45a537
feat(zeroline-pane):create_Line_added
marcvanraalte Mar 16, 2023
a2cf7e1
feat(line.test.ts):create_tests_added
marcvanraalte Mar 20, 2023
977a7ca
feat(line-editor.ts):remove_line_and_test
marcvanraalte Mar 20, 2023
88bd000
feat(line-editor):add_add_button_and_test
marcvanraalte Mar 20, 2023
4e2bdb4
Merge branch 'main' into 985_process_editor
marcvanraalte Mar 20, 2023
e8a1d19
feat(process-editor.ts):editor_added
marcvanraalte Mar 21, 2023
c5b6a3e
fix(Process.scd):GeneralEquipment_added
marcvanraalte Mar 22, 2023
8c7cfb6
fix(Process.scd):GeneralEquipment_added
marcvanraalte Mar 22, 2023
0663528
Merge branch 'main' into 986_edit-wizard_process
marcvanraalte Mar 22, 2023
fc98bf3
feat(process-editor):edit_wizard_added
marcvanraalte Mar 23, 2023
858332e
feat(process-editor-wizard-editing.test):added
marcvanraalte Mar 23, 2023
b3dd976
feat(process-editor-snap):snapshot_updated
marcvanraalte Mar 27, 2023
39bad7e
feat(process-editor-wizard-editing):added
marcvanraalte Mar 27, 2023
dff9e9f
feat(process.test.ts):test_added
marcvanraalte Mar 27, 2023
309b6d4
Merge branch 'main' into 986_edit-wizard_process
Stef3st Apr 20, 2023
33a7f2b
fix: type can be nullable
Stef3st Apr 24, 2023
f6fd5fc
Merge branch '986_edit-wizard_process' of https://github.com/openscd/…
Stef3st Apr 24, 2023
17117a3
fix: fixed tests for nullable
Stef3st Apr 24, 2023
ac0c6a1
fix: nullswitch in unit test
Stef3st Apr 24, 2023
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
17 changes: 16 additions & 1 deletion src/editors/substation/process-editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import {
state,
} from 'lit-element';

import { translate } from 'lit-translate';

import '@material/mwc-icon';
import '@material/mwc-icon-button';
import '@material/mwc-menu';
Expand All @@ -22,7 +24,9 @@ import './substation-editor.js';
import './process-editor.js';

import { styles } from './foundation.js';
import { getChildElementsByTagName } from '../../foundation.js';
import { newWizardEvent, getChildElementsByTagName } from '../../foundation.js';

import { wizards } from '../../wizards/wizard-library.js';

@customElement('process-editor')
export class ProcessEditor extends LitElement {
Expand All @@ -44,6 +48,11 @@ export class ProcessEditor extends LitElement {
return `${name} ${desc ? `—${desc}` : ''}`;
}

private openEditWizard(): void {
const wizard = wizards['Process'].edit(this.element);
if (wizard) this.dispatchEvent(newWizardEvent(wizard));
}

private renderConductingEquipments(): TemplateResult {
const ConductingEquipments = getChildElementsByTagName(
this.element,
Expand Down Expand Up @@ -143,6 +152,12 @@ export class ProcessEditor extends LitElement {

render(): TemplateResult {
return html`<action-pane label=${this.header}>
<abbr slot="action" title="${translate('edit')}">
<mwc-icon-button
icon="edit"
@click=${() => this.openEditWizard()}
></mwc-icon-button>
</abbr>
${this.renderConductingEquipments()}${this.renderGeneralEquipments()}${this.renderFunctions()}${this.renderLNodes()}
${this.renderLines()} ${this.renderSubstations()}${this.renderProcesses()}
</action-pane>`;
Expand Down
103 changes: 103 additions & 0 deletions src/wizards/process.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
import { html, TemplateResult } from 'lit-element';
import { get, translate } from 'lit-translate';

import {
cloneElement,
createElement,
getChildElementsByTagName,
getValue,
SimpleAction,
Wizard,
WizardActor,
WizardInputElement,
} from '../foundation.js';

function updateProcessAction(element: Element): WizardActor {
return (inputs: WizardInputElement[]): SimpleAction[] => {
const tapProcessAttrs: Record<string, string | null> = {};
const tapProcessKeys = ['name', 'desc', 'type'];
tapProcessKeys.forEach(key => {
tapProcessAttrs[key] = getValue(inputs.find(i => i.label === key)!);
});

if (
tapProcessKeys.some(
key => tapProcessAttrs[key] !== element.getAttribute(key)
)
) {
const newElement = cloneElement(element, tapProcessAttrs);
return [
{
old: { element },
new: { element: newElement },
},
];
}
return [];
};
}

interface ContentOptions {
name: string | null;
desc: string | null;
type: string | null;
reservedNames: string[];
}

export function contentProcessWizard(
content: ContentOptions
): TemplateResult[] {
return [
html`<wizard-textfield
label="name"
.maybeValue=${content.name}
helper="${translate('scl.name')}"
required
validationMessage="${translate('textfield.required')}"
.reservedValues=${content.reservedNames}
dialogInitialFocus
></wizard-textfield>`,
html`<wizard-textfield
label="desc"
.maybeValue=${content.desc}
nullable
helper="${translate('scl.desc')}"
></wizard-textfield>`,
html`<wizard-textfield
label="type"
.maybeValue=${content.type}
Stef3st marked this conversation as resolved.
Show resolved Hide resolved
nullable
helper="${translate('scl.type')}"
></wizard-textfield>`,
];
}

export function editProcessWizard(element: Element): Wizard {
const name = element.getAttribute('name');
const desc = element.getAttribute('desc');
const type = element.getAttribute('type');
const reservedNames: string[] = getChildElementsByTagName(
element.parentElement!,
'Process'
)
.filter(sibling => sibling !== element)
.map(sibling => sibling.getAttribute('name')!);
return [
{
title: get('wizard.title.edit', { tagName: 'Process' }),
primary: {
icon: 'save',
label: get('save'),
action: updateProcessAction(element),
},
content: [
...contentProcessWizard({
name,
desc,
type,
reservedNames,
}),
],
},
];
}
3 changes: 2 additions & 1 deletion src/wizards/wizard-library.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import {
} from './transformerWinding.js';
import { createTapChangerWizard, editTapChangerWizard } from './tapchanger.js';
import { createLineWizard, editLineWizard } from './line.js';
import { editProcessWizard } from './process.js';

type SclElementWizard = (
element: Element,
Expand Down Expand Up @@ -388,7 +389,7 @@ export const wizards: Record<
create: emptyWizard,
},
Process: {
edit: emptyWizard,
edit: editProcessWizard,
create: emptyWizard,
},
ProtNs: {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
import { expect, fixture, html } from '@open-wc/testing';

import '../../../mock-wizard-editor.js';
import { MockWizardEditor } from '../../../mock-wizard-editor.js';

import '../../../../src/editors/substation/process-editor.js';
import { ProcessEditor } from '../../../../src/editors/substation/process-editor.js';
import { WizardTextField } from '../../../../src/wizard-textfield.js';

describe('process-editor wizarding editing integration', () => {
let doc: XMLDocument;
let parent: MockWizardEditor;
let element: ProcessEditor | null;

describe('edit wizard', () => {
let nameField: WizardTextField;
let descField: WizardTextField;
let typeField: WizardTextField;

let primaryAction: HTMLElement;
let secondaryAction: HTMLElement;

beforeEach(async () => {
doc = await fetch('/test/testfiles/editors/substation/Process.scd')
.then(response => response.text())
.then(str => new DOMParser().parseFromString(str, 'application/xml'));
parent = <MockWizardEditor>(
await fixture(
html`<mock-wizard-editor
><process-editor
.element=${doc.querySelector('Process[name="ProcessGenConduct"]')}
></process-editor
></mock-wizard-editor>`
)
);
element = parent.querySelector('process-editor');
await (<HTMLElement>(
element?.shadowRoot?.querySelector('mwc-icon-button[icon="edit"]')
)).click();
await parent.updateComplete;

nameField = <WizardTextField>(
parent.wizardUI.dialog?.querySelector('wizard-textfield[label="name"]')
);

typeField = <WizardTextField>(
parent.wizardUI.dialog?.querySelector('wizard-textfield[label="type"]')
);

secondaryAction = <HTMLElement>(
parent.wizardUI.dialog?.querySelector(
'mwc-button[slot="secondaryAction"]'
)
);
primaryAction = <HTMLElement>(
parent.wizardUI.dialog?.querySelector(
'mwc-button[slot="primaryAction"]'
)
);
});
it('closes on secondary action', async () => {
secondaryAction.click();
await new Promise(resolve => setTimeout(resolve, 100)); // await animation
expect(parent.wizardUI.dialog).to.not.exist;
});

it('does not change name attribute if not unique within parent element', async () => {
const oldName = nameField.value;
nameField.value = 'ProcProcSubAA1';
primaryAction.click();
await parent.updateComplete;
expect(
doc
.querySelector('Process[name="ProcessGenConduct"]')
?.getAttribute('name')
).to.equal(oldName);
});

it('changes name attribute on primary action', async () => {
nameField.value = 'newName';
primaryAction.click();
await parent.updateComplete;
expect(doc.querySelector('Process')?.getAttribute('name')).to.equal(
'newName'
);
});

it('changes desc attribute on primary action', async () => {
descField = <WizardTextField>(
parent.wizardUI.dialog?.querySelector('wizard-textfield[label="desc"]')
);
await new Promise(resolve => setTimeout(resolve, 100)); // await animation
descField.nullSwitch!.click();
await parent.updateComplete;
descField.value = 'newDesc';
console.log(descField.value);
primaryAction.click();
await parent.updateComplete;
expect(
doc
.querySelector('Process[name="ProcessGenConduct"]')
?.getAttribute('desc')
).to.equal('newDesc');
});

it('deletes desc attribute if wizard-textfield is deactivated', async () => {
await new Promise(resolve => setTimeout(resolve, 100)); // await animation
descField.nullSwitch!.click();
await parent.updateComplete;
await primaryAction.click();
await parent.updateComplete;
expect(
doc
.querySelector('Process[name="ProcessGenConduct"]')
?.getAttribute('desc')
).to.be.null;
});

it('changes type attribute on primary action', async () => {
await new Promise(resolve => setTimeout(resolve, 100));
typeField.nullSwitch!.click();
await parent.updateComplete;
typeField.value = 'newType';
primaryAction.click();
await parent.updateComplete;
expect(
doc
.querySelector('Process[name="ProcessGenConduct"]')
?.getAttribute('type')
).to.equal('newType');
});
});
});
1 change: 0 additions & 1 deletion test/integration/editors/substation/zeroline-pane.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { MockWizardEditor } from '../../../mock-wizard-editor.js';
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 { IconButton } from '@material/mwc-icon-button';
import { ListItem } from '@material/mwc-list/mwc-list-item';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ snapshots["web component rendering Process element rendering LNode, GeneralEquip
label="ProcessGenConduct "
tabindex="0"
>
<abbr
slot="action"
title="[edit]"
>
<mwc-icon-button icon="edit">
</mwc-icon-button>
</abbr>
<conducting-equipment-editor showfunctions="">
</conducting-equipment-editor>
<general-equipment-editor showfunctions="">
Expand All @@ -25,6 +32,13 @@ snapshots["web component rendering Process element hides LNode and Function chil
label="ProcessGenConduct "
tabindex="0"
>
<abbr
slot="action"
title="[edit]"
>
<mwc-icon-button icon="edit">
</mwc-icon-button>
</abbr>
<conducting-equipment-editor>
</conducting-equipment-editor>
<general-equipment-editor>
Expand All @@ -38,6 +52,13 @@ snapshots["web component rendering Process element rendering Substation and Proc
label="ProcProcSubAA1 "
tabindex="0"
>
<abbr
slot="action"
title="[edit]"
>
<mwc-icon-button icon="edit">
</mwc-icon-button>
</abbr>
<substation-editor showfunctions="">
</substation-editor>
<process-editor showfunctions="">
Expand All @@ -51,6 +72,13 @@ snapshots["web component rendering Process element rendering a Line child looks
label="ProcessLine "
tabindex="0"
>
<abbr
slot="action"
title="[edit]"
>
<mwc-icon-button icon="edit">
</mwc-icon-button>
</abbr>
<line-editor showfunctions="">
</line-editor>
</action-pane>
Expand Down
Loading