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(foundation): change menu action API #769

Merged
merged 2 commits into from
May 24, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
14 changes: 9 additions & 5 deletions src/editors/templates/datype-wizards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@ import {
EditorAction,
getValue,
identity,
newActionEvent,
newSubWizardEvent,
newWizardEvent,
patterns,
Replace,
selector,
Wizard,
WizardAction,
WizardActor,
WizardInputElement,
WizardMenuActor,
Expand All @@ -36,14 +37,17 @@ import {
} from './foundation.js';

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

function openAddBda(parent: Element): WizardMenuActor {
return (): WizardAction[] => {
return [() => createBDAWizard(parent)];
return (wizard: Element): void => {
wizard.dispatchEvent(newSubWizardEvent(() => createBDAWizard(parent)));
};
}

Expand Down
18 changes: 11 additions & 7 deletions src/editors/templates/dotype-wizards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ import {
getValue,
identity,
isPublic,
newActionEvent,
newSubWizardEvent,
newWizardEvent,
Replace,
selector,
Wizard,
WizardAction,
WizardActor,
WizardInputElement,
WizardMenuActor,
Expand All @@ -40,8 +41,11 @@ import {
} from './foundation.js';

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

Expand Down Expand Up @@ -296,14 +300,14 @@ export function createDOTypeWizard(
}

function openAddSdo(parent: Element): WizardMenuActor {
return (): WizardAction[] => {
return [() => sDOWizard({ parent })!];
return (wizard: Element): void => {
wizard.dispatchEvent(newSubWizardEvent(() => sDOWizard({ parent })!));
};
}

function openAddDa(parent: Element): WizardMenuActor {
return (): WizardAction[] => {
return [() => createDaWizard(parent)!];
return (wizard: Element): void => {
wizard.dispatchEvent(newSubWizardEvent(() => createDaWizard(parent)!));
};
}

Expand Down
14 changes: 9 additions & 5 deletions src/editors/templates/enumtype-wizard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,25 @@ import {
getValue,
identity,
isPublic,
newActionEvent,
newSubWizardEvent,
newWizardEvent,
patterns,
Replace,
selector,
Wizard,
WizardAction,
WizardActor,
WizardInputElement,
WizardMenuActor,
} from '../../foundation.js';
import { CreateOptions, UpdateOptions, WizardOptions } from './foundation.js';

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

Expand Down Expand Up @@ -250,8 +254,8 @@ export function createEnumTypeWizard(
}

function openAddEnumVal(parent: Element): WizardMenuActor {
return (): WizardAction[] => {
return [() => eNumValWizard({ parent })];
return (wizard: Element): void => {
wizard.dispatchEvent(newSubWizardEvent(() => eNumValWizard({ parent })));
};
}

Expand Down
13 changes: 8 additions & 5 deletions src/editors/templates/lnodetype-wizard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ import {
getValue,
identity,
isPublic,
newActionEvent,
newSubWizardEvent,
newWizardEvent,
patterns,
Replace,
selector,
Wizard,
WizardAction,
WizardActor,
WizardInputElement,
WizardMenuActor,
Expand All @@ -44,14 +44,17 @@ import {
} from './foundation.js';

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

function openAddDo(parent: Element): WizardMenuActor {
return (): WizardAction[] => {
return [() => dOWizard({ parent })!];
return (wizard: Element): void => {
wizard.dispatchEvent(newSubWizardEvent(() => dOWizard({ parent })!));
};
}

Expand Down
2 changes: 1 addition & 1 deletion src/foundation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ interface WizardInputCheckbox extends WizardInputBase {
}

/** @returns [[`WizardAction`]]s to dispatch on [[`WizardDialog`]] menu action. */
export type WizardMenuActor = () => WizardAction[];
export type WizardMenuActor = (wizard: Element) => void;

/** User interactions rendered in the wizard-dialog menu */
export interface MenuAction {
Expand Down
18 changes: 4 additions & 14 deletions src/wizard-dialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ import {
identity,
WizardInput,
WizardMenuActor,
newSubWizardEvent,
} from './foundation.js';

function renderWizardInput(
Expand Down Expand Up @@ -214,20 +213,11 @@ export class WizardDialog extends LitElement {
return true;
}

/** Triggers sub-wizard or editor-action with valid manu action */
async menuAct(action?: WizardMenuActor): Promise<boolean> {
if (!action) return false;
/** Triggers menu action callback */
async menuAct(action?: WizardMenuActor): Promise<void> {
if (!action) return;

const wizardActions = action();

wizardActions.forEach(wa => {
if (isWizardFactory(wa)) this.dispatchEvent(newSubWizardEvent(wa));
else {
this.dispatchEvent(newWizardEvent());
this.dispatchEvent(newActionEvent(wa));
}
});
return true;
action(this);
}

private onClosed(ae: CustomEvent<{ action: string } | null>): void {
Expand Down
9 changes: 7 additions & 2 deletions src/wizards/bda.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import {
EditorAction,
getValue,
isPublic,
newActionEvent,
newWizardEvent,
Wizard,
WizardActor,
WizardInputElement,
Expand All @@ -16,8 +18,11 @@ import {
import { getValAction, wizardContent } from './abstractda.js';

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

Expand Down
9 changes: 7 additions & 2 deletions src/wizards/da.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import {
EditorAction,
getValue,
isPublic,
newActionEvent,
newWizardEvent,
Wizard,
WizardActor,
WizardInputElement,
Expand All @@ -21,8 +23,11 @@ import { getValAction, wizardContent } from './abstractda.js';
import { functionalConstraintEnum } from './foundation/enums.js';

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

Expand Down
5 changes: 3 additions & 2 deletions src/wizards/dataset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@ import {
WizardActor,
WizardInputElement,
WizardMenuActor,
newSubWizardEvent,
} from '../foundation.js';
import { createFCDAsWizard } from './fcda.js';

function openFcdaWizard(element: Element): WizardMenuActor {
return (): WizardAction[] => {
return [() => createFCDAsWizard(element)];
return (wizard: Element): void => {
wizard.dispatchEvent(newSubWizardEvent(() => createFCDAsWizard(element)));
};
}

Expand Down
17 changes: 9 additions & 8 deletions src/wizards/gsecontrol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@ import {
identity,
isPublic,
MenuAction,
newActionEvent,
newSubWizardEvent,
newWizardEvent,
selector,
Wizard,
WizardAction,
WizardActor,
WizardInputElement,
WizardMenuActor,
Expand Down Expand Up @@ -432,22 +433,22 @@ export function removeGseControlAction(element: Element): ComplexAction | null {
}

export function removeGseControl(element: Element): WizardMenuActor {
return (): WizardAction[] => {
return (wizard: Element): void => {
const complexAction = removeGseControlAction(element);
if (complexAction) return [complexAction];
return [];
if (complexAction) wizard.dispatchEvent(newActionEvent(complexAction));
wizard.dispatchEvent(newWizardEvent());
};
}

function openDataSetWizard(element: Element): WizardMenuActor {
return (): WizardAction[] => {
return [() => editDataSetWizard(element)];
return (wizard: Element): void => {
wizard.dispatchEvent(newSubWizardEvent(() => editDataSetWizard(element)));
};
}

function openGseWizard(element: Element): WizardMenuActor {
return (): WizardAction[] => {
return [() => editGseWizard(element)];
return (wizard: Element): void => {
wizard.dispatchEvent(newSubWizardEvent(() => editGseWizard(element)));
};
}

Expand Down
22 changes: 13 additions & 9 deletions src/wizards/ied.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ import {
EditorAction,
identity,
isPublic,
newActionEvent,
newSubWizardEvent,
newWizardEvent,
Wizard,
WizardAction,
WizardActor,
WizardInputElement,
WizardMenuActor
WizardMenuActor,
} from '../foundation.js';
import { patterns } from "./foundation/limits.js";
import { patterns } from './foundation/limits.js';

import { updateNamingAttributeWithReferencesAction } from "./foundation/actions.js";
import { deleteReferences } from "./foundation/references.js";
Expand Down Expand Up @@ -129,13 +130,16 @@ export function removeIEDWizard(element: Element): Wizard | null {

export function editIEDWizard(element: Element): Wizard {
function removeIED(element: Element): WizardMenuActor {
return (): WizardAction[] => {
const wizard = removeIEDWizard(element);
if (wizard) {
return [() => wizard];
}
return (wizard: Element): void => {
const removeWizard = removeIEDWizard(element);
if (removeWizard)
wizard.dispatchEvent(newSubWizardEvent(() => removeWizard));

// If no Wizard is needed, just remove the element.
return [{ old: { parent: element.parentElement!, element } }];
wizard.dispatchEvent(
newActionEvent({ old: { parent: element.parentElement!, element } })
);
wizard.dispatchEvent(newWizardEvent());
};
}

Expand Down
Loading