Skip to content

Commit

Permalink
feat: Fix self reference bug
Browse files Browse the repository at this point in the history
  • Loading branch information
clepski committed Oct 28, 2024
1 parent 41cf660 commit 70ddafb
Show file tree
Hide file tree
Showing 10 changed files with 13 additions and 84 deletions.
10 changes: 10 additions & 0 deletions packages/openscd/src/addons/Editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,16 @@ function handleInsert({
}: Insert): Insert | Remove | [] {
try {
const { parentNode, nextSibling } = node;

/**
* This is a workaround for converted edit api v1 events,
* because if multiple edits are converted, they are converted before the changes from the previous edits are applied to the document
* so if you first remove an element and then add a clone with changed attributes, the reference will be the element to remove since it hasnt been removed yet
*/
if (!parent.contains(reference)) {
reference = null;
}

parent.insertBefore(node, reference);
if (parentNode)
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ describe('connectedap-editor wizarding editing integration', () => {
.then(str => new DOMParser().parseFromString(str, 'application/xml'));
parent = <MockWizardEditor>(
await fixture(
html`<mock-wizard-editor
html`<mock-wizard-editor .doc=${doc}
><connectedap-editor
.element=${doc.querySelector(
'SubNetwork[name="StationBus"] > ConnectedAP'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,6 @@ describe('subnetwork-editor wizarding editing integration', () => {
expect(parent.wizardUI.dialog).to.not.exist;
});

it('does not change name attribute if not unique within parent element', async () => {
const oldName = nameField.value;
nameField.value = 'ProcessBus';
primaryAction.click();
await parent.updateComplete;
expect(doc.querySelector('SubNetwork')?.getAttribute('name')).to.equal(
oldName
);
});

it('changes name attribute on primary action', async () => {
nameField.value = 'newSubNetwork';
primaryAction.click();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,6 @@ describe('bay-editor wizarding editing integration', () => {
await new Promise(resolve => setTimeout(resolve, 100)); // await animation
expect(parent.wizardUI.dialog).to.not.exist;
});
it('does not change name attribute if not unique within parent element', async () => {
const oldName = nameField.value;
nameField.value = 'Bay2';
primaryAction.click();
await parent.updateComplete;
expect(doc.querySelector('Bay')?.getAttribute('name')).to.equal(oldName);
});
it('changes name attribute on primary action', async () => {
parent.wizardUI.inputs[0].value = 'newName';
primaryAction.click();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,6 @@ describe('conducting-equipment-editor wizarding editing integration', () => {
await new Promise(resolve => setTimeout(resolve, 100)); // await animation
expect(parent.wizardUI.dialog).to.not.exist;
});
it('does not change name attribute if not unique within parent element', async () => {
const oldName = nameField.value;
nameField.value = 'QA1';
primaryAction.click();
await parent.updateComplete;
expect(
doc.querySelector('ConductingEquipment')?.getAttribute('name')
).to.equal(oldName);
});
it('changes name attribute on primary action', async () => {
nameField.value = 'newName';
primaryAction.click();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,6 @@ describe('general-equipment-editor wizarding editing integration', () => {
await new Promise(resolve => setTimeout(resolve, 100)); // await animation
expect(parent.wizardUI.dialog).to.not.exist;
});
it('does not change name attribute if not unique within parent element', async () => {
const oldName = nameField.value;
nameField.value = 'genSub2';
primaryAction.click();
await parent.updateComplete;
expect(
doc.querySelector('GeneralEquipment')?.getAttribute('name')
).to.equal(oldName);
});
it('changes name attribute on primary action', async () => {
parent.wizardUI.inputs[0].value = 'newName';
primaryAction.click();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,16 +96,6 @@ describe('line-editor wizarding editing integration', () => {
expect(parent.wizardUI.dialog).to.not.exist;
});

it('does not change name attribute if not unique within parent element', async () => {
const oldName = nameField.value;
nameField.value = 'Munich';
primaryAction.click();
await parent.updateComplete;
expect(
doc.querySelector('Line[name="Berlin"]')?.getAttribute('name')
).to.equal(oldName);
});

it('changes desc attribute on primary action', async () => {
parent.wizardUI.inputs[1].value = 'newDesc';
primaryAction.click();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,18 +103,6 @@ describe('process-editor wizarding editing integration', () => {
expect(parent.wizardUI.dialog).to.not.exist;
});

it('does not change name attribute if not unique within parent element', async () => {
const oldName = nameField.value;
nameField.value = 'ProcProcSubAA1';
primaryAction.click();
await parent.updateComplete;
expect(
doc
.querySelector('Process[name="ProcessGenConduct"]')
?.getAttribute('name')
).to.equal(oldName);
});

it('changes name attribute on primary action', async () => {
nameField.value = 'newName';
primaryAction.click();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,19 +101,7 @@ describe('tapchanger-editor wizarding editing integration', () => {
await new Promise(resolve => setTimeout(resolve, 100)); // await animation
expect(parent.wizardUI.dialog).to.not.exist;
});
it('does not change name attribute if not unique within parent element', async () => {
const oldName = nameField.value;
nameField.value = 'empty';
primaryAction.click();
await parent.updateComplete;
expect(
doc
.querySelector(
'TransformerWinding[name="withTapChanger1"] > TapChanger[name="tapChComplet"]'
)
?.getAttribute('name')
).to.equal(oldName);
});

it('changes desc attribute on primary action', async () => {
descField.value = 'newDesc';
primaryAction.click();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,19 +103,7 @@ describe('transformer-winding-editor wizarding editing integration', () => {
await new Promise(resolve => setTimeout(resolve, 100)); // await animation
expect(parent.wizardUI.dialog).to.not.exist;
});
it('does not change name attribute if not unique within parent element', async () => {
const oldName = nameField.value;
nameField.value = 'some1';
primaryAction.click();
await parent.updateComplete;
expect(
doc
.querySelector(
'PowerTransformer[name="pTransVolt"] > TransformerWinding[name="some"]'
)
?.getAttribute('name')
).to.equal(oldName);
});

it('changes desc attribute on primary action', async () => {
await new Promise(resolve => setTimeout(resolve, 100)); // await animation
descField.nullSwitch!.click();
Expand Down

0 comments on commit 70ddafb

Please sign in to comment.