Skip to content

Commit

Permalink
replace static memo
Browse files Browse the repository at this point in the history
  • Loading branch information
gt2345 committed Oct 11, 2024
1 parent 636289d commit 765da1c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
10 changes: 4 additions & 6 deletions webui/react/src/components/ExperimentContinueModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { Body } from 'hew/Typography';
import { Loaded } from 'hew/utils/loadable';
import yaml from 'js-yaml';
import _ from 'lodash';
import React, { useCallback, useEffect, useId, useMemo, useState } from 'react';
import React, { useCallback, useEffect, useId, useState } from 'react';

import useFeature from 'hooks/useFeature';
import { paths } from 'routes/utils';
Expand Down Expand Up @@ -116,8 +116,6 @@ const ExperimentContinueModalComponent = ({
: [ExperimentCopyMapping, experimentEntityCopyMap];
const actionCopy = actionCopyMap[modalState.type];

const requiredFields = useMemo(() => [EXPERIMENT_NAME], []);

const handleModalClose = () => {
setModalState(DEFAULT_MODAL_STATE);
onClose?.();
Expand All @@ -139,7 +137,7 @@ const ExperimentContinueModalComponent = ({
const hasError = hasErrors(form);
const values = form.getFieldsValue();
const missingRequiredFields = Object.entries(values).some(([key, value]) => {
return requiredFields.includes(key) && !value;
return EXPERIMENT_NAME === key && !value;
});
setDisabled(hasError || missingRequiredFields);
};
Expand Down Expand Up @@ -330,8 +328,8 @@ const ExperimentContinueModalComponent = ({
};
return _.isEqual(prev, newModalState) ? prev : newModalState;
});
form.validateFields(requiredFields); // initial disabled state set here, gets updated later in handleFieldsChange
}, [entityCopyMap, experiment, trial, type, isReactivate, form, requiredFields]);
form.validateFields([EXPERIMENT_NAME]); // initial disabled state set here, gets updated later in handleFieldsChange
}, [entityCopyMap, experiment, trial, type, isReactivate, form]);

if (!experiment || (!isReactivate && !trial)) return <></>;

Expand Down
8 changes: 3 additions & 5 deletions webui/react/src/components/ExperimentCreateModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,6 @@ const ExperimentCreateModalComponent = ({
? `Fork ${capitalize(entityCopy.experiment)} ${experiment.id}`
: `Continue ${capitalize(entityCopy.trial)} ${trial?.id}`;

const requiredFields = useMemo(() => [EXPERIMENT_NAME], []);

const handleModalClose = () => {
setModalState(DEFAULT_MODAL_STATE);
onClose?.();
Expand All @@ -140,7 +138,7 @@ const ExperimentCreateModalComponent = ({
const hasError = hasErrors(form);
const values = form.getFieldsValue();
const missingRequiredFields = Object.entries(values).some(([key, value]) => {
return requiredFields.includes(key) && !value;
return EXPERIMENT_NAME === key && !value;
});
setDisabled(hasError || missingRequiredFields);
};
Expand Down Expand Up @@ -315,8 +313,8 @@ const ExperimentCreateModalComponent = ({
};
return _.isEqual(prev, newModalState) ? prev : newModalState;
});
form.validateFields(requiredFields); // initial disabled state set here, gets updated later in handleFieldsChange
}, [entityCopy, experiment, trial, type, isFork, form, requiredFields]);
form.validateFields([EXPERIMENT_NAME]); // initial disabled state set here, gets updated later in handleFieldsChange
}, [entityCopy, experiment, trial, type, isFork, form]);

if (!experiment || (!isFork && !trial)) return <></>;

Expand Down

0 comments on commit 765da1c

Please sign in to comment.