From 00689bbcfddd1f64eaf00fdef6583f917ebbef32 Mon Sep 17 00:00:00 2001 From: Radoslaw Szwajkowski Date: Thu, 27 Jun 2024 19:27:21 +0200 Subject: [PATCH] :bug: Refactor task state to icon mapping (#1984) Follow the mapping used by the drawer with following changes: 1. use PauseCircleIcon also for QuotaBlocked state 2. use TaskIcon for Ready state (instead of CheckCircleIcon) 3. use CheckCircleIcon for state Succeeded Part-of: #1969 --------- Signed-off-by: Radoslaw Szwajkowski --- ...{taskStateToIcon.tsx => TaskStateIcon.tsx} | 32 +++++++++------ client/src/app/components/Icons/index.ts | 2 +- .../task-manager/TaskManagerDrawer.tsx | 39 ++++--------------- client/src/app/pages/tasks/tasks-page.tsx | 4 +- 4 files changed, 31 insertions(+), 46 deletions(-) rename client/src/app/components/Icons/{taskStateToIcon.tsx => TaskStateIcon.tsx} (55%) diff --git a/client/src/app/components/Icons/taskStateToIcon.tsx b/client/src/app/components/Icons/TaskStateIcon.tsx similarity index 55% rename from client/src/app/components/Icons/taskStateToIcon.tsx rename to client/src/app/components/Icons/TaskStateIcon.tsx index a4b616febe..11af306b5c 100644 --- a/client/src/app/components/Icons/taskStateToIcon.tsx +++ b/client/src/app/components/Icons/TaskStateIcon.tsx @@ -1,13 +1,18 @@ import { TaskState } from "@app/api/models"; -import React from "react"; +import React, { FC } from "react"; import { Icon } 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 ExclamationCircleIcon from "@patternfly/react-icons/dist/esm/icons/exclamation-circle-icon"; -import UnknownIcon from "@patternfly/react-icons/dist/esm/icons/unknown-icon"; +import { + CheckCircleIcon, + TimesCircleIcon, + InProgressIcon, + ExclamationCircleIcon, + UnknownIcon, + PendingIcon, + TaskIcon, + PauseCircleIcon, +} from "@patternfly/react-icons"; -export const taskStateToIcon = (state?: TaskState) => { +export const TaskStateIcon: FC<{ state?: TaskState }> = ({ state }) => { switch (state) { case "not supported": case "No task": @@ -26,14 +31,17 @@ export const taskStateToIcon = (state?: TaskState) => { ); - case "Pending": + case "Running": return ; - case "Created": + case "Pending": + return ; case "QuotaBlocked": - case "Running": - case "Ready": case "Postponed": + return ; + case "Created": + case "Ready": + return ; default: - return <>; + return ; } }; diff --git a/client/src/app/components/Icons/index.ts b/client/src/app/components/Icons/index.ts index 1ad916bfe6..bdcc8a6e08 100644 --- a/client/src/app/components/Icons/index.ts +++ b/client/src/app/components/Icons/index.ts @@ -1,4 +1,4 @@ export * from "./OptionalTooltip"; export * from "./IconedStatus"; export * from "./IconWithLabel"; -export * from "./taskStateToIcon"; +export * from "./TaskStateIcon"; diff --git a/client/src/app/components/task-manager/TaskManagerDrawer.tsx b/client/src/app/components/task-manager/TaskManagerDrawer.tsx index 3836087f9e..63ccc967c4 100644 --- a/client/src/app/components/task-manager/TaskManagerDrawer.tsx +++ b/client/src/app/components/task-manager/TaskManagerDrawer.tsx @@ -18,14 +18,7 @@ import { NotificationDrawerListItemHeader, Tooltip, } from "@patternfly/react-core"; -import { - CubesIcon, - InProgressIcon, - PauseCircleIcon, - PendingIcon, - CheckCircleIcon, - TaskIcon, -} from "@patternfly/react-icons"; +import { CubesIcon } from "@patternfly/react-icons"; import { css } from "@patternfly/react-styles"; import { TaskState } from "@app/api/models"; @@ -33,6 +26,7 @@ import { useTaskManagerContext } from "./TaskManagerContext"; import { useServerTasks } from "@app/queries/tasks"; import "./TaskManagerDrawer.css"; +import { TaskStateIcon } from "../Icons"; /** A version of `Task` specific for the task manager drawer components */ interface TaskManagerTask { @@ -126,28 +120,11 @@ export const TaskManagerDrawer: React.FC = forwardRef( ); TaskManagerDrawer.displayName = "TaskManagerDrawer"; -const TaskStateToIcon: React.FC<{ task: TaskManagerTask }> = ({ task }) => - task.state === "Ready" ? ( - - - - ) : task.state === "Postponed" ? ( - - - - ) : task.state === "Pending" ? ( - - - - ) : task.state === "Running" ? ( - - - - ) : ( - - - - ); +const TaskStateToIcon: React.FC<{ taskState: TaskState }> = ({ taskState }) => ( + + + +); const TaskItem: React.FC<{ task: TaskManagerTask; @@ -174,7 +151,7 @@ const TaskItem: React.FC<{ } + icon={} > {/* Put the item's action menu here */} diff --git a/client/src/app/pages/tasks/tasks-page.tsx b/client/src/app/pages/tasks/tasks-page.tsx index 915deccbcb..3e9e2c9bc7 100644 --- a/client/src/app/pages/tasks/tasks-page.tsx +++ b/client/src/app/pages/tasks/tasks-page.tsx @@ -43,7 +43,7 @@ import { TablePersistenceKeyPrefix } from "@app/Constants"; import { useSelectionState } from "@migtools/lib-ui"; import { useServerTasks } from "@app/queries/tasks"; import { Task } from "@app/api/models"; -import { IconWithLabel, taskStateToIcon } from "@app/components/Icons"; +import { IconWithLabel, TaskStateIcon } from "@app/components/Icons"; import { ManageColumnsToolbar } from "../applications/applications-table/components/manage-columns-toolbar"; import dayjs from "dayjs"; import { useTaskActions } from "./useTaskActions"; @@ -226,7 +226,7 @@ export const TasksPage: React.FC = () => { kind: kind ?? addon, state: ( } label={