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

feat(wizards/reportcontrol): add related sub-wizards #499

Merged
Merged
Show file tree
Hide file tree
Changes from 6 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
2 changes: 2 additions & 0 deletions src/translations/de.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ export const de: Translations = {
securityEnabled: 'Aktive Sicherungsmaßnahmen',
DataSet: 'Datensetz',
Communication: 'Kommunikation',
TrgOps: 'Triggerbedingungen',
OptFields: 'Optionale felder',
},
settings: {
title: 'Einstellungen',
Expand Down
2 changes: 2 additions & 0 deletions src/translations/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ export const en = {
securityEnabled: 'Security enabled',
DataSet: 'Dataset',
Communication: 'Communication',
TrgOps: 'Trigger options',
OptFields: 'Optional fields',
},
settings: {
title: 'Settings',
Expand Down
25 changes: 12 additions & 13 deletions src/wizards/dataset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ import {
cloneElement,
getValue,
identity,
newWizardEvent,
newSubWizardEvent,
selector,
Update,
Wizard,
WizardAction,
WizardActor,
WizardInput,
} from '../foundation.js';
import { wizards } from './wizard-library.js';
import { createFCDAsWizard } from './fcda.js';

function updateDataSetAction(element: Element): WizardActor {
return (inputs: WizardInput[], wizard: Element): WizardAction[] => {
Expand Down Expand Up @@ -95,6 +95,7 @@ export function editDataSetWizard(element: Element): Wizard {
.maybeValue=${name}
helper="${translate('scl.name')}"
required
disabled="true"
>
</wizard-textfield>`,
html`<wizard-textfield
Expand All @@ -105,17 +106,6 @@ export function editDataSetWizard(element: Element): Wizard {
required
>
</wizard-textfield>`,
html`<mwc-button
icon="add"
label="${translate('wizard.title.add', { tagName: 'FCDA' })}"
@click=${(e: Event) => {
const wizard = wizards['FCDA'].create(element);
if (wizard) {
e.target?.dispatchEvent(newWizardEvent(wizard));
e.target?.dispatchEvent(newWizardEvent());
}
}}
></mwc-button>`,
html`<filtered-list multi
>${Array.from(element.querySelectorAll('FCDA')).map(
fcda =>
Expand All @@ -124,6 +114,15 @@ export function editDataSetWizard(element: Element): Wizard {
>`
)}</filtered-list
>`,
html`<mwc-button
icon="add"
label="${translate('wizard.title.add', { tagName: 'FCDA' })}"
@click="${(e: Event) => {
e.target?.dispatchEvent(
newSubWizardEvent(() => createFCDAsWizard(element))
);
}}"
></mwc-button>`,
],
},
];
Expand Down
19 changes: 10 additions & 9 deletions src/wizards/fcda.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,8 @@ function getReader(server: Element): (path: string[]) => Promise<Directory> {
};
}

export function createFCDAsWizard(parent: Element): Wizard | undefined {
export function createFCDAsWizard(parent: Element): Wizard {
const server = parent.closest('Server');
if (!server) return;

return [
{
Expand All @@ -127,13 +126,15 @@ export function createFCDAsWizard(parent: Element): Wizard | undefined {
action: createFCDAsAction(parent),
},
content: [
html`<finder-list
multi
.paths=${[['Server: ' + identity(server)]]}
.read=${getReader(server)}
.getDisplayString=${getDisplayString}
.getTitle=${(path: string[]) => path[path.length - 1]}
></finder-list>`,
server
? html`<finder-list
multi
.paths=${[['Server: ' + identity(server)]]}
.read=${getReader(server)}
.getDisplayString=${getDisplayString}
.getTitle=${(path: string[]) => path[path.length - 1]}
></finder-list>`
: html``,
],
},
];
Expand Down
45 changes: 45 additions & 0 deletions src/wizards/reportcontrol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ import {
Delete,
} from '../foundation.js';
import { maxLength, patterns } from './foundation/limits.js';
import { editTrgOpsWizard } from './trgops.js';
import { editOptFieldsWizard } from './optfields.js';
import { editDataSetWizard } from './dataset.js';

export function removeReportControlAction(element: Element): Delete[] {
if (!element.parentElement) return [];
Expand Down Expand Up @@ -241,6 +244,12 @@ export function editReportControlWizard(element: Element): Wizard {
const bufTime = element.getAttribute('bufTime');
const intgPd = element.getAttribute('intgPd');

const trgOps = element.querySelector('TrgOps');
const optFields = element.querySelector('OptFields');
const dataSet = element.parentElement?.querySelector(
`DataSet[name="${element.getAttribute('datSet')}"]`
);

return [
{
title: get('wizard.title.edit', { tagName: element.tagName }),
Expand All @@ -261,6 +270,42 @@ export function editReportControlWizard(element: Element): Wizard {
bufTime,
intgPd,
}),
dataSet
? html`<mwc-button
label=${translate('scl.DataSet')}
icon="edit"
id="editdataset"
@click=${(e: MouseEvent) => {
e.target?.dispatchEvent(
newSubWizardEvent(() => editDataSetWizard(dataSet))
);
}}
></mwc-button>`
: html``,
trgOps
? html`<mwc-button
label=${translate('scl.TrgOps')}
icon="edit"
id="trgops"
JakobVogelsang marked this conversation as resolved.
Show resolved Hide resolved
@click=${(e: MouseEvent) => {
e.target?.dispatchEvent(
newSubWizardEvent(() => editTrgOpsWizard(trgOps))
);
}}
></mwc-button>`
: html``,
optFields
? html`<mwc-button
label=${translate('scl.OptFields')}
icon="edit"
id="optfields"
JakobVogelsang marked this conversation as resolved.
Show resolved Hide resolved
@click=${(e: MouseEvent) => {
e.target?.dispatchEvent(
newSubWizardEvent(() => editOptFieldsWizard(optFields))
);
}}
></mwc-button>`
: html``,
html`<mwc-button
label="${translate('remove')}"
icon="delete"
Expand Down
24 changes: 1 addition & 23 deletions src/wizards/trgops.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,13 @@ import '@material/mwc-list/mwc-list-item';
import '../wizard-select.js';
import {
cloneElement,
EditorAction,
getValue,
Wizard,
WizardAction,
WizardActor,
WizardInput,
} from '../foundation.js';

function updateIntPdInParentReportAction(
report: Element | null,
isPeriodActive: boolean
): EditorAction | undefined {
if (
!report ||
(isPeriodActive && report.getAttribute('intgPd')) ||
(!isPeriodActive && !report.getAttribute('intgPd'))
)
return;

const intgPd = isPeriodActive ? '1000' : null;
const newElement = cloneElement(report, { intgPd });
return { old: { element: report }, new: { element: newElement } };
}

function updateTrgOpsAction(element: Element): WizardActor {
return (inputs: WizardInput[]): WizardAction[] => {
const dchg = getValue(inputs.find(i => i.label === 'dchg')!);
Expand All @@ -56,12 +39,7 @@ function updateTrgOpsAction(element: Element): WizardActor {
});
const trgOptAction = { old: { element }, new: { element: newElement } };

const intPdAction = updateIntPdInParentReportAction(
element.parentElement,
period === 'true' ? true : false
);

return intPdAction ? [trgOptAction, intPdAction] : [trgOptAction];
return [trgOptAction];
};
}

Expand Down
54 changes: 54 additions & 0 deletions test/integration/wizards/reportcontrol-wizarding-editing.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ describe('Wizards for SCL element ReportControl', () => {
let parentIED: Element;

beforeEach(async () => {
element.workflow.length = 0; // remove all wizard from FIFO queue
parentIED = doc.querySelector('IED')!;
element.workflow.push(() => selectReportControlWizard(parentIED));
await element.requestUpdate();
Expand Down Expand Up @@ -162,6 +163,59 @@ describe('Wizards for SCL element ReportControl', () => {
expect(report.innerHTML).to.contain('ReportCb');
});

it('opens edit wizard for DataSet element on edit dataset button click', async () => {
const editDataSetButton = <Button>(
element.wizardUI.dialog!.querySelector('mwc-button[id="editdataset"]')!
);

await editDataSetButton.updateComplete;
editDataSetButton.click();
await new Promise(resolve => setTimeout(resolve, 100)); // await animation

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

expect(nameField.value).to.equal(
doc.querySelectorAll('DataSet')[1].getAttribute('name')
);
});

it('opens edit wizard for TrgOps element on edit trigger options button click', async () => {
const editTrgOpsButton = <Button>(
element.wizardUI.dialog!.querySelector('mwc-button[id="trgops"]')!
);

await editTrgOpsButton.updateComplete;
editTrgOpsButton.click();
await new Promise(resolve => setTimeout(resolve, 100)); // await animation

const dchgSelect = <WizardTextField>(
element.wizardUI.dialog?.querySelector('wizard-select[label="dchg"]')
);
await dchgSelect.updateComplete;

expect(dchgSelect).to.exist;
});

it('opens edit wizard for OptFields element on edit optional fields button click', async () => {
const editTrgOpsButton = <Button>(
JakobVogelsang marked this conversation as resolved.
Show resolved Hide resolved
element.wizardUI.dialog!.querySelector('mwc-button[id="optfields"]')!
);

await editTrgOpsButton.updateComplete;
editTrgOpsButton.click();
await new Promise(resolve => setTimeout(resolve, 100)); // await animation

const dchgSelect = <WizardTextField>(
JakobVogelsang marked this conversation as resolved.
Show resolved Hide resolved
element.wizardUI.dialog?.querySelector('wizard-select[label="seqNum"]')
);
await dchgSelect.updateComplete;

expect(dchgSelect).to.exist;
});

it('removes the ReportControl element and its referenced elements on remove button click', async () => {
expect(
doc.querySelector(
Expand Down
11 changes: 6 additions & 5 deletions test/unit/wizards/__snapshots__/dataset.test.snap.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ snapshots["dataset wizards include a dataset edit wizard looks like the latest s
>
<div id="wizard-content">
<wizard-textfield
disabled=""
helper="[scl.name]"
label="name"
required=""
Expand All @@ -22,11 +23,6 @@ snapshots["dataset wizards include a dataset edit wizard looks like the latest s
required=""
>
</wizard-textfield>
<mwc-button
icon="add"
label="[wizard.title.add]"
>
</mwc-button>
<filtered-list multi="">
<mwc-check-list-item
aria-disabled="false"
Expand Down Expand Up @@ -59,6 +55,11 @@ snapshots["dataset wizards include a dataset edit wizard looks like the latest s
CBSW/ XSWI 2.OpSlc.dsd sasd.ads.asd (ST)
</mwc-check-list-item>
</filtered-list>
<mwc-button
icon="add"
label="[wizard.title.add]"
>
</mwc-button>
</div>
<mwc-button
dialogaction="close"
Expand Down
18 changes: 18 additions & 0 deletions test/unit/wizards/__snapshots__/reportcontrol.test.snap.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,24 @@ snapshots["Wizards for SCL ReportControl element define an edit wizard that look
type="number"
>
</wizard-textfield>
<mwc-button
icon="edit"
id="editdataset"
label="[scl.DataSet]"
>
</mwc-button>
<mwc-button
icon="edit"
id="trgops"
label="[scl.TrgOps]"
>
</mwc-button>
<mwc-button
icon="edit"
id="optfields"
label="[scl.OptFields]"
>
</mwc-button>
<mwc-button
icon="delete"
label="[remove]"
Expand Down
8 changes: 4 additions & 4 deletions test/unit/wizards/dataset.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect, fixture, html } from '@open-wc/testing';
import sinon, { SinonSpy } from 'sinon';
import { SinonSpy, spy } from 'sinon';

import '../../mock-wizard.js';
import { MockWizard } from '../../mock-wizard.js';
Expand Down Expand Up @@ -36,9 +36,9 @@ describe('dataset wizards', () => {
element.workflow.push(() => wizard);
await element.requestUpdate();

wizardEvent = sinon.spy();
wizardEvent = spy();
window.addEventListener('wizard', wizardEvent);
actionEvent = sinon.spy();
actionEvent = spy();
window.addEventListener('editor-action', actionEvent);
});

Expand All @@ -50,7 +50,7 @@ describe('dataset wizards', () => {
element.wizardUI.dialog?.querySelector('mwc-button[icon="add"]')
);
await addButton.click();
expect(wizardEvent).to.be.calledTwice;
expect(wizardEvent).to.be.calledOnce;
});

describe('with stand alone DataSet', () => {
Expand Down
Loading