[ML] Data Frame Analytics creation wizard: ensure included fields table updates correctly (#103191) (#103510)

* fix includes table rerender loop

* remove unnecessary comment
This commit is contained in:
Melissa Alvarez 2021-06-28 14:34:28 -04:00 committed by GitHub
parent bd7e1d6d2d
commit 0faaada551
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 28 deletions

View file

@ -84,7 +84,6 @@ const checkboxDisabledCheck = (item: FieldSelectionItem) =>
export const AnalysisFieldsTable: FC<{
dependentVariable?: string;
includes: string[];
loadingItems: boolean;
setFormState: React.Dispatch<React.SetStateAction<any>>;
minimumFieldsRequiredMessage?: string;
setMinimumFieldsRequiredMessage: React.Dispatch<React.SetStateAction<any>>;
@ -94,7 +93,6 @@ export const AnalysisFieldsTable: FC<{
}> = ({
dependentVariable,
includes,
loadingItems,
setFormState,
minimumFieldsRequiredMessage,
setMinimumFieldsRequiredMessage,

View file

@ -105,7 +105,6 @@ export const ConfigurationStepForm: FC<ConfigurationStepProps> = ({
const { currentSavedSearch, currentIndexPattern } = mlContext;
const { savedSearchQuery, savedSearchQueryStr } = useSavedSearch();
const [loadingFieldOptions, setLoadingFieldOptions] = useState<boolean>(false);
const [fieldOptionsFetchFail, setFieldOptionsFetchFail] = useState<boolean>(false);
const [loadingDepVarOptions, setLoadingDepVarOptions] = useState<boolean>(false);
const [dependentVariableFetchFail, setDependentVariableFetchFail] = useState<boolean>(false);
@ -247,21 +246,17 @@ export const ConfigurationStepForm: FC<ConfigurationStepProps> = ({
if (firstUpdate.current) {
firstUpdate.current = false;
}
// Reset if jobType changes (jobType requires dependent_variable to be set -
// which won't be the case if switching from outlier detection)
if (jobTypeChanged) {
setLoadingFieldOptions(true);
}
const depVarNotIncluded =
isJobTypeWithDepVar && includes.length > 0 && includes.includes(dependentVariable) === false;
// Ensure runtime field is in 'includes' table if it is set as dependent variable
const depVarIsRuntimeField =
isJobTypeWithDepVar &&
depVarNotIncluded &&
runtimeMappings &&
Object.keys(runtimeMappings).includes(dependentVariable) &&
includes.length > 0 &&
includes.includes(dependentVariable) === false;
Object.keys(runtimeMappings).includes(dependentVariable);
let formToUse = form;
if (depVarIsRuntimeField) {
if (depVarIsRuntimeField || depVarNotIncluded) {
formToUse = cloneDeep(form);
formToUse.includes = [...includes, dependentVariable];
}
@ -279,24 +274,22 @@ export const ConfigurationStepForm: FC<ConfigurationStepProps> = ({
(field) => field.is_included === true && field.is_required === false
);
const formStateUpdated = {
...(shouldUpdateModelMemoryLimit ? { modelMemoryLimit: expectedMemory } : {}),
...(depVarIsRuntimeField || jobTypeChanged || depVarNotIncluded
? { includes: formToUse.includes }
: {}),
requiredFieldsError: !hasRequiredFields ? requiredFieldsErrorText : undefined,
};
if (jobTypeChanged) {
setLoadingFieldOptions(false);
setFieldOptionsFetchFail(false);
setMaxDistinctValuesError(undefined);
setUnsupportedFieldsError(undefined);
setFormState({
...(shouldUpdateModelMemoryLimit ? { modelMemoryLimit: expectedMemory } : {}),
requiredFieldsError: !hasRequiredFields ? requiredFieldsErrorText : undefined,
includes: formToUse.includes,
});
setIncludesTableItems(fieldSelection ? fieldSelection : []);
} else {
setFormState({
...(shouldUpdateModelMemoryLimit ? { modelMemoryLimit: expectedMemory } : {}),
requiredFieldsError: !hasRequiredFields ? requiredFieldsErrorText : undefined,
includes: formToUse.includes,
});
}
setFormState(formStateUpdated);
setFetchingExplainData(false);
} else {
const {
@ -319,7 +312,6 @@ export const ConfigurationStepForm: FC<ConfigurationStepProps> = ({
: DEFAULT_MODEL_MEMORY_LIMIT.outlier_detection;
setEstimatedModelMemoryLimit(fallbackModelMemoryLimit);
setLoadingFieldOptions(false);
setFieldOptionsFetchFail(true);
setMaxDistinctValuesError(maxDistinctValuesErrorMessage);
setUnsupportedFieldsError(unsupportedFieldsErrorMessage);
@ -650,7 +642,6 @@ export const ConfigurationStepForm: FC<ConfigurationStepProps> = ({
tableItems={includesTableItems}
unsupportedFieldsError={unsupportedFieldsError}
setUnsupportedFieldsError={setUnsupportedFieldsError}
loadingItems={loadingFieldOptions}
setFormState={setFormState}
/>
{showScatterplotMatrix && (

View file

@ -82,7 +82,6 @@ export const JobType: FC<Props> = ({ type, setFormState }) => {
setFormState({
previousJobType: type,
jobType,
includes: [],
requiredFieldsError: undefined,
});
setSelectedCard({ [jobType]: !selectedCard[jobType] });