Skip to content

Commit

Permalink
refactoring code as suggested in konveyor#2100
Browse files Browse the repository at this point in the history
Signed-off-by: HadasahR <[email protected]>
  • Loading branch information
HadasahR authored and mguetta1 committed Nov 18, 2024
1 parent 76a051a commit f6e5257
Showing 1 changed file with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -34,3 +34,30 @@ export const ApplicationAnalysisStatus: React.FC<
> = ({ state }) => {
return <IconedStatus preset={getTaskStatus(state)} />;
};
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<IconedStatusPreset, { label: string }> => ({
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
});

0 comments on commit f6e5257

Please sign in to comment.