diff --git a/client/public/locales/en/translation.json b/client/public/locales/en/translation.json index 0363a01f83..43852f0859 100644 --- a/client/public/locales/en/translation.json +++ b/client/public/locales/en/translation.json @@ -106,7 +106,7 @@ "maxfileSize": "Max file size of 1MB exceeded. Upload a smaller file.", "dragAndDropFile": "Drag and drop your file here or upload one.", "uploadYamlFile": "Upload your YAML file", - "deleteQuestionnaire": "Deleting a questionnaire will cascade into the deletion of all answered questionnaires associated to applications and/or archetypes.", + "deleteQuestionnire": "Deleting a questionnaire will cascade into the deletion of all answered questionnaires associated to applications and/or archetypes.", "confirmDeletion": "Confirm deletion by typing <1>{{nameToDelete}} below:" }, "title": { @@ -122,6 +122,7 @@ "importApplicationFile": "Import application file", "import": "Import {{what}}", "leavePage": "Leave page", + "leaveAssessment": "Leave assessment", "new": "New {{what}}", "newArchetype": "Create new archetype", "newAssessment": "New assessment", diff --git a/client/src/app/Routes.tsx b/client/src/app/Routes.tsx index 1575586ea6..7c013154d5 100644 --- a/client/src/app/Routes.tsx +++ b/client/src/app/Routes.tsx @@ -12,7 +12,6 @@ import { ErrorBoundary } from "react-error-boundary"; import { ErrorFallback } from "@app/components/ErrorFallback"; import { FEATURES_ENABLED } from "./FeatureFlags"; -const Assessment = lazy(() => import("./pages/assessment/assessment-page")); const Review = lazy(() => import("./pages/review/review-page")); const AssessmentSettings = lazy( () => @@ -80,16 +79,6 @@ export const devRoutes: IRoute[] = [ comp: ManageImports, exact: false, }, - { - path: Paths.archetypesAssessment, - comp: Assessment, - exact: false, - }, - { - path: Paths.applicationsAssessment, - comp: Assessment, - exact: false, - }, { path: Paths.archetypeReview, comp: Review, diff --git a/client/src/app/pages/assessment/assessment-page.tsx b/client/src/app/pages/assessment/assessment-page.tsx deleted file mode 100644 index e834e4f158..0000000000 --- a/client/src/app/pages/assessment/assessment-page.tsx +++ /dev/null @@ -1,73 +0,0 @@ -import React, { useState } from "react"; -import { useParams } from "react-router-dom"; -import { useTranslation } from "react-i18next"; -import { AxiosError } from "axios"; -import { - Alert, - AlertActionCloseButton, - Bullseye, - PageSection, - PageSectionTypes, -} from "@patternfly/react-core"; -import BanIcon from "@patternfly/react-icons/dist/esm/icons/ban-icon"; -import { AssessmentRoute } from "@app/Paths"; -import { getAxiosErrorMessage } from "@app/utils/utils"; -import { SimpleEmptyState } from "@app/components/SimpleEmptyState"; -import { useFetchAssessmentById } from "@app/queries/assessments"; -import { AssessmentPageHeader } from "./components/assessment-page-header"; -import { AssessmentWizard } from "./components/assessment-wizard/assessment-wizard"; - -const AssessmentPage: React.FC = () => { - const { t } = useTranslation(); - - const { assessmentId } = useParams(); - - const { assessment, isFetching, fetchError } = - useFetchAssessmentById(assessmentId); - - const [saveError, setSaveError] = useState(); - - if (fetchError) { - return ( - <> - - - - - - - - - - ); - } - return ( - <> - - - - - {saveError && ( - setSaveError(undefined)} /> - } - /> - )} - - - - ); -}; -export default AssessmentPage; diff --git a/client/src/app/pages/assessment/components/assessment-actions/components/dynamic-assessment-actions-row.tsx b/client/src/app/pages/assessment/components/assessment-actions/components/dynamic-assessment-actions-row.tsx index e7651c7a05..7a532b8938 100644 --- a/client/src/app/pages/assessment/components/assessment-actions/components/dynamic-assessment-actions-row.tsx +++ b/client/src/app/pages/assessment/components/assessment-actions/components/dynamic-assessment-actions-row.tsx @@ -11,7 +11,7 @@ import { useCreateAssessmentMutation, useDeleteAssessmentMutation, } from "@app/queries/assessments"; -import { Button } from "@patternfly/react-core"; +import { Button, Spinner } from "@patternfly/react-core"; import React, { FunctionComponent } from "react"; import { useHistory } from "react-router-dom"; import "./dynamic-assessment-actions-row.css"; @@ -20,7 +20,11 @@ import { formatPath, getAxiosErrorMessage } from "@app/utils/utils"; import { Td } from "@patternfly/react-table"; import { NotificationsContext } from "@app/components/NotificationsContext"; import { useTranslation } from "react-i18next"; -import { useQueryClient } from "@tanstack/react-query"; +import { + useIsFetching, + useIsMutating, + useQueryClient, +} from "@tanstack/react-query"; import { TrashIcon } from "@patternfly/react-icons"; import useIsArchetype from "@app/hooks/useIsArchetype"; @@ -36,11 +40,19 @@ interface DynamicAssessmentActionsRowProps { archetype?: Archetype; assessment?: Assessment; isReadonly?: boolean; + onOpenModal: (assessment: Assessment) => void; } const DynamicAssessmentActionsRow: FunctionComponent< DynamicAssessmentActionsRowProps -> = ({ questionnaire, application, archetype, assessment, isReadonly }) => { +> = ({ + questionnaire, + application, + archetype, + assessment, + isReadonly, + onOpenModal, +}) => { const isArchetype = useIsArchetype(); const history = useHistory(); const { t } = useTranslation(); @@ -64,7 +76,11 @@ const DynamicAssessmentActionsRow: FunctionComponent< }), variant: "success", }); - queryClient.invalidateQueries([assessmentsByItemIdQueryKey]); + queryClient.invalidateQueries([ + assessmentsByItemIdQueryKey, + application?.id, + isArchetype, + ]); }; const onDeleteError = (error: AxiosError) => { @@ -74,10 +90,11 @@ const DynamicAssessmentActionsRow: FunctionComponent< }); }; - const { mutate: deleteAssessment } = useDeleteAssessmentMutation( - onDeleteAssessmentSuccess, - onDeleteError - ); + const { mutate: deleteAssessment, isLoading: isDeleting } = + useDeleteAssessmentMutation(onDeleteAssessmentSuccess, onDeleteError); + + const isFetching = useIsFetching(); + const isMutating = useIsMutating(); const { mutateAsync: deleteAssessmentAsync } = useDeleteAssessmentMutation( onDeleteAssessmentSuccess, @@ -117,19 +134,8 @@ const DynamicAssessmentActionsRow: FunctionComponent< try { const result = await createAssessmentAsync(newAssessment); - if (isArchetype) { - history.push( - formatPath(Paths.archetypesAssessment, { - assessmentId: result.id, - }) - ); - } else { - history.push( - formatPath(Paths.applicationsAssessment, { - assessmentId: result.id, - }) - ); - } + + onOpenModal(result); } catch (error) { console.error("Error while creating assessment:", error); pushNotification({ @@ -165,17 +171,8 @@ const DynamicAssessmentActionsRow: FunctionComponent< if (action === AssessmentAction.Take) { takeAssessment(); - } else if (action === AssessmentAction.Continue) { - history.push( - formatPath( - isArchetype - ? Paths.archetypesAssessment - : Paths.applicationsAssessment, - { - assessmentId: assessment?.id, - } - ) - ); + } else if (action === AssessmentAction.Continue && assessment?.id) { + onOpenModal(assessment); } else if (action === AssessmentAction.Retake) { if (assessment) { try { @@ -204,7 +201,7 @@ const DynamicAssessmentActionsRow: FunctionComponent< <>
- {!isReadonly ? ( + {isReadonly ? null : !isDeleting && !isFetching && !isMutating ? ( - ) : null} + ) : ( + + Loading... + + )} {assessment?.status === "complete" ? (