Skip to content

Commit

Permalink
Fix duplicate name in updateValue bug
Browse files Browse the repository at this point in the history
  • Loading branch information
dqnykamp committed Feb 11, 2023
1 parent ea923e3 commit f1e39d1
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 7 deletions.
37 changes: 37 additions & 0 deletions cypress/e2e/DoenetML/tagSpecific/updatevalue.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -2088,4 +2088,41 @@ describe('UpdateValue Tag Tests', function () {

})

it.only('bug fix: no duplicate name error, #1921', () => {

cy.window().then(async (win) => {
win.postMessage({
doenetML: `
<updateValue target="v.tail.coords" newValue="(3,4)"><label>Move tail</label></updateValue>
<triggerSet>
<label>Move both</label>
<updateValue target="v.head.coords" newValue="(5,6)" />
<updateValue target="v.tail.coords" newValue="(7,2)" />
</triggerSet><graph>
<vector name="v" />
</graph><copy source="v.tail" assignNames="vt" /><copy source="v.head" assignNames="vh" />
`}, "*");
});

cy.get('#\\/_updatevalue1').should('contain.text', 'Move tail')
cy.get('#\\/_triggerset1').should('contain.text', 'Move both')
cy.get('#\\/vh .mjx-mrow').eq(0).should('have.text', "(1,0)")
cy.get('#\\/vt .mjx-mrow').eq(0).should('have.text', "(0,0)")

cy.get('#\\/_updatevalue1').click();

cy.get('#\\/vt .mjx-mrow').should('contain.text', "(3,4)")

cy.get('#\\/vt .mjx-mrow').eq(0).should('have.text', "(3,4)")
cy.get('#\\/vh .mjx-mrow').eq(0).should('have.text', "(4,4)")

cy.get('#\\/_triggerset1').click();
cy.get('#\\/vt .mjx-mrow').should('contain.text', "(7,2)")

cy.get('#\\/vt .mjx-mrow').eq(0).should('have.text', "(7,2)")
cy.get('#\\/vh .mjx-mrow').eq(0).should('have.text', "(9,4)")


})

});
2 changes: 1 addition & 1 deletion src/Core/Core.js
Original file line number Diff line number Diff line change
Expand Up @@ -1253,7 +1253,7 @@ export default class Core {
});

}

if (componentClass.keepChildrenSerialized) {
let childrenAddressed = new Set([]);

Expand Down
12 changes: 6 additions & 6 deletions src/Core/utils/serializedStateProcessing.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ export async function expandDoenetMLsToFullSerializedComponents({
};

originalCopyWithUri.children = [extContent, ...originalCopyWithUri.children];

}
}
}
Expand Down Expand Up @@ -586,9 +586,9 @@ function copyTargetOrFromURIAttributeCreatesCopyComponent(serializedComponents,
}
}

function breakUpTargetIntoPropsAndIndices(serializedComponents, componentInfoObjects) {
function breakUpTargetIntoPropsAndIndices(serializedComponents, componentInfoObjects, ancestorString = "") {

for (let component of serializedComponents) {
for (let [component_ind, component] of serializedComponents.entries()) {

// Note: do not do this for collect, as this dot notation would be confusing for collect

Expand Down Expand Up @@ -703,7 +703,7 @@ function breakUpTargetIntoPropsAndIndices(serializedComponents, componentInfoObj
// then wrap the extract in a setup and append
// and modify the updateValue/animateFromSequence to point to the extract

let longNameId = "fromExtendedSource|" + serializedComponents.length;
let longNameId = "fromExtendedSource" + ancestorString + "|" + component_ind;
let nameForExtract = createUniqueName("extract", longNameId);
newComponent.doenetAttributes.prescribedName = nameForExtract;
newComponent.doenetAttributes.createdFromMacro = true;
Expand Down Expand Up @@ -752,7 +752,7 @@ function breakUpTargetIntoPropsAndIndices(serializedComponents, componentInfoObj
}

if (component.children) {
breakUpTargetIntoPropsAndIndices(component.children, componentInfoObjects);
breakUpTargetIntoPropsAndIndices(component.children, componentInfoObjects, ancestorString + "|" + component_ind);
}
}
}
Expand Down Expand Up @@ -2475,7 +2475,7 @@ export function createComponentNames({ serializedComponents, namespaceStack = []

children = children.slice(1)

let separateNewNamespaceInfo = { namespace: prescribedName, componentCounts: {}, namesUsed:{} };
let separateNewNamespaceInfo = { namespace: prescribedName, componentCounts: {}, namesUsed: {} };
namespaceStack.push(separateNewNamespaceInfo);

createComponentNames({
Expand Down

0 comments on commit f1e39d1

Please sign in to comment.