Skip to content

Commit 3dcd6b5

Browse files
refactor(editors/templates/lnodetype): use menu actions (openscd#622)
1 parent 42c2b29 commit 3dcd6b5

File tree

3 files changed

+66
-48
lines changed

3 files changed

+66
-48
lines changed

src/editors/templates/lnodetype-wizard.ts

Lines changed: 26 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,10 @@ import {
2929
Replace,
3030
selector,
3131
Wizard,
32+
WizardAction,
3233
WizardActor,
3334
WizardInput,
35+
WizardMenuActor,
3436
} from '../../foundation.js';
3537
import { WizardSelect } from '../../wizard-select.js';
3638
import {
@@ -42,6 +44,18 @@ import {
4244
WizardOptions,
4345
} from './foundation.js';
4446

47+
function remove(element: Element): WizardMenuActor {
48+
return (): EditorAction[] => {
49+
return [{ old: { parent: element.parentElement!, element } }];
50+
};
51+
}
52+
53+
function openAddDo(parent: Element): WizardMenuActor {
54+
return (): WizardAction[] => {
55+
return [() => dOWizard({ parent })!];
56+
};
57+
}
58+
4559
function updateDoAction(element: Element): WizardActor {
4660
return (inputs: WizardInput[]): EditorAction[] => {
4761
const name = getValue(inputs.find(i => i.label === 'name')!)!;
@@ -613,25 +627,19 @@ export function lNodeTypeWizard(
613627
label: get('save'),
614628
action: updateLNodeTypeAction(lnodetype),
615629
},
630+
menuActions: [
631+
{
632+
label: get('remove'),
633+
icon: 'delete',
634+
action: remove(lnodetype),
635+
},
636+
{
637+
label: get('scl.DO'),
638+
icon: 'playlist_add',
639+
action: openAddDo(lnodetype),
640+
},
641+
],
616642
content: [
617-
html`<mwc-button
618-
icon="delete"
619-
trailingIcon
620-
label="${translate('remove')}"
621-
@click=${(e: MouseEvent) => {
622-
e.target!.dispatchEvent(newWizardEvent());
623-
e.target!.dispatchEvent(
624-
newActionEvent({
625-
old: {
626-
parent: lnodetype.parentElement!,
627-
element: lnodetype,
628-
reference: lnodetype.nextSibling,
629-
},
630-
})
631-
);
632-
}}
633-
fullwidth
634-
></mwc-button> `,
635643
html`<wizard-textfield
636644
label="id"
637645
helper="${translate('scl.id')}"
@@ -656,18 +664,6 @@ export function lNodeTypeWizard(
656664
required
657665
pattern="${patterns.lnClass}"
658666
></wizard-textfield>`,
659-
html` <mwc-button
660-
slot="graphic"
661-
icon="playlist_add"
662-
trailingIcon
663-
label="${translate('scl.DO')}"
664-
@click=${(e: Event) => {
665-
const wizard = dOWizard({
666-
parent: lnodetype,
667-
});
668-
if (wizard) e.target!.dispatchEvent(newSubWizardEvent(wizard));
669-
}}
670-
></mwc-button>`,
671667
html`
672668
<mwc-list
673669
style="margin-top: 0px;"

test/integration/editors/templates/__snapshots__/lnodetype-wizard.test.snap.js

Lines changed: 38 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,45 @@ snapshots["LNodeType wizards defines a lNodeTypeHelperWizard looks like the late
77
heading="[lnodetype.wizard.title.edit]"
88
open=""
99
>
10-
<div id="wizard-content">
11-
<mwc-button
12-
fullwidth=""
13-
icon="delete"
14-
label="[remove]"
15-
trailingicon=""
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"
1617
>
17-
</mwc-button>
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.DO]
41+
</span>
42+
<mwc-icon slot="graphic">
43+
playlist_add
44+
</mwc-icon>
45+
</mwc-list-item>
46+
</mwc-menu>
47+
</nav>
48+
<div id="wizard-content">
1849
<wizard-textfield
1950
dialoginitialfocus=""
2051
helper="[scl.id]"
@@ -40,13 +71,6 @@ snapshots["LNodeType wizards defines a lNodeTypeHelperWizard looks like the late
4071
required=""
4172
>
4273
</wizard-textfield>
43-
<mwc-button
44-
icon="playlist_add"
45-
label="[scl.DO]"
46-
slot="graphic"
47-
trailingicon=""
48-
>
49-
</mwc-button>
5074
<mwc-list style="margin-top: 0px;">
5175
<mwc-list-item
5276
aria-disabled="false"

test/integration/editors/templates/lnodetype-wizard.test.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ describe('LNodeType wizards', () => {
5858
)
5959
);
6060
deleteButton = <HTMLElement>(
61-
parent.wizardUI.dialog?.querySelector('mwc-button[icon="delete"]')
61+
parent.wizardUI.dialog?.querySelector('mwc-menu > mwc-list-item')
6262
);
6363
});
6464

@@ -505,9 +505,7 @@ describe('LNodeType wizards', () => {
505505
await parent.requestUpdate();
506506
await new Promise(resolve => setTimeout(resolve, 100)); // await animation
507507
(<HTMLElement>(
508-
parent.wizardUI.dialog?.querySelectorAll(
509-
'mwc-button[icon="playlist_add"]'
510-
)[0]
508+
parent.wizardUI.dialog?.querySelectorAll('mwc-menu > mwc-list-item')[1]
511509
)).click();
512510
await parent.requestUpdate();
513511
await new Promise(resolve => setTimeout(resolve, 100)); // await animation

0 commit comments

Comments
 (0)