-
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.
Add inherited status and refactor status components
- Loading branch information
1 parent
4141e60
commit 2ab869d
Showing
5 changed files
with
63 additions
and
89 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
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
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
54 changes: 34 additions & 20 deletions
54
...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,50 +1,64 @@ | ||
import React from "react"; | ||
import { useTranslation } from "react-i18next"; | ||
import { Spinner } from "@patternfly/react-core"; | ||
|
||
import { EmptyTextMessage } from "@app/components/EmptyTextMessage"; | ||
import { Application } from "@app/api/models"; | ||
import { IconedStatus } from "@app/components/IconedStatus"; | ||
import { IconedStatus, IconedStatusPreset } from "@app/components/IconedStatus"; | ||
import { useFetchAssessmentsByItemId } from "@app/queries/assessments"; | ||
import { useFetchQuestionnaires } from "@app/queries/questionnaires"; | ||
|
||
export interface ApplicationAssessmentStatusProps { | ||
import { useFetchArchetypes } from "@app/queries/archetypes"; | ||
interface ApplicationAssessmentStatusProps { | ||
application: Application; | ||
isLoading?: boolean; | ||
} | ||
|
||
export const ApplicationAssessmentStatus: React.FC< | ||
ApplicationAssessmentStatusProps | ||
> = ({ application, isLoading = false }) => { | ||
> = ({ application }) => { | ||
const { t } = useTranslation(); | ||
|
||
const { archetypes, isFetching } = useFetchArchetypes(); | ||
|
||
const applicationArchetypes = application.archetypes?.map((archetypeRef) => { | ||
return archetypes?.find((archetype) => archetype.id === archetypeRef.id); | ||
}); | ||
|
||
const hasAssessedArchetype = applicationArchetypes?.some( | ||
(archetype) => !!archetype?.assessments?.length | ||
); | ||
|
||
const { | ||
assessments, | ||
isFetching: isFetchingAssessmentsById, | ||
fetchError, | ||
} = useFetchAssessmentsByItemId(false, application.id); | ||
const { questionnaires } = useFetchQuestionnaires(); | ||
const requiredQuestionnaireExists = questionnaires?.some( | ||
(q) => q.required === true | ||
); | ||
//NOTE: Application.assessed is true if an app is assigned to an archetype and no required questionnaires exist | ||
if (application?.assessed && requiredQuestionnaireExists) { | ||
return <IconedStatus preset="Completed" />; | ||
} | ||
|
||
if (fetchError) { | ||
return <EmptyTextMessage message={t("terms.notAvailable")} />; | ||
} | ||
|
||
if (isLoading || isFetchingAssessmentsById) { | ||
if (isFetching || isFetchingAssessmentsById) { | ||
return <Spinner size="md" />; | ||
} | ||
|
||
if ( | ||
assessments?.some((a) => a.status === "started" || a.status === "complete") | ||
let statusPreset: IconedStatusPreset = "NotStarted"; // Default status | ||
let tooltipCount: number = 0; | ||
|
||
if (application?.assessed) { | ||
statusPreset = "Completed"; | ||
} else if (hasAssessedArchetype) { | ||
statusPreset = "InheritedAssessments"; | ||
const assessedArchetypeCount = | ||
applicationArchetypes?.filter((archetype) => !!archetype?.assessments) | ||
.length || 0; | ||
tooltipCount = assessedArchetypeCount; | ||
} else if ( | ||
assessments?.some( | ||
(assessment) => | ||
assessment.status === "started" || assessment.status === "complete" | ||
) | ||
) { | ||
return <IconedStatus preset="InProgress" />; | ||
statusPreset = "InProgress"; | ||
} | ||
|
||
return <IconedStatus preset="NotStarted" />; | ||
console.log("tooltipCount", tooltipCount); | ||
return <IconedStatus preset={statusPreset} tooltipCount={tooltipCount} />; | ||
}; |
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