Skip to content

Commit

Permalink
Add inherited status and refactor status components
Browse files Browse the repository at this point in the history
Signed-off-by: ibolton336 <[email protected]>
  • Loading branch information
ibolton336 committed Dec 13, 2023
1 parent d927adc commit b6aface
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 89 deletions.
2 changes: 2 additions & 0 deletions client/public/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,8 @@
"insecureTracker": "Insecure mode deactivates certificate verification. Use insecure mode for instances that have self-signed certificates.",
"inheritedReviewTooltip_singular": "This application is inheriting a review from an archetype.",
"inheritedReviewTooltip_plural": "This application is inheriting reviews from {{count}} archetypes.",
"inheritedAssessmentTooltip_singular": "This application is inheriting an assessment from an archetype.",
"inheritedAssessmentTooltip_plural": "This application is inheriting assessments from {{count}} archetypes.",
"jiraInstanceNotConnected": "Jira instance {{name}} is not connected.",
"manageDependenciesInstructions": "Add northbound and southbound dependencies for the selected application here. Note that any selections made will be saved automatically. To undo any changes, you must manually delete the applications from the dropdowns.",
"noDataAvailableBody": "No data available to be shown here.",
Expand Down
15 changes: 12 additions & 3 deletions client/src/app/components/IconedStatus.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import UnknownIcon from "@patternfly/react-icons/dist/esm/icons/unknown-icon";
import QuestionCircleIcon from "@patternfly/react-icons/dist/esm/icons/question-circle-icon";

