@@ -190,53 +190,60 @@ function _Search(_props: Props) {
190190
191191 addExpression ( groupIndex : number ) {
192192 const groups : InputSearchExpressionGroup [ ] = [ ...this . state . groups ] ;
193- const group = groups [ groupIndex ] ;
194- const maxKey = group . expressions . reduce ( ( max , p ) => p . key > max ? p . key : max , group . expressions [ 0 ] . key ) ;
193+ const group = { ...groups [ groupIndex ] } ;
194+ const expressions = [ ...group . expressions ] ;
195+ const maxKey = expressions . reduce ( ( max , p ) => p . key > max ? p . key : max , expressions [ 0 ] . key ) ;
195196 const newEx = this . newExpression ( maxKey + 1 , '&&' ) ;
196- group . expressions . push ( newEx ) ;
197- if ( group . expressions . length === 2 ) {
197+ expressions . push ( newEx ) ;
198+ if ( expressions . length === 2 ) {
198199 newEx . unlocked = true ;
199200 } else {
200- group . expressions . forEach ( ex => ex . unlocked = false ) ;
201- newEx . clause = group . expressions [ 1 ] . clause ;
201+ expressions . forEach ( ex => ex . unlocked = false ) ;
202+ newEx . clause = expressions [ 1 ] . clause ;
202203 }
204+ group . expressions = expressions ;
205+ groups [ groupIndex ] = group ;
203206 this . setState ( { groups } ) ;
204207 }
205208
206209 updateExpression ( partialEx : Partial < InputSearchExpression > , groupIndex : number , index : number ) {
207210 const groups : InputSearchExpressionGroup [ ] = [ ...this . state . groups ] ;
208- const group = groups [ groupIndex ] ;
209- const ex = SandDance . VegaMorphCharts . util . clone ( group . expressions [ index ] ) ;
210- if ( ex . name !== partialEx . name ) {
211+ const group = { ...groups [ groupIndex ] } ;
212+ const expressions = [ ...group . expressions ] ;
213+ const currentEx = expressions [ index ] ;
214+ if ( currentEx . name !== partialEx . name ) {
211215 //choose an appropriate operator when switching data type
212- const oldColumn = getColumnWithName ( ex . name , this . state . sortedColumns ) ;
216+ const oldColumn = getColumnWithName ( currentEx . name , this . state . sortedColumns ) ;
213217 const newColumn = getColumnWithName ( partialEx . name , this . state . sortedColumns ) ;
214218 const oldType = oldColumn && oldColumn . type ;
215219 const newType = newColumn && newColumn . type ;
216220 if ( oldType !== newType ) {
217221 const newOperators = getValidOperators ( newColumn ) . map ( validOperator => validOperator [ 0 ] ) ;
218222 //see if old operator is compatible
219- if ( newOperators . indexOf ( ex . operator ) < 0 ) {
223+ if ( newOperators . indexOf ( currentEx . operator ) < 0 ) {
220224 //not compatible, so choose "equal"
221225 partialEx . operator = '==' ;
222226 }
223227 }
224228 }
225- Object . assign ( ex , partialEx ) ;
229+ const ex = { ... currentEx , ... partialEx } ;
226230 clearExpressionValidation ( ex ) ;
227- group . expressions [ index ] = ex ;
231+ expressions [ index ] = ex ;
232+ group . expressions = expressions ;
233+ groups [ groupIndex ] = group ;
228234 this . setState ( { groups } ) ;
229235 }
230236
231237 deleteExpression ( groupIndex : number , index : number ) {
232238 const groups : InputSearchExpressionGroup [ ] = [ ...this . state . groups ] ;
233- const group = groups [ groupIndex ] ;
239+ const group = { ... groups [ groupIndex ] } ;
234240 const expressions : InputSearchExpression [ ] = [ ...group . expressions ] ;
235241 expressions . splice ( index , 1 ) ;
236242 if ( expressions . length === 2 ) {
237243 expressions [ 1 ] . unlocked = true ;
238244 }
239245 group . expressions = expressions ;
246+ groups [ groupIndex ] = group ;
240247 this . setState ( { groups } ) ;
241248 }
242249
0 commit comments