File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -35,6 +35,7 @@ import {
3535import { dataTest } from "../../lib/attributes" ;
3636import ContactToolbar from "./ContactToolbar" ;
3737import { getCookie , setCookie } from "../../lib/cookie" ;
38+ import { deepCopy } from "../utils" ;
3839
3940export class AssignmentTexterContactControls extends React . Component {
4041 constructor ( props ) {
@@ -124,7 +125,10 @@ export class AssignmentTexterContactControls extends React.Component {
124125 let currentInteractionStep = null ;
125126
126127 if ( availableSteps . length > 0 ) {
127- currentInteractionStep = availableSteps [ availableSteps . length - 1 ] ;
128+ const currentInteractionStep = deepCopy (
129+ availableSteps [ availableSteps . length - 1 ]
130+ ) ;
131+
128132 currentInteractionStep . question . filteredAnswerOptions =
129133 currentInteractionStep . question . answerOptions ;
130134 }
Original file line number Diff line number Diff line change @@ -27,3 +27,16 @@ export function getButtonProps(props) {
2727 ] ;
2828 return pick ( props , validProps ) ;
2929}
30+
31+ // Create a deep copy of an object so nested properties are also mutable
32+ export function deepCopy ( obj ) {
33+ if ( Array . isArray ( obj ) ) {
34+ return obj . map ( item => deepCopy ( item ) ) ;
35+ } else if ( typeof obj === "object" && obj !== null ) {
36+ return Object . fromEntries (
37+ Object . entries ( obj ) . map ( ( [ key , value ] ) => [ key , deepCopy ( value ) ] )
38+ ) ;
39+ } else {
40+ return obj ;
41+ }
42+ }
You can’t perform that action at this time.
0 commit comments