@@ -35,7 +35,6 @@ import {
35
35
EMPTY_INPUT_MAP_ENTRY ,
36
36
WorkflowConfig ,
37
37
getCharacterLimitedString ,
38
- ModelInputFormField ,
39
38
INPUT_TRANSFORM_OPTIONS ,
40
39
} from '../../../../../../common' ;
41
40
import {
@@ -47,7 +46,6 @@ import { AppState, getMappings, useAppDispatch } from '../../../../../store';
47
46
import {
48
47
getDataSourceId ,
49
48
getObjsFromJSONLines ,
50
- parseModelInputs ,
51
49
sanitizeJSONPath ,
52
50
} from '../../../../../utils' ;
53
51
import { ConfigureExpressionModal , ConfigureTemplateModal } from './modals/' ;
@@ -108,15 +106,15 @@ export function ModelInputs(props: ModelInputsProps) {
108
106
number | undefined
109
107
> ( undefined ) ;
110
108
111
- // on initial load of the models, update model interface states
109
+ // get the model interface based on the selected ID and list of known models
112
110
useEffect ( ( ) => {
113
111
if ( ! isEmpty ( models ) ) {
114
112
const modelId = getIn ( values , modelFieldPath ) ?. id ;
115
113
if ( modelId ) {
116
114
setModelInterface ( models [ modelId ] ?. interface ) ;
117
115
}
118
116
}
119
- } , [ models ] ) ;
117
+ } , [ models , getIn ( values , modelFieldPath ) ?. id ] ) ;
120
118
121
119
// persisting doc/query/index mapping fields to collect a list
122
120
// of options to display in the dropdowns when configuring input / output maps
@@ -217,31 +215,6 @@ export function ModelInputs(props: ModelInputsProps) {
217
215
setFieldTouched ( inputMapFieldPath , true ) ;
218
216
}
219
217
220
- // The options for keys can change. We update what options are available, based
221
- // on if there is a model interface found, and additionally filter out any
222
- // options that are already being used in the input map, to discourage duplicate keys.
223
- const [ keyOptions , setKeyOptions ] = useState < ModelInputFormField [ ] > ( [ ] ) ;
224
- useEffect ( ( ) => {
225
- setKeyOptions ( parseModelInputs ( modelInterface ) ) ;
226
- } , [ modelInterface ] ) ;
227
- useEffect ( ( ) => {
228
- if ( modelInterface !== undefined ) {
229
- const modelInputs = parseModelInputs ( modelInterface ) ;
230
- if ( getIn ( values , inputMapFieldPath ) !== undefined ) {
231
- const existingKeys = getIn ( values , inputMapFieldPath ) . map (
232
- ( inputMapEntry : InputMapEntry ) => inputMapEntry . key
233
- ) as string [ ] ;
234
- setKeyOptions (
235
- modelInputs . filter (
236
- ( modelInput ) => ! existingKeys . includes ( modelInput . label )
237
- )
238
- ) ;
239
- } else {
240
- setKeyOptions ( modelInputs ) ;
241
- }
242
- }
243
- } , [ getIn ( values , inputMapFieldPath ) , modelInterface ] ) ;
244
-
245
218
const valueOptions =
246
219
props . context === PROCESSOR_CONTEXT . INGEST
247
220
? docFields
@@ -255,37 +228,38 @@ export function ModelInputs(props: ModelInputsProps) {
255
228
const populatedMap = field . value ?. length !== 0 ;
256
229
return (
257
230
< >
258
- < EuiPanel >
259
- { props . context === PROCESSOR_CONTEXT . SEARCH_RESPONSE && (
260
- < >
261
- < BooleanField
262
- fieldPath = { oneToOnePath }
263
- label = "Merge source data"
264
- type = "Switch"
265
- inverse = { true }
266
- helpText = "Merge multiple documents into a single document for model processing. To process only one document, turn off merge source data."
267
- />
268
- < EuiSpacer size = "s" />
269
- { oneToOneChanged && (
270
- < >
271
- < EuiCallOut
272
- size = "s"
273
- color = "warning"
274
- iconType = { 'alert' }
275
- title = {
276
- < EuiText size = "s" >
277
- You have changed how source data will be processed.
278
- You may need to update any existing input values to
279
- reflect the updated data structure.
280
- </ EuiText >
281
- }
282
- />
283
- < EuiSpacer size = "s" />
284
- </ >
285
- ) }
286
- </ >
287
- ) }
288
- { populatedMap ? (
231
+ { populatedMap ? (
232
+ < EuiPanel >
233
+ { props . context === PROCESSOR_CONTEXT . SEARCH_RESPONSE && (
234
+ < >
235
+ < BooleanField
236
+ fieldPath = { oneToOnePath }
237
+ label = "Merge source data"
238
+ type = "Switch"
239
+ inverse = { true }
240
+ helpText = "Merge multiple documents into a single document for model processing. To process only one document, turn off merge source data."
241
+ />
242
+ < EuiSpacer size = "s" />
243
+ { oneToOneChanged && (
244
+ < >
245
+ < EuiCallOut
246
+ size = "s"
247
+ color = "warning"
248
+ iconType = { 'alert' }
249
+ title = {
250
+ < EuiText size = "s" >
251
+ You have changed how source data will be
252
+ processed. You may need to update any existing
253
+ input values to reflect the updated data
254
+ structure.
255
+ </ EuiText >
256
+ }
257
+ />
258
+ < EuiSpacer size = "s" />
259
+ </ >
260
+ ) }
261
+ </ >
262
+ ) }
289
263
< EuiCompressedFormRow
290
264
fullWidth = { true }
291
265
key = { inputMapFieldPath }
@@ -343,20 +317,10 @@ export function ModelInputs(props: ModelInputsProps) {
343
317
< EuiFlexItem >
344
318
< >
345
319
{ /**
346
- * We determine if there is an interface based on if there are key options or not,
347
- * as the options would be derived from the underlying interface.
348
- * And if so, these values should be static.
349
- * So, we only display the static text with no mechanism to change it's value.
350
- * Note we still allow more entries, if a user wants to override / add custom
351
- * keys if there is some gaps in the model interface.
320
+ * If there is a model interface, display the field name.
321
+ * Otherwise, leave as a free-form text box for a user to enter manually.
352
322
*/ }
353
- { ! isEmpty ( keyOptions ) &&
354
- ! isEmpty (
355
- getIn (
356
- values ,
357
- `${ inputMapFieldPath } .${ idx } .key`
358
- )
359
- ) ? (
323
+ { ! isEmpty ( modelInterface ) ? (
360
324
< EuiText
361
325
size = "s"
362
326
style = { { marginTop : '4px' } }
@@ -366,13 +330,6 @@ export function ModelInputs(props: ModelInputsProps) {
366
330
`${ inputMapFieldPath } .${ idx } .key`
367
331
) }
368
332
</ EuiText >
369
- ) : ! isEmpty ( keyOptions ) ? (
370
- < SelectWithCustomOptions
371
- fieldPath = { `${ inputMapFieldPath } .${ idx } .key` }
372
- options = { keyOptions as any [ ] }
373
- placeholder = { `Name` }
374
- allowCreate = { true }
375
- />
376
333
) : (
377
334
< TextField
378
335
fullWidth = { true }
@@ -628,16 +585,21 @@ export function ModelInputs(props: ModelInputsProps) {
628
585
) }
629
586
</ >
630
587
</ EuiFlexItem >
631
- < EuiFlexItem grow = { false } >
632
- < EuiSmallButtonIcon
633
- iconType = { 'trash' }
634
- color = "danger"
635
- aria-label = "Delete"
636
- onClick = { ( ) => {
637
- deleteMapEntry ( field . value , idx ) ;
638
- } }
639
- />
640
- </ EuiFlexItem >
588
+ { /**
589
+ * Only allow deleting entries if no defined model interface
590
+ */ }
591
+ { isEmpty ( modelInterface ) && (
592
+ < EuiFlexItem grow = { false } >
593
+ < EuiSmallButtonIcon
594
+ iconType = { 'trash' }
595
+ color = "danger"
596
+ aria-label = "Delete"
597
+ onClick = { ( ) => {
598
+ deleteMapEntry ( field . value , idx ) ;
599
+ } }
600
+ />
601
+ </ EuiFlexItem >
602
+ ) }
641
603
</ >
642
604
</ EuiFlexGroup >
643
605
</ EuiFlexItem >
@@ -646,33 +608,38 @@ export function ModelInputs(props: ModelInputsProps) {
646
608
) ;
647
609
}
648
610
) }
649
- < EuiFlexItem grow = { false } >
650
- < div >
651
- < EuiSmallButtonEmpty
652
- style = { { marginLeft : '-8px' , marginTop : '0px' } }
653
- iconType = { 'plusInCircle' }
654
- iconSide = "left"
655
- onClick = { ( ) => {
656
- addMapEntry ( field . value ) ;
657
- } }
658
- >
659
- { `Add input` }
660
- </ EuiSmallButtonEmpty >
661
- </ div >
662
- </ EuiFlexItem >
611
+ { /**
612
+ * Only allow adding entries if no defined model interface
613
+ */ }
614
+ { isEmpty ( modelInterface ) && (
615
+ < EuiFlexItem grow = { false } >
616
+ < div >
617
+ < EuiSmallButtonEmpty
618
+ style = { { marginLeft : '-8px' , marginTop : '0px' } }
619
+ iconType = { 'plusInCircle' }
620
+ iconSide = "left"
621
+ onClick = { ( ) => {
622
+ addMapEntry ( field . value ) ;
623
+ } }
624
+ >
625
+ { `Add input` }
626
+ </ EuiSmallButtonEmpty >
627
+ </ div >
628
+ </ EuiFlexItem >
629
+ ) }
663
630
</ EuiFlexGroup >
664
631
</ EuiCompressedFormRow >
665
- ) : (
666
- < EuiSmallButton
667
- style = { { width : '100px' } }
668
- onClick = { ( ) => {
669
- setFieldValue ( field . name , [ EMPTY_INPUT_MAP_ENTRY ] ) ;
670
- } }
671
- >
672
- { 'Configure' }
673
- </ EuiSmallButton >
674
- ) }
675
- </ EuiPanel >
632
+ </ EuiPanel >
633
+ ) : (
634
+ < EuiSmallButton
635
+ style = { { width : '100px' } }
636
+ onClick = { ( ) => {
637
+ setFieldValue ( field . name , [ EMPTY_INPUT_MAP_ENTRY ] ) ;
638
+ } }
639
+ >
640
+ { 'Configure' }
641
+ </ EuiSmallButton >
642
+ ) }
676
643
</ >
677
644
) ;
678
645
} }
0 commit comments