diff --git a/x-pack/legacy/plugins/ml/public/application/data_frame_analytics/pages/analytics_management/components/create_analytics_form/create_analytics_form.tsx b/x-pack/legacy/plugins/ml/public/application/data_frame_analytics/pages/analytics_management/components/create_analytics_form/create_analytics_form.tsx index e419d8b340e76d..c8377360a9d15f 100644 --- a/x-pack/legacy/plugins/ml/public/application/data_frame_analytics/pages/analytics_management/components/create_analytics_form/create_analytics_form.tsx +++ b/x-pack/legacy/plugins/ml/public/application/data_frame_analytics/pages/analytics_management/components/create_analytics_form/create_analytics_form.tsx @@ -20,7 +20,6 @@ import { debounce } from 'lodash'; import { i18n } from '@kbn/i18n'; import { FormattedMessage } from '@kbn/i18n/react'; -import useUpdateEffect from 'react-use/lib/useUpdateEffect'; import { useMlKibana } from '../../../../../contexts/kibana'; import { ml } from '../../../../../services/ml_api_service'; @@ -58,6 +57,7 @@ export const CreateAnalyticsForm: FC = ({ actions, sta const { form, indexPatternsMap, isAdvancedEditorEnabled, isJobCreated, requestMessages } = state; const forceInput = useRef(null); + const firstUpdate = useRef(true); const { createIndexPattern, @@ -148,6 +148,10 @@ export const CreateAnalyticsForm: FC = ({ actions, sta }; const debouncedGetExplainData = debounce(async () => { + const shouldUpdateModelMemoryLimit = !firstUpdate.current || !modelMemoryLimit; + if (firstUpdate.current) { + firstUpdate.current = false; + } // Reset if sourceIndex or jobType changes (jobType requires dependent_variable to be set - // which won't be the case if switching from outlier detection) if (previousSourceIndex !== sourceIndex || previousJobType !== jobType) { @@ -166,10 +170,12 @@ export const CreateAnalyticsForm: FC = ({ actions, sta ); const expectedMemoryWithoutDisk = resp.memory_estimation?.expected_memory_without_disk; - // If sourceIndex has changed load analysis field options again - if (previousSourceIndex !== sourceIndex || previousJobType !== jobType) { + if (shouldUpdateModelMemoryLimit) { setEstimatedModelMemoryLimit(expectedMemoryWithoutDisk); + } + // If sourceIndex has changed load analysis field options again + if (previousSourceIndex !== sourceIndex || previousJobType !== jobType) { const analyzedFieldsOptions: EuiComboBoxOptionOption[] = []; if (resp.field_selection) { @@ -181,7 +187,7 @@ export const CreateAnalyticsForm: FC = ({ actions, sta } setFormState({ - ...(!modelMemoryLimit ? { modelMemoryLimit: expectedMemoryWithoutDisk } : {}), + ...(shouldUpdateModelMemoryLimit ? { modelMemoryLimit: expectedMemoryWithoutDisk } : {}), excludesOptions: analyzedFieldsOptions, loadingFieldOptions: false, fieldOptionsFetchFail: false, @@ -189,7 +195,7 @@ export const CreateAnalyticsForm: FC = ({ actions, sta }); } else { setFormState({ - ...(!modelMemoryLimit ? { modelMemoryLimit: expectedMemoryWithoutDisk } : {}), + ...(shouldUpdateModelMemoryLimit ? { modelMemoryLimit: expectedMemoryWithoutDisk } : {}), }); } } catch (e) { @@ -211,7 +217,7 @@ export const CreateAnalyticsForm: FC = ({ actions, sta fieldOptionsFetchFail: true, maxDistinctValuesError: errorMessage, loadingFieldOptions: false, - modelMemoryLimit: fallbackModelMemoryLimit, + ...(shouldUpdateModelMemoryLimit ? { modelMemoryLimit: fallbackModelMemoryLimit } : {}), }); } }, 400); @@ -316,7 +322,7 @@ export const CreateAnalyticsForm: FC = ({ actions, sta } }, [sourceIndex, jobType, sourceIndexNameEmpty]); - useUpdateEffect(() => { + useEffect(() => { const hasBasicRequiredFields = jobType !== undefined && sourceIndex !== '' && sourceIndexNameValid === true; diff --git a/x-pack/legacy/plugins/ml/public/application/data_frame_analytics/pages/analytics_management/hooks/use_create_analytics_form/use_create_analytics_form.ts b/x-pack/legacy/plugins/ml/public/application/data_frame_analytics/pages/analytics_management/hooks/use_create_analytics_form/use_create_analytics_form.ts index bb01cfaf7b042a..39a71c43bb3f99 100644 --- a/x-pack/legacy/plugins/ml/public/application/data_frame_analytics/pages/analytics_management/hooks/use_create_analytics_form/use_create_analytics_form.ts +++ b/x-pack/legacy/plugins/ml/public/application/data_frame_analytics/pages/analytics_management/hooks/use_create_analytics_form/use_create_analytics_form.ts @@ -318,6 +318,7 @@ export const useCreateAnalyticsForm = (): CreateAnalyticsFormProps => { switchToAdvancedEditor(); } else { setFormState(getCloneFormStateFromJobConfig(config)); + setEstimatedModelMemoryLimit(config.model_memory_limit); } dispatch({ type: ACTION.SET_JOB_CLONE, cloneJob });