From 68133cc038d36eb19a5aa8b71682208b33c7b041 Mon Sep 17 00:00:00 2001 From: ibolton336 Date: Thu, 31 Aug 2023 12:48:38 -0400 Subject: [PATCH] wip --- client/src/app/api/rest.ts | 13 ++++++++- .../application-assessment.tsx | 10 ++----- .../components/assessment-actions-table.tsx | 28 +++++++++---------- client/src/app/queries/assessments.ts | 17 ++++++++++- client/src/mocks/stub-new-work/assessments.ts | 7 +++++ 5 files changed, 52 insertions(+), 23 deletions(-) diff --git a/client/src/app/api/rest.ts b/client/src/app/api/rest.ts index 11e6263e68..776a05f22e 100644 --- a/client/src/app/api/rest.ts +++ b/client/src/app/api/rest.ts @@ -236,6 +236,14 @@ export const getAssessments = (filters: { .then((response) => response.data); }; +export const getAssessmentsByAppId = ( + applicationId?: number +): Promise => { + return axios + .get(`${ASSESSMENTS}/${applicationId}/assessments`) + .then((response) => response.data); +}; + export const createAssessment = ( obj: InitialAssessment ): Promise => { @@ -548,7 +556,10 @@ export const getFileReports = ( ) : Promise.reject(); -export const getIncidents = (issueId?: number, params: HubRequestParams = {}) => +export const getIncidents = ( + issueId?: number, + params: HubRequestParams = {} +) => issueId ? getHubPaginatedResult( ANALYSIS_ISSUE_INCIDENTS.replace("/:issueId/", `/${String(issueId)}/`), diff --git a/client/src/app/pages/applications/application-assessment/application-assessment.tsx b/client/src/app/pages/applications/application-assessment/application-assessment.tsx index ca1512db8a..1101dfe201 100644 --- a/client/src/app/pages/applications/application-assessment/application-assessment.tsx +++ b/client/src/app/pages/applications/application-assessment/application-assessment.tsx @@ -1,4 +1,4 @@ -import React, { useEffect, useState } from "react"; +import React, { useState } from "react"; import { useParams } from "react-router-dom"; import { useTranslation } from "react-i18next"; import { AxiosError } from "axios"; @@ -8,25 +8,21 @@ import { Bullseye, } from "@patternfly/react-core"; import BanIcon from "@patternfly/react-icons/dist/esm/icons/ban-icon"; -import yaml from "js-yaml"; - import { AssessmentRoute } from "@app/Paths"; -import { Assessment } from "@app/api/models"; -import { getAssessmentById } from "@app/api/rest"; import { getAxiosErrorMessage } from "@app/utils/utils"; import { ApplicationAssessmentPage } from "./components/application-assessment-page"; import { ApplicationAssessmentWizard } from "./components/application-assessment-wizard"; import { SimpleEmptyState } from "@app/components/SimpleEmptyState"; import { ConditionalRender } from "@app/components/ConditionalRender"; import { AppPlaceholder } from "@app/components/AppPlaceholder"; -import { useFetchAssessmentByID } from "@app/queries/assessments"; +import { useFetchAssessmentById } from "@app/queries/assessments"; export const ApplicationAssessment: React.FC = () => { const { t } = useTranslation(); const { assessmentId } = useParams(); const { assessment, isFetching, fetchError } = - useFetchAssessmentByID(assessmentId); + useFetchAssessmentById(assessmentId); const [saveError, setSaveError] = useState(); diff --git a/client/src/app/pages/applications/assessment-actions/components/assessment-actions-table.tsx b/client/src/app/pages/applications/assessment-actions/components/assessment-actions-table.tsx index f4173ea2d6..9ef0f4b583 100644 --- a/client/src/app/pages/applications/assessment-actions/components/assessment-actions-table.tsx +++ b/client/src/app/pages/applications/assessment-actions/components/assessment-actions-table.tsx @@ -1,5 +1,4 @@ import React from "react"; -import { useTranslation } from "react-i18next"; import { Table, Tbody, Td, Th, Thead, Tr } from "@patternfly/react-table"; import { useLocalTableControls } from "@app/hooks/table-controls"; @@ -15,11 +14,11 @@ import { InitialAssessment, Questionnaire, } from "@app/api/models"; -import { Button } from "@patternfly/react-core"; import { Paths, formatPath } from "@app/Paths"; import { useHistory } from "react-router-dom"; import { useFetchQuestionnaires } from "@app/queries/questionnaires"; import { useCreateAssessmentMutation } from "@app/queries/assessments"; +import DynamicAssessmentButton from "./dynamic-assessment-button"; export interface AssessmentActionsTableProps { application?: Application; } @@ -54,8 +53,10 @@ const AssessmentActionsTable: React.FC = ({ onErrorHandler ); - const handleAssessmentCreationAndNav = async ( - questionnaire: Questionnaire + const onHandleAssessmentAction = async ( + questionnaire: Questionnaire, + assessment: Assessment, + action: any ) => { //TODO handle archetypes here too if (!application) { @@ -82,6 +83,10 @@ const AssessmentActionsTable: React.FC = ({ } }; + if (!application) { + return
Application is undefined
; + } + return ( <> = ({ {questionnaire.name} diff --git a/client/src/app/queries/assessments.ts b/client/src/app/queries/assessments.ts index 183db6a24b..c84e082a76 100644 --- a/client/src/app/queries/assessments.ts +++ b/client/src/app/queries/assessments.ts @@ -11,12 +11,14 @@ import { deleteAssessment, getAssessmentById, getAssessments, + getAssessmentsByAppId, } from "@app/api/rest"; import { AxiosError, AxiosResponse } from "axios"; import { Application, Assessment, InitialAssessment } from "@app/api/models"; export const assessmentsQueryKey = "assessments"; export const assessmentQueryKey = "assessment"; +export const assessmentsByAppIdQueryKey = "assessmentsByAppId"; export const useFetchApplicationAssessments = ( applications: Application[] = [] @@ -81,7 +83,7 @@ export const useDeleteAssessmentMutation = ( }); }; -export const useFetchAssessmentByID = (id: number | string) => { +export const useFetchAssessmentById = (id: number | string) => { const { data, isLoading, error } = useQuery({ queryKey: [assessmentQueryKey, id], queryFn: () => getAssessmentById(id), @@ -93,3 +95,16 @@ export const useFetchAssessmentByID = (id: number | string) => { fetchError: error, }; }; + +export const useFetchAssessmentsByAppId = (applicationId: number) => { + const { data, isLoading, error } = useQuery({ + queryKey: [assessmentsByAppIdQueryKey, applicationId], + queryFn: () => getAssessmentsByAppId(applicationId), + onError: (error: AxiosError) => console.log("error, ", error), + }); + return { + assessments: data, + isFetching: isLoading, + fetchError: error, + }; +}; diff --git a/client/src/mocks/stub-new-work/assessments.ts b/client/src/mocks/stub-new-work/assessments.ts index 5f32264c25..462528e738 100644 --- a/client/src/mocks/stub-new-work/assessments.ts +++ b/client/src/mocks/stub-new-work/assessments.ts @@ -200,6 +200,13 @@ export const handlers = [ return res(ctx.json(mockAssessmentArray)); }), + rest.get( + `${AppRest.APPLICATIONS}/:applicationId/assessments`, + (req, res, ctx) => { + return res(ctx.json(mockAssessmentArray)); + } + ), + rest.get(`${AppRest.ASSESSMENTS}/:assessmentId`, (req, res, ctx) => { const { assessmentId } = req.params;
- +