Skip to content

Commit

Permalink
[Logs UI] Disable ML job setup form while setup is pending (elastic#5…
Browse files Browse the repository at this point in the history
…4705)

This disables the configuration for in the log rate and categories setup screens while the setup process is ongoing.
  • Loading branch information
weltenwort authored and jkelastic committed Jan 17, 2020
1 parent 6a3e670 commit 6049abf
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ import { LoadingOverlayWrapper } from '../../../loading_overlay_wrapper';
import { ValidatedIndex, ValidationIndicesUIError } from './validation';

export const AnalysisSetupIndicesForm: React.FunctionComponent<{
disabled?: boolean;
indices: ValidatedIndex[];
isValidating: boolean;
onChangeSelectedIndices: (selectedIndices: ValidatedIndex[]) => void;
valid: boolean;
}> = ({ indices, isValidating, onChangeSelectedIndices, valid }) => {
}> = ({ disabled = false, indices, isValidating, onChangeSelectedIndices, valid }) => {
const handleCheckboxChange = useCallback(
(event: React.ChangeEvent<HTMLInputElement>) => {
onChangeSelectedIndices(
Expand All @@ -40,7 +41,7 @@ export const AnalysisSetupIndicesForm: React.FunctionComponent<{
label={<EuiCode>{index.name}</EuiCode>}
onChange={handleCheckboxChange}
checked={index.validity === 'valid' && index.isSelected}
disabled={index.validity === 'invalid'}
disabled={disabled || index.validity === 'invalid'}
/>
);

Expand All @@ -52,7 +53,7 @@ export const AnalysisSetupIndicesForm: React.FunctionComponent<{
</div>
);
}),
[handleCheckboxChange, indices]
[disabled, handleCheckboxChange, indices]
);

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,12 @@ function selectedDateToParam(selectedDate: Moment | null) {
}

export const AnalysisSetupTimerangeForm: React.FunctionComponent<{
disabled?: boolean;
setStartTime: (startTime: number | undefined) => void;
setEndTime: (endTime: number | undefined) => void;
startTime: number | undefined;
endTime: number | undefined;
}> = ({ setStartTime, setEndTime, startTime, endTime }) => {
}> = ({ disabled = false, setStartTime, setEndTime, startTime, endTime }) => {
const now = useMemo(() => moment(), []);
const selectedEndTimeIsToday = !endTime || moment(endTime).isSame(now, 'day');
const startTimeValue = useMemo(() => {
Expand Down Expand Up @@ -86,9 +87,11 @@ export const AnalysisSetupTimerangeForm: React.FunctionComponent<{
>
<EuiFlexGroup gutterSize="s">
<EuiFormControlLayout
clear={startTime ? { onClick: () => setStartTime(undefined) } : undefined}
clear={startTime && !disabled ? { onClick: () => setStartTime(undefined) } : undefined}
isDisabled={disabled}
>
<FixedDatePicker
disabled={disabled}
showTimeSelect
selected={startTimeValue}
onChange={date => setStartTime(selectedDateToParam(date))}
Expand All @@ -107,9 +110,11 @@ export const AnalysisSetupTimerangeForm: React.FunctionComponent<{
>
<EuiFlexGroup gutterSize="s">
<EuiFormControlLayout
clear={endTime ? { onClick: () => setEndTime(undefined) } : undefined}
clear={endTime && !disabled ? { onClick: () => setEndTime(undefined) } : undefined}
isDisabled={disabled}
>
<FixedDatePicker
disabled={disabled}
showTimeSelect
selected={endTimeValue}
onChange={date => setEndTime(selectedDateToParam(date))}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ import { EuiSpacer, EuiForm, EuiCallOut } from '@elastic/eui';
import { EuiContainedStepProps } from '@elastic/eui/src/components/steps/steps';
import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n/react';
import React from 'react';
import React, { useMemo } from 'react';

import { SetupStatus } from '../../../../../common/log_analysis';
import { AnalysisSetupIndicesForm } from './analysis_setup_indices_form';
import { AnalysisSetupTimerangeForm } from './analysis_setup_timerange_form';
import { ValidatedIndex, ValidationIndicesUIError } from './validation';
Expand All @@ -21,6 +22,7 @@ interface InitialConfigurationStepProps {
endTime: number | undefined;
isValidating: boolean;
validatedIndices: ValidatedIndex[];
setupStatus: SetupStatus;
setValidatedIndices: (selectedIndices: ValidatedIndex[]) => void;
validationErrors?: ValidationIndicesUIError[];
}
Expand All @@ -39,20 +41,25 @@ export const InitialConfigurationStep: React.FunctionComponent<InitialConfigurat
endTime,
isValidating,
validatedIndices,
setupStatus,
setValidatedIndices,
validationErrors = [],
}: InitialConfigurationStepProps) => {
const disabled = useMemo(() => !editableFormStatus.includes(setupStatus), [setupStatus]);

return (
<>
<EuiSpacer size="m" />
<EuiForm>
<AnalysisSetupTimerangeForm
disabled={disabled}
setStartTime={setStartTime}
setEndTime={setEndTime}
startTime={startTime}
endTime={endTime}
/>
<AnalysisSetupIndicesForm
disabled={disabled}
indices={validatedIndices}
isValidating={isValidating}
onChangeSelectedIndices={setValidatedIndices}
Expand All @@ -65,6 +72,13 @@ export const InitialConfigurationStep: React.FunctionComponent<InitialConfigurat
);
};

const editableFormStatus = [
'required',
'requiredForReconfiguration',
'requiredForUpdate',
'failed',
];

const errorCalloutTitle = i18n.translate(
'xpack.infra.analysisSetup.steps.initialConfigurationStep.errorCalloutTitle',
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export const LogEntryCategoriesSetupContent: React.FunctionComponent = () => {
endTime,
isValidating,
validatedIndices,
setupStatus,
setValidatedIndices,
validationErrors,
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export const LogEntryRateSetupContent: React.FunctionComponent = () => {
endTime,
isValidating,
validatedIndices,
setupStatus,
setValidatedIndices,
validationErrors,
}),
Expand Down

0 comments on commit 6049abf

Please sign in to comment.