From 0f62f5c94077e4abf0e18ab3b4ea131879f81d96 Mon Sep 17 00:00:00 2001 From: Dallas Date: Mon, 7 Aug 2023 09:50:59 -0500 Subject: [PATCH] :seedling: 1236 - changes to StatusIcon (now IconedStatus) (#1250) closes #1236 --------- Signed-off-by: gitdallas --- .../applications-table-assessment.tsx | 9 +- .../application-analysis-status.tsx | 4 +- .../application-assessment-status.tsx | 10 +- .../bulk-copy-assessment-review-form.tsx | 6 +- .../manage-imports/manage-imports.tsx | 29 +--- .../jira/components/tracker-status.tsx | 6 +- .../iconed-status/iconed-status.tsx | 106 ++++++++++++++ .../shared/components/iconed-status/index.ts | 1 + .../__snapshots__/status-icon.test.tsx.snap | 54 +++++-- .../tests/status-icon.test.tsx | 4 +- client/src/app/shared/components/index.ts | 2 +- .../shared/components/status-icon/index.ts | 1 - .../components/status-icon/status-icon.tsx | 138 ------------------ 13 files changed, 170 insertions(+), 200 deletions(-) create mode 100644 client/src/app/shared/components/iconed-status/iconed-status.tsx create mode 100644 client/src/app/shared/components/iconed-status/index.ts rename client/src/app/shared/components/{status-icon => iconed-status}/tests/__snapshots__/status-icon.test.tsx.snap (72%) rename client/src/app/shared/components/{status-icon => iconed-status}/tests/status-icon.test.tsx (63%) delete mode 100644 client/src/app/shared/components/status-icon/index.ts delete mode 100644 client/src/app/shared/components/status-icon/status-icon.tsx diff --git a/client/src/app/pages/applications/applications-table-assessment/applications-table-assessment.tsx b/client/src/app/pages/applications/applications-table-assessment/applications-table-assessment.tsx index f099a5bfb0..fb6f974dd9 100644 --- a/client/src/app/pages/applications/applications-table-assessment/applications-table-assessment.tsx +++ b/client/src/app/pages/applications/applications-table-assessment/applications-table-assessment.tsx @@ -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, @@ -32,7 +32,6 @@ import { AppTableWithControls, ConditionalRender, NoDataEmptyState, - StatusIcon, KebabDropdown, ToolbarBulkSelector, ConfirmDialog, @@ -313,10 +312,8 @@ export const ApplicationsTable: React.FC = () => { ), }, { - title: item.review ? ( - - ) : ( - + title: ( + ), }, { diff --git a/client/src/app/pages/applications/components/application-analysis-status.tsx b/client/src/app/pages/applications/components/application-analysis-status.tsx index ec6f8bb2f9..0ca60e5834 100644 --- a/client/src/app/pages/applications/components/application-analysis-status.tsx +++ b/client/src/app/pages/applications/components/application-analysis-status.tsx @@ -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; @@ -39,5 +39,5 @@ export const ApplicationAnalysisStatus: React.FC< return "NotStarted"; }; - return ; + return ; }; diff --git a/client/src/app/pages/applications/components/application-assessment-status/application-assessment-status.tsx b/client/src/app/pages/applications/components/application-assessment-status/application-assessment-status.tsx index 13eff6403f..58be4ea186 100644 --- a/client/src/app/pages/applications/components/application-assessment-status/application-assessment-status.tsx +++ b/client/src/app/pages/applications/components/application-assessment-status/application-assessment-status.tsx @@ -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"; @@ -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"; @@ -42,8 +42,8 @@ export const ApplicationAssessmentStatus: React.FC< } return assessment ? ( - + ) : ( - + ); }; diff --git a/client/src/app/pages/applications/components/bulk-copy-assessment-review-form/bulk-copy-assessment-review-form.tsx b/client/src/app/pages/applications/components/bulk-copy-assessment-review-form/bulk-copy-assessment-review-form.tsx index 03da3097f8..79f1800a2e 100644 --- a/client/src/app/pages/applications/components/bulk-copy-assessment-review-form/bulk-copy-assessment-review-form.tsx +++ b/client/src/app/pages/applications/components/bulk-copy-assessment-review-form/bulk-copy-assessment-review-form.tsx @@ -24,7 +24,7 @@ import { global_palette_gold_400 as gold } from "@patternfly/react-tokens"; import { AppTableWithControls, - StatusIcon, + IconedStatus, ToolbarBulkSelector, } from "@app/shared/components"; @@ -252,9 +252,9 @@ export const BulkCopyAssessmentReviewForm: React.FC< }, { title: app.review ? ( - + ) : ( - + ), }, ], diff --git a/client/src/app/pages/applications/manage-imports/manage-imports.tsx b/client/src/app/pages/applications/manage-imports/manage-imports.tsx index ff9194851a..ad1eecd57a 100644 --- a/client/src/app/pages/applications/manage-imports/manage-imports.tsx +++ b/client/src/app/pages/applications/manage-imports/manage-imports.tsx @@ -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, @@ -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, @@ -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, @@ -187,25 +182,13 @@ export const ManageImports: React.FC = () => { currentPageItems.forEach((item) => { let status; if (item.importStatus === "Completed") { - status = ; + status = ; } else if (item.importStatus === "In Progress") { - status = ( - - - - - {t("terms.inProgress")} - - ); + status = ; } else { status = ( - { return ( <> - ; +}; + +export interface IIconedStatusProps { + preset?: IconedStatusPreset; + status?: IconedStatusStatusType; + icon?: React.ReactNode; + className?: string; + label?: React.ReactNode | string; +} + +export const IconedStatus: React.FC = ({ + preset, + status, + icon, + className = "", + label, +}: IIconedStatusProps) => { + const { t } = useTranslation(); + const presets: IconedStatusPresetType = { + Canceled: { + icon: , + status: "info", + label: t("terms.canceled"), + }, + Completed: { + icon: , + status: "success", + label: t("terms.completed"), + }, + Error: { + icon: , + status: "danger", + label: t("terms.error"), + }, + Failed: { + icon: , + status: "danger", + label: t("terms.failed"), + }, + InProgress: { + icon: , + status: "info", + label: t("terms.inProgress"), + }, + NotStarted: { + icon: , + label: t("terms.notStarted"), + }, + Ok: { + icon: , + status: "success", + }, + Scheduled: { + icon: , + status: "info", + label: t("terms.scheduled"), + }, + Unknown: { + icon: , + }, + }; + const presetProps = preset && presets[preset]; + + return ( + + + + {icon || presetProps?.icon || } + + + {label || presetProps?.label} + + ); +}; diff --git a/client/src/app/shared/components/iconed-status/index.ts b/client/src/app/shared/components/iconed-status/index.ts new file mode 100644 index 0000000000..8b4eb03bae --- /dev/null +++ b/client/src/app/shared/components/iconed-status/index.ts @@ -0,0 +1 @@ +export * from "./iconed-status"; diff --git a/client/src/app/shared/components/status-icon/tests/__snapshots__/status-icon.test.tsx.snap b/client/src/app/shared/components/iconed-status/tests/__snapshots__/status-icon.test.tsx.snap similarity index 72% rename from client/src/app/shared/components/status-icon/tests/__snapshots__/status-icon.test.tsx.snap rename to client/src/app/shared/components/iconed-status/tests/__snapshots__/status-icon.test.tsx.snap index f05f1e0850..4a5443690b 100644 --- a/client/src/app/shared/components/status-icon/tests/__snapshots__/status-icon.test.tsx.snap +++ b/client/src/app/shared/components/iconed-status/tests/__snapshots__/status-icon.test.tsx.snap @@ -6,29 +6,51 @@ exports[`StatusIcon Renders without crashing 1`] = ` "baseElement":
- - - terms.notStarted +
+ + + + + +
+
+ terms.notStarted +
, "container":
- - - terms.notStarted +
+ + + + + +
+
+ terms.notStarted +
, "debug": [Function], diff --git a/client/src/app/shared/components/status-icon/tests/status-icon.test.tsx b/client/src/app/shared/components/iconed-status/tests/status-icon.test.tsx similarity index 63% rename from client/src/app/shared/components/status-icon/tests/status-icon.test.tsx rename to client/src/app/shared/components/iconed-status/tests/status-icon.test.tsx index 6154546830..d96a227bb6 100644 --- a/client/src/app/shared/components/status-icon/tests/status-icon.test.tsx +++ b/client/src/app/shared/components/iconed-status/tests/status-icon.test.tsx @@ -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(); + const wrapper = render(); expect(wrapper).toMatchSnapshot(); }); }); diff --git a/client/src/app/shared/components/index.ts b/client/src/app/shared/components/index.ts index 85f34137fd..3adc16e64a 100644 --- a/client/src/app/shared/components/index.ts +++ b/client/src/app/shared/components/index.ts @@ -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"; diff --git a/client/src/app/shared/components/status-icon/index.ts b/client/src/app/shared/components/status-icon/index.ts deleted file mode 100644 index 1f89f164e5..0000000000 --- a/client/src/app/shared/components/status-icon/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from "./status-icon"; diff --git a/client/src/app/shared/components/status-icon/status-icon.tsx b/client/src/app/shared/components/status-icon/status-icon.tsx deleted file mode 100644 index d2955ff203..0000000000 --- a/client/src/app/shared/components/status-icon/status-icon.tsx +++ /dev/null @@ -1,138 +0,0 @@ -import React from "react"; -import { useTranslation } from "react-i18next"; -import { - Flex, - FlexItem, - SpinnerProps, - TextContent, -} from "@patternfly/react-core"; -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 { SVGIconProps } from "@patternfly/react-icons/dist/js/createIcon"; -import ExclamationCircleIcon from "@patternfly/react-icons/dist/esm/icons/exclamation-circle-icon"; -import UnknownIcon from "@patternfly/react-icons/dist/esm/icons/unknown-icon"; -import { - global_disabled_color_200 as disabledColor, - global_success_color_100 as successColor, - global_Color_dark_200 as unknownColor, - global_info_color_200 as loadingColor, - global_danger_color_100 as errorColor, - global_info_color_100 as infoColor, -} from "@patternfly/react-tokens"; - -export type StatusIconType = - | "Canceled" - | "Completed" - | "Error" - | "Failed" - | "InProgress" - | "NotStarted" - | "Ok" - | "Scheduled" - | "Unknown"; - -type IconListType = { - [key in StatusIconType]: { - Icon: React.ComponentClass | React.FC; - color: { name: string; value: string; var: string }; - }; -}; -const iconList: IconListType = { - Canceled: { - Icon: TimesCircleIcon, - color: infoColor, - }, - Completed: { - Icon: CheckCircleIcon, - color: successColor, - }, - Error: { - Icon: ExclamationCircleIcon, - color: errorColor, - }, - Failed: { - Icon: ExclamationCircleIcon, - color: errorColor, - }, - InProgress: { - Icon: InProgressIcon, - color: loadingColor, - }, - NotStarted: { - Icon: TimesCircleIcon, - color: unknownColor, - }, - Ok: { - Icon: CheckCircleIcon, - color: successColor, - }, - Scheduled: { - Icon: InProgressIcon, - color: infoColor, - }, - Unknown: { - Icon: UnknownIcon, - color: unknownColor, - }, -}; - -export interface IStatusIconProps { - status: StatusIconType; - isDisabled?: boolean; - className?: string; - label?: React.ReactNode | string; -} - -export const StatusIcon: React.FC = ({ - status, - isDisabled = false, - className = "", - label, -}: IStatusIconProps) => { - const { t } = useTranslation(); - - const Icon = iconList[status].Icon; - const icon = ( - - ); - - if (!label) { - switch (status) { - case "Canceled": - label = t("terms.canceled"); - break; - case "Completed": - label = t("terms.completed"); - break; - case "Error": - label = t("terms.error"); - break; - case "Failed": - label = t("terms.failed"); - break; - case "InProgress": - label = t("terms.inProgress"); - break; - case "NotStarted": - label = t("terms.notStarted"); - break; - case "Scheduled": - label = t("terms.scheduled"); - break; - default: - label = t("terms.unknown"); - break; - } - } - - return ( - - {icon} {label} - - ); -};