-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🐛 determine assessment status from all assessments
Signed-off-by: ibolton336 <ibolton@redhat.com>
- Loading branch information
1 parent
94b56fb
commit 549edb6
Showing
2 changed files
with
25 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 24 additions & 28 deletions
52
...s/applications/components/application-assessment-status/application-assessment-status.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" />; | ||
}; |