From 6eb6bb1d7e6204c473173bca55f8773ba2f06917 Mon Sep 17 00:00:00 2001 From: Mgrdich <46796009+Mgrdich@users.noreply.github.com> Date: Mon, 18 Apr 2022 14:14:53 +0400 Subject: [PATCH] Smart filters improvements (#1814) * Add Filters add button and remove the Add Filter Icon * Generalize DeleteFilterModal and write tests suites + add custom addModal hook * add react-testing-hook-lib + add tests to useModal hook * Add parameter to ConfirmationModal + remove delete Modal add generic modal in add filter page * implementing the modal hook on add Filter * Finalize the Smart Filters functionality * Styling code modifications * Styling code modifications * Filters styling code modifcations * minor modifications in the tests suites * minor tests suites description modifications * minor tests suites code modifications * Adding unNamed Filter selection option + tests suites * Fix typo Signed-off-by: Roman Zabaluev * Adding tests Wuites to AddEditFilterContainer and to addFilter * Add Filters add button and remove the Add Filter Icon * Generalize DeleteFilterModal and write tests suites + add custom addModal hook * add react-testing-hook-lib + add tests to useModal hook * Add parameter to ConfirmationModal + remove delete Modal add generic modal in add filter page * implementing the modal hook on add Filter * Finalize the Smart Filters functionality * Styling code modifications * Styling code modifications * Filters styling code modifcations * minor modifications in the tests suites * minor tests suites description modifications * minor tests suites code modifications * Adding unNamed Filter selection option + tests suites * Fix typo Signed-off-by: Roman Zabaluev * Adding tests Wuites to AddEditFilterContainer and to addFilter * q parameter modifications in the SmartFilters * Add popup close functionality after applying the filters Co-authored-by: Roman Zabaluev --- kafka-ui-react-app/package-lock.json | 22 ++ kafka-ui-react-app/package.json | 1 + .../Filters/AddEditFilterContainer.tsx | 166 ++++++------ .../Details/Messages/Filters/AddFilter.tsx | 166 ++++-------- .../Details/Messages/Filters/EditFilter.tsx | 19 +- .../Messages/Filters/Filters.styled.ts | 100 ++++---- .../Details/Messages/Filters/Filters.tsx | 13 +- .../Details/Messages/Filters/SavedFilters.tsx | 109 ++++++++ .../__tests__/AddEditFilterContainer.spec.tsx | 80 ++---- .../Filters/__tests__/AddFilter.spec.tsx | 239 +++++++++--------- .../Filters/__tests__/EditFilter.spec.tsx | 8 +- .../Filters/__tests__/FilterModal.spec.tsx | 9 +- .../Filters/__tests__/Filters.spec.tsx | 66 +++-- .../Filters/__tests__/SavedFilters.spec.tsx | 157 ++++++++++++ .../ConfirmationModal/ConfirmationModal.tsx | 8 +- .../__test__/ConfirmationModal.spec.tsx | 14 +- .../src/components/common/Icons/SavedIcon.tsx | 29 +++ .../src/lib/hooks/__tests__/useModal.spec.ts | 66 +++++ kafka-ui-react-app/src/lib/hooks/useModal.ts | 32 +++ kafka-ui-react-app/src/theme/theme.ts | 1 + 20 files changed, 830 insertions(+), 475 deletions(-) create mode 100644 kafka-ui-react-app/src/components/Topics/Topic/Details/Messages/Filters/SavedFilters.tsx create mode 100644 kafka-ui-react-app/src/components/Topics/Topic/Details/Messages/Filters/__tests__/SavedFilters.spec.tsx create mode 100644 kafka-ui-react-app/src/components/common/Icons/SavedIcon.tsx create mode 100644 kafka-ui-react-app/src/lib/hooks/__tests__/useModal.spec.ts create mode 100644 kafka-ui-react-app/src/lib/hooks/useModal.ts diff --git a/kafka-ui-react-app/package-lock.json b/kafka-ui-react-app/package-lock.json index 2b4612881c..7e78f2137e 100644 --- a/kafka-ui-react-app/package-lock.json +++ b/kafka-ui-react-app/package-lock.json @@ -4869,6 +4869,19 @@ "@testing-library/dom": "^8.0.0" } }, + "@testing-library/react-hooks": { + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/@testing-library/react-hooks/-/react-hooks-7.0.2.tgz", + "integrity": "sha512-dYxpz8u9m4q1TuzfcUApqi8iFfR6R0FaMbr2hjZJy1uC8z+bO/K4v8Gs9eogGKYQop7QsrBTFkv/BCF7MzD2Cg==", + "dev": true, + "requires": { + "@babel/runtime": "^7.12.5", + "@types/react": ">=16.9.0", + "@types/react-dom": ">=16.9.0", + "@types/react-test-renderer": ">=16.9.0", + "react-error-boundary": "^3.1.0" + } + }, "@testing-library/user-event": { "version": "13.5.0", "resolved": "https://registry.npmjs.org/@testing-library/user-event/-/user-event-13.5.0.tgz", @@ -17194,6 +17207,15 @@ "scheduler": "^0.20.2" } }, + "react-error-boundary": { + "version": "3.1.4", + "resolved": "https://registry.npmjs.org/react-error-boundary/-/react-error-boundary-3.1.4.tgz", + "integrity": "sha512-uM9uPzZJTF6wRQORmSrvOIgt4lJ9MC1sNgEOj2XGsDTRE4kmpWxg7ENK9EWNKJRMAOY9z0MuF4yIfl6gp4sotA==", + "dev": true, + "requires": { + "@babel/runtime": "^7.12.5" + } + }, "react-error-overlay": { "version": "6.0.10", "resolved": "https://registry.npmjs.org/react-error-overlay/-/react-error-overlay-6.0.10.tgz", diff --git a/kafka-ui-react-app/package.json b/kafka-ui-react-app/package.json index 71dca68a70..8671b35133 100644 --- a/kafka-ui-react-app/package.json +++ b/kafka-ui-react-app/package.json @@ -82,6 +82,7 @@ "@openapitools/openapi-generator-cli": "^2.4.15", "@testing-library/dom": "^8.11.1", "@testing-library/jest-dom": "^5.14.1", + "@testing-library/react-hooks": "^7.0.2", "@testing-library/user-event": "^13.5.0", "@types/classnames": "^2.2.11", "@types/enzyme": "^3.10.9", diff --git a/kafka-ui-react-app/src/components/Topics/Topic/Details/Messages/Filters/AddEditFilterContainer.tsx b/kafka-ui-react-app/src/components/Topics/Topic/Details/Messages/Filters/AddEditFilterContainer.tsx index bf30ad7b95..8f710cb8f5 100644 --- a/kafka-ui-react-app/src/components/Topics/Topic/Details/Messages/Filters/AddEditFilterContainer.tsx +++ b/kafka-ui-react-app/src/components/Topics/Topic/Details/Messages/Filters/AddEditFilterContainer.tsx @@ -7,41 +7,38 @@ import { FormProvider, Controller, useForm } from 'react-hook-form'; import { ErrorMessage } from '@hookform/error-message'; import { Button } from 'components/common/Button/Button'; import { FormError } from 'components/common/Input/Input.styled'; -import { MessageFilters } from 'components/Topics/Topic/Details/Messages/Filters/Filters'; +import { AddMessageFilters } from 'components/Topics/Topic/Details/Messages/Filters/AddFilter'; import { yupResolver } from '@hookform/resolvers/yup'; import yup from 'lib/yupExtended'; const validationSchema = yup.object().shape({ - name: yup.string().required(), + saveFilter: yup.boolean(), code: yup.string().required(), + name: yup.string().when('saveFilter', { + is: (value: boolean | undefined) => typeof value === 'undefined' || value, + then: (schema) => schema.required(), + otherwise: (schema) => schema.notRequired(), + }), }); export interface AddEditFilterContainerProps { - title: string; cancelBtnHandler: () => void; submitBtnText: string; inputDisplayNameDefaultValue?: string; inputCodeDefaultValue?: string; - toggleSaveFilterValue?: boolean; - toggleSaveFilterSetter?: () => void; - createNewFilterText?: string; - submitCallback?: (values: MessageFilters) => void; - submitCallbackWithReset?: boolean; + isAdd?: boolean; + submitCallback?: (values: AddMessageFilters) => void; } const AddEditFilterContainer: React.FC = ({ - title, cancelBtnHandler, submitBtnText, inputDisplayNameDefaultValue = '', inputCodeDefaultValue = '', - toggleSaveFilterValue, - toggleSaveFilterSetter, - createNewFilterText, submitCallback, - submitCallbackWithReset, + isAdd, }) => { - const methods = useForm({ + const methods = useForm({ mode: 'onChange', resolver: yupResolver(validationSchema), }); @@ -53,88 +50,77 @@ const AddEditFilterContainer: React.FC = ({ } = methods; const onSubmit = React.useCallback( - (values: MessageFilters) => { + (values: AddMessageFilters) => { submitCallback?.(values); - if (submitCallbackWithReset) { - reset({ name: '', code: '' }); - } + reset({ name: '', code: '', saveFilter: false }); }, - [reset, submitCallback, submitCallbackWithReset] + [isAdd, reset, submitCallback] ); return ( - <> - {title} - - {createNewFilterText && ( - {createNewFilterText} + +
+
+ Filter code + ( +