Skip to content

Commit b4c69c5

Browse files
refactor(foundation): make reference within editor-action optional (#325)
* refactor(foundation): change EditorAction api make reference optional * refactor(Editor): get reference onAction with undefined reference * test(Editing): add integration test * fix(lnodetype-wizard): fix getReference with addig LNodeType from template * refactor(templates): remove reference from create actions * refactor(communication): remove reference from create actions * refactor(substation): remove reference from create action * refactor(templates): remove reference from create action * refactor(communication mapping): remove reference from create action * refactor(iedimport): remove reference from create action
1 parent 81e1d3d commit b4c69c5

27 files changed

+300
-112
lines changed

src/Editing.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
Delete,
77
EditorAction,
88
EditorActionEvent,
9+
getReference,
910
isCreate,
1011
isDelete,
1112
isMove,
@@ -17,6 +18,7 @@ import {
1718
newLogEvent,
1819
newValidateEvent,
1920
OpenDocEvent,
21+
SCLTag,
2022
SimpleAction,
2123
Update,
2224
} from './foundation.js';
@@ -72,6 +74,12 @@ export function Editing<TBase extends LitElementConstructor>(Base: TBase) {
7274
private onCreate(action: Create) {
7375
if (!this.checkCreateValidity(action)) return false;
7476

77+
if (action.new.reference === undefined)
78+
action.new.reference = getReference(
79+
action.new.parent,
80+
<SCLTag>action.new.element.tagName
81+
);
82+
7583
action.new.parent.insertBefore(action.new.element, action.new.reference);
7684
return true;
7785
}
@@ -89,6 +97,9 @@ export function Editing<TBase extends LitElementConstructor>(Base: TBase) {
8997
}
9098

9199
private onDelete(action: Delete) {
100+
if (!action.old.reference)
101+
action.old.reference = action.old.element.nextSibling;
102+
92103
action.old.element.remove();
93104
return true;
94105
}
@@ -138,6 +149,15 @@ export function Editing<TBase extends LitElementConstructor>(Base: TBase) {
138149
private onMove(action: Move) {
139150
if (!this.checkMoveValidity(action)) return false;
140151

152+
if (!action.old.reference)
153+
action.old.reference = action.old.element.nextSibling;
154+
155+
if (action.new.reference === undefined)
156+
action.new.reference = getReference(
157+
action.new.parent,
158+
<SCLTag>action.old.element.tagName
159+
);
160+
141161
action.new.parent.insertBefore(action.old.element, action.new.reference);
142162
return true;
143163
}

src/editors/Communication.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import {
55
newWizardEvent,
66
newActionEvent,
77
createElement,
8-
getReference,
98
} from '../foundation.js';
109

1110
import { selectors, styles } from './communication/foundation.js';
@@ -25,7 +24,6 @@ export default class CommunicationPlugin extends LitElement {
2524
new: {
2625
parent: this.doc.documentElement,
2726
element: createElement(this.doc, 'Communication', {}),
28-
reference: getReference(this.doc.documentElement, 'Communication'),
2927
},
3028
})
3129
);

src/editors/Templates.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { translate } from 'lit-translate';
33

44
import {
55
createElement,
6-
getReference,
76
identity,
87
newActionEvent,
98
newWizardEvent,
@@ -127,10 +126,6 @@ export default class TemplatesPlugin extends LitElement {
127126
new: {
128127
parent: this.doc.documentElement,
129128
element: createElement(this.doc, 'DataTypeTemplates', {}),
130-
reference: getReference(
131-
this.doc.documentElement,
132-
'DataTypeTemplates'
133-
),
134129
},
135130
})
136131
);

src/editors/communication/connectedap-editor.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import {
2424
getValue,
2525
createElement,
2626
ComplexAction,
27-
getReference,
2827
} from '../../foundation.js';
2928

3029
import {
@@ -114,7 +113,6 @@ function createConnectedApAction(parent: Element): WizardActor {
114113
iedName: value.iedName,
115114
apName: value.apName,
116115
}),
117-
reference: getReference(parent, 'ConnectedAP'),
118116
},
119117
}
120118
);
@@ -225,7 +223,6 @@ export function editConnectedApAction(parent: Element): WizardActor {
225223
new: {
226224
parent: parent,
227225
element: newAddress,
228-
reference: getReference(parent, 'Address'),
229226
},
230227
});
231228

