From b1ab12c3915f0da0c8fa2dfd5cd5db7bbddd8256 Mon Sep 17 00:00:00 2001 From: Jakob Vogelsang Date: Mon, 21 Mar 2022 10:04:13 +0100 Subject: [PATCH] refactor(wizards/gsecontrol): remove button from wizard content --- src/wizards/gsecontrol.ts | 86 ++++++++++--------- .../gsecontrolwizarding-editing.test.ts | 56 ++++++++---- .../reportcontrol-wizarding-editing.test.ts | 1 - .../__snapshots__/gsecontrol.test.snap.js | 66 ++++++++++---- test/unit/wizards/gsecontrol.test.ts | 14 +-- 5 files changed, 139 insertions(+), 84 deletions(-) diff --git a/src/wizards/gsecontrol.ts b/src/wizards/gsecontrol.ts index edab6d0e5d..29fe089564 100644 --- a/src/wizards/gsecontrol.ts +++ b/src/wizards/gsecontrol.ts @@ -19,13 +19,14 @@ import { getValue, identity, isPublic, - newActionEvent, + MenuAction, newSubWizardEvent, - newWizardEvent, selector, Wizard, + WizardAction, WizardActor, WizardInput, + WizardMenuActor, } from '../foundation.js'; import { maxLength, patterns } from './foundation/limits.js'; import { editDataSetWizard } from './dataset.js'; @@ -107,7 +108,7 @@ export function renderGseAttributes( ]; } -export function removeGseControl(element: Element): ComplexAction | null { +export function removeGseControlAction(element: Element): ComplexAction | null { if (!element.parentElement) return null; const dataSet = element.parentElement.querySelector( @@ -166,6 +167,26 @@ export function removeGseControl(element: Element): ComplexAction | null { }; } +export function removeGseControl(element: Element): WizardMenuActor { + return (): WizardAction[] => { + const complexAction = removeGseControlAction(element); + if (complexAction) return [complexAction]; + return []; + }; +} + +function openDataSetWizard(element: Element): WizardMenuActor { + return (): WizardAction[] => { + return [() => editDataSetWizard(element)]; + }; +} + +function openGseWizard(element: Element): WizardMenuActor { + return (): WizardAction[] => { + return [() => editGseWizard(element)]; + }; +} + export function updateGseControlAction(element: Element): WizardActor { return (inputs: WizardInput[]): EditorAction[] => { const name = inputs.find(i => i.label === 'name')!.value!; @@ -214,6 +235,27 @@ export function editGseControlWizard(element: Element): Wizard { `DataSet[name="${element.getAttribute('datSet')}"]` ); + const menuActions: MenuAction[] = []; + menuActions.push({ + icon: 'delete', + label: get('remove'), + action: removeGseControl(element), + }); + + if (dataSet) + menuActions.push({ + icon: 'edit', + label: get('scl.DataSet'), + action: openDataSetWizard(dataSet), + }); + + if (gSE) + menuActions.push({ + icon: 'edit', + label: get('scl.Communication'), + action: openGseWizard(gSE), + }); + return [ { title: get('wizard.title.edit', { tagName: element.tagName }), @@ -223,18 +265,8 @@ export function editGseControlWizard(element: Element): Wizard { label: get('save'), action: updateGseControlAction(element), }, + menuActions, content: [ - html` { - const complexAction = removeGseControl(element); - if (complexAction) - e.target?.dispatchEvent(newActionEvent(complexAction)); - - e.target?.dispatchEvent(newWizardEvent()); - }} - >`, ...renderGseAttributes( name, desc, @@ -243,32 +275,6 @@ export function editGseControlWizard(element: Element): Wizard { fixedOffs, securityEnabled ), - dataSet - ? html`` - : html``, - gSE - ? html`` - : html``, ], }, ]; diff --git a/test/integration/wizards/gsecontrolwizarding-editing.test.ts b/test/integration/wizards/gsecontrolwizarding-editing.test.ts index 19ac859fdb..882dcb1e5b 100644 --- a/test/integration/wizards/gsecontrolwizarding-editing.test.ts +++ b/test/integration/wizards/gsecontrolwizarding-editing.test.ts @@ -3,7 +3,6 @@ import { expect, fixture, html } from '@open-wc/testing'; import '../../mock-wizard-editor.js'; import { MockWizardEditor } from '../../mock-wizard-editor.js'; -import { Button } from '@material/mwc-button'; import { ListItemBase } from '@material/mwc-list/mwc-list-item-base'; import { @@ -166,13 +165,15 @@ describe('Wizards for SCL element GSEControl', () => { }); it('opens edit wizard for DataSet element on edit dataset button click', async () => { - const editDataSetButton =