Skip to content

Commit 6fb99ee

Browse files
committed
Add validation for duplicate run group name error
Signed-off-by: Nana Nosirova <10577112+nananosirova@users.noreply.github.com>
1 parent 222ef71 commit 6fb99ee

2 files changed

Lines changed: 22 additions & 4 deletions

File tree

frontend/src/concepts/pipelines/content/experiment/CreateExperimentModal.tsx

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import {
44
Button,
55
Form,
66
FormGroup,
7+
HelperText,
8+
HelperTextItem,
79
Stack,
810
StackItem,
911
TextInput,
@@ -26,16 +28,23 @@ import { TrackingOutcome } from '#~/concepts/analyticsTracking/trackingPropertie
2628

2729
type CreateExperimentModalProps = {
2830
onClose: (experiment?: ExperimentKF) => void;
31+
existingNames?: string[];
2932
};
3033

3134
const eventName = 'Experiment Created';
32-
const CreateExperimentModal: React.FC<CreateExperimentModalProps> = ({ onClose }) => {
35+
const CreateExperimentModal: React.FC<CreateExperimentModalProps> = ({
36+
onClose,
37+
existingNames = [],
38+
}) => {
3339
const { project, api, apiAvailable } = usePipelinesAPI();
3440
const [submitting, setSubmitting] = React.useState(false);
3541
const [error, setError] = React.useState<Error | undefined>();
3642
const [{ name, description }, setData, resetData] = useCreateExperimentData();
3743

38-
const haveEnoughData = !!name;
44+
const isDuplicate = existingNames.some(
45+
(existing) => existing.toLowerCase() === name.trim().toLowerCase(),
46+
);
47+
const haveEnoughData = !!name && !isDuplicate;
3948

4049
const onBeforeClose = (experiment?: ExperimentKF) => {
4150
onClose(experiment);
@@ -72,11 +81,19 @@ const CreateExperimentModal: React.FC<CreateExperimentModalProps> = ({ onClose }
7281
id="experiment-name"
7382
name="experiment-name"
7483
value={name}
84+
validated={isDuplicate ? 'error' : 'default'}
7585
onChange={(_, value) => setData('name', value)}
7686
maxLength={NAME_CHARACTER_LIMIT}
7787
/>
78-
79-
<CharLimitHelperText limit={NAME_CHARACTER_LIMIT} currentLength={name.length} />
88+
{isDuplicate ? (
89+
<HelperText>
90+
<HelperTextItem variant="error">
91+
A run group with this name already exists.
92+
</HelperTextItem>
93+
</HelperText>
94+
) : (
95+
<CharLimitHelperText limit={NAME_CHARACTER_LIMIT} currentLength={name.length} />
96+
)}
8097
</FormGroup>
8198
</StackItem>
8299
<StackItem>

frontend/src/concepts/pipelines/content/experiment/ExperimentSelector.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ const InnerExperimentSelector: React.FC<
128128
</SearchSelector>
129129
{isModalOpen && (
130130
<CreateExperimentModal
131+
existingNames={experiments.map((e) => e.display_name)}
131132
onClose={(experiment) => {
132133
setIsModalOpen(false);
133134
if (experiment) {

0 commit comments

Comments
 (0)