kafka-ui/kafka-ui-react-app/src/lib/hooks/useModal.ts
Mgrdich 6eb6bb1d7e
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 <rzabaluev@provectus.com>

* 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 <rzabaluev@provectus.com>

* 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 <rzabaluev@provectus.com>
2022-04-18 14:14:53 +04:00

32 lines
636 B
TypeScript

import { useCallback, useState } from 'react';
interface UseModalReturn {
isOpen: boolean;
setOpen(): void;
setClose(): void;
toggle(): void;
}
const useModal = (initialModalState?: boolean): UseModalReturn => {
const [modalOpen, setModalOpen] = useState<boolean>(!!initialModalState);
const setOpen = useCallback(() => {
setModalOpen(true);
}, []);
const setClose = useCallback(() => {
setModalOpen(false);
}, []);
const toggle = useCallback(() => {
setModalOpen((prev) => !prev);
}, []);
return {
isOpen: modalOpen,
setOpen,
setClose,
toggle,
};
};
export default useModal;