Skip to content

Commit 32d7629

Browse files
refactor(wizards/gsecontrol): remove button from wizard content (openscd#624)
1 parent 96d79e5 commit 32d7629

File tree

5 files changed

+139
-84
lines changed

5 files changed

+139
-84
lines changed

src/wizards/gsecontrol.ts

Lines changed: 46 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,14 @@ import {
1919
getValue,
2020
identity,
2121
isPublic,
22-
newActionEvent,
22+
MenuAction,
2323
newSubWizardEvent,
24-
newWizardEvent,
2524
selector,
2625
Wizard,
26+
WizardAction,
2727
WizardActor,
2828
WizardInput,
29+
WizardMenuActor,
2930
} from '../foundation.js';
3031
import { maxLength, patterns } from './foundation/limits.js';
3132
import { editDataSetWizard } from './dataset.js';
@@ -107,7 +108,7 @@ export function renderGseAttributes(
107108
];
108109
}
109110

110-
export function removeGseControl(element: Element): ComplexAction | null {
111+
export function removeGseControlAction(element: Element): ComplexAction | null {
111112
if (!element.parentElement) return null;
112113

113114
const dataSet = element.parentElement.querySelector(
@@ -166,6 +167,26 @@ export function removeGseControl(element: Element): ComplexAction | null {
166167
};
167168
}
168169

170+
export function removeGseControl(element: Element): WizardMenuActor {
171+
return (): WizardAction[] => {
172+
const complexAction = removeGseControlAction(element);
173+
if (complexAction) return [complexAction];
174+
return [];
175+
};
176+
}
177+
178+
function openDataSetWizard(element: Element): WizardMenuActor {
179+
return (): WizardAction[] => {
180+
return [() => editDataSetWizard(element)];
181+
};
182+
}
183+
184+
function openGseWizard(element: Element): WizardMenuActor {
185+
return (): WizardAction[] => {
186+
return [() => editGseWizard(element)];
187+
};
188+
}
189+
169190
export function updateGseControlAction(element: Element): WizardActor {
170191
return (inputs: WizardInput[]): EditorAction[] => {
171192
const name = inputs.find(i => i.label === 'name')!.value!;
@@ -214,6 +235,27 @@ export function editGseControlWizard(element: Element): Wizard {
214235
`DataSet[name="${element.getAttribute('datSet')}"]`
215236
);
216237

238+
const menuActions: MenuAction[] = [];
239+
menuActions.push({
240+
icon: 'delete',
241+
label: get('remove'),
242+
action: removeGseControl(element),
243+
});
244+
245+
if (dataSet)
246+
menuActions.push({
247+
icon: 'edit',
248+
label: get('scl.DataSet'),
249+
action: openDataSetWizard(dataSet),
250+
});
251+
252+
if (gSE)
253+
menuActions.push({
254+
icon: 'edit',
255+
label: get('scl.Communication'),
256+
action: openGseWizard(gSE),
257+
});
258+
217259
return [
218260
{
219261
title: get('wizard.title.edit', { tagName: element.tagName }),
@@ -223,18 +265,8 @@ export function editGseControlWizard(element: Element): Wizard {
223265
label: get('save'),
224266
action: updateGseControlAction(element),
225267
},
268+
menuActions,
226269
content: [
227-
html`<mwc-button
228-
label="${translate('remove')}"
229-
icon="delete"
230-
@click=${(e: MouseEvent) => {
231-
const complexAction = removeGseControl(element);
232-
if (complexAction)
233-
e.target?.dispatchEvent(newActionEvent(complexAction));
234-
235-
e.target?.dispatchEvent(newWizardEvent());
236-
}}
237-
></mwc-button>`,
238270
...renderGseAttributes(
239271
name,
240272
desc,
@@ -243,32 +275,6 @@ export function editGseControlWizard(element: Element): Wizard {
243275
fixedOffs,
244276
securityEnabled
245277
),
246-
dataSet
247-
? html`<mwc-button
248-
id="editdataset"
249-
label=${translate('wizard.title.edit', {
250-
tagName: get('scl.DataSet'),
251-
})}
252-
icon="edit"
253-
@click="${(e: MouseEvent) => {
254-
e.target?.dispatchEvent(
255-
newSubWizardEvent(() => editDataSetWizard(dataSet))
256-
);
257-
}}}"
258-
></mwc-button>`
259-
: html``,
260-
gSE
261-
? html`<mwc-button
262-
id="editgse"
263-
label=${translate('scl.Communication')}
264-
icon="edit"
265-
@click="${(e: MouseEvent) => {
266-
e.target?.dispatchEvent(
267-
newSubWizardEvent(() => editGseWizard(gSE))
268-
);
269-
}}}"
270-
></mwc-button>`
271-
: html``,
272278
],
273279
},
274280
];

test/integration/wizards/gsecontrolwizarding-editing.test.ts

Lines changed: 37 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { expect, fixture, html } from '@open-wc/testing';
33
import '../../mock-wizard-editor.js';
44
import { MockWizardEditor } from '../../mock-wizard-editor.js';
55

6-
import { Button } from '@material/mwc-button';
76
import { ListItemBase } from '@material/mwc-list/mwc-list-item-base';
87

98
import {
@@ -166,13 +165,15 @@ describe('Wizards for SCL element GSEControl', () => {
166165
});
167166

168167
it('opens edit wizard for DataSet element on edit dataset button click', async () => {
169-
const editDataSetButton = <Button>(
170-
element.wizardUI.dialog!.querySelector(
171-
'mwc-button[id="editdataset"]'
172-
)!
168+
const editDataSetButton = <HTMLElement>(
169+
Array.from(
170+
element.wizardUI.dialog!.querySelectorAll<ListItemBase>(
171+
'mwc-menu > mwc-list-item'
172+
)
173+
).find(item => item.innerHTML.includes(`[scl.DataSet]`))
173174
);
174175

175-
await editDataSetButton.updateComplete;
176+
await element.wizardUI.dialog?.requestUpdate();
176177
editDataSetButton.click();
177178
await new Promise(resolve => setTimeout(resolve, 100)); // await animation
178179

@@ -189,12 +190,15 @@ describe('Wizards for SCL element GSEControl', () => {
189190
});
190191

191192
it('opens a editGseWizard on edit GSE button click', async () => {
192-
const editGseButton = <Button>(
193-
element.wizardUI.dialog!.querySelector('mwc-button[id="editgse"]')!
193+
const editGseButton = <HTMLElement>(
194+
Array.from(
195+
element.wizardUI.dialog!.querySelectorAll<ListItemBase>(
196+
'mwc-menu > mwc-list-item'
197+
)
198+
).find(item => item.innerHTML.includes(`[scl.Communication]`))
194199
);
195-
expect(editGseButton).to.exist;
196200

197-
await editGseButton.updateComplete;
201+
await element.wizardUI.dialog?.requestUpdate();
198202
editGseButton.click();
199203
await new Promise(resolve => setTimeout(resolve, 100)); // await animation
200204
const macField = <WizardTextField>(
@@ -217,11 +221,17 @@ describe('Wizards for SCL element GSEControl', () => {
217221
doc.querySelector('IED[name="IED1"] DataSet[name="GooseDataSet1"]')
218222
).to.exist;
219223
expect(doc.querySelector('GSE[cbName="GCB"]')).to.exist;
220-
const deleteButton = <Button>(
221-
element.wizardUI.dialog!.querySelector('mwc-button[icon="delete"]')!
224+
225+
const deleteButton = <HTMLElement>(
226+
Array.from(
227+
element.wizardUI.dialog!.querySelectorAll<ListItemBase>(
228+
'mwc-menu > mwc-list-item'
229+
)
230+
).find(item => item.innerHTML.includes(`[remove]`))
222231
);
223-
await deleteButton.updateComplete;
232+
await element.wizardUI.dialog?.requestUpdate();
224233
deleteButton.click();
234+
225235
expect(doc.querySelector('IED[name="IED1"] GSEControl[name="GCB"]')).to
226236
.not.exist;
227237
expect(
@@ -240,11 +250,14 @@ describe('Wizards for SCL element GSEControl', () => {
240250
});
241251

242252
it('does not show edit DataSet button', async () => {
243-
const editGseButton = <Button>(
244-
element.wizardUI.dialog!.querySelector(
245-
'mwc-button[id="editdataset"]'
246-
)!
253+
const editGseButton = <HTMLElement>(
254+
Array.from(
255+
element.wizardUI.dialog!.querySelectorAll<ListItemBase>(
256+
'mwc-menu > mwc-list-item'
257+
)
258+
).find(item => item.innerHTML.includes(`[scl.DataSet]`))
247259
);
260+
248261
expect(editGseButton).to.not.exist;
249262
});
250263
});
@@ -260,9 +273,14 @@ describe('Wizards for SCL element GSEControl', () => {
260273
});
261274

262275
it('does not show edit DataSet button', async () => {
263-
const editGseButton = <Button>(
264-
element.wizardUI.dialog!.querySelector('mwc-button[id="editgse"]')!
276+
const editGseButton = <HTMLElement>(
277+
Array.from(
278+
element.wizardUI.dialog!.querySelectorAll<ListItemBase>(
279+
'mwc-menu > mwc-list-item'
280+
)
281+
).find(item => item.innerHTML.includes(`[scl.Communication]`))
265282
);
283+
266284
expect(editGseButton).to.not.exist;
267285
});
268286
});

test/integration/wizards/reportcontrol-wizarding-editing.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { expect, fixture, html } from '@open-wc/testing';
33
import '../../mock-wizard-editor.js';
44
import { MockWizardEditor } from '../../mock-wizard-editor.js';
55

6-
import { Button } from '@material/mwc-button';
76
import { ListItemBase } from '@material/mwc-list/mwc-list-item-base';
87

98
import { FilteredList } from '../../../src/filtered-list.js';

test/unit/wizards/__snapshots__/gsecontrol.test.snap.js

Lines changed: 49 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -174,12 +174,56 @@ snapshots["gsecontrol wizards editGseControlWizard looks like the latest snapsho
174174
heading="[wizard.title.edit]"
175175
open=""
176176
>
177-
<div id="wizard-content">
178-
<mwc-button
179-
icon="delete"
180-
label="[remove]"
177+
<nav>
178+
<mwc-icon-button icon="more_vert">
179+
</mwc-icon-button>
180+
<mwc-menu
181+
class="actions-menu"
182+
corner="BOTTOM_RIGHT"
183+
menucorner="END"
181184
>
182-
</mwc-button>
185+
<mwc-list-item
186+
aria-disabled="false"
187+
graphic="icon"
188+
mwc-list-item=""
189+
tabindex="-1"
190+
>
191+
<span>
192+
[remove]
193+
</span>
194+
<mwc-icon slot="graphic">
195+
delete
196+
</mwc-icon>
197+
</mwc-list-item>
198+
<mwc-list-item
199+
aria-disabled="false"
200+
graphic="icon"
201+
mwc-list-item=""
202+
tabindex="-1"
203+
>
204+
<span>
205+
[scl.DataSet]
206+
</span>
207+
<mwc-icon slot="graphic">
208+
edit
209+
</mwc-icon>
210+
</mwc-list-item>
211+
<mwc-list-item
212+
aria-disabled="false"
213+
graphic="icon"
214+
mwc-list-item=""
215+
tabindex="-1"
216+
>
217+
<span>
218+
[scl.Communication]
219+
</span>
220+
<mwc-icon slot="graphic">
221+
edit
222+
</mwc-icon>
223+
</mwc-list-item>
224+
</mwc-menu>
225+
</nav>
226+
<div id="wizard-content">
183227
<wizard-textfield
184228
dialoginitialfocus=""
185229
helper="[scl.name]"
@@ -265,18 +309,6 @@ snapshots["gsecontrol wizards editGseControlWizard looks like the latest snapsho
265309
SignatureAndEncryption
266310
</mwc-list-item>
267311
</wizard-select>
268-
<mwc-button
269-
icon="edit"
270-
id="editdataset"
271-
label="[wizard.title.edit]"
272-
>
273-
</mwc-button>
274-
<mwc-button
275-
icon="edit"
276-
id="editgse"
277-
label="[scl.Communication]"
278-
>
279-
</mwc-button>
280312
</div>
281313
<mwc-button
282314
dialogaction="close"

test/unit/wizards/gsecontrol.test.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
} from '../../../src/foundation.js';
1616
import {
1717
editGseControlWizard,
18-
removeGseControl,
18+
removeGseControlAction,
1919
renderGseAttributes,
2020
selectGseControlWizard,
2121
updateGseControlAction,
@@ -149,7 +149,7 @@ describe('gsecontrol wizards', () => {
149149

150150
it('removes GSEControl and its refereced DataSet if no other GSEControl are aasinged', () => {
151151
const gseControl = ln01gse.querySelector('GSEControl')!;
152-
const actions = <Delete[]>removeGseControl(gseControl)!.actions;
152+
const actions = <Delete[]>removeGseControlAction(gseControl)!.actions;
153153
expect(actions.length).to.equal(2);
154154
expect(actions[0]).to.satisfy(isDelete);
155155
expect(actions[0].old.element).to.equal(gseControl);
@@ -159,36 +159,36 @@ describe('gsecontrol wizards', () => {
159159

160160
it('removes GSEControl only if other GSEControl is assinged to the same DataSet', () => {
161161
const gseControl = ln02gse.querySelector('GSEControl')!;
162-
const actions = <Delete[]>removeGseControl(gseControl)!.actions;
162+
const actions = <Delete[]>removeGseControlAction(gseControl)!.actions;
163163
expect(actions.length).to.equal(1);
164164
expect(actions[0]).to.satisfy(isDelete);
165165
expect(actions[0].old.element).to.equal(gseControl);
166166
});
167167

168168
it('removes GSEControl only if other ReportControlBlock is assinged to the same DataSet', () => {
169169
const gseControl = ln02rp.querySelector('GSEControl')!;
170-
const actions = <Delete[]>removeGseControl(gseControl)!.actions;
170+
const actions = <Delete[]>removeGseControlAction(gseControl)!.actions;
171171
expect(actions.length).to.equal(1);
172172
expect(actions[0]).to.satisfy(isDelete);
173173
expect(actions[0].old.element).to.equal(gseControl);
174174
});
175175

176176
it('removes GSEControl only if other SMV is assinged to the same DataSet', () => {
177177
const gseControl = ln02smv.querySelector('GSEControl')!;
178-
const actions = <Delete[]>removeGseControl(gseControl)!.actions;
178+
const actions = <Delete[]>removeGseControlAction(gseControl)!.actions;
179179
expect(actions.length).to.equal(1);
180180
expect(actions[0]).to.satisfy(isDelete);
181181
expect(actions[0].old.element).to.equal(gseControl);
182182
});
183183

184184
it('does not remove with missing parent element', () => {
185-
const action = removeGseControl(missingparent);
185+
const action = removeGseControlAction(missingparent);
186186
expect(action).to.be.null;
187187
});
188188

189189
it('removes GSE element if present in the Communication section', () => {
190190
const gseControl = doc.querySelector('IED[name="IED1"] GSEControl')!;
191-
const actions = <Delete[]>removeGseControl(gseControl)!.actions;
191+
const actions = <Delete[]>removeGseControlAction(gseControl)!.actions;
192192
expect(actions.length).to.equal(3);
193193
expect(actions[0]).to.satisfy(isDelete);
194194
expect(actions[0].old.element).to.equal(gseControl);

0 commit comments

Comments
 (0)