Skip to content

Commit a8cc0b3

Browse files
refactor(wizards/reportcontrol): remove mwc-button from dialog content
1 parent 8fb125c commit a8cc0b3

File tree

3 files changed

+178
-92
lines changed

3 files changed

+178
-92
lines changed

src/wizards/reportcontrol.ts

Lines changed: 58 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ import {
2020
identity,
2121
isPublic,
2222
newSubWizardEvent,
23-
newWizardEvent,
24-
newActionEvent,
2523
selector,
2624
SimpleAction,
2725
Wizard,
@@ -30,6 +28,9 @@ import {
3028
Delete,
3129
getUniqueElementName,
3230
ComplexAction,
31+
WizardMenuActor,
32+
WizardAction,
33+
MenuAction,
3334
} from '../foundation.js';
3435
import { FinderList } from '../finder-list.js';
3536
import { dataAttributePicker, iEDPicker } from './foundation/finder.js';
@@ -399,6 +400,32 @@ function getRptEnabledAction(
399400
};
400401
}
401402

403+
export function removeReportControl(element: Element): WizardMenuActor {
404+
return (): WizardAction[] => {
405+
const complexAction = removeReportControlAction(element);
406+
if (complexAction) return [complexAction];
407+
return [];
408+
};
409+
}
410+
411+
function openDataSetWizard(element: Element): WizardMenuActor {
412+
return (): WizardAction[] => {
413+
return [() => editDataSetWizard(element)];
414+
};
415+
}
416+
417+
function openTrgOpsWizard(element: Element): WizardMenuActor {
418+
return (): WizardAction[] => {
419+
return [() => editTrgOpsWizard(element)];
420+
};
421+
}
422+
423+
function openOptFieldsWizard(element: Element): WizardMenuActor {
424+
return (): WizardAction[] => {
425+
return [() => editOptFieldsWizard(element)];
426+
};
427+
}
428+
402429
function updateReportControlAction(element: Element): WizardActor {
403430
return (inputs: WizardInput[]): EditorAction[] => {
404431
const attributes: Record<string, string | null> = {};
@@ -476,6 +503,34 @@ export function editReportControlWizard(element: Element): Wizard {
476503
`DataSet[name="${element.getAttribute('datSet')}"]`
477504
);
478505

506+
const menuActions: MenuAction[] = [];
507+
menuActions.push({
508+
icon: 'delete',
509+
label: get('remove'),
510+
action: removeReportControl(element),
511+
});
512+
513+
if (dataSet)
514+
menuActions.push({
515+
icon: 'edit',
516+
label: get('scl.DataSet'),
517+
action: openDataSetWizard(dataSet),
518+
});
519+
520+
if (trgOps)
521+
menuActions.push({
522+
icon: 'edit',
523+
label: get('scl.TrgOps'),
524+
action: openTrgOpsWizard(trgOps),
525+
});
526+
527+
if (optFields)
528+
menuActions.push({
529+
icon: 'edit',
530+
label: get('scl.OptFields'),
531+
action: openOptFieldsWizard(optFields),
532+
});
533+
479534
return [
480535
{
481536
title: get('wizard.title.edit', { tagName: element.tagName }),
@@ -485,6 +540,7 @@ export function editReportControlWizard(element: Element): Wizard {
485540
label: get('save'),
486541
action: updateReportControlAction(element),
487542
},
543+
menuActions,
488544
content: [
489545
...contentReportControlWizard({
490546
name,
@@ -496,53 +552,6 @@ export function editReportControlWizard(element: Element): Wizard {
496552
bufTime,
497553
intgPd,
498554
}),
499-
dataSet
500-
? html`<mwc-button
501-
label=${translate('scl.DataSet')}
502-
icon="edit"
503-
id="editdataset"
504-
@click=${(e: MouseEvent) => {
505-
e.target?.dispatchEvent(
506-
newSubWizardEvent(() => editDataSetWizard(dataSet))
507-
);
508-
}}
509-
></mwc-button>`
510-
: html``,
511-
trgOps
512-
? html`<mwc-button
513-
label=${translate('scl.TrgOps')}
514-
icon="edit"
515-
id="edittrgops"
516-
@click=${(e: MouseEvent) => {
517-
e.target?.dispatchEvent(
518-
newSubWizardEvent(() => editTrgOpsWizard(trgOps))
519-
);
520-
}}
521-
></mwc-button>`
522-
: html``,
523-
optFields
524-
? html`<mwc-button
525-
label=${translate('scl.OptFields')}
526-
icon="edit"
527-
id="editoptfields"
528-
@click=${(e: MouseEvent) => {
529-
e.target?.dispatchEvent(
530-
newSubWizardEvent(() => editOptFieldsWizard(optFields))
531-
);
532-
}}
533-
></mwc-button>`
534-
: html``,
535-
html`<mwc-button
536-
label="${translate('remove')}"
537-
icon="delete"
538-
@click=${(e: MouseEvent) => {
539-
const complexAction = removeReportControlAction(element);
540-
if (complexAction)
541-
e.target?.dispatchEvent(newActionEvent(complexAction));
542-
543-
e.target?.dispatchEvent(newWizardEvent());
544-
}}
545-
></mwc-button>`,
546555
],
547556
},
548557
];

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

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -235,11 +235,15 @@ describe('Wizards for SCL element ReportControl', () => {
235235
});
236236

237237
it('opens edit wizard for DataSet element on edit dataset button click', async () => {
238-
const editDataSetButton = <Button>(
239-
element.wizardUI.dialog!.querySelector('mwc-button[id="editdataset"]')!
238+
const editDataSetButton = <HTMLElement>(
239+
Array.from(
240+
element.wizardUI.dialog!.querySelectorAll<ListItemBase>(
241+
'mwc-menu > mwc-list-item'
242+
)
243+
).find(item => item.innerHTML.includes(`[scl.DataSet]`))
240244
);
241245

242-
await editDataSetButton.updateComplete;
246+
await element.wizardUI.dialog?.requestUpdate();
243247
editDataSetButton.click();
244248
await new Promise(resolve => setTimeout(resolve, 100)); // await animation
245249

@@ -254,11 +258,15 @@ describe('Wizards for SCL element ReportControl', () => {
254258
});
255259

256260
it('opens edit wizard for TrgOps element on edit trigger options button click', async () => {
257-
const editTrgOpsButton = <Button>(
258-
element.wizardUI.dialog!.querySelector('mwc-button[id="edittrgops"]')!
261+
const editTrgOpsButton = <HTMLElement>(
262+
Array.from(
263+
element.wizardUI.dialog!.querySelectorAll<ListItemBase>(
264+
'mwc-menu > mwc-list-item'
265+
)
266+
).find(item => item.innerHTML.includes(`[scl.TrgOps]`))
259267
);
260268

261-
await editTrgOpsButton.updateComplete;
269+
await element.wizardUI.dialog?.requestUpdate();
262270
editTrgOpsButton.click();
263271
await new Promise(resolve => setTimeout(resolve, 100)); // await animation
264272

@@ -271,13 +279,15 @@ describe('Wizards for SCL element ReportControl', () => {
271279
});
272280

273281
it('opens edit wizard for OptFields element on edit optional fields button click', async () => {
274-
const editOptFieldsButton = <Button>(
275-
element.wizardUI.dialog!.querySelector(
276-
'mwc-button[id="editoptfields"]'
277-
)!
282+
const editOptFieldsButton = <HTMLElement>(
283+
Array.from(
284+
element.wizardUI.dialog!.querySelectorAll<ListItemBase>(
285+
'mwc-menu > mwc-list-item'
286+
)
287+
).find(item => item.innerHTML.includes(`[scl.OptFields]`))
278288
);
279289

280-
await editOptFieldsButton.updateComplete;
290+
await element.wizardUI.dialog?.requestUpdate();
281291
editOptFieldsButton.click();
282292
await new Promise(resolve => setTimeout(resolve, 100)); // await animation
283293

@@ -302,11 +312,17 @@ describe('Wizards for SCL element ReportControl', () => {
302312
'IED[name="IED2"] LN[lnClass="XSWI"][inst="1"] DataSet[name="dataSet"]'
303313
)
304314
).to.exist;
305-
const deleteButton = <Button>(
306-
element.wizardUI.dialog!.querySelector('mwc-button[icon="delete"]')!
315+
316+
const deleteElement = <HTMLElement>(
317+
Array.from(
318+
element.wizardUI.dialog!.querySelectorAll<ListItemBase>(
319+
'mwc-menu > mwc-list-item'
320+
)
321+
).find(item => item.innerHTML.includes(`[remove]`))
307322
);
308-
await deleteButton.updateComplete;
309-
deleteButton.click();
323+
await element.wizardUI.dialog?.requestUpdate();
324+
deleteElement.click();
325+
310326
expect(
311327
doc.querySelector(
312328
'IED[name="IED2"] LN[lnClass="XSWI"][inst="1"] ReportControl[name="ReportCb2"]'

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

Lines changed: 89 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,72 @@ snapshots["Wizards for SCL ReportControl element define an edit wizard that for
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.TrgOps]
55+
</span>
56+
<mwc-icon slot="graphic">
57+
edit
58+
</mwc-icon>
59+
</mwc-list-item>
60+
<mwc-list-item
61+
aria-disabled="false"
62+
graphic="icon"
63+
mwc-list-item=""
64+
role="menuitem"
65+
tabindex="-1"
66+
>
67+
<span>
68+
[scl.OptFields]
69+
</span>
70+
<mwc-icon slot="graphic">
71+
edit
72+
</mwc-icon>
73+
</mwc-list-item>
74+
</mwc-menu>
75+
</nav>
1076
<div id="wizard-content">
1177
<wizard-textfield
1278
dialoginitialfocus=""
@@ -72,29 +138,6 @@ snapshots["Wizards for SCL ReportControl element define an edit wizard that for
72138
type="number"
73139
>
74140
</wizard-textfield>
75-
<mwc-button
76-
icon="edit"
77-
id="editdataset"
78-
label="[scl.DataSet]"
79-
>
80-
</mwc-button>
81-
<mwc-button
82-
icon="edit"
83-
id="edittrgops"
84-
label="[scl.TrgOps]"
85-
>
86-
</mwc-button>
87-
<mwc-button
88-
icon="edit"
89-
id="editoptfields"
90-
label="[scl.OptFields]"
91-
>
92-
</mwc-button>
93-
<mwc-button
94-
icon="delete"
95-
label="[remove]"
96-
>
97-
</mwc-button>
98141
</div>
99142
<mwc-button
100143
dialogaction="close"
@@ -121,6 +164,29 @@ snapshots["Wizards for SCL ReportControl element define an edit wizard that for
121164
heading="[wizard.title.edit]"
122165
open=""
123166
>
167+
<nav>
168+
<mwc-icon-button icon="more_vert">
169+
</mwc-icon-button>
170+
<mwc-menu
171+
class="actions-menu"
172+
corner="BOTTOM_RIGHT"
173+
menucorner="END"
174+
>
175+
<mwc-list-item
176+
aria-disabled="false"
177+
graphic="icon"
178+
mwc-list-item=""
179+
tabindex="-1"
180+
>
181+
<span>
182+
[remove]
183+
</span>
184+
<mwc-icon slot="graphic">
185+
delete
186+
</mwc-icon>
187+
</mwc-list-item>
188+
</mwc-menu>
189+
</nav>
124190
<div id="wizard-content">
125191
<wizard-textfield
126192
dialoginitialfocus=""
@@ -189,11 +255,6 @@ snapshots["Wizards for SCL ReportControl element define an edit wizard that for
189255
type="number"
190256
>
191257
</wizard-textfield>
192-
<mwc-button
193-
icon="delete"
194-
label="[remove]"
195-
>
196-
</mwc-button>
197258
</div>
198259
<mwc-button
199260
dialogaction="close"

0 commit comments

Comments
 (0)