From f6e525763bc637c0d61425b7be82eee559ccf255 Mon Sep 17 00:00:00 2001 From: HadasahR Date: Sun, 3 Nov 2024 14:05:13 +0200 Subject: [PATCH 1/4] refactoring code as suggested in #2100 Signed-off-by: HadasahR --- .../application-analysis-status.tsx | 29 ++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) 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 4462aacaff..18ba6e3e57 100644 --- a/client/src/app/pages/applications/components/application-analysis-status.tsx +++ b/client/src/app/pages/applications/components/application-analysis-status.tsx @@ -2,7 +2,7 @@ import React from "react"; import { TaskState } from "@app/api/models"; import { IconedStatus, IconedStatusPreset } from "@app/components/Icons"; - +import { useTranslation } from "react-i18next"; export interface ApplicationAnalysisStatusProps { state: TaskState; } @@ -34,3 +34,30 @@ export const ApplicationAnalysisStatus: React.FC< > = ({ state }) => { return ; }; +export const mapAnalysisStateToLabel = (value: TaskState) => { + const presetKey: IconedStatusPreset = getTaskStatus(value); + const { t } = useTranslation(); + const presets = buildPresets(t); + const label = presets[presetKey]?.label ?? t("terms.unknown"); + return label; +}; +export const buildPresets = ( + t: (key: string) => string +): Record => ({ + Canceled: { label: t("terms.canceled") }, + Scheduled: { label: t("terms.scheduled") }, + Completed: { label: t("terms.completed") }, + CompletedWithErrors: { label: t("terms.completedWithErrors") }, + Failed: { label: t("terms.failed") }, + InProgress: { label: t("terms.inProgress") }, + NotStarted: { label: t("terms.notStarted") }, + InheritedReviews: { label: t("terms.inheritedReviews") }, + InProgressInheritedReviews: { label: t("terms.inProgressInheritedReviews") }, + InProgressInheritedAssessments: { + label: t("terms.inProgressInheritedAssessments"), + }, + InheritedAssessments: { label: t("terms.inheritedAssessments") }, + Error: { label: t("terms.error") }, // Add Error with a label + Ok: { label: t("terms.ok") }, // Add Ok with a label + Unknown: { label: t("terms.unknown") }, // Add Unknown with a label +}); From d2096ca78fa99877f5a7eed32db9402a4e3c83eb Mon Sep 17 00:00:00 2001 From: Maayan Hadasi Date: Mon, 18 Nov 2024 22:57:09 +0200 Subject: [PATCH 2/4] Changes after review Signed-off-by: Maayan Hadasi --- .../application-analysis-status.tsx | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) 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 18ba6e3e57..887345144b 100644 --- a/client/src/app/pages/applications/components/application-analysis-status.tsx +++ b/client/src/app/pages/applications/components/application-analysis-status.tsx @@ -2,7 +2,6 @@ import React from "react"; import { TaskState } from "@app/api/models"; import { IconedStatus, IconedStatusPreset } from "@app/components/Icons"; -import { useTranslation } from "react-i18next"; export interface ApplicationAnalysisStatusProps { state: TaskState; } @@ -34,30 +33,32 @@ export const ApplicationAnalysisStatus: React.FC< > = ({ state }) => { return ; }; -export const mapAnalysisStateToLabel = (value: TaskState) => { + +export const mapAnalysisStateToLabel = ( + value: TaskState, + t: (key: string) => string +) => { const presetKey: IconedStatusPreset = getTaskStatus(value); - const { t } = useTranslation(); const presets = buildPresets(t); const label = presets[presetKey]?.label ?? t("terms.unknown"); return label; }; + export const buildPresets = ( t: (key: string) => string ): Record => ({ + InProgressInheritedReviews: { label: t("terms.inProgress") }, + InProgressInheritedAssessments: { label: t("terms.inProgress") }, + InheritedReviews: { label: t("terms.completed") }, + InheritedAssessments: { label: t("terms.completed") }, Canceled: { label: t("terms.canceled") }, - Scheduled: { label: t("terms.scheduled") }, Completed: { label: t("terms.completed") }, CompletedWithErrors: { label: t("terms.completedWithErrors") }, + Error: { label: t("terms.error") }, Failed: { label: t("terms.failed") }, InProgress: { label: t("terms.inProgress") }, NotStarted: { label: t("terms.notStarted") }, - InheritedReviews: { label: t("terms.inheritedReviews") }, - InProgressInheritedReviews: { label: t("terms.inProgressInheritedReviews") }, - InProgressInheritedAssessments: { - label: t("terms.inProgressInheritedAssessments"), - }, - InheritedAssessments: { label: t("terms.inheritedAssessments") }, - Error: { label: t("terms.error") }, // Add Error with a label + Scheduled: { label: t("terms.scheduled") }, Ok: { label: t("terms.ok") }, // Add Ok with a label Unknown: { label: t("terms.unknown") }, // Add Unknown with a label }); From 179248da9b6c0ebea3c8564aa562724fbbadd845 Mon Sep 17 00:00:00 2001 From: Maayan Hadasi Date: Tue, 19 Nov 2024 10:19:17 +0200 Subject: [PATCH 3/4] Use buildPresetLabels in IconedStatus to improve label management and consistency Signed-off-by: Maayan Hadasi --- client/public/locales/en/translation.json | 3 ++- .../src/app/components/Icons/IconedStatus.tsx | 26 ++++++++++--------- .../application-analysis-status.tsx | 6 ++--- 3 files changed, 19 insertions(+), 16 deletions(-) diff --git a/client/public/locales/en/translation.json b/client/public/locales/en/translation.json index a26eb9ebb9..37ec58db06 100644 --- a/client/public/locales/en/translation.json +++ b/client/public/locales/en/translation.json @@ -502,7 +502,8 @@ "user": "User", "version": "Version", "workPriority": "Work priority", - "YAMLTemplate": "YAML template" + "YAMLTemplate": "YAML template", + "ok": "OK" }, "titles": { "archetypeDrawer": "Archetype details", diff --git a/client/src/app/components/Icons/IconedStatus.tsx b/client/src/app/components/Icons/IconedStatus.tsx index 984031d995..1539cd4ece 100644 --- a/client/src/app/components/Icons/IconedStatus.tsx +++ b/client/src/app/components/Icons/IconedStatus.tsx @@ -13,6 +13,7 @@ import { UnknownIcon, TopologyIcon, } from "@patternfly/react-icons"; +import { buildPresetLabels } from "@app/pages/applications/components/application-analysis-status"; export type IconedStatusPreset = | "InheritedReviews" @@ -62,11 +63,12 @@ export const IconedStatus: React.FC = ({ tooltipCount = 0, }: IIconedStatusProps) => { const { t } = useTranslation(); + const messages = buildPresetLabels(t); const presets: IconedStatusPresetType = { InProgressInheritedReviews: { icon: , status: "info", - label: t("terms.inProgress"), + label: messages.InProgressInheritedReviews.label, tooltipMessage: t("message.inheritedReviewTooltip", { count: tooltipCount, }), @@ -75,7 +77,7 @@ export const IconedStatus: React.FC = ({ InProgressInheritedAssessments: { icon: , status: "info", - label: t("terms.inProgress"), + label: messages.InProgressInheritedAssessments.label, tooltipMessage: t("message.inheritedAssessmentTooltip", { count: tooltipCount, }), @@ -84,7 +86,7 @@ export const IconedStatus: React.FC = ({ InheritedReviews: { icon: , status: "success", - label: t("terms.completed"), + label: messages.InheritedReviews.label, tooltipMessage: t("message.inheritedReviewTooltip", { count: tooltipCount, }), @@ -93,7 +95,7 @@ export const IconedStatus: React.FC = ({ InheritedAssessments: { icon: , status: "success", - label: t("terms.completed"), + label: messages.InheritedAssessments.label, tooltipMessage: t("message.inheritedAssessmentTooltip", { count: tooltipCount, }), @@ -102,36 +104,36 @@ export const IconedStatus: React.FC = ({ Canceled: { icon: , status: "info", - label: t("terms.canceled"), + label: messages.Canceled.label, }, Completed: { icon: , status: "success", - label: t("terms.completed"), + label: messages.Completed.label, }, CompletedWithErrors: { icon: , status: "warning", - label: t("terms.completedWithErrors"), + label: messages.CompletedWithErrors.label, }, Error: { icon: , status: "danger", - label: t("terms.error"), + label: messages.Error.label, }, Failed: { icon: , status: "danger", - label: t("terms.failed"), + label: messages.Failed.label, }, InProgress: { icon: , status: "info", - label: t("terms.inProgress"), + label: messages.InProgress.label, }, NotStarted: { icon: , - label: t("terms.notStarted"), + label: messages.NotStarted.label, }, Ok: { icon: , @@ -140,7 +142,7 @@ export const IconedStatus: React.FC = ({ Scheduled: { icon: , status: "info", - label: t("terms.scheduled"), + label: messages.Scheduled.label, }, Unknown: { icon: , 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 887345144b..8cea066070 100644 --- a/client/src/app/pages/applications/components/application-analysis-status.tsx +++ b/client/src/app/pages/applications/components/application-analysis-status.tsx @@ -39,12 +39,12 @@ export const mapAnalysisStateToLabel = ( t: (key: string) => string ) => { const presetKey: IconedStatusPreset = getTaskStatus(value); - const presets = buildPresets(t); - const label = presets[presetKey]?.label ?? t("terms.unknown"); + const presets = buildPresetLabels(t); + const label = presets[presetKey]?.label ?? presets.Unknown.label; return label; }; -export const buildPresets = ( +export const buildPresetLabels = ( t: (key: string) => string ): Record => ({ InProgressInheritedReviews: { label: t("terms.inProgress") }, From f628c04c1ebc48a3b486bf2acc771019b4e6b5c0 Mon Sep 17 00:00:00 2001 From: Maayan Hadasi Date: Tue, 19 Nov 2024 20:30:17 +0200 Subject: [PATCH 4/4] Replace buildPresetLabels func Signed-off-by: Maayan Hadasi --- .../src/app/components/Icons/IconedStatus.tsx | 20 ++++++++++++++- .../application-analysis-status.tsx | 25 ++++--------------- 2 files changed, 24 insertions(+), 21 deletions(-) diff --git a/client/src/app/components/Icons/IconedStatus.tsx b/client/src/app/components/Icons/IconedStatus.tsx index 1539cd4ece..4c81a283eb 100644 --- a/client/src/app/components/Icons/IconedStatus.tsx +++ b/client/src/app/components/Icons/IconedStatus.tsx @@ -13,7 +13,6 @@ import { UnknownIcon, TopologyIcon, } from "@patternfly/react-icons"; -import { buildPresetLabels } from "@app/pages/applications/components/application-analysis-status"; export type IconedStatusPreset = | "InheritedReviews" @@ -164,3 +163,22 @@ export const IconedStatus: React.FC = ({ /> ); }; + +export const buildPresetLabels = ( + t: (key: string) => string +): Record => ({ + InProgressInheritedReviews: { label: t("terms.inProgress") }, + InProgressInheritedAssessments: { label: t("terms.inProgress") }, + InheritedReviews: { label: t("terms.completed") }, + InheritedAssessments: { label: t("terms.completed") }, + Canceled: { label: t("terms.canceled") }, + Completed: { label: t("terms.completed") }, + CompletedWithErrors: { label: t("terms.completedWithErrors") }, + Error: { label: t("terms.error") }, + Failed: { label: t("terms.failed") }, + InProgress: { label: t("terms.inProgress") }, + NotStarted: { label: t("terms.notStarted") }, + Scheduled: { label: t("terms.scheduled") }, + Ok: { label: t("terms.ok") }, // Add Ok with a label + Unknown: { label: t("terms.unknown") }, // Add Unknown with a label +}); 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 8cea066070..a0ea6bd883 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,11 @@ import React from "react"; import { TaskState } from "@app/api/models"; -import { IconedStatus, IconedStatusPreset } from "@app/components/Icons"; +import { + buildPresetLabels, + IconedStatus, + IconedStatusPreset, +} from "@app/components/Icons"; export interface ApplicationAnalysisStatusProps { state: TaskState; } @@ -43,22 +47,3 @@ export const mapAnalysisStateToLabel = ( const label = presets[presetKey]?.label ?? presets.Unknown.label; return label; }; - -export const buildPresetLabels = ( - t: (key: string) => string -): Record => ({ - InProgressInheritedReviews: { label: t("terms.inProgress") }, - InProgressInheritedAssessments: { label: t("terms.inProgress") }, - InheritedReviews: { label: t("terms.completed") }, - InheritedAssessments: { label: t("terms.completed") }, - Canceled: { label: t("terms.canceled") }, - Completed: { label: t("terms.completed") }, - CompletedWithErrors: { label: t("terms.completedWithErrors") }, - Error: { label: t("terms.error") }, - Failed: { label: t("terms.failed") }, - InProgress: { label: t("terms.inProgress") }, - NotStarted: { label: t("terms.notStarted") }, - Scheduled: { label: t("terms.scheduled") }, - Ok: { label: t("terms.ok") }, // Add Ok with a label - Unknown: { label: t("terms.unknown") }, // Add Unknown with a label -});