Skip to content

Commit 6650f1b

Browse files
authored
Editing the terms shouldn't throw alerts. (#1701)
1 parent d2172b4 commit 6650f1b

File tree

1 file changed

+15
-10
lines changed
  • odd-platform-ui/src/components/Terms/TermSearch/TermForm

1 file changed

+15
-10
lines changed

odd-platform-ui/src/components/Terms/TermSearch/TermForm/TermsForm.tsx

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -80,18 +80,23 @@ const TermsForm: FC<TermsFormDialogProps> = ({ btnCreateEl }) => {
8080
};
8181

8282
const onSubmit = (data: TermFormData) => {
83-
const duplicateTerm = existingTerms.find(
84-
(existingTerm: TermDetails) =>
85-
existingTerm.name === data.name &&
86-
existingTerm.namespace.name === data.namespaceName
87-
);
88-
89-
if (duplicateTerm) {
90-
setError('A term with the same name already exists in this namespace.');
91-
return;
83+
// Check if we're in create mode (no term.id present)
84+
if (!term?.id) {
85+
const duplicateTerm = existingTerms.find(
86+
(existingTerm: TermDetails) =>
87+
existingTerm.name === data.name &&
88+
existingTerm.namespace.name === data.namespaceName
89+
);
90+
91+
if (duplicateTerm) {
92+
setError('A term with the same name already exists in this namespace.');
93+
return;
94+
}
9295
}
9396

9497
const parsedData = { ...data };
98+
99+
// Determine whether to create or update the term
95100
(term && term.id
96101
? dispatch(updateTerm({ termId: term.id, termFormData: parsedData }))
97102
: dispatch(createTerm({ termFormData: parsedData }))
@@ -210,4 +215,4 @@ const TermsForm: FC<TermsFormDialogProps> = ({ btnCreateEl }) => {
210215
);
211216
};
212217

213-
export default TermsForm;
218+
export default TermsForm;

0 commit comments

Comments
 (0)