Skip to content

Commit

Permalink
🌱 1236 - changes to StatusIcon (now IconedStatus) (konveyor#1250)
Browse files Browse the repository at this point in the history
closes konveyor#1236

---------

Signed-off-by: gitdallas <[email protected]>
  • Loading branch information
gitdallas authored Aug 7, 2023
1 parent f489d36 commit 0f62f5c
Show file tree
Hide file tree
Showing 13 changed files with 170 additions and 200 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { useState } from "react";
import { useHistory } from "react-router-dom";
import { AxiosError } from "axios";
import { useTranslation, Trans } from "react-i18next";

import { IconedStatus } from "@app/shared/components";
import {
Button,
ButtonVariant,
Expand Down Expand Up @@ -32,7 +32,6 @@ import {
AppTableWithControls,
ConditionalRender,
NoDataEmptyState,
StatusIcon,
KebabDropdown,
ToolbarBulkSelector,
ConfirmDialog,
Expand Down Expand Up @@ -313,10 +312,8 @@ export const ApplicationsTable: React.FC = () => {
),
},
{
title: item.review ? (
<StatusIcon status="Completed" />
) : (
<StatusIcon status="NotStarted" />
title: (
<IconedStatus preset={item.review ? "Completed" : "NotStarted"} />
),
},
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from "react";

import { TaskState } from "@app/api/models";
import { StatusIcon } from "@app/shared/components";
import { IconedStatus } from "@app/shared/components";

export interface ApplicationAnalysisStatusProps {
state: TaskState;
Expand Down Expand Up @@ -39,5 +39,5 @@ export const ApplicationAnalysisStatus: React.FC<
return "NotStarted";
};

return <StatusIcon status={getTaskStatus(state)} />;
return <IconedStatus preset={getTaskStatus(state)} />;
};
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { useTranslation } from "react-i18next";

import {
EmptyTextMessage,
StatusIcon,
StatusIconType,
IconedStatus,
IconedStatusPreset,
} from "@app/shared/components";
import { Assessment } from "@app/api/models";
import { Spinner } from "@patternfly/react-core";
Expand All @@ -16,7 +16,7 @@ export interface ApplicationAssessmentStatusProps {
fetchError?: AxiosError;
}

const getStatusIconFrom = (assessment: Assessment): StatusIconType => {
const getStatusIconFrom = (assessment: Assessment): IconedStatusPreset => {
switch (assessment.status) {
case "EMPTY":
return "NotStarted";
Expand All @@ -42,8 +42,8 @@ export const ApplicationAssessmentStatus: React.FC<
}

return assessment ? (
<StatusIcon status={getStatusIconFrom(assessment)} />
<IconedStatus preset={getStatusIconFrom(assessment)} />
) : (
<StatusIcon status="NotStarted" />
<IconedStatus preset="NotStarted" />
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { global_palette_gold_400 as gold } from "@patternfly/react-tokens";

import {
AppTableWithControls,
StatusIcon,
IconedStatus,
ToolbarBulkSelector,
} from "@app/shared/components";

Expand Down Expand Up @@ -252,9 +252,9 @@ export const BulkCopyAssessmentReviewForm: React.FC<
},
{
title: app.review ? (
<StatusIcon status="Completed" />
<IconedStatus preset="Completed" />
) : (
<StatusIcon status="NotStarted" />
<IconedStatus preset="NotStarted" />
),
},
],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import React, { useState } from "react";
import { useHistory } from "react-router-dom";
import { useTranslation } from "react-i18next";
import { StatusIcon } from "@app/shared/components";
import { IconedStatus } from "@app/shared/components";
import {
Button,
ButtonVariant,
Flex,
FlexItem,
Modal,
PageSection,
Popover,
Expand All @@ -24,8 +22,6 @@ import {
sortable,
truncate,
} from "@patternfly/react-table";
import InProgressIcon from "@patternfly/react-icons/dist/esm/icons/in-progress-icon";

import {
AppPlaceholder,
AppTableWithControls,
Expand All @@ -37,11 +33,10 @@ import {

import { formatPath, Paths } from "@app/Paths";
import { ApplicationImportSummary } from "@app/api/models";
import { formatDate, getAxiosErrorMessage } from "@app/utils/utils";
import { formatDate } from "@app/utils/utils";

import { ImportApplicationsForm } from "../components/import-applications-form";
import { useLegacyPaginationState } from "@app/shared/hooks/useLegacyPaginationState";
import { AxiosError } from "axios";
import {
useDeleteImportSummaryMutation,
useFetchImportSummaries,
Expand Down Expand Up @@ -187,25 +182,13 @@ export const ManageImports: React.FC = () => {
currentPageItems.forEach((item) => {
let status;
if (item.importStatus === "Completed") {
status = <StatusIcon status="Completed" />;
status = <IconedStatus preset="Completed" />;
} else if (item.importStatus === "In Progress") {
status = (
<Flex
spaceItems={{ default: "spaceItemsSm" }}
alignItems={{ default: "alignItemsCenter" }}
flexWrap={{ default: "nowrap" }}
style={{ whiteSpace: "nowrap" }}
>
<FlexItem>
<InProgressIcon />
</FlexItem>
<FlexItem>{t("terms.inProgress")}</FlexItem>
</Flex>
);
status = <IconedStatus preset="InProgress" />;
} else {
status = (
<StatusIcon
status="Error"
<IconedStatus
preset="Error"
label={
<Popover
position="right"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useState } from "react";
import { StatusIcon } from "@app/shared/components";
import { IconedStatus } from "@app/shared/components";

import spacing from "@patternfly/react-styles/css/utilities/Spacing/spacing";
import { useTranslation } from "react-i18next";
Expand Down Expand Up @@ -31,8 +31,8 @@ const TrackerStatus = ({ name, connected, message }: ITrackerStatusProps) => {

return (
<>
<StatusIcon
status={connected ? "Ok" : "Error"}
<IconedStatus
preset={connected ? "Ok" : "Error"}
className={spacing.mlSm}
label={
connected ? (
Expand Down
106 changes: 106 additions & 0 deletions client/src/app/shared/components/iconed-status/iconed-status.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
import React from "react";
import { Flex, FlexItem, Icon } 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";

export type IconedStatusPreset =
| "Canceled"
| "Completed"
| "Error"
| "Failed"
| "InProgress"
| "NotStarted"
| "Ok"
| "Scheduled"
| "Unknown";

export type IconedStatusStatusType =
| "custom"
| "info"
| "success"
| "warning"
| "danger";

type IconedStatusPresetType = {
[key in IconedStatusPreset]: Omit<IIconedStatusProps, "preset">;
};

export interface IIconedStatusProps {
preset?: IconedStatusPreset;
status?: IconedStatusStatusType;
icon?: React.ReactNode;
className?: string;
label?: React.ReactNode | string;
}

export const IconedStatus: React.FC<IIconedStatusProps> = ({
preset,
status,
icon,
className = "",
label,
}: IIconedStatusProps) => {
const { t } = useTranslation();
const presets: IconedStatusPresetType = {
Canceled: {
icon: <TimesCircleIcon />,
status: "info",
label: t("terms.canceled"),
},
Completed: {
icon: <CheckCircleIcon />,
status: "success",
label: t("terms.completed"),
},
Error: {
icon: <ExclamationCircleIcon />,
status: "danger",
label: t("terms.error"),
},
Failed: {
icon: <ExclamationCircleIcon />,
status: "danger",
label: t("terms.failed"),
},
InProgress: {
icon: <InProgressIcon />,
status: "info",
label: t("terms.inProgress"),
},
NotStarted: {
icon: <TimesCircleIcon />,
label: t("terms.notStarted"),
},
Ok: {
icon: <CheckCircleIcon />,
status: "success",
},
Scheduled: {
icon: <InProgressIcon />,
status: "info",
label: t("terms.scheduled"),
},
Unknown: {
icon: <UnknownIcon />,
},
};
const presetProps = preset && presets[preset];

return (
<Flex
flexWrap={{ default: "nowrap" }}
spaceItems={{ default: "spaceItemsSm" }}
>
<FlexItem>
<Icon status={status || presetProps?.status} className={className}>
{icon || presetProps?.icon || <UnknownIcon />}
</Icon>
</FlexItem>
<FlexItem>{label || presetProps?.label}</FlexItem>
</Flex>
);
};
1 change: 1 addition & 0 deletions client/src/app/shared/components/iconed-status/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./iconed-status";
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,51 @@ exports[`StatusIcon Renders without crashing 1`] = `
"baseElement": <body>
<div>
<div
class="pf-v5-c-content"
class="pf-v5-l-flex pf-m-space-items-sm pf-m-nowrap"
>
<test-file-stub
classname=""
color="#6a6e73"
isinline="true"
/>
terms.notStarted
<div
class=""
>
<span
class="pf-v5-c-icon"
>
<span
class="pf-v5-c-icon__content"
>
<test-file-stub />
</span>
</span>
</div>
<div
class=""
>
terms.notStarted
</div>
</div>
</div>
</body>,
"container": <div>
<div
class="pf-v5-c-content"
class="pf-v5-l-flex pf-m-space-items-sm pf-m-nowrap"
>
<test-file-stub
classname=""
color="#6a6e73"
isinline="true"
/>
terms.notStarted
<div
class=""
>
<span
class="pf-v5-c-icon"
>
<span
class="pf-v5-c-icon__content"
>
<test-file-stub />
</span>
</span>
</div>
<div
class=""
>
terms.notStarted
</div>
</div>
</div>,
"debug": [Function],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { render } from "@app/test-config/test-utils";
import React from "react";
import { StatusIcon } from "../status-icon";
import { IconedStatus } from "../iconed-status";

describe("StatusIcon", () => {
it("Renders without crashing", () => {
const wrapper = render(<StatusIcon status="NotStarted" />);
const wrapper = render(<IconedStatus preset="NotStarted" />);
expect(wrapper).toMatchSnapshot();
});
});
2 changes: 1 addition & 1 deletion client/src/app/shared/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ export { ProposedActionLabel } from "./proposed-action-label";
export { RiskLabel } from "./risk-label";
export { SimpleEmptyState } from "./simple-empty-state";
export * from "./simple-select";
export * from "./status-icon";
export * from "./iconed-status";
export { ToolbarBulkSelector } from "./toolbar-bulk-selector";
1 change: 0 additions & 1 deletion client/src/app/shared/components/status-icon/index.ts

This file was deleted.

Loading

0 comments on commit 0f62f5c

Please sign in to comment.