Skip to content

Commit

Permalink
Fix duplicate name in updateValue bug (#1929)
Browse files Browse the repository at this point in the history
  • Loading branch information
dqnykamp authored Feb 27, 2023
1 parent ff5bfe2 commit 6834848
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 4 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 @@ -2168,4 +2168,41 @@ describe('UpdateValue Tag Tests', function () {

})

it('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)")


})

});
8 changes: 4 additions & 4 deletions src/Core/utils/serializedStateProcessing.js
Original file line number Diff line number Diff line change
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

0 comments on commit 6834848

Please sign in to comment.