@@ -41,15 +41,15 @@ function updateGivenVariable(
4141 '#text' : newVariableValue . label ,
4242 } ;
4343 }
44- if ( updatedVariable [ '@_wgt' ] ) {
44+ if ( newVariableValue . isWeight && updatedVariable [ '@_wgt' ] ) {
4545 updatedVariable [ '@_wgt' ] = newVariableValue . isWeight ? 'wgt' : '' ;
4646 } else {
4747 updatedVariable = {
4848 ...updatedVariable ,
4949 '@_wgt' : newVariableValue . isWeight ? 'wgt' : '' ,
5050 } ;
5151 }
52- if ( updatedVariable [ '@_wgt-var' ] ) {
52+ if ( newVariableValue . isWeight && updatedVariable [ '@_wgt-var' ] ) {
5353 updatedVariable [ '@_wgt-var' ] = newVariableValue . isWeight
5454 ? ''
5555 : newVariableValue . assignedWeight ;
@@ -85,7 +85,9 @@ function updateGivenVariable(
8585 }
8686 updatedVariable = {
8787 ...updatedVariable ,
88- universe : newVariableValue . universe ,
88+ universe : newVariableValue . universe . length
89+ ? newVariableValue . universe
90+ : updatedVariable . universe ,
8991 } ;
9092 return updatedVariable ;
9193}
@@ -130,7 +132,7 @@ export function changeWeightForSelectedVariables(
130132 category . catStat [ 0 ] ,
131133 {
132134 '#text' :
133- weightID && weightID !== 'remove'
135+ weightID . length && weightID !== 'remove'
134136 ? frequencyTableForSelectedVariables [ variableID ] [
135137 category . catValu
136138 ] || 0
@@ -145,14 +147,15 @@ export function changeWeightForSelectedVariables(
145147 category . catStat ,
146148 {
147149 '#text' :
148- weightID && weightID !== 'remove'
150+ weightID . length && weightID !== 'remove'
149151 ? frequencyTableForSelectedVariables [ variableID ] [
150152 category . catValu
151153 ] || 0
152154 : 0 ,
153155 '@_type' : 'freq' ,
154156 '@_wgtd' : 'wgtd' ,
155- '@_wgt-var' : weightID && weightID !== 'remove' ? weightID : '' ,
157+ '@_wgt-var' :
158+ weightID . length && weightID !== 'remove' ? weightID : '' ,
156159 } ,
157160 ] ;
158161 }
@@ -291,7 +294,12 @@ export function changeGroupsForMultipleVariables(
291294 const variablesAsArray = variableGroup [ '@_var' ] ?. length
292295 ? variableGroup [ '@_var' ] ?. split ( ' ' ) || [ ]
293296 : [ ] ;
294- variablesAsArray . push ( ...variableIDs ) ;
297+ // Add variables that are not already in the group
298+ for ( const variableID of variableIDs ) {
299+ if ( ! variablesAsArray . includes ( variableID ) ) {
300+ variablesAsArray . push ( variableID ) ;
301+ }
302+ }
295303 variableGroup [ '@_var' ] = variablesAsArray . join ( ' ' ) ;
296304 }
297305 updatedGroupArray . push ( variableGroup ) ;
0 commit comments