Skip to content

Commit

Permalink
[ML] Job validation next button should always be available.
Browse files Browse the repository at this point in the history
  • Loading branch information
walterra committed Dec 17, 2020
1 parent b366241 commit ae33db6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,20 @@ export class ValidateJobUI extends Component {
.validateJob({ duration, fields, job })
.then((messages) => {
shouldShowLoadingIndicator = false;

const messagesContainError = messages.some((m) => m.status === VALIDATION_STATUS.ERROR);

if (messagesContainError) {
messages.push({
id: 'job_validation_includes_error',
text: i18n.translate('xpack.ml.validateJob.jobValidationIncludesErrorText', {
defaultMessage:
'Job validation has failed, but you can still continue and create the job. Please be aware the job may encounter problems when running.',
}),
status: VALIDATION_STATUS.WARNING,
});
}

this.setState({
...this.state,
ui: {
Expand All @@ -233,9 +247,7 @@ export class ValidateJobUI extends Component {
title: job.job_id,
});
if (typeof this.props.setIsValid === 'function') {
this.props.setIsValid(
messages.some((m) => m.status === VALIDATION_STATUS.ERROR) === false
);
this.props.setIsValid(!messagesContainError);
}
})
.catch((error) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

import React, { Fragment, FC, useContext, useState, useEffect } from 'react';
import React, { Fragment, FC, useContext, useEffect } from 'react';
import { WizardNav } from '../wizard_nav';
import { WIZARD_STEPS, StepProps } from '../step_types';
import { JobCreatorContext } from '../job_creator_context';
Expand All @@ -21,7 +21,6 @@ const idFilterList = [

export const ValidationStep: FC<StepProps> = ({ setCurrentStep, isCurrentStep }) => {
const { jobCreator, jobCreatorUpdate, jobValidator } = useContext(JobCreatorContext);
const [nextActive, setNextActive] = useState(false);

if (jobCreator.type === JOB_TYPE.ADVANCED) {
// for advanced jobs, ignore time range warning as the
Expand Down Expand Up @@ -50,13 +49,8 @@ export const ValidationStep: FC<StepProps> = ({ setCurrentStep, isCurrentStep })
}, []);

// keep a record of the advanced validation in the jobValidator
// and disable the next button if any advanced checks have failed.
// note, it is not currently possible to get to a state where any of the
// advanced validation checks return an error because they are all
// caught in previous basic checks
function setIsValid(valid: boolean) {
jobValidator.advancedValid = valid;
setNextActive(valid);
}

return (
Expand All @@ -74,7 +68,7 @@ export const ValidationStep: FC<StepProps> = ({ setCurrentStep, isCurrentStep })
<WizardNav
previous={() => setCurrentStep(WIZARD_STEPS.JOB_DETAILS)}
next={() => setCurrentStep(WIZARD_STEPS.SUMMARY)}
nextActive={nextActive}
nextActive={true}
/>
</Fragment>
)}
Expand Down

0 comments on commit ae33db6

Please sign in to comment.