import React , { Fragment , FC , useContext , useEffect , useState } from 'react' ; import { WizardNav } from '../wizard_nav' ; import { WIZARD_STEPS , StepProps } from '../step_types' ; import { JobCreatorContext } from '../job_creator_context' ; import { ml } from '../../../../../services/ml_api_service' ; import { ValidateJob } from '../../../../../components/validate_job' ; import { JOB_TYPE } from '../../../../../../../common/constants/new_job' ; const idFilterList = [ 'job_id_valid' , 'job_group_id_valid' , 'detectors_function_not_empty' , 'success_bucket_span' , ] ; export const ValidationStep = ( { setCurrentStep , isCurrentStep } ) => { const { jobCreator , jobCreatorUpdate , jobValidator } = useContext ( JobCreatorContext ) ; const [ nextActive , setNextActive ] = useState ( false ) ; if ( jobCreator . type === JOB_TYPE . ADVANCED ) { idFilterList . push ( ... [ 'time_range_short' , 'success_time_range' ] ) ; } function getJobConfig ( ) { return { ... jobCreator . jobConfig , datafeed_config : jobCreator . datafeedConfig , } ; } function getDuration ( ) { return { start : jobCreator . start , end : jobCreator . end , } ; } useEffect ( ( ) => { jobValidator . validate ( ( ) => { } , true ) ; jobCreatorUpdate ( ) ; } , [ ] ) ; function setIsValid ( valid ) { jobValidator . advancedValid = valid ; setNextActive ( valid ) ; } return ( < Fragment > { isCurrentStep && ( < Fragment > < ValidateJob getJobConfig = { getJobConfig } getDuration = { getDuration } ml = { ml } embedded = { true } setIsValid = { setIsValid } idFilterList = { idFilterList } / > < WizardNav previous = { ( ) => setCurrentStep ( WIZARD_STEPS . JOB_DETAILS ) } next = { ( ) => setCurrentStep ( WIZARD_STEPS . SUMMARY ) } nextActive = { nextActive } / > < /Fragment>)} { isCurrentStep === false && < Fragment />} < /Fragment>); } ;