Repository: provectus/kafka-ui
Issue: It's possible to save the filters with the same name for Messages
Labels: type/bug
good first issue
scope/frontend
status/accepted
status/confirmed


**Describe the bug**
It's possible to save the filters with the same name for Messages

**Set up**
https://www.kafka-ui.provectus.io/


**Steps to Reproduce**
<!-- We'd like you to provide an example setup (via docker-compose, helm, etc.) 
to reproduce the problem, especially with a complex setups. -->
Steps to reproduce the behavior:

1. Navigate to Topics
2. Turn to Messages tab for any Topic
3. Press "+ Add Filters"
4. Turn to Saved Filters
5. Check the existing Filters
6. Add the filter with the same name

**Expected behavior**
Should not be possible to submit the Filter with the same name

**Screenshots**

https://user-images.githubusercontent.com/104780608/182073770-3e266ef0-e268-44cb-8d08-c12c9aded862.mov



**Additional context**
<!--
(Add any other context about the problem here)
-->


Issue comments:

Pull request review comments:
i would suggest to use `same` instead of current here 
```suggestion
          message: 'Filter with the same name already exists',
```
Updated

Patch that resolved the issue:
diff --git a/kafka-ui-react-app/src/components/Topics/Topic/Messages/Filters/AddEditFilterContainer.tsx b/kafka-ui-react-app/src/components/Topics/Topic/Messages/Filters/AddEditFilterContainer.tsx
index 557db159ba7..757b6e171dd 100644
--- a/kafka-ui-react-app/src/components/Topics/Topic/Messages/Filters/AddEditFilterContainer.tsx
+++ b/kafka-ui-react-app/src/components/Topics/Topic/Messages/Filters/AddEditFilterContainer.tsx
@@ -27,7 +27,7 @@ export interface AddEditFilterContainerProps {
   inputDisplayNameDefaultValue?: string;
   inputCodeDefaultValue?: string;
   isAdd?: boolean;
-  submitCallback?: (values: AddMessageFilters) => void;
+  submitCallback?: (values: AddMessageFilters) => Promise<void>;
 }
 
 const AddEditFilterContainer: React.FC<AddEditFilterContainerProps> = ({
diff --git a/kafka-ui-react-app/src/components/Topics/Topic/Messages/Filters/AddFilter.tsx b/kafka-ui-react-app/src/components/Topics/Topic/Messages/Filters/AddFilter.tsx
index 7d3d95ecc76..035d98c3a39 100644
--- a/kafka-ui-react-app/src/components/Topics/Topic/Messages/Filters/AddFilter.tsx
+++ b/kafka-ui-react-app/src/components/Topics/Topic/Messages/Filters/AddFilter.tsx
@@ -6,6 +6,7 @@ import SavedFilters from 'components/Topics/Topic/Messages/Filters/SavedFilters'
 import SavedIcon from 'components/common/Icons/SavedIcon';
 import QuestionIcon from 'components/common/Icons/QuestionIcon';
 import useBoolean from 'lib/hooks/useBoolean';
+import { showAlert } from 'lib/errorHandling';
 
 import AddEditFilterContainer from './AddEditFilterContainer';
 import InfoModal from './InfoModal';
@@ -43,6 +44,19 @@ const AddFilter: React.FC<FilterModalProps> = ({
 
   const onSubmit = React.useCallback(
     async (values: AddMessageFilters) => {
+      const isFilterExists = filters.some(
+        (filter) => filter.name === values.name
+      );
+
+      if (isFilterExists) {
+        showAlert('error', {
+          id: '',
+          title: 'Validation Error',
+          message: 'Filter with the same name already exists',
+        });
+        return;
+      }
+
       const data = { ...values };
       if (data.saveFilter) {
         addFilter(data);


Test patch: