Skip to content

Commit

Permalink
🐛 determine assessment status from all assessments
Browse files Browse the repository at this point in the history
Signed-off-by: ibolton336 <ibolton@redhat.com>
  • Loading branch information
ibolton336 committed Oct 12, 2023
1 parent 94b56fb commit 549edb6
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,7 @@ export const ApplicationsTable: React.FC = () => {
{...getTdProps({ columnKey: "assessment" })}
>
<ApplicationAssessmentStatus
assessments={application.assessments}
application={application}
/>
</Td>
<Td
Expand Down
Original file line number Diff line number Diff line change
@@ -1,49 +1,45 @@
import React from "react";
import { AxiosError } from "axios";
import { useTranslation } from "react-i18next";
import { Spinner } from "@patternfly/react-core";

import { EmptyTextMessage } from "@app/components/EmptyTextMessage";
import { Assessment, Ref } from "@app/api/models";
import { IconedStatus, IconedStatusPreset } from "@app/components/IconedStatus";
import { useFetchAssessmentById } from "@app/queries/assessments";
import { Application } from "@app/api/models";
import { IconedStatus } from "@app/components/IconedStatus";
import { useFetchAssessmentsByItemId } from "@app/queries/assessments"; // Import the hook

export interface ApplicationAssessmentStatusProps {
assessments?: Ref[];
application: Application;
isLoading?: boolean;
fetchError?: AxiosError;
}

const getStatusIconFrom = (assessment: Assessment): IconedStatusPreset => {
switch (assessment.status) {
case "empty":
return "NotStarted";
case "started":
return "InProgress";
case "complete":
return "Completed";
default:
return "NotStarted";
}
};

export const ApplicationAssessmentStatus: React.FC<
ApplicationAssessmentStatusProps
> = ({ assessments, isLoading = false, fetchError = null }) => {
> = ({ application, isLoading = false }) => {
const { t } = useTranslation();
//TODO: remove this once we have a proper assessment status
const { assessment } = useFetchAssessmentById(assessments?.[0]?.id);

const {
assessments,
isFetching: isFetchingAssessmentsById,
fetchError,
} = useFetchAssessmentsByItemId(false, application.id);

if (application?.assessed) {
return <IconedStatus preset="Completed" />;
}

if (fetchError) {
return <EmptyTextMessage message={t("terms.notAvailable")} />;
}
if (isLoading) {

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

return assessment ? (
<IconedStatus preset={getStatusIconFrom(assessment)} />
) : (
<IconedStatus preset="NotStarted" />
);
if (
assessments?.some((a) => a.status === "started" || a.status === "complete")
) {
return <IconedStatus preset="InProgress" />;
}

return <IconedStatus preset="NotStarted" />;
};

0 comments on commit 549edb6

Please sign in to comment.