Skip to content

Commit

Permalink
Use buildPresetsLabels in IconedStatus to improve label management an…
Browse files Browse the repository at this point in the history
…d consistency

Signed-off-by: Maayan Hadasi <[email protected]>
  • Loading branch information
mguetta1 committed Nov 19, 2024
1 parent d2096ca commit d25f964
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 15 deletions.
3 changes: 2 additions & 1 deletion client/public/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,8 @@
"user": "User",
"version": "Version",
"workPriority": "Work priority",
"YAMLTemplate": "YAML template"
"YAMLTemplate": "YAML template",
"ok": "OK"
},
"titles": {
"archetypeDrawer": "Archetype details",
Expand Down
26 changes: 14 additions & 12 deletions client/src/app/components/Icons/IconedStatus.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
UnknownIcon,
TopologyIcon,
} from "@patternfly/react-icons";
import { buildPresetsLabels } from "@app/pages/applications/components/application-analysis-status";

export type IconedStatusPreset =
| "InheritedReviews"
Expand Down Expand Up @@ -62,11 +63,12 @@ export const IconedStatus: React.FC<IIconedStatusProps> = ({
tooltipCount = 0,
}: IIconedStatusProps) => {
const { t } = useTranslation();
const messages = buildPresetsLabels(t);
const presets: IconedStatusPresetType = {
InProgressInheritedReviews: {
icon: <InProgressIcon />,
status: "info",
label: t("terms.inProgress"),
label: messages.InProgressInheritedReviews.label,
tooltipMessage: t("message.inheritedReviewTooltip", {
count: tooltipCount,
}),
Expand All @@ -75,7 +77,7 @@ export const IconedStatus: React.FC<IIconedStatusProps> = ({
InProgressInheritedAssessments: {
icon: <InProgressIcon />,
status: "info",
label: t("terms.inProgress"),
label: messages.InProgressInheritedAssessments.label,
tooltipMessage: t("message.inheritedAssessmentTooltip", {
count: tooltipCount,
}),
Expand All @@ -84,7 +86,7 @@ export const IconedStatus: React.FC<IIconedStatusProps> = ({
InheritedReviews: {
icon: <CheckCircleIcon />,
status: "success",
label: t("terms.completed"),
label: messages.InheritedReviews.label,
tooltipMessage: t("message.inheritedReviewTooltip", {
count: tooltipCount,
}),
Expand All @@ -93,7 +95,7 @@ export const IconedStatus: React.FC<IIconedStatusProps> = ({
InheritedAssessments: {
icon: <CheckCircleIcon />,
status: "success",
label: t("terms.completed"),
label: messages.InheritedAssessments.label,
tooltipMessage: t("message.inheritedAssessmentTooltip", {
count: tooltipCount,
}),
Expand All @@ -102,36 +104,36 @@ export const IconedStatus: React.FC<IIconedStatusProps> = ({
Canceled: {
icon: <TimesCircleIcon />,
status: "info",
label: t("terms.canceled"),
label: messages.Canceled.label,
},
Completed: {
icon: <CheckCircleIcon />,
status: "success",
label: t("terms.completed"),
label: messages.Completed.label,
},
CompletedWithErrors: {
icon: <ExclamationTriangleIcon />,
status: "warning",
label: t("terms.completedWithErrors"),
label: messages.CompletedWithErrors.label,
},
Error: {
icon: <ExclamationCircleIcon />,
status: "danger",
label: t("terms.error"),
label: messages.Error.label,
},
Failed: {
icon: <ExclamationCircleIcon />,
status: "danger",
label: t("terms.failed"),
label: messages.Failed.label,
},
InProgress: {
icon: <InProgressIcon />,
status: "info",
label: t("terms.inProgress"),
label: messages.InProgress.label,
},
NotStarted: {
icon: <TimesCircleIcon />,
label: t("terms.notStarted"),
label: messages.NotStarted.label,
},
Ok: {
icon: <CheckCircleIcon />,
Expand All @@ -140,7 +142,7 @@ export const IconedStatus: React.FC<IIconedStatusProps> = ({
Scheduled: {
icon: <InProgressIcon />,
status: "info",
label: t("terms.scheduled"),
label: messages.Scheduled.label,
},
Unknown: {
icon: <UnknownIcon />,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ export const mapAnalysisStateToLabel = (
t: (key: string) => string
) => {
const presetKey: IconedStatusPreset = getTaskStatus(value);
const presets = buildPresets(t);
const presets = buildPresetsLabels(t);
const label = presets[presetKey]?.label ?? t("terms.unknown");
return label;
};

export const buildPresets = (
export const buildPresetsLabels = (
t: (key: string) => string
): Record<IconedStatusPreset, { label: string }> => ({
InProgressInheritedReviews: { label: t("terms.inProgress") },
Expand Down

0 comments on commit d25f964

Please sign in to comment.