@@ -175,7 +175,7 @@ export function DataSource(props: DataSourceProps) {
175
175
}
176
176
} , 300 ) ;
177
177
178
- const handleIndexNameChange = ( selectedOptions : any ) => {
178
+ const handleIndexNameChange = ( selectedOptions : any , oldOptions : { label : string } [ ] = props . formikProps . values . index ) => {
179
179
const indexNames = selectedOptions ;
180
180
setIndexNames ( indexNames ) ;
181
181
if ( indexNames . length > 0 ) {
@@ -184,7 +184,7 @@ export function DataSource(props: DataSourceProps) {
184
184
) ;
185
185
dispatch ( getMappings ( indices , dataSourceId ) ) ;
186
186
}
187
- if ( isSelectedOptionIndexRemoved ( ) ) {
187
+ if ( isSelectedOptionIndexRemoved ( selectedOptions , oldOptions ) ) {
188
188
if ( props . setNewIndexSelected ) {
189
189
props . setNewIndexSelected ( true ) ;
190
190
}
@@ -199,10 +199,12 @@ export function DataSource(props: DataSourceProps) {
199
199
newSelectedOptions : { label : string } [ ] = indexNames ,
200
200
oldSelectedOptions : { label : string } [ ] = props . formikProps . values . index
201
201
) => {
202
+ if ( _ . isEmpty ( oldSelectedOptions ) && _ . isEmpty ( newSelectedOptions ) ) {
203
+ return false ;
204
+ }
202
205
const newSelectedOptionsSet = new Set ( newSelectedOptions ) ;
203
206
const indexRemoved : boolean =
204
- ! ( newSelectedOptions && oldSelectedOptions ) ||
205
- oldSelectedOptions . some ( ( value ) => ! newSelectedOptionsSet . has ( value ) ) ;
207
+ oldSelectedOptions . some ( ( value ) => ! newSelectedOptionsSet . has ( value ) ) ;
206
208
return indexRemoved ;
207
209
} ;
208
210
@@ -316,7 +318,7 @@ export function DataSource(props: DataSourceProps) {
316
318
INITIAL_MODEL_CONFIGURATION_VALUES
317
319
) ;
318
320
}
319
- handleIndexNameChange ( options ) ;
321
+ handleIndexNameChange ( options , field . value ) ;
320
322
} }
321
323
selectedOptions = { field . value }
322
324
isClearable = { false }
0 commit comments