Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
ibolton336 committed Aug 31, 2023
1 parent 7bccf65 commit 68133cc
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 23 deletions.
13 changes: 12 additions & 1 deletion client/src/app/api/rest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,14 @@ export const getAssessments = (filters: {
.then((response) => response.data);
};

export const getAssessmentsByAppId = (
applicationId?: number
): Promise<Assessment[]> => {
return axios
.get(`${ASSESSMENTS}/${applicationId}/assessments`)
.then((response) => response.data);
};

export const createAssessment = (
obj: InitialAssessment
): Promise<Assessment> => {
Expand Down Expand Up @@ -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<AnalysisIncident>(
ANALYSIS_ISSUE_INCIDENTS.replace("/:issueId/", `/${String(issueId)}/`),
Expand Down
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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<AssessmentRoute>();
const { assessment, isFetching, fetchError } =
useFetchAssessmentByID(assessmentId);
useFetchAssessmentById(assessmentId);

const [saveError, setSaveError] = useState<AxiosError>();

Expand Down
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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;
}
Expand Down Expand Up @@ -54,8 +53,10 @@ const AssessmentActionsTable: React.FC<AssessmentActionsTableProps> = ({
onErrorHandler
);

const handleAssessmentCreationAndNav = async (
questionnaire: Questionnaire
const onHandleAssessmentAction = async (
questionnaire: Questionnaire,
assessment: Assessment,
action: any
) => {
//TODO handle archetypes here too
if (!application) {
Expand All @@ -82,6 +83,10 @@ const AssessmentActionsTable: React.FC<AssessmentActionsTableProps> = ({
}
};

if (!application) {
return <div>Application is undefined</div>;
}

return (
<>
<Table
Expand Down Expand Up @@ -121,16 +126,11 @@ const AssessmentActionsTable: React.FC<AssessmentActionsTableProps> = ({
{questionnaire.name}
</Td>
<Td>
<Button
type="button"
variant="primary"
//TODO:Dynamic assessment button. Determine if matching assessment. Derive button status from that
onClick={() =>
handleAssessmentCreationAndNav(questionnaire)
}
>
Take
</Button>
<DynamicAssessmentButton
questionnaire={questionnaire}
application={application}
handleAssessmentAction={onHandleAssessmentAction}
/>
</Td>
</TableRowContentWithControls>
</Tr>
Expand Down
17 changes: 16 additions & 1 deletion client/src/app/queries/assessments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[] = []
Expand Down Expand Up @@ -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),
Expand All @@ -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,
};
};
7 changes: 7 additions & 0 deletions client/src/mocks/stub-new-work/assessments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 68133cc

Please sign in to comment.