Skip to content

Commit 99af612

Browse files
committed
cleaner switch statement
1 parent 6a65f07 commit 99af612

File tree

3 files changed

+21
-14
lines changed
  • apps/webapp/app
    • components/errors
    • routes
      • _app.orgs.$organizationSlug.projects.$projectParam.env.$envParam.errors.$fingerprint
      • _app.orgs.$organizationSlug.projects.$projectParam.env.$envParam.errors._index

3 files changed

+21
-14
lines changed

apps/webapp/app/components/errors/ErrorStatusMenu.tsx

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,23 @@ const BugOffIcon = ({ className }: { className?: string }) => (
3232
<IconBugOffBase className={className} size={18} />
3333
);
3434

35-
export function ignoreActionToastMessage(data: Record<string, string>): string | undefined {
36-
if (data.action !== "ignore") return undefined;
37-
38-
const duration = data.duration ? Number(data.duration) : undefined;
39-
if (!duration) return "Error ignored indefinitely";
40-
41-
const hours = duration / (60 * 60 * 1000);
42-
if (hours < 24) return `Error ignored for ${hours} ${hours === 1 ? "hour" : "hours"}`;
43-
const days = hours / 24;
44-
return `Error ignored for ${days} ${days === 1 ? "day" : "days"}`;
35+
export function statusActionToastMessage(data: Record<string, string>): string {
36+
switch (data.action) {
37+
case "resolve":
38+
return "Error marked as resolved";
39+
case "unresolve":
40+
return "Error marked as unresolved";
41+
case "ignore": {
42+
const duration = data.duration ? Number(data.duration) : undefined;
43+
if (!duration) return "Error ignored indefinitely";
44+
const hours = duration / (60 * 60 * 1000);
45+
if (hours < 24) return `Error ignored for ${hours} ${hours === 1 ? "hour" : "hours"}`;
46+
const days = hours / 24;
47+
return `Error ignored for ${days} ${days === 1 ? "day" : "days"}`;
48+
}
49+
default:
50+
return "Error status updated";
51+
}
4552
}
4653

4754
export function ErrorStatusMenuItems({

apps/webapp/app/routes/_app.orgs.$organizationSlug.projects.$projectParam.env.$envParam.errors.$fingerprint/route.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ import { ErrorGroupActions } from "~/v3/services/errorGroupActions.server";
7979
import {
8080
ErrorStatusMenuItems,
8181
CustomIgnoreDialog,
82-
ignoreActionToastMessage,
82+
statusActionToastMessage,
8383
} from "~/components/errors/ErrorStatusMenu";
8484
import { useToast } from "~/components/primitives/Toast";
8585

@@ -752,7 +752,7 @@ function ErrorStatusDropdown({
752752

753753
const act = (data: Record<string, string>) => {
754754
setPopoverOpen(false);
755-
pendingToast.current = ignoreActionToastMessage(data);
755+
pendingToast.current = statusActionToastMessage(data);
756756
fetcher.submit(data, { method: "post" });
757757
};
758758

apps/webapp/app/routes/_app.orgs.$organizationSlug.projects.$projectParam.env.$envParam.errors._index/route.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ import { PopoverSectionHeader } from "~/components/primitives/Popover";
5252
import {
5353
ErrorStatusMenuItems,
5454
CustomIgnoreDialog,
55-
ignoreActionToastMessage,
55+
statusActionToastMessage,
5656
} from "~/components/errors/ErrorStatusMenu";
5757
import { useToast } from "~/components/primitives/Toast";
5858
import TooltipPortal from "~/components/primitives/TooltipPortal";
@@ -652,7 +652,7 @@ function ErrorActionsCell({
652652
taskIdentifier={errorGroup.taskIdentifier}
653653
onAction={(data) => {
654654
close();
655-
pendingToast.current = ignoreActionToastMessage(data);
655+
pendingToast.current = statusActionToastMessage(data);
656656
fetcher.submit(data, { method: "post", action: actionUrl });
657657
}}
658658
onCustomIgnore={() => {

0 commit comments

Comments
 (0)