Skip to content

Commit

Permalink
small refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
jgowdyelastic committed Sep 30, 2020
1 parent f5af7b5 commit f816aa9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const idFilterList = [
export const ValidationStep: FC<StepProps> = ({ 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
Expand Down Expand Up @@ -58,6 +59,7 @@ export const ValidationStep: FC<StepProps> = ({ 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 (
Expand All @@ -72,7 +74,9 @@ export const ValidationStep: FC<StepProps> = ({ setCurrentStep, isCurrentStep })
setIsValid={setIsValid}
idFilterList={idFilterList}
/>
{jobCreator.type === JOB_TYPE.ADVANCED && <ValidationWarningCallout />}

{showValidationWarning && <ValidationWarningCallout />}

<WizardNav
previous={() => setCurrentStep(WIZARD_STEPS.JOB_DETAILS)}
next={() => setCurrentStep(WIZARD_STEPS.SUMMARY)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<EuiCallOut
title={
<FormattedMessage
Expand All @@ -35,5 +26,5 @@ export const ValidationWarningCallout: FC = () => {
Please be aware the this job may encounter problems when running."
/>
</EuiCallOut>
) : null;
);
};

0 comments on commit f816aa9

Please sign in to comment.