diff --git a/client/src/app/pages/applications/application-assessment/components/application-assessment-page/application-assessment-page-header.tsx b/client/src/app/pages/applications/application-assessment/components/application-assessment-page/application-assessment-page-header.tsx index 10961379ee..e9542a9f84 100644 --- a/client/src/app/pages/applications/application-assessment/components/application-assessment-page/application-assessment-page-header.tsx +++ b/client/src/app/pages/applications/application-assessment/components/application-assessment-page/application-assessment-page-header.tsx @@ -4,7 +4,6 @@ import { useTranslation } from "react-i18next"; import { Button, ButtonVariant, Modal, Text } from "@patternfly/react-core"; import { ConfirmDialog, PageHeader } from "@app/shared/components"; -import { useEntityModal } from "@app/shared/hooks"; import { ApplicationDependenciesFormContainer } from "@app/shared/containers"; import { Paths } from "@app/Paths"; import { Application, Assessment } from "@app/api/models"; @@ -33,13 +32,8 @@ export const ApplicationAssessmentPageHeader: React.FC< } }, [assessment]); - // Dependencies modal - const { - isOpen: isDependenciesModalOpen, - data: applicationToManageDependencies, - update: openDependenciesModal, - close: closeDependenciesModal, - } = useEntityModal(); + const [applicationDependenciesToManage, setApplicationDependenciesToManage] = + React.useState(null); return ( <> @@ -61,7 +55,9 @@ export const ApplicationAssessmentPageHeader: React.FC< btnActions={ <> {application && ( - )} @@ -71,17 +67,17 @@ export const ApplicationAssessmentPageHeader: React.FC< /> setApplicationDependenciesToManage(null)} > - {applicationToManageDependencies && ( + {applicationDependenciesToManage && ( setApplicationDependenciesToManage(null)} /> )} diff --git a/client/src/app/pages/applications/applications-table-analyze/applications-table-analyze.tsx b/client/src/app/pages/applications/applications-table-analyze/applications-table-analyze.tsx index bedd28f960..52a1e15581 100644 --- a/client/src/app/pages/applications/applications-table-analyze/applications-table-analyze.tsx +++ b/client/src/app/pages/applications/applications-table-analyze/applications-table-analyze.tsx @@ -26,7 +26,6 @@ import { } from "@patternfly/react-table"; import TagIcon from "@patternfly/react-icons/dist/esm/icons/tag-icon"; import PencilAltIcon from "@patternfly/react-icons/dist/esm/icons/pencil-alt-icon"; - import keycloak from "@app/keycloak"; import { AppPlaceholder, diff --git a/client/src/app/shared/hooks/index.ts b/client/src/app/shared/hooks/index.ts index ec483a08e4..452d14cb0c 100644 --- a/client/src/app/shared/hooks/index.ts +++ b/client/src/app/shared/hooks/index.ts @@ -1,2 +1 @@ -export { useEntityModal } from "./useEntityModal"; export { useAssessApplication } from "./useAssessApplication"; diff --git a/client/src/app/shared/hooks/useEntityModal/index.ts b/client/src/app/shared/hooks/useEntityModal/index.ts deleted file mode 100644 index 7d7faa96a4..0000000000 --- a/client/src/app/shared/hooks/useEntityModal/index.ts +++ /dev/null @@ -1 +0,0 @@ -export { useEntityModal } from "./useEntityModal"; diff --git a/client/src/app/shared/hooks/useEntityModal/useEntityModal.test.tsx b/client/src/app/shared/hooks/useEntityModal/useEntityModal.test.tsx deleted file mode 100644 index cd66df8006..0000000000 --- a/client/src/app/shared/hooks/useEntityModal/useEntityModal.test.tsx +++ /dev/null @@ -1,46 +0,0 @@ -import { renderHook, act } from "@testing-library/react-hooks"; -import { useEntityModal } from "./useEntityModal"; - -describe("useEntityModal", () => { - it("onCreate", () => { - const { result } = renderHook(() => useEntityModal()); - - // - const { create } = result.current; - act(() => create()); - expect(result.current.isOpen).toEqual(true); - expect(result.current.data).toBeUndefined(); - }); - - it("onUpdate", () => { - const ENTITY = "hello"; - - const { result } = renderHook(() => useEntityModal()); - - // - const { update } = result.current; - act(() => update(ENTITY)); - - expect(result.current.isOpen).toEqual(true); - expect(result.current.data).toEqual(ENTITY); - }); - - it("Close after update", () => { - const ENTITY = "hello"; - - const { result } = renderHook(() => useEntityModal()); - const { update, close } = result.current; - - // update - act(() => update(ENTITY)); - - expect(result.current.isOpen).toEqual(true); - expect(result.current.data).toEqual(ENTITY); - - // close - act(() => close()); - - expect(result.current.isOpen).toEqual(false); - expect(result.current.data).toBeUndefined(); - }); -}); diff --git a/client/src/app/shared/hooks/useEntityModal/useEntityModal.ts b/client/src/app/shared/hooks/useEntityModal/useEntityModal.ts deleted file mode 100644 index 0ae2a94c21..0000000000 --- a/client/src/app/shared/hooks/useEntityModal/useEntityModal.ts +++ /dev/null @@ -1,86 +0,0 @@ -import { useCallback, useReducer } from "react"; -import { ActionType, createAction, getType } from "typesafe-actions"; - -const startCreate = createAction("useEntityModal/action/startCreate")(); -const startUpdate = createAction("useEntityModal/action/startUpdate")(); -const startClose = createAction("useEntityModal/action/startClose")(); - -// State -type State = Readonly<{ - data: any; - isOpen: boolean; -}>; - -const defaultState: State = { - data: undefined, - isOpen: false, -}; - -// Reducer - -type Action = ActionType< - typeof startCreate | typeof startUpdate | typeof startClose ->; - -const reducer = (state: State, action: Action): State => { - switch (action.type) { - case getType(startCreate): - return { - ...state, - data: undefined, - isOpen: true, - }; - case getType(startUpdate): - return { - ...state, - data: action.payload, - isOpen: true, - }; - case getType(startClose): - return { - ...state, - data: undefined, - isOpen: false, - }; - default: - return state; - } -}; - -// Hook - -interface HookState { - data?: T; - isOpen: boolean; - create: () => void; - update: (data: T) => void; - close: () => void; -} - -export const useEntityModal = (): HookState => { - const [state, dispatch] = useReducer(reducer, { - ...defaultState, - }); - - const createHandler = useCallback(() => { - dispatch(startCreate()); - }, []); - - const updateHandler = useCallback((entity: T) => { - dispatch(startUpdate(entity)); - }, []); - - const closeHandler = useCallback(() => { - dispatch(startClose()); - }, []); - - return { - data: state.data, - isOpen: state.isOpen, - create: createHandler, - update: updateHandler, - close: closeHandler, - }; -}; - -export default useEntityModal;