Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Reduce assessment calls in effort to reduce network overhead #1724

Merged
merged 1 commit into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,10 @@ import {
useFetchApplications,
} from "@app/queries/applications";
import { useCancelTaskMutation, useFetchTasks } from "@app/queries/tasks";
import { useDeleteAssessmentMutation } from "@app/queries/assessments";
import {
useDeleteAssessmentMutation,
useFetchAssessments,
} from "@app/queries/assessments";
import { useDeleteReviewMutation } from "@app/queries/reviews";
import { useFetchIdentities } from "@app/queries/identities";
import { useFetchTagsWithTagItems } from "@app/queries/tags";
Expand All @@ -104,6 +107,7 @@ import { TaskGroupProvider } from "../analysis-wizard/components/TaskGroupContex
import { ApplicationIdentityForm } from "../components/application-identity-form/application-identity-form";
import { ApplicationReviewStatus } from "../components/application-review-status/application-review-status";
import { KebabDropdown } from "@app/components/KebabDropdown";
import { useFetchArchetypes } from "@app/queries/archetypes";

export const ApplicationsTable: React.FC = () => {
const { t } = useTranslation();
Expand Down Expand Up @@ -207,6 +211,9 @@ export const ApplicationsTable: React.FC = () => {
refetch: fetchApplications,
} = useFetchApplications();

const { assessments } = useFetchAssessments();
const { archetypes } = useFetchArchetypes();

const onDeleteApplicationSuccess = (appIDCount: number) => {
pushNotification({
title: t("toastr.success.applicationDeleted", {
Expand Down Expand Up @@ -885,6 +892,8 @@ export const ApplicationsTable: React.FC = () => {
>
<ApplicationAssessmentStatus
application={application}
assessments={assessments}
archetypes={archetypes}
key={`${application?.id}-assessment-status`}
/>
</Td>
Expand Down Expand Up @@ -1059,6 +1068,7 @@ export const ApplicationsTable: React.FC = () => {
<ApplicationDetailDrawer
application={activeItem}
applications={applications}
assessments={assessments}
onCloseClick={clearActiveItem}
onEditClick={() => setSaveApplicationModalState(activeItem)}
task={activeItem ? getTask(activeItem) : null}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,20 @@
import React from "react";
import { useTranslation } from "react-i18next";
import { Spinner } from "@patternfly/react-core";
import { EmptyTextMessage } from "@app/components/EmptyTextMessage";
import { Application, Assessment } from "@app/api/models";
import { Application, Archetype, Assessment } from "@app/api/models";
import { IconedStatus, IconedStatusPreset } from "@app/components/IconedStatus";
import { useFetchAssessments } from "@app/queries/assessments";
import { useFetchArchetypes } from "@app/queries/archetypes";
interface ApplicationAssessmentStatusProps {
application: Application;
assessments: Assessment[];
archetypes: Archetype[];
isLoading?: boolean;
}

export const ApplicationAssessmentStatus: React.FC<
ApplicationAssessmentStatusProps
> = ({ application }) => {
> = ({ application, assessments, archetypes }) => {
const { t } = useTranslation();

const { archetypes, isFetching } = useFetchArchetypes(application);
const { assessments, fetchError } = useFetchAssessments();

const filteredAssessments = assessments?.filter(
(assessment: Assessment) => assessment.application?.id === application.id
);
Expand Down Expand Up @@ -84,14 +80,10 @@ export const ApplicationAssessmentStatus: React.FC<
};
}, [archetypes, assessments]);

if (fetchError) {
if (archetypes?.length === 0 || assessments?.length === 0) {
return <EmptyTextMessage message={t("terms.notAvailable")} />;
}

if (isFetching || isFetching) {
return <Spinner size="md" />;
}

let statusPreset: IconedStatusPreset = "NotStarted"; // Default status
let tooltipCount: number = 0;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {
MimeType,
Ref,
Archetype,
AssessmentWithSectionOrder,
} from "@app/api/models";
import {
IPageDrawerContentProps,
Expand Down Expand Up @@ -64,6 +65,7 @@ export interface IApplicationDetailDrawerProps
application: Application | null;
task: Task | undefined | null;
applications?: Application[];
assessments?: AssessmentWithSectionOrder[];
onEditClick: () => void;
}

Expand All @@ -77,7 +79,7 @@ enum TabKey {

export const ApplicationDetailDrawer: React.FC<
IApplicationDetailDrawerProps
> = ({ onCloseClick, application, task, onEditClick }) => {
> = ({ onCloseClick, application, assessments, task, onEditClick }) => {
const { t } = useTranslation();
const [activeTabKey, setActiveTabKey] = React.useState<TabKey>(
TabKey.Details
Expand Down Expand Up @@ -212,9 +214,16 @@ export const ApplicationDetailDrawer: React.FC<
<DescriptionListTerm>
{t("terms.archetypesAssessed")}
</DescriptionListTerm>
<DescriptionListDescription>
<AssessedArchetypes application={application} />
</DescriptionListDescription>
{assessments && assessments.length ? (
<DescriptionListDescription>
<AssessedArchetypes
application={application}
assessments={assessments}
/>
</DescriptionListDescription>
) : (
<EmptyTextMessage message={t("terms.none")} />
)}
</DescriptionListGroup>

<DescriptionListGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,19 @@ import { Label, LabelGroup, Spinner } from "@patternfly/react-core";
import { EmptyTextMessage } from "@app/components/EmptyTextMessage";
import { useTranslation } from "react-i18next";
import { useFetchArchetypes } from "@app/queries/archetypes";
import { useFetchAssessments } from "@app/queries/assessments";

interface IAssessedArchetypesProps {
application: Application | null;
assessments: AssessmentWithSectionOrder[] | null;
}

export const AssessedArchetypes: React.FC<IAssessedArchetypesProps> = ({
application,
assessments,
}) => {
const { t } = useTranslation();
const { archetypes, isFetching: isFetchingArchetypes } =
useFetchArchetypes(application);
const { assessments, isFetching: isFetchingAssessments } =
useFetchAssessments();

const assessedArchetypes = React.useMemo(() => {
if (!archetypes || !assessments) return [];
Expand All @@ -32,7 +31,7 @@ export const AssessedArchetypes: React.FC<IAssessedArchetypesProps> = ({
);
}, [archetypes, assessments]);

if (isFetchingArchetypes || isFetchingAssessments) {
if (isFetchingArchetypes) {
return <Spinner size="md" />;
}

Expand Down
6 changes: 1 addition & 5 deletions client/src/app/queries/applications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@ import {
updateApplication,
} from "@app/api/rest";
import { reviewsQueryKey } from "./reviews";
import {
assessmentsByItemIdQueryKey,
assessmentsQueryKey,
} from "./assessments";
import { assessmentsByItemIdQueryKey } from "./assessments";
import saveAs from "file-saver";

export const ApplicationDependencyQueryKey = "applicationdependencies";
Expand All @@ -45,7 +42,6 @@ export const useFetchApplications = (refetchDisabled: boolean = false) => {
refetchInterval: !refetchDisabled ? 5000 : false,
onSuccess: () => {
queryClient.invalidateQueries([reviewsQueryKey]);
queryClient.invalidateQueries([assessmentsQueryKey]);
queryClient.invalidateQueries([assessmentsByItemIdQueryKey]);
},
onError: (error: AxiosError) => console.log(error),
Expand Down
6 changes: 1 addition & 5 deletions client/src/app/queries/archetypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@ import {
getArchetypes,
updateArchetype,
} from "@app/api/rest";
import {
assessmentsQueryKey,
assessmentsByItemIdQueryKey,
} from "./assessments";
import { assessmentsByItemIdQueryKey } from "./assessments";
import { reviewsQueryKey } from "./reviews";
import { useState } from "react";

Expand Down Expand Up @@ -43,7 +40,6 @@ export const useFetchArchetypes = (forApplication?: Application | null) => {
}

queryClient.invalidateQueries([reviewsQueryKey]);
queryClient.invalidateQueries([assessmentsQueryKey]);
queryClient.invalidateQueries([assessmentsByItemIdQueryKey]);
},
onError: (error: AxiosError) => console.log(error),
Expand Down
Loading