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

refactor(editors/template/dotype): dotype/sdo wizards use menu actions #628

Merged
merged 3 commits into from
Mar 21, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
108 changes: 41 additions & 67 deletions src/editors/templates/dotype-wizards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ import {
getValue,
identity,
isPublic,
newActionEvent,
newSubWizardEvent,
newWizardEvent,
Replace,
selector,
Wizard,
WizardAction,
WizardActor,
WizardInput,
WizardMenuActor,
} from '../../foundation.js';
import { createDaWizard, editDAWizard } from '../../wizards/da.js';
import { patterns } from '../../wizards/foundation/limits.js';
Expand All @@ -39,6 +39,12 @@ import {
WizardOptions,
} from './foundation.js';

function remove(element: Element): WizardMenuActor {
return (): EditorAction[] => {
return [{ old: { parent: element.parentElement!, element } }];
};
}

function updateSDoAction(element: Element): WizardActor {
return (inputs: WizardInput[]): EditorAction[] => {
const name = getValue(inputs.find(i => i.label === 'name')!)!;
Expand Down Expand Up @@ -96,37 +102,20 @@ function sDOWizard(options: WizardOptions): Wizard | undefined {
)
).find(isPublic) ?? null;

const [title, action, type, deleteButton, name, desc] = sdo
const [title, action, type, menuActions, name, desc] = sdo
? [
get('sdo.wizard.title.edit'),
updateSDoAction(sdo),
sdo.getAttribute('type'),
html`<mwc-button
icon="delete"
trailingIcon
label="${translate('remove')}"
@click=${(e: MouseEvent) => {
e.target!.dispatchEvent(newWizardEvent());
e.target!.dispatchEvent(
newActionEvent({
old: {
parent: sdo.parentElement!,
element: sdo,
reference: sdo.nextSibling,
},
})
);
}}
fullwidth
></mwc-button> `,
[{ icon: 'delete', label: get('remove'), action: remove(sdo) }],
sdo.getAttribute('name'),
sdo.getAttribute('desc'),
]
: [
get('sdo.wizard.title.add'),
createSDoAction((<CreateOptions>options).parent),
null,
html``,
undefined,
'',
null,
];
Expand All @@ -140,8 +129,8 @@ function sDOWizard(options: WizardOptions): Wizard | undefined {
title,
element: sdo ?? undefined,
primary: { icon: '', label: get('save'), action },
menuActions,
content: [
deleteButton,
html`<wizard-textfield
label="name"
.maybeValue=${name}
Expand Down Expand Up @@ -306,6 +295,18 @@ export function createDOTypeWizard(
];
}

function openAddSdo(parent: Element): WizardMenuActor {
return (): WizardAction[] => {
return [() => sDOWizard({ parent })!];
};
}

function openAddDa(parent: Element): WizardMenuActor {
return (): WizardAction[] => {
return [() => createDaWizard(parent)!];
};
}

function updateDOTypeAction(element: Element): WizardActor {
return (inputs: WizardInput[]): EditorAction[] => {
const id = getValue(inputs.find(i => i.label === 'id')!)!;
Expand Down Expand Up @@ -358,25 +359,24 @@ export function dOTypeWizard(
label: get('save'),
action: updateDOTypeAction(dotype),
},
menuActions: [
{
label: get('remove'),
icon: 'delete',
action: remove(dotype),
},
{
label: get('scl.DO'),
icon: 'playlist_add',
action: openAddSdo(dotype),
},
{
label: get('scl.DA'),
icon: 'playlist_add',
action: openAddDa(dotype),
},
],
content: [
html`<mwc-button
icon="delete"
trailingIcon
label="${translate('remove')}"
@click=${(e: MouseEvent) => {
e.target!.dispatchEvent(newWizardEvent());
e.target!.dispatchEvent(
newActionEvent({
old: {
parent: dotype.parentElement!,
element: dotype,
reference: dotype.nextSibling,
},
})
);
}}
fullwidth
></mwc-button> `,
html`<wizard-textfield
label="id"
helper="${translate('scl.id')}"
Expand All @@ -400,32 +400,6 @@ export function dOTypeWizard(
.maybeValue=${dotype.getAttribute('cdc')}
pattern="${patterns.normalizedString}"
></wizard-textfield>`,
html`<section>
<mwc-button
slot="graphic"
icon="playlist_add"
trailingIcon
label="${translate('scl.DO')}"
@click=${(e: Event) => {
const wizard = sDOWizard({
parent: dotype,
});
if (wizard) e.target!.dispatchEvent(newSubWizardEvent(wizard));
}}
></mwc-button>
<mwc-button
slot="graphic"
icon="playlist_add"
trailingIcon
label="${translate('scl.DA')}"
@click=${(e: Event) => {
if (dotype)
e.target!.dispatchEvent(
newSubWizardEvent(createDaWizard(dotype))
);
}}
></mwc-button>
</section>`,
html`
<mwc-list
style="margin-top: 0px;"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -723,14 +723,59 @@ snapshots["DOType wizards defines a dOTypeWizard looks like the latest snapshot"
heading="[dotype.wizard.title.edit]"
open=""
>
<div id="wizard-content">
<mwc-button
fullwidth=""
icon="delete"
label="[remove]"
trailingicon=""
<nav>
<mwc-icon-button icon="more_vert">
</mwc-icon-button>
<mwc-menu
class="actions-menu"
corner="BOTTOM_RIGHT"
menucorner="END"
>
</mwc-button>
<mwc-list-item
aria-disabled="false"
graphic="icon"
mwc-list-item=""
role="menuitem"
tabindex="0"
>
<span>
[remove]
</span>
<mwc-icon slot="graphic">
delete
</mwc-icon>
</mwc-list-item>
<mwc-list-item
aria-disabled="false"
graphic="icon"
mwc-list-item=""
role="menuitem"
tabindex="-1"
>
<span>
[scl.DO]
</span>
<mwc-icon slot="graphic">
playlist_add
</mwc-icon>
</mwc-list-item>
<mwc-list-item
aria-disabled="false"
graphic="icon"
mwc-list-item=""
role="menuitem"
tabindex="-1"
>
<span>
[scl.DA]
</span>
<mwc-icon slot="graphic">
playlist_add
</mwc-icon>
</mwc-list-item>
</mwc-menu>
</nav>
<div id="wizard-content">
<wizard-textfield
dialoginitialfocus=""
helper="[scl.id]"
Expand All @@ -755,22 +800,6 @@ snapshots["DOType wizards defines a dOTypeWizard looks like the latest snapshot"
pattern="([ -~]|[…]|[ -퟿]|[-�])*"
>
</wizard-textfield>
<section>
<mwc-button
icon="playlist_add"
label="[scl.DO]"
slot="graphic"
trailingicon=""
>
</mwc-button>
<mwc-button
icon="playlist_add"
label="[scl.DA]"
slot="graphic"
trailingicon=""
>
</mwc-button>
</section>
<mwc-list style="margin-top: 0px;">
<mwc-list-item
aria-disabled="false"
Expand Down Expand Up @@ -1009,14 +1038,31 @@ snapshots["DOType wizards defines a sDOWizard to edit an existing SDO looks like
heading="[sdo.wizard.title.edit]"
open=""
>
<div id="wizard-content">
<mwc-button
fullwidth=""
icon="delete"
label="[remove]"
trailingicon=""
<nav>
<mwc-icon-button icon="more_vert">
</mwc-icon-button>
<mwc-menu
class="actions-menu"
corner="BOTTOM_RIGHT"
menucorner="END"
>
</mwc-button>
<mwc-list-item
aria-disabled="false"
graphic="icon"
mwc-list-item=""
role="menuitem"
tabindex="0"
>
<span>
[remove]
</span>
<mwc-icon slot="graphic">
delete
</mwc-icon>
</mwc-list-item>
</mwc-menu>
</nav>
<div id="wizard-content">
<wizard-textfield
dialoginitialfocus=""
helper="[scl.name]"
Expand Down
Loading