4
4
*/
5
5
6
6
import React , { useEffect , useState } from 'react' ;
7
+ import { useSelector } from 'react-redux' ;
7
8
import semver from 'semver' ;
8
- import { getEffectiveVersion } from '../../../pages/workflows/new_workflow/new_workflow' ;
9
9
import {
10
10
EuiSmallButtonEmpty ,
11
11
EuiSmallButtonIcon ,
@@ -29,7 +29,7 @@ import {
29
29
WorkflowFormValues ,
30
30
} from '../../../../common' ;
31
31
import { formikToUiConfig , getDataSourceFromURL } from '../../../utils' ;
32
-
32
+ import { getEffectiveVersion } from '../../../pages/workflows/new_workflow/new_workflow' ;
33
33
import {
34
34
CollapseProcessor ,
35
35
CopyIngestProcessor ,
@@ -53,6 +53,12 @@ import {
53
53
MIN_SUPPORTED_VERSION ,
54
54
MINIMUM_FULL_SUPPORTED_VERSION ,
55
55
} from '../../../../common' ;
56
+ import {
57
+ AppState ,
58
+ setIngestPipelineErrors ,
59
+ setSearchPipelineErrors ,
60
+ useAppDispatch ,
61
+ } from '../../../store' ;
56
62
57
63
interface ProcessorsListProps {
58
64
uiConfig : WorkflowConfig ;
@@ -67,13 +73,26 @@ const PANEL_ID = 0;
67
73
* General component for configuring pipeline processors (ingest / search request / search response)
68
74
*/
69
75
export function ProcessorsList ( props : ProcessorsListProps ) {
76
+ const dispatch = useAppDispatch ( ) ;
77
+ const {
78
+ ingestPipeline : ingestPipelineErrors ,
79
+ searchPipeline : searchPipelineErrors ,
80
+ } = useSelector ( ( state : AppState ) => state . errors ) ;
70
81
const { values, errors, touched } = useFormikContext < WorkflowFormValues > ( ) ;
71
82
const [ version , setVersion ] = useState < string > ( '' ) ;
72
83
const location = useLocation ( ) ;
73
84
const [ processorAdded , setProcessorAdded ] = useState < boolean > ( false ) ;
74
85
const [ isPopoverOpen , setPopover ] = useState ( false ) ;
75
86
const [ processors , setProcessors ] = useState < IProcessorConfig [ ] > ( [ ] ) ;
76
87
88
+ function clearProcessorErrors ( ) : void {
89
+ if ( props . context === PROCESSOR_CONTEXT . INGEST ) {
90
+ dispatch ( setIngestPipelineErrors ( { errors : { } } ) ) ;
91
+ } else {
92
+ dispatch ( setSearchPipelineErrors ( { errors : { } } ) ) ;
93
+ }
94
+ }
95
+
77
96
const closePopover = ( ) => {
78
97
setPopover ( false ) ;
79
98
} ;
@@ -258,6 +277,7 @@ export function ProcessorsList(props: ProcessorsListProps) {
258
277
// the list of processors. Additionally, persist any current form state
259
278
// (touched, errors) so they are re-initialized when the form is reset.
260
279
function addProcessor ( processor : IProcessorConfig ) : void {
280
+ clearProcessorErrors ( ) ;
261
281
props . setCachedFormikState ( {
262
282
errors,
263
283
touched,
@@ -295,6 +315,7 @@ export function ProcessorsList(props: ProcessorsListProps) {
295
315
// (getting any updated/interim values along the way) delete
296
316
// the specified processor from the list of processors
297
317
function deleteProcessor ( processorIdToDelete : string ) : void {
318
+ clearProcessorErrors ( ) ;
298
319
const existingConfig = cloneDeep ( props . uiConfig as WorkflowConfig ) ;
299
320
let newConfig = formikToUiConfig ( values , existingConfig ) ;
300
321
switch ( props . context ) {
@@ -341,6 +362,23 @@ export function ProcessorsList(props: ProcessorsListProps) {
341
362
}
342
363
} catch ( e ) { }
343
364
365
+ const processorFormError =
366
+ hasErrors && allTouched
367
+ ? 'Invalid or missing fields detected'
368
+ : undefined ;
369
+ const processorRuntimeError =
370
+ props . context === PROCESSOR_CONTEXT . INGEST
371
+ ? getIn (
372
+ ingestPipelineErrors ,
373
+ `${ processorIndex } .errorMsg` ,
374
+ undefined
375
+ )
376
+ : getIn (
377
+ searchPipelineErrors ,
378
+ `${ processorIndex } .errorMsg` ,
379
+ undefined
380
+ ) ;
381
+
344
382
return (
345
383
< EuiFlexItem key = { processorIndex } >
346
384
< EuiPanel paddingSize = "s" >
@@ -354,14 +392,15 @@ export function ProcessorsList(props: ProcessorsListProps) {
354
392
< EuiFlexItem grow = { false } >
355
393
< EuiText > { `${ processor . name || 'Processor' } ` } </ EuiText >
356
394
</ EuiFlexItem >
357
- { hasErrors && allTouched && (
395
+ { ( processorFormError !== undefined ||
396
+ processorRuntimeError !== undefined ) && (
358
397
< EuiFlexItem grow = { false } >
359
398
< EuiIconTip
360
399
aria-label = "Warning"
361
400
size = "m"
362
401
type = "alert"
363
402
color = "danger"
364
- content = "Invalid or missing fields detected"
403
+ content = { processorFormError || processorRuntimeError }
365
404
position = "right"
366
405
/>
367
406
</ EuiFlexItem >
0 commit comments