export type IconedStatusPreset =
| "Inherited"
| "InheritedReviews"
| "InheritedAssessments"
| "Canceled"
| "Completed"
| "Error"
Expand Down Expand Up @@ -51,14 +52,22 @@ export const IconedStatus: React.FC<IIconedStatusProps> = ({
}: IIconedStatusProps) => {
const { t } = useTranslation();
const presets: IconedStatusPresetType = {
Inherited: {
InheritedReviews: {
icon: <QuestionCircleIcon />,
status: "info",
label: t("terms.inherited"),
tooltipMessage: t("message.inheritedReviewTooltip", {
count: tooltipCount,
}),
},
InheritedAssessments: {
icon: <QuestionCircleIcon />,
status: "info",
label: t("terms.inherited"),
tooltipMessage: t("message.inheritedAssessmentTooltip", {
count: tooltipCount,
}),
},
Canceled: {
icon: <TimesCircleIcon />,
status: "info",
Expand Down Expand Up @@ -102,7 +111,7 @@ export const IconedStatus: React.FC<IIconedStatusProps> = ({
},
};
const presetProps = preset && presets[preset];

console.log("presetProps", presetProps);
const IconWithOptionalTooltip: React.FC<{ children: React.ReactElement }> = ({
children,
}) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ import {
MenuToggle,
MenuToggleElement,
Modal,
Flex,
FlexItem,
} from "@patternfly/react-core";
import { PencilAltIcon, TagIcon, EllipsisVIcon } from "@patternfly/react-icons";
import {
Expand All @@ -30,7 +28,6 @@ import {
ActionsColumn,
Tbody,
} from "@patternfly/react-table";
import { QuestionCircleIcon } from "@patternfly/react-icons/dist/esm/icons/question-circle-icon";

// @app components and utilities
import { AppPlaceholder } from "@app/components/AppPlaceholder";
Expand Down Expand Up @@ -107,7 +104,6 @@ import {
getTaskById,
} from "@app/api/rest";
import { ApplicationDependenciesForm } from "@app/components/ApplicationDependenciesFormContainer/ApplicationDependenciesForm";
import { useFetchArchetypes } from "@app/queries/archetypes";
import { useState } from "react";
import { ApplicationAnalysisStatus } from "../components/application-analysis-status";
import { ApplicationDetailDrawer } from "../components/application-detail-drawer/application-detail-drawer";
Expand Down Expand Up @@ -221,8 +217,6 @@ export const ApplicationsTable: React.FC = () => {
refetch: fetchApplications,
} = useFetchApplications();

const { archetypes } = useFetchArchetypes();

const onDeleteApplicationSuccess = (appIDCount: number) => {
pushNotification({
title: t("toastr.success.applicationDeleted", {
Expand Down Expand Up @@ -870,18 +864,6 @@ export const ApplicationsTable: React.FC = () => {
>
<Tbody>
{currentPageItems?.map((application, rowIndex) => {
const applicationArchetypes = application.archetypes?.map(
(archetypeRef) => {
return archetypes.find(
(archetype) => archetype.id === archetypeRef.id
);
}
);

const hasAssessedArchetype = applicationArchetypes?.some(
(archetype) => !!archetype?.assessments?.length
);

return (
<Tr
key={application.name}
Expand Down Expand Up @@ -915,23 +897,10 @@ export const ApplicationsTable: React.FC = () => {
modifier="truncate"
{...getTdProps({ columnKey: "assessment" })}
>
<Flex alignItems={{ default: "alignItemsCenter" }}>
<FlexItem>
<ApplicationAssessmentStatus
application={application}
/>
</FlexItem>
<FlexItem>
{hasAssessedArchetype ? (
<ConditionalTooltip
isTooltipEnabled={hasAssessedArchetype || false}
content={t("message.archetypeAlreadyAssessed")}
>
<QuestionCircleIcon />
</ConditionalTooltip>
) : null}
</FlexItem>
</Flex>
<ApplicationAssessmentStatus
application={application}
key={`${application?.id}-assessment-status`}
/>
</Td>
<Td
width={15}
Expand All @@ -940,30 +909,8 @@ export const ApplicationsTable: React.FC = () => {
>
<ApplicationReviewStatus
application={application}
archetypes={archetypes}
key={`${application?.id}-review-status`}
/>

{/* <Flex alignItems={{ default: "alignItemsCenter" }}>
<FlexItem>
<IconedStatus
preset={
isAppReviewed || hasReviewedArchetype
? "Completed"
: "NotStarted"
}
/>
</FlexItem>
<FlexItem>
{hasReviewedArchetype ? (
<ConditionalTooltip
isTooltipEnabled={hasReviewedArchetype || false}
content={t("message.archetypeAlreadyReviewed")}
>
<QuestionCircleIcon />
</ConditionalTooltip>
) : null}
</FlexItem>
</Flex> */}
</Td>
<Td
width={10}
Expand Down
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} />;
};
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
import React from "react";
import { Application, Archetype } from "@app/api/models";
import { Application } from "@app/api/models";
import { IconedStatus, IconedStatusPreset } from "@app/components/IconedStatus";
import { Spinner } from "@patternfly/react-core";
import { EmptyTextMessage } from "@app/components/EmptyTextMessage";
import { useTranslation } from "react-i18next";
import { useFetchArchetypes } from "@app/queries/archetypes";

export interface ApplicationReviewStatusProps {
application: Application;
archetypes?: Archetype[];
isLoading?: boolean;
}

export const ApplicationReviewStatus: React.FC<
ApplicationReviewStatusProps
> = ({ application, archetypes, isLoading = false }) => {
> = ({ application }) => {
const { t } = useTranslation();

const { archetypes, isFetching } = useFetchArchetypes();
const isAppReviewed = !!application.review;

const applicationArchetypes = application.archetypes?.map((archetypeRef) => {
Expand All @@ -25,22 +27,22 @@ export const ApplicationReviewStatus: React.FC<
applicationArchetypes?.filter((archetype) => !!archetype?.review).length ||
0;

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

let statusPreset: IconedStatusPreset;
let tooltipCount = 0;

if (isAppReviewed) {
statusPreset = "Completed";
} else if (reviewedArchetypeCount > 0) {
statusPreset = "Inherited";
statusPreset = "InheritedReviews";
tooltipCount = reviewedArchetypeCount;
} else {
statusPreset = "NotStarted";
}

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

if (!applicationArchetypes || applicationArchetypes.length === 0) {
return <EmptyTextMessage message={t("terms.notAvailable")} />;
}
Expand Down

0 comments on commit b6aface

Please sign in to comment.