Skip to content

Commit

Permalink
Update icon status for reviews
Browse files Browse the repository at this point in the history
  • Loading branch information
ibolton336 committed Dec 13, 2023
1 parent 2004213 commit 4141e60
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 12 deletions.
3 changes: 3 additions & 0 deletions client/public/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,8 @@
"duplicateWave": "The migration wave could not be created due to a conflict with an existing wave. Make sure the name and start/end dates are unique and try again.",
"importErrorCheckDocumentation": "For status Error imports, check the documentation to ensure your file is structured correctly.",
"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.",
"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 Expand Up @@ -328,6 +330,7 @@
"inProgress": "In-progress",
"instanceType": "Instance type",
"instance": "Instance",
"inherited": "Inherited",
"issueType": "Issue type",
"jiraConfig": "Jira configuration",
"issue": "Issue",
Expand Down
32 changes: 28 additions & 4 deletions client/src/app/components/IconedStatus.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import React from "react";
import { Flex, FlexItem, Icon } from "@patternfly/react-core";
import { Flex, FlexItem, Icon, Tooltip } from "@patternfly/react-core";
import { useTranslation } from "react-i18next";
import CheckCircleIcon from "@patternfly/react-icons/dist/esm/icons/check-circle-icon";
import TimesCircleIcon from "@patternfly/react-icons/dist/esm/icons/times-circle-icon";
import InProgressIcon from "@patternfly/react-icons/dist/esm/icons/in-progress-icon";
import ExclamationCircleIcon from "@patternfly/react-icons/dist/esm/icons/exclamation-circle-icon";
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"
| "Canceled"
| "Completed"
| "Error"
Expand Down Expand Up @@ -35,6 +37,8 @@ export interface IIconedStatusProps {
icon?: React.ReactNode;
className?: string;
label?: React.ReactNode | string;
tooltipMessage?: string;
tooltipCount?: number;
}

export const IconedStatus: React.FC<IIconedStatusProps> = ({
Expand All @@ -43,9 +47,18 @@ export const IconedStatus: React.FC<IIconedStatusProps> = ({
icon,
className = "",
label,
tooltipCount = 0,
}: IIconedStatusProps) => {
const { t } = useTranslation();
const presets: IconedStatusPresetType = {
Inherited: {
icon: <QuestionCircleIcon />,
status: "info",
label: t("terms.inherited"),
tooltipMessage: t("message.inheritedReviewTooltip", {
count: tooltipCount,
}),
},
Canceled: {
icon: <TimesCircleIcon />,
status: "info",
Expand Down Expand Up @@ -90,15 +103,26 @@ export const IconedStatus: React.FC<IIconedStatusProps> = ({
};
const presetProps = preset && presets[preset];

const IconWithOptionalTooltip: React.FC<{ children: React.ReactElement }> = ({
children,
}) =>
presetProps?.tooltipMessage ? (
<Tooltip content={presetProps?.tooltipMessage}>{children}</Tooltip>
) : (
<>{children}</>
);

return (
<Flex
flexWrap={{ default: "nowrap" }}
spaceItems={{ default: "spaceItemsSm" }}
>
<FlexItem>
<Icon status={status || presetProps?.status} className={className}>
{icon || presetProps?.icon || <UnknownIcon />}
</Icon>
<IconWithOptionalTooltip>
<Icon status={status || presetProps?.status} className={className}>
{icon || presetProps?.icon || <UnknownIcon />}
</Icon>
</IconWithOptionalTooltip>
</FlexItem>
<FlexItem>{label || presetProps?.label}</FlexItem>
</Flex>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ import {
ConditionalTableBody,
TableRowContentWithControls,
} from "@app/components/TableControls";
import { IconedStatus } from "@app/components/IconedStatus";
import { ToolbarBulkSelector } from "@app/components/ToolbarBulkSelector";
import { ConfirmDialog } from "@app/components/ConfirmDialog";
import { NotificationsContext } from "@app/components/NotificationsContext";
Expand Down Expand Up @@ -116,6 +115,7 @@ import { SimpleDocumentViewerModal } from "@app/components/SimpleDocumentViewer"
import { AnalysisWizard } from "../analysis-wizard/analysis-wizard";
import { TaskGroupProvider } from "../analysis-wizard/components/TaskGroupContext";
import { ApplicationIdentityForm } from "../components/application-identity-form/application-identity-form";
import { ApplicationReviewStatus } from "../components/application-review-status/application-review-status";

export const ApplicationsTable: React.FC = () => {
const { t } = useTranslation();
Expand Down Expand Up @@ -870,7 +870,6 @@ export const ApplicationsTable: React.FC = () => {
>
<Tbody>
{currentPageItems?.map((application, rowIndex) => {
const isAppReviewed = !!application.review;
const applicationArchetypes = application.archetypes?.map(
(archetypeRef) => {
return archetypes.find(
Expand All @@ -879,10 +878,6 @@ export const ApplicationsTable: React.FC = () => {
}
);

const hasReviewedArchetype = applicationArchetypes?.some(
(archetype) => !!archetype?.review
);

const hasAssessedArchetype = applicationArchetypes?.some(
(archetype) => !!archetype?.assessments?.length
);
Expand Down Expand Up @@ -943,7 +938,12 @@ export const ApplicationsTable: React.FC = () => {
modifier="truncate"
{...getTdProps({ columnKey: "review" })}
>
<Flex alignItems={{ default: "alignItemsCenter" }}>
<ApplicationReviewStatus
application={application}
archetypes={archetypes}
/>

{/* <Flex alignItems={{ default: "alignItemsCenter" }}>
<FlexItem>
<IconedStatus
preset={
Expand All @@ -963,7 +963,7 @@ export const ApplicationsTable: React.FC = () => {
</ConditionalTooltip>
) : null}
</FlexItem>
</Flex>
</Flex> */}
</Td>
<Td
width={10}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import React from "react";
import { Application, Archetype } 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";

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

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

const applicationArchetypes = application.archetypes?.map((archetypeRef) => {
return archetypes?.find((archetype) => archetype.id === archetypeRef.id);
});

const reviewedArchetypeCount =
applicationArchetypes?.filter((archetype) => !!archetype?.review).length ||
0;

let statusPreset: IconedStatusPreset;
let tooltipCount = 0;

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

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

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

return <IconedStatus preset={statusPreset} tooltipCount={tooltipCount} />;
};

0 comments on commit 4141e60

Please sign in to comment.