Skip to content

Commit 1e896b3

Browse files
refactor(editors/template/dotype): dotype/sdo wizards use menu actions (openscd#628)
* refactor(editors/template/dotype): refactor sdo wizard remove button from content * refactor(editors/template/dotype): refactor dotype wizard remove button from content
1 parent 582a2fa commit 1e896b3

File tree

4 files changed

+162
-109
lines changed

4 files changed

+162
-109
lines changed

src/editors/templates/dotype-wizards.ts

Lines changed: 41 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ import {
1919
getValue,
2020
identity,
2121
isPublic,
22-
newActionEvent,
2322
newSubWizardEvent,
24-
newWizardEvent,
2523
Replace,
2624
selector,
2725
Wizard,
26+
WizardAction,
2827
WizardActor,
2928
WizardInput,
29+
WizardMenuActor,
3030
} from '../../foundation.js';
3131
import { createDaWizard, editDAWizard } from '../../wizards/da.js';
3232
import { patterns } from '../../wizards/foundation/limits.js';
@@ -39,6 +39,12 @@ import {
3939
WizardOptions,
4040
} from './foundation.js';
4141

42+
function remove(element: Element): WizardMenuActor {
43+
return (): EditorAction[] => {
44+
return [{ old: { parent: element.parentElement!, element } }];
45+
};
46+
}
47+
4248
function updateSDoAction(element: Element): WizardActor {
4349
return (inputs: WizardInput[]): EditorAction[] => {
4450
const name = getValue(inputs.find(i => i.label === 'name')!)!;
@@ -96,37 +102,20 @@ function sDOWizard(options: WizardOptions): Wizard | undefined {
96102
)
97103
).find(isPublic) ?? null;
98104

99-
const [title, action, type, deleteButton, name, desc] = sdo
105+
const [title, action, type, menuActions, name, desc] = sdo
100106
? [
101107
get('sdo.wizard.title.edit'),
102108
updateSDoAction(sdo),
103109
sdo.getAttribute('type'),
104-
html`<mwc-button
105-
icon="delete"
106-
trailingIcon
107-
label="${translate('remove')}"
108-
@click=${(e: MouseEvent) => {
109-
e.target!.dispatchEvent(newWizardEvent());
110-
e.target!.dispatchEvent(
111-
newActionEvent({
112-
old: {
113-
parent: sdo.parentElement!,
114-
element: sdo,
115-
reference: sdo.nextSibling,
116-
},
117-
})
118-
);
119-
}}
120-
fullwidth
121-
></mwc-button> `,
110+
[{ icon: 'delete', label: get('remove'), action: remove(sdo) }],
122111
sdo.getAttribute('name'),
123112
sdo.getAttribute('desc'),
124113
]
125114
: [
126115
get('sdo.wizard.title.add'),
127116
createSDoAction((<CreateOptions>options).parent),
128117
null,
129-
html``,
118+
undefined,
130119
'',
131120
null,
132121
];
@@ -140,8 +129,8 @@ function sDOWizard(options: WizardOptions): Wizard | undefined {
140129
title,
141130
element: sdo ?? undefined,
142131
primary: { icon: '', label: get('save'), action },
132+
menuActions,
143133
content: [
144-
deleteButton,
145134
html`<wizard-textfield
146135
label="name"
147136
.maybeValue=${name}
@@ -306,6 +295,18 @@ export function createDOTypeWizard(
306295
];
307296
}
308297

298+
function openAddSdo(parent: Element): WizardMenuActor {
299+
return (): WizardAction[] => {
300+
return [() => sDOWizard({ parent })!];
301+
};
302+
}
303+
304+
function openAddDa(parent: Element): WizardMenuActor {
305+
return (): WizardAction[] => {
306+
return [() => createDaWizard(parent)!];
307+
};
308+
}
309+
309310
function updateDOTypeAction(element: Element): WizardActor {
310311
return (inputs: WizardInput[]): EditorAction[] => {
311312
const id = getValue(inputs.find(i => i.label === 'id')!)!;
@@ -358,25 +359,24 @@ export function dOTypeWizard(
358359
label: get('save'),
359360
action: updateDOTypeAction(dotype),
360361
},
362+
menuActions: [
363+
{
364+
label: get('remove'),
365+
icon: 'delete',
366+
action: remove(dotype),
367+
},
368+
{
369+
label: get('scl.DO'),
370+
icon: 'playlist_add',
371+
action: openAddSdo(dotype),
372+
},
373+
{
374+
label: get('scl.DA'),
375+
icon: 'playlist_add',
376+
action: openAddDa(dotype),
377+
},
378+
],
361379
content: [
362-
html`<mwc-button
363-
icon="delete"
364-
trailingIcon
365-
label="${translate('remove')}"
366-
@click=${(e: MouseEvent) => {
367-
e.target!.dispatchEvent(newWizardEvent());
368-
e.target!.dispatchEvent(
369-
newActionEvent({
370-
old: {
371-
parent: dotype.parentElement!,
372-
element: dotype,
373-
reference: dotype.nextSibling,
374-
},
375-
})
376-
);
377-
}}
378-
fullwidth
379-
></mwc-button> `,
380380
html`<wizard-textfield
381381
label="id"
382382
helper="${translate('scl.id')}"
@@ -400,32 +400,6 @@ export function dOTypeWizard(
400400
.maybeValue=${dotype.getAttribute('cdc')}
401401
pattern="${patterns.normalizedString}"
402402
></wizard-textfield>`,
403-
html`<section>
404-
<mwc-button
405-
slot="graphic"
406-
icon="playlist_add"
407-
trailingIcon
408-
label="${translate('scl.DO')}"
409-
@click=${(e: Event) => {
410-
const wizard = sDOWizard({
411-
parent: dotype,
412-
});
413-
if (wizard) e.target!.dispatchEvent(newSubWizardEvent(wizard));
414-
}}
415-
></mwc-button>
416-
<mwc-button
417-
slot="graphic"
418-
icon="playlist_add"
419-
trailingIcon
420-
label="${translate('scl.DA')}"
421-
@click=${(e: Event) => {
422-
if (dotype)
423-
e.target!.dispatchEvent(
424-
newSubWizardEvent(createDaWizard(dotype))
425-
);
426-
}}
427-
></mwc-button>
428-
</section>`,
429403
html`
430404
<mwc-list
431405
style="margin-top: 0px;"

test/integration/editors/templates/__snapshots__/dotype-wizarding.test.snap.js

Lines changed: 76 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -723,14 +723,59 @@ snapshots["DOType wizards defines a dOTypeWizard looks like the latest snapshot"
723723
heading="[dotype.wizard.title.edit]"
724724
open=""
725725
>
726-
<div id="wizard-content">
727-
<mwc-button
728-
fullwidth=""
729-
icon="delete"
730-
label="[remove]"
731-
trailingicon=""
726+
<nav>
727+
<mwc-icon-button icon="more_vert">
728+
</mwc-icon-button>
729+
<mwc-menu
730+
class="actions-menu"
731+
corner="BOTTOM_RIGHT"
732+
menucorner="END"
732733
>
733-
</mwc-button>
734+
<mwc-list-item
735+
aria-disabled="false"
736+
graphic="icon"
737+
mwc-list-item=""
738+
role="menuitem"
739+
tabindex="0"
740+
>
741+
<span>
742+
[remove]
743+
</span>
744+
<mwc-icon slot="graphic">
745+
delete
746+
</mwc-icon>
747+
</mwc-list-item>
748+
<mwc-list-item
749+
aria-disabled="false"
750+
graphic="icon"
751+
mwc-list-item=""
752+
role="menuitem"
753+
tabindex="-1"
754+
>
755+
<span>
756+
[scl.DO]
757+
</span>
758+
<mwc-icon slot="graphic">
759+
playlist_add
760+
</mwc-icon>
761+
</mwc-list-item>
762+
<mwc-list-item
763+
aria-disabled="false"
764+
graphic="icon"
765+
mwc-list-item=""
766+
role="menuitem"
767+
tabindex="-1"
768+
>
769+
<span>
770+
[scl.DA]
771+
</span>
772+
<mwc-icon slot="graphic">
773+
playlist_add
774+
</mwc-icon>
775+
</mwc-list-item>
776+
</mwc-menu>
777+
</nav>
778+
<div id="wizard-content">
734779
<wizard-textfield
735780
dialoginitialfocus=""
736781
helper="[scl.id]"
@@ -755,22 +800,6 @@ snapshots["DOType wizards defines a dOTypeWizard looks like the latest snapshot"
755800
pattern="([ -~]|[…]|[ -퟿]|[-�])*"
756801
>
757802
</wizard-textfield>
758-
<section>
759-
<mwc-button
760-
icon="playlist_add"
761-
label="[scl.DO]"
762-
slot="graphic"
763-
trailingicon=""
764-
>
765-
</mwc-button>
766-
<mwc-button
767-
icon="playlist_add"
768-
label="[scl.DA]"
769-
slot="graphic"
770-
trailingicon=""
771-
>
772-
</mwc-button>
773-
</section>
774803
<mwc-list style="margin-top: 0px;">
775804
<mwc-list-item
776805
aria-disabled="false"
@@ -1009,14 +1038,31 @@ snapshots["DOType wizards defines a sDOWizard to edit an existing SDO looks like
10091038
heading="[sdo.wizard.title.edit]"
10101039
open=""
10111040
>
1012-
<div id="wizard-content">
1013-
<mwc-button
1014-
fullwidth=""
1015-
icon="delete"
1016-
label="[remove]"
1017-
trailingicon=""
1041+
<nav>
1042+
<mwc-icon-button icon="more_vert">
1043+
</mwc-icon-button>
1044+
<mwc-menu
1045+
class="actions-menu"
1046+
corner="BOTTOM_RIGHT"
1047+
menucorner="END"
10181048
>
1019-
</mwc-button>
1049+
<mwc-list-item
1050+
aria-disabled="false"
1051+
graphic="icon"
1052+
mwc-list-item=""
1053+
role="menuitem"
1054+
tabindex="0"
1055+
>
1056+
<span>
1057+
[remove]
1058+
</span>
1059+
<mwc-icon slot="graphic">
1060+
delete
1061+
</mwc-icon>
1062+
</mwc-list-item>
1063+
</mwc-menu>
1064+
</nav>
1065+
<div id="wizard-content">
10201066
<wizard-textfield
10211067
dialoginitialfocus=""
10221068
helper="[scl.name]"

0 commit comments

Comments
 (0)