diff --git a/client/public/locales/en/translation.json b/client/public/locales/en/translation.json index 7fe9fd91c9..c64b5bc8af 100644 --- a/client/public/locales/en/translation.json +++ b/client/public/locales/en/translation.json @@ -75,6 +75,7 @@ }, "composed": { "add": "Add {{what}}", + "new": "New {{what}}", "applicationAssessment": "Application assessment", "applicationInventory": "Application inventory", "businessCriticality": "Business criticality (1=low, 10=high)", @@ -170,8 +171,8 @@ "noDataAvailableTitle": "No data available", "noResultsFoundBody": "No results match the filter criteria. Remove all filters or clear all filters to show results.", "noResultsFoundTitle": "No results found", - "overrideAssessmentDescription": "The archetype for {{what}} already has an assessment.", - "overrideAssessmentConfirmation": "Do you want to create a dedicated assessment for this application?", + "overrideAssessmentDescription": "The application {{name}} already is associated with archetypes: {{what}}.", + "overrideAssessmentConfirmation": "Do you want to create a dedicated assessment for this application and override the inherited archetype assessment(s)?", "overrideReviewConfirmation": "This application has already been reviewed. Do you want to continue?", "reasonForError": "The reported reason for the error:", "reviewInstructions": "Use this section to provide your assessment of the possible migration/modernization plan and effort estimation.", diff --git a/client/src/app/Paths.ts b/client/src/app/Paths.ts index d293facac0..27d3dbc904 100644 --- a/client/src/app/Paths.ts +++ b/client/src/app/Paths.ts @@ -11,6 +11,7 @@ export enum Paths { archetypesAssessment = "/archetypes/assessment/:assessmentId", applicationsAssessment = "/applications/assessment/:assessmentId", applicationAssessmentActions = "/applications/assessment-actions/:applicationId", + viewArchetypes = "/applications/view-archetypes/:applicationId/archetypes/:archetypeId", archetypeAssessmentActions = "/archetypes/assessment-actions/:archetypeId", applicationAssessmentSummary = "/applications/assessment-summary/:assessmentId", archetypeAssessmentSummary = "/archetypes/assessment-summary/:assessmentId", @@ -57,6 +58,11 @@ export interface AssessmentActionsRoute { archetypeId?: string; } +export interface ViewArchetypesRoute { + applicationId?: string; + archetypeId?: string; +} + export interface ReviewRoute { applicationId?: string; archetypeId?: string; diff --git a/client/src/app/Routes.tsx b/client/src/app/Routes.tsx index 25a700720c..fb4bac0ab9 100644 --- a/client/src/app/Routes.tsx +++ b/client/src/app/Routes.tsx @@ -44,6 +44,10 @@ const Questionnaire = lazy( () => import("./pages/assessment-management/questionnaire/questionnaire-page") ); +const ViewArchetypes = lazy( + () => + import("./pages/assessment/components/view-archetypes/view-archetypes-page") +); const AssessmentActions = lazy( () => import( @@ -101,6 +105,11 @@ export const devRoutes: IRoute[] = [ comp: AssessmentActions, exact: false, }, + { + path: Paths.viewArchetypes, + comp: ViewArchetypes, + exact: false, + }, { path: Paths.applicationAssessmentSummary, comp: AssessmentSummary, diff --git a/client/src/app/pages/applications/applications-table-assessment/applications-table-assessment.tsx b/client/src/app/pages/applications/applications-table-assessment/applications-table-assessment.tsx index 09c3dedb33..5d82ba8841 100644 --- a/client/src/app/pages/applications/applications-table-assessment/applications-table-assessment.tsx +++ b/client/src/app/pages/applications/applications-table-assessment/applications-table-assessment.tsx @@ -65,7 +65,7 @@ import { useQueryClient } from "@tanstack/react-query"; import { useLocalTableControls } from "@app/hooks/table-controls"; // Queries -import { Application, Assessment, Task } from "@app/api/models"; +import { Application, Assessment, Ref, Task } from "@app/api/models"; import { ApplicationsQueryKey, useBulkDeleteApplicationMutation, @@ -73,7 +73,7 @@ import { } from "@app/queries/applications"; import { useFetchTasks } from "@app/queries/tasks"; import { useDeleteAssessmentMutation } from "@app/queries/assessments"; -import { useDeleteReviewMutation, useFetchReviews } from "@app/queries/reviews"; +import { useDeleteReviewMutation } from "@app/queries/reviews"; import { useFetchIdentities } from "@app/queries/identities"; import { useFetchTagCategories } from "@app/queries/tags"; @@ -86,6 +86,7 @@ import { ImportApplicationsForm } from "../components/import-applications-form"; import { ConditionalRender } from "@app/components/ConditionalRender"; import { NoDataEmptyState } from "@app/components/NoDataEmptyState"; import { ConditionalTooltip } from "@app/components/ConditionalTooltip"; +import { getAssessmentsByItemId } from "@app/api/rest"; export const ApplicationsTable: React.FC = () => { const { t } = useTranslation(); @@ -106,28 +107,17 @@ export const ApplicationsTable: React.FC = () => { const createUpdateApplications = saveApplicationModalState !== "create" ? saveApplicationModalState : null; - const [applicationToCopyAssessmentFrom, setApplicationToCopyAssessmentFrom] = - React.useState(null); - - const isCopyAssessmentModalOpen = applicationToCopyAssessmentFrom !== null; - - const [isAssessModalOpen, setAssessModalOpen] = React.useState(false); + const [archetypeRefsToOverride, setArchetypeRefsToOverride] = React.useState< + Ref[] | null + >(null); - const [ - applicationToCopyAssessmentAndReviewFrom, - setCopyAssessmentAndReviewModalState, - ] = React.useState(null); - - const isCopyAssessmentAndReviewModalOpen = - applicationToCopyAssessmentAndReviewFrom !== null; + const [applicationToAssess, setApplicationToAssess] = + React.useState(null); const [applicationDependenciesToManage, setApplicationDependenciesToManage] = React.useState(null); const isDependenciesModalOpen = applicationDependenciesToManage !== null; - const [applicationToAssess, setApplicationToAssess] = - React.useState(null); - const [assessmentToEdit, setAssessmentToEdit] = React.useState(null); @@ -156,9 +146,6 @@ export const ApplicationsTable: React.FC = () => { refetch: fetchApplications, } = useFetchApplications(); - //TODO: check if any archetypes match this application here - const matchingArchetypes = []; - const onDeleteApplicationSuccess = (appIDCount: number) => { pushNotification({ title: t("toastr.success.applicationDeleted", { @@ -401,12 +388,6 @@ export const ApplicationsTable: React.FC = () => { selectionState: { selectedItems: selectedRows }, } = tableControls; - const { - reviews, - isFetching: isFetchingReviews, - fetchError: fetchErrorReviews, - } = useFetchReviews(); - const [isApplicationImportModalOpen, setIsApplicationImportModalOpen] = React.useState(false); @@ -460,19 +441,56 @@ export const ApplicationsTable: React.FC = () => { : []; const dropdownItems = [...importDropdownItems, ...applicationDeleteDropdown]; - const assessSelectedApp = (application: Application) => { - // if application/archetype has an assessment, ask if user wants to override it - if (matchingArchetypes.length) { - setAssessModalOpen(true); - setApplicationToAssess(application); + const handleNavToAssessment = (application: Application) => { + application?.id && + history.push( + formatPath(Paths.applicationAssessmentActions, { + applicationId: application?.id, + }) + ); + }; + + const handleNavToViewArchetypes = (application: Application) => { + application?.id && + archetypeRefsToOverride?.length && + history.push( + formatPath(Paths.viewArchetypes, { + applicationId: application?.id, + archetypeId: archetypeRefsToOverride[0].id, + }) + ); + }; + + const assessSelectedApp = async (application: Application) => { + setApplicationToAssess(application); + + if (application?.archetypes?.length) { + for (const archetypeRef of application.archetypes) { + try { + const assessments = await getAssessmentsByItemId( + true, + archetypeRef.id + ); + + if (assessments && assessments.length > 0) { + setArchetypeRefsToOverride(application.archetypes); + break; + } else { + handleNavToAssessment(application); + } + } catch (error) { + console.error( + `Error fetching archetype with ID ${archetypeRef.id}:`, + error + ); + pushNotification({ + title: t("terms.error"), + variant: "danger", + }); + } + } } else { - application?.id && - history.push( - formatPath(Paths.applicationAssessmentActions, { - applicationId: application?.id, - }) - ); - setApplicationToAssess(null); + handleNavToAssessment(application); } }; const reviewSelectedApp = (application: Application) => { @@ -858,23 +876,36 @@ export const ApplicationsTable: React.FC = () => { }} /> archetypeRef.name) + .join(", ") || "Archetype name", + })} + message={t("message.overrideAssessmentConfirmation")} titleIconVariant={"warning"} - isOpen={isAssessModalOpen} - message={t("message.overrideArchetypeConfirmation")} + isOpen={archetypeRefsToOverride !== null} confirmBtnVariant={ButtonVariant.primary} - confirmBtnLabel={t("actions.accept")} + confirmBtnLabel={t("actions.override")} cancelBtnLabel={t("actions.cancel")} - onCancel={() => setApplicationToAssess(null)} - onClose={() => setApplicationToAssess(null)} - onConfirm={() => { + customActionLabel={t("actions.viewArchetypes")} + onCancel={() => setArchetypeRefsToOverride(null)} + onClose={() => setArchetypeRefsToOverride(null)} + onCustomAction={() => { applicationToAssess && - history.push( - formatPath(Paths.applicationAssessmentActions, { - applicationId: applicationToAssess?.id, - }) - ); - setApplicationToAssess(null); + handleNavToViewArchetypes(applicationToAssess); + }} + onConfirm={() => { + history.push( + formatPath(Paths.applicationAssessmentActions, { + applicationId: activeRowItem?.id, + }) + ); + setArchetypeRefsToOverride(null); + applicationToAssess && handleNavToAssessment(applicationToAssess); }} /> 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 e718baf9c4..69df98b501 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 @@ -5,14 +5,13 @@ import { Assessment, InitialAssessment, Questionnaire, - Ref, } from "@app/api/models"; import { assessmentsByItemIdQueryKey, useCreateAssessmentMutation, useDeleteAssessmentMutation, } from "@app/queries/assessments"; -import { Button, ButtonVariant } from "@patternfly/react-core"; +import { Button } from "@patternfly/react-core"; import React, { FunctionComponent } from "react"; import { useHistory } from "react-router-dom"; import "./dynamic-assessment-actions-row.css"; @@ -23,8 +22,6 @@ import { NotificationsContext } from "@app/components/NotificationsContext"; import { useTranslation } from "react-i18next"; import { useQueryClient } from "@tanstack/react-query"; import { TrashIcon } from "@patternfly/react-icons"; -import { ConfirmDialog } from "@app/components/ConfirmDialog"; -import { getAssessmentsByItemId } from "@app/api/rest"; import useIsArchetype from "@app/hooks/useIsArchetype"; enum AssessmentAction { @@ -38,11 +35,12 @@ interface DynamicAssessmentActionsRowProps { application?: Application; archetype?: Archetype; assessment?: Assessment; + isReadonly?: boolean; } const DynamicAssessmentActionsRow: FunctionComponent< DynamicAssessmentActionsRowProps -> = ({ questionnaire, application, archetype, assessment }) => { +> = ({ questionnaire, application, archetype, assessment, isReadonly }) => { const isArchetype = useIsArchetype(); const history = useHistory(); const { t } = useTranslation(); @@ -50,9 +48,6 @@ const DynamicAssessmentActionsRow: FunctionComponent< const { pushNotification } = React.useContext(NotificationsContext); - const [archetypeRefToOverride, setArchetypeRefToOverride] = - React.useState(null); - const onSuccessHandler = () => {}; const onErrorHandler = () => {}; @@ -148,17 +143,7 @@ const DynamicAssessmentActionsRow: FunctionComponent< if (!isArchetype && application?.archetypes?.length) { for (const archetypeRef of application.archetypes) { try { - const assessments = await getAssessmentsByItemId( - true, - archetypeRef.id - ); - - if (assessments && assessments.length > 0) { - setArchetypeRefToOverride(archetypeRef); - break; - } else { - createAssessment(); - } + createAssessment(); } catch (error) { console.error( `Error fetching archetype with ID ${archetypeRef.id}:`, @@ -227,16 +212,18 @@ const DynamicAssessmentActionsRow: FunctionComponent< <>
- + {!isReadonly ? ( + + ) : null} {assessment?.status === "complete" ? ( + ) : isReadonly ? ( + ) : null}
@@ -275,37 +266,6 @@ const DynamicAssessmentActionsRow: FunctionComponent< ) : null} - setArchetypeRefToOverride(null)} - onClose={() => setArchetypeRefToOverride(null)} - //TODO - // onCustomAction={() => { - // //nav to view archetypes - // console.log("nav to view archetypes"); - // }} - onConfirm={() => { - history.push( - formatPath(Paths.applicationsAssessment, { - assessmentId: archetypeRefToOverride?.id, - }) - ); - setArchetypeRefToOverride(null); - createAssessment(); - }} - /> ); }; diff --git a/client/src/app/pages/assessment/components/assessment-actions/components/questionnaires-table.tsx b/client/src/app/pages/assessment/components/assessment-actions/components/questionnaires-table.tsx index 77acd47bd3..f5848175a2 100644 --- a/client/src/app/pages/assessment/components/assessment-actions/components/questionnaires-table.tsx +++ b/client/src/app/pages/assessment/components/assessment-actions/components/questionnaires-table.tsx @@ -19,6 +19,7 @@ import DynamicAssessmentActionsRow from "./dynamic-assessment-actions-row"; interface QuestionnairesTableProps { tableName: string; isFetching: boolean; + isReadonly?: boolean; application?: Application; archetype?: Archetype; assessments?: Assessment[]; @@ -28,7 +29,7 @@ interface QuestionnairesTableProps { const QuestionnairesTable: React.FC = ({ assessments, questionnaires, - isFetching, + isReadonly, application, archetype, tableName, @@ -109,6 +110,7 @@ const QuestionnairesTable: React.FC = ({ questionnaire={questionnaire} application={application} archetype={archetype} + isReadonly={isReadonly} /> ) : null} diff --git a/client/src/app/pages/assessment/components/view-archetypes/components/view-archetypes-table.tsx b/client/src/app/pages/assessment/components/view-archetypes/components/view-archetypes-table.tsx new file mode 100644 index 0000000000..c6b741f9e5 --- /dev/null +++ b/client/src/app/pages/assessment/components/view-archetypes/components/view-archetypes-table.tsx @@ -0,0 +1,50 @@ +import React from "react"; +import { Ref } from "@app/api/models"; +import { useFetchQuestionnaires } from "@app/queries/questionnaires"; +import { useFetchAssessmentsByItemId } from "@app/queries/assessments"; +import { useFetchArchetypeById } from "@app/queries/archetypes"; +import QuestionnairesTable from "../../assessment-actions/components/questionnaires-table"; + +export interface ViewArchetypesTableProps { + archetypeRef?: Ref | null; +} + +const ViewArchetypesTable: React.FC = ({ + archetypeRef, +}) => { + const { questionnaires, isFetching: isFetchingQuestionnaires } = + useFetchQuestionnaires(); + const { archetype } = useFetchArchetypeById(archetypeRef?.id); + const { assessments, isFetching: isFetchingAssessmentsById } = + useFetchAssessmentsByItemId(true, archetypeRef?.id); + + const requiredQuestionnaires = questionnaires.filter( + (questionnaire) => questionnaire.required + ); + const archivedQuestionnaires = questionnaires.filter( + (questionnaire) => !questionnaire.required + ); + return ( + <> + + + + + ); +}; + +export default ViewArchetypesTable; diff --git a/client/src/app/pages/assessment/components/view-archetypes/view-archetypes-page.tsx b/client/src/app/pages/assessment/components/view-archetypes/view-archetypes-page.tsx new file mode 100644 index 0000000000..a3f6e29132 --- /dev/null +++ b/client/src/app/pages/assessment/components/view-archetypes/view-archetypes-page.tsx @@ -0,0 +1,106 @@ +import React, { useEffect } from "react"; +import { + Text, + TextContent, + PageSection, + PageSectionVariants, + Breadcrumb, + BreadcrumbItem, +} from "@patternfly/react-core"; +import { Link, useParams } from "react-router-dom"; +import { ViewArchetypesRoute, Paths } from "@app/Paths"; +import { ConditionalRender } from "@app/components/ConditionalRender"; +import { AppPlaceholder } from "@app/components/AppPlaceholder"; +import ViewArchetypesTable from "./components/view-archetypes-table"; +import { useFetchArchetypeById } from "@app/queries/archetypes"; +import { useFetchApplicationById } from "@app/queries/applications"; +import { OptionWithValue, SimpleSelect } from "@app/components/SimpleSelect"; +import { Ref } from "@app/api/models"; +import { formatPath } from "@app/utils/utils"; + +const ViewArchetypes: React.FC = () => { + const { applicationId, archetypeId } = useParams(); + const { archetype } = useFetchArchetypeById(archetypeId); + const { application } = useFetchApplicationById(applicationId); + + const [activeArchetype, setActiveArchetype] = React.useState( + null + ); + useEffect(() => { + if (archetypeId && archetype) { + setActiveArchetype({ + id: parseInt(archetypeId, 10), + name: archetype.name, + }); + } + }, [archetypeId, archetype]); + + function mapRefToOption(ref: Ref | null): OptionWithValue { + if (ref) { + return { + value: ref, + toString: () => ref.name, + }; + } else { + return { + value: null, + toString: () => "All", + }; + } + } + const options: OptionWithValue[] = [ + ...(application?.archetypes?.map(mapRefToOption) || []), + ]; + + return ( + <> + + + View Archetypes + + + + Applications + + + {application?.name} + + + Archetypes + + + {archetype?.name} + + + + + }> + {application?.archetypes && application?.archetypes?.length > 1 && ( + { + const selectedArchetype = + selection as OptionWithValue; + setActiveArchetype(selectedArchetype.value); + }} + options={options} + /> + )} + + {} + + + + + ); +}; + +export default ViewArchetypes;