Skip to content

Commit b0db54f

Browse files
refactor(wizards/sampledvaluecontrol): remove mwc-button from wizards content (openscd#625)
1 parent 32d7629 commit b0db54f

File tree

3 files changed

+147
-61
lines changed

3 files changed

+147
-61
lines changed

src/wizards/sampledvaluecontrol.ts

Lines changed: 63 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,20 @@ import {
1818
getValue,
1919
identity,
2020
isPublic,
21-
newActionEvent,
21+
MenuAction,
2222
newSubWizardEvent,
23-
newWizardEvent,
2423
selector,
2524
Wizard,
25+
WizardAction,
2626
WizardActor,
2727
WizardInput,
28+
WizardMenuActor,
2829
} from '../foundation.js';
2930
import { securityEnableEnum, smpModEnum } from './foundation/enums.js';
3031
import { maxLength, patterns } from './foundation/limits.js';
3132
import { editSMvWizard } from './smv.js';
3233
import { editSmvOptsWizard } from './smvopts.js';
34+
import { editDataSetWizard } from './dataset.js';
3335

3436
function getSMV(element: Element): Element | null {
3537
const cbName = element.getAttribute('name');
@@ -192,6 +194,32 @@ function contentSampledValueControlWizard(
192194
];
193195
}
194196

197+
function removeSampledValueControl(element: Element): WizardMenuActor {
198+
return (): WizardAction[] => {
199+
const complexAction = removeSampledValueControlAction(element);
200+
if (complexAction) return [complexAction];
201+
return [];
202+
};
203+
}
204+
205+
function openDataSetWizard(element: Element): WizardMenuActor {
206+
return (): WizardAction[] => {
207+
return [() => editDataSetWizard(element)];
208+
};
209+
}
210+
211+
function openSmvOptsWizard(element: Element): WizardMenuActor {
212+
return (): WizardAction[] => {
213+
return [() => editSmvOptsWizard(element)];
214+
};
215+
}
216+
217+
function openSMvWizard(element: Element): WizardMenuActor {
218+
return (): WizardAction[] => {
219+
return [() => editSMvWizard(element)];
220+
};
221+
}
222+
195223
function updateSampledValueControlAction(element: Element): WizardActor {
196224
return (inputs: WizardInput[]): EditorAction[] => {
197225
const attributes: Record<string, string | null> = {};
@@ -240,6 +268,38 @@ export function editSampledValueControlWizard(element: Element): Wizard {
240268
const sMV = getSMV(element);
241269
const smvOpts = element.querySelector('SmvOpts')!;
242270

271+
const dataSet = element.parentElement?.querySelector(
272+
`DataSet[name="${element.getAttribute('datSet')}"]`
273+
);
274+
275+
const menuActions: MenuAction[] = [];
276+
menuActions.push({
277+
icon: 'delete',
278+
label: get('remove'),
279+
action: removeSampledValueControl(element),
280+
});
281+
282+
if (dataSet)
283+
menuActions.push({
284+
icon: 'edit',
285+
label: get('scl.DataSet'),
286+
action: openDataSetWizard(dataSet),
287+
});
288+
289+
if (smvOpts)
290+
menuActions.push({
291+
icon: 'edit',
292+
label: get('scl.SmvOpts'),
293+
action: openSmvOptsWizard(smvOpts),
294+
});
295+
296+
if (sMV)
297+
menuActions.push({
298+
icon: 'edit',
299+
label: get('scl.Communication'),
300+
action: openSMvWizard(sMV),
301+
});
302+
243303
return [
244304
{
245305
title: get('wizard.title.edit', { tagName: element.tagName }),
@@ -249,6 +309,7 @@ export function editSampledValueControlWizard(element: Element): Wizard {
249309
label: get('save'),
250310
action: updateSampledValueControlAction(element),
251311
},
312+
menuActions,
252313
content: [
253314
...contentSampledValueControlWizard({
254315
name,
@@ -260,40 +321,6 @@ export function editSampledValueControlWizard(element: Element): Wizard {
260321
nofASDU,
261322
securityEnable,
262323
}),
263-
sMV
264-
? html`<mwc-button
265-
id="editsmv"
266-
label=${translate('scl.Communication')}
267-
icon="edit"
268-
@click="${(e: MouseEvent) => {
269-
e.target?.dispatchEvent(
270-
newSubWizardEvent(() => editSMvWizard(sMV))
271-
);
272-
}}}"
273-
></mwc-button>`
274-
: html``,
275-
html`<mwc-button
276-
id="editsmvopts"
277-
label=${translate('scl.SmvOpts')}
278-
icon="edit"
279-
@click="${(e: MouseEvent) => {
280-
e.target?.dispatchEvent(
281-
newSubWizardEvent(() => editSmvOptsWizard(smvOpts))
282-
);
283-
}}}"
284-
></mwc-button>`,
285-
html`<mwc-button
286-
label="${translate('remove')}"
287-
icon="delete"
288-
@click=${(e: MouseEvent) => {
289-
const complexAction = removeSampledValueControlAction(element);
290-
291-
if (complexAction)
292-
e.target?.dispatchEvent(newActionEvent(complexAction));
293-
294-
e.target?.dispatchEvent(newWizardEvent());
295-
}}
296-
></mwc-button>`,
297324
],
298325
},
299326
];

test/integration/wizards/sampledvaluecontrol-wizarding-editing.test.ts

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { expect, fixture, html } from '@open-wc/testing';
33
import '../../mock-wizard-editor.js';
44
import { MockWizardEditor } from '../../mock-wizard-editor.js';
55

6-
import { Button } from '@material/mwc-button';
76
import { ListItemBase } from '@material/mwc-list/mwc-list-item-base';
87

98
import { FilteredList } from '../../../src/filtered-list.js';
@@ -177,9 +176,15 @@ describe('Wizards for SCL element SampledValueControl', () => {
177176
});
178177

179178
it('does not render SMV edit button', async () => {
180-
const editSMvButton = <Button>(
181-
element.wizardUI.dialog!.querySelector('mwc-button[id="editsmv"]')!
179+
const editSMvButton = <HTMLElement>(
180+
Array.from(
181+
element.wizardUI.dialog!.querySelectorAll<ListItemBase>(
182+
'mwc-menu > mwc-list-item'
183+
)
184+
).find(item => item.innerHTML.includes(`[scl.Communication]`))
182185
);
186+
187+
await element.wizardUI.dialog?.requestUpdate();
183188
expect(editSMvButton).not.to.exist;
184189
});
185190
});
@@ -217,12 +222,17 @@ describe('Wizards for SCL element SampledValueControl', () => {
217222
});
218223

219224
it('opens a edit wizard for SMV on edit SMV button click', async () => {
220-
const editSMvButton = <Button>(
221-
element.wizardUI.dialog!.querySelector('mwc-button[id="editsmv"]')!
225+
const editSMvButton = <HTMLElement>(
226+
Array.from(
227+
element.wizardUI.dialog!.querySelectorAll<ListItemBase>(
228+
'mwc-menu > mwc-list-item'
229+
)
230+
).find(item => item.innerHTML.includes(`[scl.Communication]`))
222231
);
232+
233+
await element.wizardUI.dialog?.requestUpdate();
223234
expect(editSMvButton).to.exist;
224235

225-
await editSMvButton.updateComplete;
226236
editSMvButton.click();
227237
await new Promise(resolve => setTimeout(resolve, 100)); // await animation
228238

@@ -241,14 +251,17 @@ describe('Wizards for SCL element SampledValueControl', () => {
241251
});
242252

243253
it('opens a edit wizard for SMV on edit SMV button click', async () => {
244-
const editSmvOptsButton = <Button>(
245-
element.wizardUI.dialog!.querySelector(
246-
'mwc-button[id="editsmvopts"]'
247-
)!
254+
const editSmvOptsButton = <HTMLElement>(
255+
Array.from(
256+
element.wizardUI.dialog!.querySelectorAll<ListItemBase>(
257+
'mwc-menu > mwc-list-item'
258+
)
259+
).find(item => item.innerHTML.includes(`[scl.SmvOpts]`))
248260
);
261+
262+
await element.wizardUI.dialog?.requestUpdate();
249263
expect(editSmvOptsButton).to.exist;
250264

251-
await editSmvOptsButton.updateComplete;
252265
editSmvOptsButton.click();
253266
await new Promise(resolve => setTimeout(resolve, 100)); // await animation
254267

@@ -272,10 +285,15 @@ describe('Wizards for SCL element SampledValueControl', () => {
272285
.to.exist;
273286
expect(doc.querySelector('SMV[cbName="MSVCB01"]')).to.exist;
274287

275-
const deleteButton = <Button>(
276-
element.wizardUI.dialog!.querySelector('mwc-button[icon="delete"]')!
288+
const deleteButton = <HTMLElement>(
289+
Array.from(
290+
element.wizardUI.dialog!.querySelectorAll<ListItemBase>(
291+
'mwc-menu > mwc-list-item'
292+
)
293+
).find(item => item.innerHTML.includes(`[remove]`))
277294
);
278-
await deleteButton.updateComplete;
295+
296+
await element.wizardUI.dialog?.requestUpdate();
279297
deleteButton.click();
280298

281299
expect(

test/unit/wizards/__snapshots__/sampledvaluecontrol.test.snap.js

Lines changed: 52 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,58 @@ snapshots["Wizards for SCL element SampledValueControl define an edit wizard tha
77
heading="[wizard.title.edit]"
88
open=""
99
>
10+
<nav>
11+
<mwc-icon-button icon="more_vert">
12+
</mwc-icon-button>
13+
<mwc-menu
14+
class="actions-menu"
15+
corner="BOTTOM_RIGHT"
16+
menucorner="END"
17+
>
18+
<mwc-list-item
19+
aria-disabled="false"
20+
graphic="icon"
21+
mwc-list-item=""
22+
role="menuitem"
23+
tabindex="0"
24+
>
25+
<span>
26+
[remove]
27+
</span>
28+
<mwc-icon slot="graphic">
29+
delete
30+
</mwc-icon>
31+
</mwc-list-item>
32+
<mwc-list-item
33+
aria-disabled="false"
34+
graphic="icon"
35+
mwc-list-item=""
36+
role="menuitem"
37+
tabindex="-1"
38+
>
39+
<span>
40+
[scl.DataSet]
41+
</span>
42+
<mwc-icon slot="graphic">
43+
edit
44+
</mwc-icon>
45+
</mwc-list-item>
46+
<mwc-list-item
47+
aria-disabled="false"
48+
graphic="icon"
49+
mwc-list-item=""
50+
role="menuitem"
51+
tabindex="-1"
52+
>
53+
<span>
54+
[scl.SmvOpts]
55+
</span>
56+
<mwc-icon slot="graphic">
57+
edit
58+
</mwc-icon>
59+
</mwc-list-item>
60+
</mwc-menu>
61+
</nav>
1062
<div id="wizard-content">
1163
<wizard-textfield
1264
dialoginitialfocus=""
@@ -125,17 +177,6 @@ snapshots["Wizards for SCL element SampledValueControl define an edit wizard tha
125177
SignatureAndEncryption
126178
</mwc-list-item>
127179
</wizard-select>
128-
<mwc-button
129-
icon="edit"
130-
id="editsmvopts"
131-
label="[scl.SmvOpts]"
132-
>
133-
</mwc-button>
134-
<mwc-button
135-
icon="delete"
136-
label="[remove]"
137-
>
138-
</mwc-button>
139180
</div>
140181
<mwc-button
141182
dialogaction="close"

0 commit comments

Comments
 (0)