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

feat(wizards/dataset): remove unselected FCDA with update action #358

Merged
merged 3 commits into from
Nov 8, 2021
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
12 changes: 12 additions & 0 deletions __snapshots__/dataset wizards.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
aria-disabled="false"
graphic="control"
mwc-list-item=""
selected=""
tabindex="0"
value="IED2>>CBSW>GooseDataSet1>CBSW/ XSWI 2.Pos stVal (ST)"
>
Expand All @@ -44,11 +45,22 @@
aria-disabled="false"
graphic="control"
mwc-list-item=""
selected=""
tabindex="-1"
value="IED2>>CBSW>GooseDataSet1>CBSW/ XSWI 2.Pos q (ST)"
>
CBSW/ XSWI 2.Pos q (ST)
</mwc-check-list-item>
<mwc-check-list-item
aria-disabled="false"
graphic="control"
mwc-list-item=""
selected=""
tabindex="-1"
value="IED2>>CBSW>GooseDataSet1>CBSW/ XSWI 2.OpSlc.dsd sasd.ads.asd (ST)"
>
CBSW/ XSWI 2.OpSlc.dsd sasd.ads.asd (ST)
</mwc-check-list-item>
</filtered-list>
</div>
<mwc-button
Expand Down
2 changes: 1 addition & 1 deletion src/foundation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,7 @@ function fCDASelector(tagName: SCLTag, identity: string): string {
const [ldInst, prefix, lnClass, lnInst] = childIdentity.split(/[ /.]/);

const matchDoDa = childIdentity.match(
/.([A-Z][a-z0-9.]*) ([A-Za-z0-9.]*) \(/
/.([A-Z][A-Za-z0-9.]*) ([A-Za-z0-9.]*) \(/
);
const doName = matchDoDa && matchDoDa[1] ? matchDoDa[1] : '';
const daName = matchDoDa && matchDoDa[2] ? matchDoDa[2] : '';
Expand Down
52 changes: 40 additions & 12 deletions src/wizards/dataset.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { CheckListItem } from '@material/mwc-list/mwc-check-list-item';
import { html } from 'lit-element';
import { get, translate } from 'lit-translate';

Expand All @@ -6,40 +7,67 @@ import {
getValue,
identity,
newWizardEvent,
selector,
Update,
Wizard,
WizardAction,
WizardActor,
WizardInput,
} from '../foundation.js';
import { wizards } from './wizard-library.js';

export function updateDataSetAction(element: Element): WizardActor {
return (inputs: WizardInput[]): WizardAction[] => {
function updateDataSetAction(element: Element): WizardActor {
return (inputs: WizardInput[], wizard: Element): WizardAction[] => {
const name = inputs.find(i => i.label === 'name')!.value!;
const desc = getValue(inputs.find(i => i.label === 'desc')!);

const oldName = element.getAttribute('name');
if (name === oldName && desc === element.getAttribute('desc')) return [];

const newElement = cloneElement(element, { name, desc });
const dataSetUpdateAction: Update[] = [];
if (!(name === oldName && desc === element.getAttribute('desc'))) {
const newElement = cloneElement(element, { name, desc });

const dataSetUpdateAction = [
{ old: { element }, new: { element: newElement } },
];
dataSetUpdateAction.push({
old: { element },
new: { element: newElement },
});
}

const cbUpdateAction =
const controlBlockUpdateActions =
name !== oldName
? Array.from(
element.parentElement?.querySelectorAll(
`ReportControlBock[datSet=${oldName}], GSEControl[datSet=${oldName}],SampledValueControl[datSet=${oldName}] `
) ?? []
).map(cb => {
const newCb = cloneElement(element, { datSet: name });
const newCb = cloneElement(cb, { datSet: name });
return { old: { element: cb }, new: { element: newCb } };
})
: [];

return dataSetUpdateAction.concat(cbUpdateAction);
const fCDARemoveActions = Array.from(
wizard.shadowRoot!.querySelectorAll(
'filtered-list > mwc-check-list-item:not([selected])'
)
)
.map(listItem =>
element.querySelector(selector('FCDA', (<CheckListItem>listItem).value))
)
.filter(fcda => fcda)
.map(fcda => {
return {
old: {
parent: element,
element: fcda!,
reference: fcda!.nextSibling,
},
};
});

return [
...fCDARemoveActions,
...dataSetUpdateAction,
...controlBlockUpdateActions,
];
};
}

Expand Down Expand Up @@ -86,7 +114,7 @@ export function editDataSetWizard(element: Element): Wizard {
html`<filtered-list multi
>${Array.from(element.querySelectorAll('FCDA')).map(
fcda =>
html`<mwc-check-list-item value="${identity(fcda)}"
html`<mwc-check-list-item selected value="${identity(fcda)}"
>${(<string>identity(fcda)).split('>')[4]}</mwc-check-list-item
>`
)}</filtered-list
Expand Down
1 change: 1 addition & 0 deletions test/testfiles/wizards/gsecontrol.scd
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@
<DataSet name="GooseDataSet1">
<FCDA ldInst="CBSW" prefix="" lnClass="XSWI" lnInst="2" doName="Pos" daName="stVal" fc="ST"/>
<FCDA ldInst="CBSW" prefix="" lnClass="XSWI" lnInst="2" doName="Pos" daName="q" fc="ST"/>
<FCDA ldInst="CBSW" prefix="" lnClass="XSWI" lnInst="2" doName="OpSlc.dsd" daName="sasd.ads.asd" fc="ST"/>
</DataSet>
<GSEControl type="GOOSE" appID="0002" fixedOffs="false" confRev="1" name="GCB" datSet="GooseDataSet1">
</GSEControl>
Expand Down
Loading