Skip to content

Commit 104b245

Browse files
committed
fix(tLN): make supervision removal remove Val textContent instead of DOI (closes #129)
1 parent 0ce54df commit 104b245

File tree

3 files changed

+28
-16
lines changed

3 files changed

+28
-16
lines changed

tDataSet/removeDataSet.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@ describe("Utility function to remove DataSet element", () => {
1818
'ExtRef[srcCBName="someGse"], ExtRef[srcCBName="someGse2"], ExtRef[srcCBName="someGse3"]',
1919
),
2020
);
21-
const doi = extRefs[0].ownerDocument.querySelector(
22-
'LN[lnClass="LGOS"][inst="1"] > DOI',
21+
const val = extRefs[0].ownerDocument.querySelector(
22+
'LN[lnClass="LGOS"][inst="1"] > DOI[name="GoCBRef"] > DAI[name="setSrcRef"] > Val',
2323
)!;
2424
const ln = extRefs[0].ownerDocument.querySelector(
2525
'LN[lnClass="LGOS"][inst="2"]',
2626
);
2727

2828
it("returns empty string when remove.node is not DataSet", () =>
29-
expect(removeDataSet({ node: doi })).to.be.empty);
29+
expect(removeDataSet({ node: val })).to.be.empty);
3030

3131
it("removes DataSet also removes/updates dependant data", () =>
3232
expect(edits.length).to.equal(10));
@@ -42,7 +42,7 @@ describe("Utility function to remove DataSet element", () => {
4242
});
4343

4444
it("including the subscriber supervision", () => {
45-
expect((edits[5] as Remove).node).to.equal(doi);
45+
expect((edits[5] as Remove).node).to.equal(val.firstChild);
4646
expect((edits[6] as Remove).node).to.equal(ln);
4747
});
4848

tExtRef/unsubscribe.spec.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ describe("Function allowing to unsubscribe multiple external references", () =>
9292
'ExtRef[srcCBName="someGse"], ExtRef[srcCBName="someGse2"]',
9393
);
9494
const edits = unsubscribe(extRefs);
95-
const doi = extRefs[0].ownerDocument.querySelector(
96-
'LN[lnClass="LGOS"][inst="1"] > DOI',
95+
const val = extRefs[0].ownerDocument.querySelector(
96+
'LN[lnClass="LGOS"][inst="1"] > DOI[name="GoCBRef"] > DAI[name="setSrcRef"] > Val',
9797
);
9898
const ln = extRefs[0].ownerDocument.querySelector(
9999
'LN[lnClass="LGOS"][inst="2"]',
@@ -107,7 +107,7 @@ describe("Function allowing to unsubscribe multiple external references", () =>
107107
expect(edits[2]).to.satisfies(isUpdate);
108108
expect((edits[2] as Update).element).to.equal(extRefs[2]);
109109
expect(edits[3]).to.satisfies(isRemove);
110-
expect((edits[3] as Remove).node).to.equal(doi);
110+
expect((edits[3] as Remove).node).to.equal(val.firstChild);
111111
expect(edits[4]).to.satisfies(isRemove);
112112
expect((edits[4] as Remove).node).to.equal(ln);
113113
});
@@ -157,8 +157,8 @@ describe("Function allowing to unsubscribe multiple external references", () =>
157157
withSubscriptionSupervision,
158158
'ExtRef[srcCBName="someSmv"]',
159159
);
160-
const doi = extRefs[0].ownerDocument.querySelector(
161-
'LN[lnClass="LSVS"][inst="1"] > DOI',
160+
const val = extRefs[0].ownerDocument.querySelector(
161+
'LN[lnClass="LSVS"][inst="1"] > DOI[name="SvCBRef"] > DAI[name="setSrcRef"] > Val',
162162
);
163163
const edits = unsubscribe(extRefs);
164164

@@ -170,7 +170,7 @@ describe("Function allowing to unsubscribe multiple external references", () =>
170170
expect(edits[2]).to.satisfies(isRemove);
171171
expect((edits[2] as Remove).node).to.equal(extRefs[1].parentElement);
172172
expect(edits[3]).to.satisfies(isRemove);
173-
expect((edits[3] as Remove).node).to.equal(doi);
173+
expect((edits[3] as Remove).node).to.equal(val!.firstChild);
174174
});
175175

176176
it("with ignoreSupervision do not remove subscription LGOS supervision", () => {

tLN/removeSubscriptionSupervision.ts

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,29 @@ type GroupedExtRefs = {
1414
function removableSupervisionElement(
1515
ctrlBlock: Element,
1616
subscriberIed: Element,
17-
): Element | null {
17+
): Node | Element | null {
1818
const supervisionType = ctrlBlock.tagName === "GSEControl" ? "LGOS" : "LSVS";
19+
const doiName = ctrlBlock.tagName === "GSEControl" ? "GoCBRef" : "SvCBRef";
1920

2021
const valElement = Array.from(
2122
subscriberIed.querySelectorAll(
22-
`LN[lnClass="${supervisionType}"] > DOI > DAI > Val`,
23+
`LN[lnClass="${supervisionType}"] > DOI[name="${doiName}"] > DAI[name="setSrcRef"] > Val`,
2324
),
2425
).find((val) => val.textContent === controlBlockObjRef(ctrlBlock));
2526
if (!valElement) return null;
2627

2728
const ln = valElement.closest("LN")!;
28-
const doi = valElement.closest("DOI")!;
29-
3029
// do not remove logical nodes `LGOS`, `LSVS` unless privately tagged
3130
const canRemoveLn = ln.querySelector(
3231
':scope > Private[type="OpenSCD.create"]',
3332
);
33+
if (canRemoveLn) return ln;
3434

35-
return canRemoveLn ? ln : doi;
35+
return (
36+
Array.from(valElement.childNodes).find(
37+
(child: Node) => child.nodeType === Node.TEXT_NODE,
38+
) ?? null
39+
);
3640
}
3741

3842
/** @returns Whether `DA` with name `setSrcRef` can edited by SCL editor */
@@ -44,7 +48,15 @@ function isSupervisionEditable(
4448
ctrlBlock,
4549
subscriberIed,
4650
);
47-
const supervisionLn = supervisionElement?.closest("LN") ?? null;
51+
if (!supervisionElement) return false;
52+
53+
let supervisionLn: Element | null = null;
54+
55+
if (supervisionElement.nodeType === Node.TEXT_NODE) {
56+
supervisionLn = supervisionElement.parentElement?.closest("LN") ?? null;
57+
} else {
58+
supervisionLn = (supervisionElement as Element).closest("LN") ?? null;
59+
}
4860
if (!supervisionLn) return false;
4961

5062
return isSrcRefEditable(supervisionLn);

0 commit comments

Comments
 (0)