src/editors/communication/subnetwork-editor.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import {
2020
patterns,
2121
compareNames,
2222
createElement,
23-
getReference,
2423
cloneElement,
2524
} from '../../foundation.js';
2625

@@ -149,7 +148,6 @@ export function createSubNetworkAction(parent: Element): WizardActor {
149148
new: {
150149
parent,
151150
element,
152-
reference: getReference(parent, 'SubNetwork'),
153151
},
154152
};
155153

src/editors/substation/guess-wizard.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import {
88
compareNames,
99
createElement,
1010
EditorAction,
11-
getReference,
1211
Wizard,
1312
WizardActor,
1413
WizardInput,
@@ -205,7 +204,6 @@ function guessBasedOnCSWI(doc: XMLDocument): WizardActor {
205204
new: {
206205
parent: substation,
207206
element: voltageLevel,
208-
reference: getReference(substation, 'VoltageLevel'),
209207
},
210208
});
211209

src/editors/templates/datype-wizards.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,11 @@ import { get, translate } from 'lit-translate';
44
import {
55
Create,
66
EditorAction,
7-
getReference,
87
getValue,
98
identity,
109
newActionEvent,
1110
newWizardEvent,
1211
patterns,
13-
SCLTag,
1412
selector,
1513
Wizard,
1614
WizardActor,
@@ -167,7 +165,6 @@ function addPredefinedDAType(
167165
new: {
168166
parent,
169167
element,
170-
reference: getReference(parent, <SCLTag>element.tagName),
171168
},
172169
});
173170

src/editors/templates/dotype-wizards.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,11 @@ import {
66
Create,
77
createElement,
88
EditorAction,
9-
getReference,
109
getValue,
1110
identity,
1211
isPublic,
1312
newActionEvent,
1413
newWizardEvent,
15-
SCLTag,
1614
selector,
1715
Wizard,
1816
WizardActor,
@@ -74,7 +72,6 @@ function createSDoAction(parent: Element): WizardActor {
7472
new: {
7573
parent,
7674
element,
77-
reference: getReference(parent, <SCLTag>element.tagName),
7875
},
7976
});
8077

@@ -216,7 +213,6 @@ function addPredefinedDOType(
216213
new: {
217214
parent,
218215
element,
219-
reference: getReference(parent, <SCLTag>element.tagName),
220216
},
221217
});
222218

src/editors/templates/enumtype-wizard.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,12 @@ import {
55
cloneElement,
66
createElement,
77
EditorAction,
8-
getReference,
98
getValue,
109
identity,
1110
isPublic,
1211
newActionEvent,
1312
newWizardEvent,
1413
patterns,
15-
SCLTag,
1614
selector,
1715
Wizard,
1816
WizardActor,
@@ -57,7 +55,6 @@ function createEnumValAction(parent: Element): WizardActor {
5755
new: {
5856
parent,
5957
element,
60-
reference: getReference(parent, 'EnumVal'),
6158
},
6259
};
6360

@@ -195,7 +192,6 @@ function createAction(parent: Element, templates: XMLDocument): WizardActor {
195192
new: {
196193
parent,
197194
element,
198-
reference: getReference(parent, <SCLTag>element.tagName),
199195
},
200196
};
201197

src/editors/templates/foundation.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@ import {
55
cloneElement,
66
Create,
77
EditorAction,
8-
getReference,
98
getValue,
109
isPublic,
11-
SCLTag,
1210
WizardActor,
1311
WizardInput,
1412
} from '../../foundation.js';
@@ -98,7 +96,6 @@ export function addReferencedDataTypes(
9896
new: {
9997
parent,
10098
element: <Element>adjacent.cloneNode(true),
101-
reference: getReference(parent, <SCLTag>adjacent.tagName),
10299
},
103100
});
104101
});

0 commit comments

Comments
 (0)