From f816aa91c589df5742ada4fa18ed1c64bce15c0a Mon Sep 17 00:00:00 2001 From: James Gowdy Date: Wed, 30 Sep 2020 13:48:14 +0100 Subject: [PATCH] small refactor --- .../components/validation_step/validation.tsx | 6 +++++- .../validation_warning_callout.tsx | 15 +++------------ 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/x-pack/plugins/ml/public/application/jobs/new_job/pages/components/validation_step/validation.tsx b/x-pack/plugins/ml/public/application/jobs/new_job/pages/components/validation_step/validation.tsx index 43ce6286ab915..f34faa0fac94f 100644 --- a/x-pack/plugins/ml/public/application/jobs/new_job/pages/components/validation_step/validation.tsx +++ b/x-pack/plugins/ml/public/application/jobs/new_job/pages/components/validation_step/validation.tsx @@ -23,6 +23,7 @@ const idFilterList = [ export const ValidationStep: FC = ({ setCurrentStep, isCurrentStep }) => { const { jobCreator, jobCreatorUpdate, jobValidator } = useContext(JobCreatorContext); const [nextActive, setNextActive] = useState(false); + const [showValidationWarning, setShowValidationWarning] = useState(false); if (jobCreator.type === JOB_TYPE.ADVANCED) { // for advanced jobs, ignore time range warning as the @@ -58,6 +59,7 @@ export const ValidationStep: FC = ({ setCurrentStep, isCurrentStep }) function setIsValid(valid: boolean) { jobValidator.advancedValid = valid; setNextActive(jobCreator.type === JOB_TYPE.ADVANCED || valid); + setShowValidationWarning(jobCreator.type === JOB_TYPE.ADVANCED && valid === false); } return ( @@ -72,7 +74,9 @@ export const ValidationStep: FC = ({ setCurrentStep, isCurrentStep }) setIsValid={setIsValid} idFilterList={idFilterList} /> - {jobCreator.type === JOB_TYPE.ADVANCED && } + + {showValidationWarning && } + setCurrentStep(WIZARD_STEPS.JOB_DETAILS)} next={() => setCurrentStep(WIZARD_STEPS.SUMMARY)} diff --git a/x-pack/plugins/ml/public/application/jobs/new_job/pages/components/validation_step/validation_warning_callout.tsx b/x-pack/plugins/ml/public/application/jobs/new_job/pages/components/validation_step/validation_warning_callout.tsx index ed78efdc906fc..8baac84dd4461 100644 --- a/x-pack/plugins/ml/public/application/jobs/new_job/pages/components/validation_step/validation_warning_callout.tsx +++ b/x-pack/plugins/ml/public/application/jobs/new_job/pages/components/validation_step/validation_warning_callout.tsx @@ -4,21 +4,12 @@ * you may not use this file except in compliance with the Elastic License. */ -import React, { FC, useContext, useEffect, useState } from 'react'; +import React, { FC } from 'react'; import { FormattedMessage } from '@kbn/i18n/react'; import { EuiCallOut } from '@elastic/eui'; -import { JobCreatorContext } from '../job_creator_context'; -import { JOB_TYPE } from '../../../../../../../common/constants/new_job'; export const ValidationWarningCallout: FC = () => { - const { jobCreator, jobValidator, jobValidatorUpdated } = useContext(JobCreatorContext); - const [valid, setValid] = useState(false); - - useEffect(() => { - setValid(jobValidator.validationSummary.advanced); - }, [jobValidatorUpdated]); - - return jobCreator.type === JOB_TYPE.ADVANCED && valid === false ? ( + return ( { Please be aware the this job may encounter problems when running." /> - ) : null; + ); };