From 5bb9ecac2bcf9e5d95564af5491cb4a0fedd9422 Mon Sep 17 00:00:00 2001 From: BrunoQuaresma Date: Wed, 26 Mar 2025 16:43:53 +0000 Subject: [PATCH 1/6] feat: set icons for each type of notification --- site/src/components/Avatar/Avatar.tsx | 2 +- .../InboxAvatar.stories.tsx | 34 +++++++++++++++++++ .../NotificationsInbox/InboxAvatar.tsx | 30 ++++++++++++++++ .../NotificationsInbox/InboxItem.stories.tsx | 1 + .../NotificationsInbox/InboxItem.tsx | 5 ++- site/src/testHelpers/entities.ts | 2 +- 6 files changed, 69 insertions(+), 5 deletions(-) create mode 100644 site/src/modules/notifications/NotificationsInbox/InboxAvatar.stories.tsx create mode 100644 site/src/modules/notifications/NotificationsInbox/InboxAvatar.tsx diff --git a/site/src/components/Avatar/Avatar.tsx b/site/src/components/Avatar/Avatar.tsx index f5492158b4aad..46316950c80b6 100644 --- a/site/src/components/Avatar/Avatar.tsx +++ b/site/src/components/Avatar/Avatar.tsx @@ -28,7 +28,7 @@ const avatarVariants = cva( }, variant: { default: null, - icon: null, + icon: "[&_svg]:size-full", }, }, defaultVariants: { diff --git a/site/src/modules/notifications/NotificationsInbox/InboxAvatar.stories.tsx b/site/src/modules/notifications/NotificationsInbox/InboxAvatar.stories.tsx new file mode 100644 index 0000000000000..7e41e3c377a59 --- /dev/null +++ b/site/src/modules/notifications/NotificationsInbox/InboxAvatar.stories.tsx @@ -0,0 +1,34 @@ +import type { Meta, StoryObj } from "@storybook/react"; +import { InboxAvatar } from "./InboxAvatar"; + +const meta: Meta = { + title: "modules/notifications/NotificationsInbox/InboxAvatar", + component: InboxAvatar, +}; + +export default meta; +type Story = StoryObj; + +export const Workspace: Story = { + args: { + icon: "DEFAULT_WORKSPACE_ICON", + }, +}; + +export const Account: Story = { + args: { + icon: "DEFAULT_ACCOUNT_ICON", + }, +}; + +export const Template: Story = { + args: { + icon: "DEFAULT_TEMPLATE_ICON", + }, +}; + +export const Other: Story = { + args: { + icon: "DEFAULT_OTHER_ICON", + }, +}; diff --git a/site/src/modules/notifications/NotificationsInbox/InboxAvatar.tsx b/site/src/modules/notifications/NotificationsInbox/InboxAvatar.tsx new file mode 100644 index 0000000000000..64873146e7d01 --- /dev/null +++ b/site/src/modules/notifications/NotificationsInbox/InboxAvatar.tsx @@ -0,0 +1,30 @@ +import { Avatar } from "components/Avatar/Avatar"; +import { + InfoIcon, + LaptopIcon, + LayoutTemplateIcon, + UserIcon, +} from "lucide-react"; +import type { FC } from "react"; +import type React from "react"; + +export type InboxIcon = + | "DEFAULT_WORKSPACE_ICON" + | "DEFAULT_ACCOUNT_ICON" + | "DEFAULT_TEMPLATE_ICON" + | "DEFAULT_OTHER_ICON"; + +const inboxIcons: Record = { + DEFAULT_WORKSPACE_ICON: , + DEFAULT_ACCOUNT_ICON: , + DEFAULT_TEMPLATE_ICON: , + DEFAULT_OTHER_ICON: , +}; + +type InboxAvatarProps = { + icon: InboxIcon; +}; + +export const InboxAvatar: FC = ({ icon }) => { + return {inboxIcons[icon]}; +}; diff --git a/site/src/modules/notifications/NotificationsInbox/InboxItem.stories.tsx b/site/src/modules/notifications/NotificationsInbox/InboxItem.stories.tsx index 681fd0ca71d32..0fb0a22afcf9b 100644 --- a/site/src/modules/notifications/NotificationsInbox/InboxItem.stories.tsx +++ b/site/src/modules/notifications/NotificationsInbox/InboxItem.stories.tsx @@ -61,6 +61,7 @@ export const Markdown: Story = { url: "https://dev.coder.com/workspaces?filter=template%3Acoder-with-ai", }, ], + icon: "DEFAULT_TEMPLATE_ICON", }, }, }; diff --git a/site/src/modules/notifications/NotificationsInbox/InboxItem.tsx b/site/src/modules/notifications/NotificationsInbox/InboxItem.tsx index 3b8471f84a94d..2a9e8d1934fc7 100644 --- a/site/src/modules/notifications/NotificationsInbox/InboxItem.tsx +++ b/site/src/modules/notifications/NotificationsInbox/InboxItem.tsx @@ -1,13 +1,12 @@ import type { InboxNotification } from "api/typesGenerated"; -import { Avatar } from "components/Avatar/Avatar"; import { Button } from "components/Button/Button"; import { Link } from "components/Link/Link"; import { SquareCheckBig } from "lucide-react"; import type { FC } from "react"; import Markdown from "react-markdown"; import { Link as RouterLink } from "react-router-dom"; -import { cn } from "utils/cn"; import { relativeTime } from "utils/time"; +import { InboxAvatar, type InboxIcon } from "./InboxAvatar"; type InboxItemProps = { notification: InboxNotification; @@ -25,7 +24,7 @@ export const InboxItem: FC = ({ tabIndex={-1} >
- +
diff --git a/site/src/testHelpers/entities.ts b/site/src/testHelpers/entities.ts index d956e09957c7e..8194970e74c60 100644 --- a/site/src/testHelpers/entities.ts +++ b/site/src/testHelpers/entities.ts @@ -4260,7 +4260,7 @@ export const MockNotification: TypesGen.InboxNotification = { template_id: MockTemplate.id, targets: [], title: "User account created", - icon: "user", + icon: "DEFAULT_ACCOUNT_ICON", }; export const MockNotifications: TypesGen.InboxNotification[] = [ From 6182d98910179c43afcc12d717b4b623d7f357d9 Mon Sep 17 00:00:00 2001 From: BrunoQuaresma Date: Fri, 28 Mar 2025 19:30:15 +0000 Subject: [PATCH 2/6] Refactor types --- coderd/apidoc/docs.go | 17 ++++++- coderd/apidoc/swagger.json | 17 ++++++- coderd/inboxnotifications.go | 4 +- coderd/inboxnotifications_internal_test.go | 4 +- codersdk/inboxnotification.go | 30 ++++++------ docs/reference/api/notifications.md | 4 +- docs/reference/api/schemas.md | 47 +++++++++++++------ site/src/api/typesGenerated.ts | 28 ++++++----- .../InboxAvatar.stories.tsx | 22 +++++---- .../NotificationsInbox/InboxAvatar.tsx | 35 +++++++++----- 10 files changed, 137 insertions(+), 71 deletions(-) diff --git a/coderd/apidoc/docs.go b/coderd/apidoc/docs.go index a543e5b716e8f..f4d14fdbfae72 100644 --- a/coderd/apidoc/docs.go +++ b/coderd/apidoc/docs.go @@ -12389,7 +12389,7 @@ const docTemplate = `{ "format": "date-time" }, "icon": { - "type": "string" + "$ref": "#/definitions/codersdk.InboxNotificationFallbackIcon" }, "id": { "type": "string", @@ -12429,6 +12429,21 @@ const docTemplate = `{ } } }, + "codersdk.InboxNotificationFallbackIcon": { + "type": "string", + "enum": [ + "DEFAULT_ICON_WORKSPACE", + "DEFAULT_ICON_ACCOUNT", + "DEFAULT_ICON_TEMPLATE", + "DEFAULT_ICON_OTHER" + ], + "x-enum-varnames": [ + "FallbackIconWorkspace", + "FallbackIconAccount", + "FallbackIconTemplate", + "FallbackIconOther" + ] + }, "codersdk.InsightsReportInterval": { "type": "string", "enum": [ diff --git a/coderd/apidoc/swagger.json b/coderd/apidoc/swagger.json index 586f63e5c6d6f..939a9ba7d306a 100644 --- a/coderd/apidoc/swagger.json +++ b/coderd/apidoc/swagger.json @@ -11133,7 +11133,7 @@ "format": "date-time" }, "icon": { - "type": "string" + "$ref": "#/definitions/codersdk.InboxNotificationFallbackIcon" }, "id": { "type": "string", @@ -11173,6 +11173,21 @@ } } }, + "codersdk.InboxNotificationFallbackIcon": { + "type": "string", + "enum": [ + "DEFAULT_ICON_WORKSPACE", + "DEFAULT_ICON_ACCOUNT", + "DEFAULT_ICON_TEMPLATE", + "DEFAULT_ICON_OTHER" + ], + "x-enum-varnames": [ + "FallbackIconWorkspace", + "FallbackIconAccount", + "FallbackIconTemplate", + "FallbackIconOther" + ] + }, "codersdk.InsightsReportInterval": { "type": "string", "enum": ["day", "week"], diff --git a/coderd/inboxnotifications.go b/coderd/inboxnotifications.go index df6ebe9d25aaf..27de20e299825 100644 --- a/coderd/inboxnotifications.go +++ b/coderd/inboxnotifications.go @@ -29,7 +29,7 @@ const ( notificationFormatPlaintext = "plaintext" ) -var fallbackIcons = map[uuid.UUID]string{ +var fallbackIcons = map[uuid.UUID]codersdk.InboxNotificationFallbackIcon{ // workspace related notifications notifications.TemplateWorkspaceCreated: codersdk.FallbackIconWorkspace, notifications.TemplateWorkspaceManuallyUpdated: codersdk.FallbackIconWorkspace, @@ -80,7 +80,7 @@ func convertInboxNotificationResponse(ctx context.Context, logger slog.Logger, n Targets: notif.Targets, Title: notif.Title, Content: notif.Content, - Icon: notif.Icon, + Icon: codersdk.InboxNotificationFallbackIcon(notif.Icon), Actions: func() []codersdk.InboxNotificationAction { var actionsList []codersdk.InboxNotificationAction err := json.Unmarshal([]byte(notif.Actions), &actionsList) diff --git a/coderd/inboxnotifications_internal_test.go b/coderd/inboxnotifications_internal_test.go index 6dd36fcffe145..126248bc1bdcb 100644 --- a/coderd/inboxnotifications_internal_test.go +++ b/coderd/inboxnotifications_internal_test.go @@ -16,9 +16,9 @@ func TestInboxNotifications_ensureNotificationIcon(t *testing.T) { tests := []struct { name string - icon string + icon codersdk.InboxNotificationFallbackIcon templateID uuid.UUID - expectedIcon string + expectedIcon codersdk.InboxNotificationFallbackIcon }{ {"WorkspaceCreated", "", notifications.TemplateWorkspaceCreated, codersdk.FallbackIconWorkspace}, {"UserAccountCreated", "", notifications.TemplateUserAccountCreated, codersdk.FallbackIconAccount}, diff --git a/codersdk/inboxnotification.go b/codersdk/inboxnotification.go index ba68351c39bfe..3f968b4acd394 100644 --- a/codersdk/inboxnotification.go +++ b/codersdk/inboxnotification.go @@ -10,24 +10,26 @@ import ( "github.com/google/uuid" ) +type InboxNotificationFallbackIcon string + const ( - FallbackIconWorkspace = "DEFAULT_ICON_WORKSPACE" - FallbackIconAccount = "DEFAULT_ICON_ACCOUNT" - FallbackIconTemplate = "DEFAULT_ICON_TEMPLATE" - FallbackIconOther = "DEFAULT_ICON_OTHER" + FallbackIconWorkspace InboxNotificationFallbackIcon = "DEFAULT_ICON_WORKSPACE" + FallbackIconAccount InboxNotificationFallbackIcon = "DEFAULT_ICON_ACCOUNT" + FallbackIconTemplate InboxNotificationFallbackIcon = "DEFAULT_ICON_TEMPLATE" + FallbackIconOther InboxNotificationFallbackIcon = "DEFAULT_ICON_OTHER" ) type InboxNotification struct { - ID uuid.UUID `json:"id" format:"uuid"` - UserID uuid.UUID `json:"user_id" format:"uuid"` - TemplateID uuid.UUID `json:"template_id" format:"uuid"` - Targets []uuid.UUID `json:"targets" format:"uuid"` - Title string `json:"title"` - Content string `json:"content"` - Icon string `json:"icon"` - Actions []InboxNotificationAction `json:"actions"` - ReadAt *time.Time `json:"read_at"` - CreatedAt time.Time `json:"created_at" format:"date-time"` + ID uuid.UUID `json:"id" format:"uuid"` + UserID uuid.UUID `json:"user_id" format:"uuid"` + TemplateID uuid.UUID `json:"template_id" format:"uuid"` + Targets []uuid.UUID `json:"targets" format:"uuid"` + Title string `json:"title"` + Content string `json:"content"` + Icon InboxNotificationFallbackIcon `json:"icon"` + Actions []InboxNotificationAction `json:"actions"` + ReadAt *time.Time `json:"read_at"` + CreatedAt time.Time `json:"created_at" format:"date-time"` } type InboxNotificationAction struct { diff --git a/docs/reference/api/notifications.md b/docs/reference/api/notifications.md index 09890d3b17864..e298b57046d79 100644 --- a/docs/reference/api/notifications.md +++ b/docs/reference/api/notifications.md @@ -84,7 +84,7 @@ curl -X GET http://coder-server:8080/api/v2/notifications/inbox \ ], "content": "string", "created_at": "2019-08-24T14:15:22Z", - "icon": "string", + "icon": "DEFAULT_ICON_WORKSPACE", "id": "497f6eca-6276-4993-bfeb-53cbbbba6f08", "read_at": "string", "targets": [ @@ -171,7 +171,7 @@ curl -X GET http://coder-server:8080/api/v2/notifications/inbox/watch \ ], "content": "string", "created_at": "2019-08-24T14:15:22Z", - "icon": "string", + "icon": "DEFAULT_ICON_WORKSPACE", "id": "497f6eca-6276-4993-bfeb-53cbbbba6f08", "read_at": "string", "targets": [ diff --git a/docs/reference/api/schemas.md b/docs/reference/api/schemas.md index 4fee5c57d5100..1386927746e81 100644 --- a/docs/reference/api/schemas.md +++ b/docs/reference/api/schemas.md @@ -3052,7 +3052,7 @@ Git clone makes use of this by parsing the URL from: 'Username for "https://gith ], "content": "string", "created_at": "2019-08-24T14:15:22Z", - "icon": "string", + "icon": "DEFAULT_ICON_WORKSPACE", "id": "497f6eca-6276-4993-bfeb-53cbbbba6f08", "read_at": "string", "targets": [ @@ -3320,7 +3320,7 @@ Git clone makes use of this by parsing the URL from: 'Username for "https://gith ], "content": "string", "created_at": "2019-08-24T14:15:22Z", - "icon": "string", + "icon": "DEFAULT_ICON_WORKSPACE", "id": "497f6eca-6276-4993-bfeb-53cbbbba6f08", "read_at": "string", "targets": [ @@ -3334,18 +3334,18 @@ Git clone makes use of this by parsing the URL from: 'Username for "https://gith ### Properties -| Name | Type | Required | Restrictions | Description | -|---------------|-------------------------------------------------------------------------------|----------|--------------|-------------| -| `actions` | array of [codersdk.InboxNotificationAction](#codersdkinboxnotificationaction) | false | | | -| `content` | string | false | | | -| `created_at` | string | false | | | -| `icon` | string | false | | | -| `id` | string | false | | | -| `read_at` | string | false | | | -| `targets` | array of string | false | | | -| `template_id` | string | false | | | -| `title` | string | false | | | -| `user_id` | string | false | | | +| Name | Type | Required | Restrictions | Description | +|---------------|----------------------------------------------------------------------------------|----------|--------------|-------------| +| `actions` | array of [codersdk.InboxNotificationAction](#codersdkinboxnotificationaction) | false | | | +| `content` | string | false | | | +| `created_at` | string | false | | | +| `icon` | [codersdk.InboxNotificationFallbackIcon](#codersdkinboxnotificationfallbackicon) | false | | | +| `id` | string | false | | | +| `read_at` | string | false | | | +| `targets` | array of string | false | | | +| `template_id` | string | false | | | +| `title` | string | false | | | +| `user_id` | string | false | | | ## codersdk.InboxNotificationAction @@ -3363,6 +3363,23 @@ Git clone makes use of this by parsing the URL from: 'Username for "https://gith | `label` | string | false | | | | `url` | string | false | | | +## codersdk.InboxNotificationFallbackIcon + +```json +"DEFAULT_ICON_WORKSPACE" +``` + +### Properties + +#### Enumerated Values + +| Value | +|--------------------------| +| `DEFAULT_ICON_WORKSPACE` | +| `DEFAULT_ICON_ACCOUNT` | +| `DEFAULT_ICON_TEMPLATE` | +| `DEFAULT_ICON_OTHER` | + ## codersdk.InsightsReportInterval ```json @@ -3506,7 +3523,7 @@ Git clone makes use of this by parsing the URL from: 'Username for "https://gith ], "content": "string", "created_at": "2019-08-24T14:15:22Z", - "icon": "string", + "icon": "DEFAULT_ICON_WORKSPACE", "id": "497f6eca-6276-4993-bfeb-53cbbbba6f08", "read_at": "string", "targets": [ diff --git a/site/src/api/typesGenerated.ts b/site/src/api/typesGenerated.ts index 602fb582f07c9..ee857183bb68a 100644 --- a/site/src/api/typesGenerated.ts +++ b/site/src/api/typesGenerated.ts @@ -839,18 +839,6 @@ export interface ExternalAuthUser { readonly name: string; } -// From codersdk/inboxnotification.go -export const FallbackIconAccount = "DEFAULT_ICON_ACCOUNT"; - -// From codersdk/inboxnotification.go -export const FallbackIconOther = "DEFAULT_ICON_OTHER"; - -// From codersdk/inboxnotification.go -export const FallbackIconTemplate = "DEFAULT_ICON_TEMPLATE"; - -// From codersdk/inboxnotification.go -export const FallbackIconWorkspace = "DEFAULT_ICON_WORKSPACE"; - // From codersdk/deployment.go export interface Feature { readonly entitlement: Entitlement; @@ -1112,7 +1100,7 @@ export interface InboxNotification { readonly targets: readonly string[]; readonly title: string; readonly content: string; - readonly icon: string; + readonly icon: InboxNotificationFallbackIcon; readonly actions: readonly InboxNotificationAction[]; readonly read_at: string | null; readonly created_at: string; @@ -1124,6 +1112,20 @@ export interface InboxNotificationAction { readonly url: string; } +// From codersdk/inboxnotification.go +export type InboxNotificationFallbackIcon = + | "DEFAULT_ICON_ACCOUNT" + | "DEFAULT_ICON_OTHER" + | "DEFAULT_ICON_TEMPLATE" + | "DEFAULT_ICON_WORKSPACE"; + +export const InboxNotificationFallbackIcons: InboxNotificationFallbackIcon[] = [ + "DEFAULT_ICON_ACCOUNT", + "DEFAULT_ICON_OTHER", + "DEFAULT_ICON_TEMPLATE", + "DEFAULT_ICON_WORKSPACE", +]; + // From codersdk/insights.go export type InsightsReportInterval = "day" | "week"; diff --git a/site/src/modules/notifications/NotificationsInbox/InboxAvatar.stories.tsx b/site/src/modules/notifications/NotificationsInbox/InboxAvatar.stories.tsx index 7e41e3c377a59..00f7c5cd01f19 100644 --- a/site/src/modules/notifications/NotificationsInbox/InboxAvatar.stories.tsx +++ b/site/src/modules/notifications/NotificationsInbox/InboxAvatar.stories.tsx @@ -9,26 +9,32 @@ const meta: Meta = { export default meta; type Story = StoryObj; -export const Workspace: Story = { +export const Custom: Story = { args: { - icon: "DEFAULT_WORKSPACE_ICON", + icon: "/icon/git.svg", }, }; -export const Account: Story = { +export const FallbackWorkspace: Story = { args: { - icon: "DEFAULT_ACCOUNT_ICON", + icon: "DEFAULT_ICON_WORKSPACE", }, }; -export const Template: Story = { +export const FallbackAccount: Story = { args: { - icon: "DEFAULT_TEMPLATE_ICON", + icon: "DEFAULT_ICON_ACCOUNT", }, }; -export const Other: Story = { +export const FallbackTemplate: Story = { args: { - icon: "DEFAULT_OTHER_ICON", + icon: "DEFAULT_ICON_TEMPLATE", + }, +}; + +export const FallbackOther: Story = { + args: { + icon: "DEFAULT_ICON_OTHER", }, }; diff --git a/site/src/modules/notifications/NotificationsInbox/InboxAvatar.tsx b/site/src/modules/notifications/NotificationsInbox/InboxAvatar.tsx index 64873146e7d01..6f514bb1ba323 100644 --- a/site/src/modules/notifications/NotificationsInbox/InboxAvatar.tsx +++ b/site/src/modules/notifications/NotificationsInbox/InboxAvatar.tsx @@ -1,3 +1,7 @@ +import { + InboxNotificationFallbackIcons, + type InboxNotificationFallbackIcon, +} from "api/typesGenerated"; import { Avatar } from "components/Avatar/Avatar"; import { InfoIcon, @@ -8,23 +12,28 @@ import { import type { FC } from "react"; import type React from "react"; -export type InboxIcon = - | "DEFAULT_WORKSPACE_ICON" - | "DEFAULT_ACCOUNT_ICON" - | "DEFAULT_TEMPLATE_ICON" - | "DEFAULT_OTHER_ICON"; - -const inboxIcons: Record = { - DEFAULT_WORKSPACE_ICON: , - DEFAULT_ACCOUNT_ICON: , - DEFAULT_TEMPLATE_ICON: , - DEFAULT_OTHER_ICON: , +const fallbackIcons: Record = { + DEFAULT_ICON_WORKSPACE: , + DEFAULT_ICON_ACCOUNT: , + DEFAULT_ICON_TEMPLATE: , + DEFAULT_ICON_OTHER: , }; type InboxAvatarProps = { - icon: InboxIcon; + icon: string; }; export const InboxAvatar: FC = ({ icon }) => { - return {inboxIcons[icon]}; + if (isInboxNotificationFallbackIcon(icon)) { + return {fallbackIcons[icon]}; + } + + console.log("ICON"); + return ; }; + +function isInboxNotificationFallbackIcon( + icon: string, +): icon is InboxNotificationFallbackIcon { + return (InboxNotificationFallbackIcons as string[]).includes(icon); +} From 22dd6e6f5b9ce9b950d7f44c026ed11955855017 Mon Sep 17 00:00:00 2001 From: BrunoQuaresma Date: Fri, 28 Mar 2025 19:34:33 +0000 Subject: [PATCH 3/6] FMT --- .../modules/notifications/NotificationsInbox/InboxAvatar.tsx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/site/src/modules/notifications/NotificationsInbox/InboxAvatar.tsx b/site/src/modules/notifications/NotificationsInbox/InboxAvatar.tsx index 6f514bb1ba323..5ceb30bbb5b9a 100644 --- a/site/src/modules/notifications/NotificationsInbox/InboxAvatar.tsx +++ b/site/src/modules/notifications/NotificationsInbox/InboxAvatar.tsx @@ -1,6 +1,6 @@ import { - InboxNotificationFallbackIcons, type InboxNotificationFallbackIcon, + InboxNotificationFallbackIcons, } from "api/typesGenerated"; import { Avatar } from "components/Avatar/Avatar"; import { @@ -28,7 +28,6 @@ export const InboxAvatar: FC = ({ icon }) => { return {fallbackIcons[icon]}; } - console.log("ICON"); return ; }; From fa1d788fb1f7590bb111138fb4d2bf606c8e1760 Mon Sep 17 00:00:00 2001 From: BrunoQuaresma Date: Fri, 28 Mar 2025 20:05:36 +0000 Subject: [PATCH 4/6] Fix missing type issues --- .../notifications/NotificationsInbox/InboxItem.stories.tsx | 2 +- .../modules/notifications/NotificationsInbox/InboxItem.tsx | 4 ++-- site/src/testHelpers/entities.ts | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/site/src/modules/notifications/NotificationsInbox/InboxItem.stories.tsx b/site/src/modules/notifications/NotificationsInbox/InboxItem.stories.tsx index 0fb0a22afcf9b..c9ed8bb632e03 100644 --- a/site/src/modules/notifications/NotificationsInbox/InboxItem.stories.tsx +++ b/site/src/modules/notifications/NotificationsInbox/InboxItem.stories.tsx @@ -61,7 +61,7 @@ export const Markdown: Story = { url: "https://dev.coder.com/workspaces?filter=template%3Acoder-with-ai", }, ], - icon: "DEFAULT_TEMPLATE_ICON", + icon: "DEFAULT_ICON_TEMPLATE", }, }, }; diff --git a/site/src/modules/notifications/NotificationsInbox/InboxItem.tsx b/site/src/modules/notifications/NotificationsInbox/InboxItem.tsx index 2a9e8d1934fc7..e1817bf3b99ce 100644 --- a/site/src/modules/notifications/NotificationsInbox/InboxItem.tsx +++ b/site/src/modules/notifications/NotificationsInbox/InboxItem.tsx @@ -6,7 +6,7 @@ import type { FC } from "react"; import Markdown from "react-markdown"; import { Link as RouterLink } from "react-router-dom"; import { relativeTime } from "utils/time"; -import { InboxAvatar, type InboxIcon } from "./InboxAvatar"; +import { InboxAvatar } from "./InboxAvatar"; type InboxItemProps = { notification: InboxNotification; @@ -24,7 +24,7 @@ export const InboxItem: FC = ({ tabIndex={-1} >
- +
diff --git a/site/src/testHelpers/entities.ts b/site/src/testHelpers/entities.ts index fa60f8b6b75f2..2efd3580c1f94 100644 --- a/site/src/testHelpers/entities.ts +++ b/site/src/testHelpers/entities.ts @@ -4261,7 +4261,7 @@ export const MockNotification: TypesGen.InboxNotification = { template_id: MockTemplate.id, targets: [], title: "User account created", - icon: "DEFAULT_ACCOUNT_ICON", + icon: "DEFAULT_ICON_ACCOUNT", }; export const MockNotifications: TypesGen.InboxNotification[] = [ From c6fcdc7a604b5f6a454b2f9fa8740ee6eec1a063 Mon Sep 17 00:00:00 2001 From: BrunoQuaresma Date: Fri, 28 Mar 2025 20:21:42 +0000 Subject: [PATCH 5/6] Rollback enums --- coderd/apidoc/docs.go | 17 +------ coderd/apidoc/swagger.json | 17 +------ coderd/inboxnotifications.go | 46 +++++++++--------- coderd/inboxnotifications_internal_test.go | 14 +++--- coderd/inboxnotifications_test.go | 14 +++--- codersdk/inboxnotification.go | 30 ++++++------ docs/reference/api/notifications.md | 4 +- docs/reference/api/schemas.md | 47 ++++++------------- site/src/api/typesGenerated.ts | 24 +++++----- .../NotificationsInbox/InboxAvatar.tsx | 18 +++++-- 10 files changed, 96 insertions(+), 135 deletions(-) diff --git a/coderd/apidoc/docs.go b/coderd/apidoc/docs.go index f4d14fdbfae72..a543e5b716e8f 100644 --- a/coderd/apidoc/docs.go +++ b/coderd/apidoc/docs.go @@ -12389,7 +12389,7 @@ const docTemplate = `{ "format": "date-time" }, "icon": { - "$ref": "#/definitions/codersdk.InboxNotificationFallbackIcon" + "type": "string" }, "id": { "type": "string", @@ -12429,21 +12429,6 @@ const docTemplate = `{ } } }, - "codersdk.InboxNotificationFallbackIcon": { - "type": "string", - "enum": [ - "DEFAULT_ICON_WORKSPACE", - "DEFAULT_ICON_ACCOUNT", - "DEFAULT_ICON_TEMPLATE", - "DEFAULT_ICON_OTHER" - ], - "x-enum-varnames": [ - "FallbackIconWorkspace", - "FallbackIconAccount", - "FallbackIconTemplate", - "FallbackIconOther" - ] - }, "codersdk.InsightsReportInterval": { "type": "string", "enum": [ diff --git a/coderd/apidoc/swagger.json b/coderd/apidoc/swagger.json index 939a9ba7d306a..586f63e5c6d6f 100644 --- a/coderd/apidoc/swagger.json +++ b/coderd/apidoc/swagger.json @@ -11133,7 +11133,7 @@ "format": "date-time" }, "icon": { - "$ref": "#/definitions/codersdk.InboxNotificationFallbackIcon" + "type": "string" }, "id": { "type": "string", @@ -11173,21 +11173,6 @@ } } }, - "codersdk.InboxNotificationFallbackIcon": { - "type": "string", - "enum": [ - "DEFAULT_ICON_WORKSPACE", - "DEFAULT_ICON_ACCOUNT", - "DEFAULT_ICON_TEMPLATE", - "DEFAULT_ICON_OTHER" - ], - "x-enum-varnames": [ - "FallbackIconWorkspace", - "FallbackIconAccount", - "FallbackIconTemplate", - "FallbackIconOther" - ] - }, "codersdk.InsightsReportInterval": { "type": "string", "enum": ["day", "week"], diff --git a/coderd/inboxnotifications.go b/coderd/inboxnotifications.go index 27de20e299825..6da047241d790 100644 --- a/coderd/inboxnotifications.go +++ b/coderd/inboxnotifications.go @@ -29,32 +29,32 @@ const ( notificationFormatPlaintext = "plaintext" ) -var fallbackIcons = map[uuid.UUID]codersdk.InboxNotificationFallbackIcon{ +var fallbackIcons = map[uuid.UUID]string{ // workspace related notifications - notifications.TemplateWorkspaceCreated: codersdk.FallbackIconWorkspace, - notifications.TemplateWorkspaceManuallyUpdated: codersdk.FallbackIconWorkspace, - notifications.TemplateWorkspaceDeleted: codersdk.FallbackIconWorkspace, - notifications.TemplateWorkspaceAutobuildFailed: codersdk.FallbackIconWorkspace, - notifications.TemplateWorkspaceDormant: codersdk.FallbackIconWorkspace, - notifications.TemplateWorkspaceAutoUpdated: codersdk.FallbackIconWorkspace, - notifications.TemplateWorkspaceMarkedForDeletion: codersdk.FallbackIconWorkspace, - notifications.TemplateWorkspaceManualBuildFailed: codersdk.FallbackIconWorkspace, - notifications.TemplateWorkspaceOutOfMemory: codersdk.FallbackIconWorkspace, - notifications.TemplateWorkspaceOutOfDisk: codersdk.FallbackIconWorkspace, + notifications.TemplateWorkspaceCreated: codersdk.InboxNotificationFallbackIconWorkspace, + notifications.TemplateWorkspaceManuallyUpdated: codersdk.InboxNotificationFallbackIconWorkspace, + notifications.TemplateWorkspaceDeleted: codersdk.InboxNotificationFallbackIconWorkspace, + notifications.TemplateWorkspaceAutobuildFailed: codersdk.InboxNotificationFallbackIconWorkspace, + notifications.TemplateWorkspaceDormant: codersdk.InboxNotificationFallbackIconWorkspace, + notifications.TemplateWorkspaceAutoUpdated: codersdk.InboxNotificationFallbackIconWorkspace, + notifications.TemplateWorkspaceMarkedForDeletion: codersdk.InboxNotificationFallbackIconWorkspace, + notifications.TemplateWorkspaceManualBuildFailed: codersdk.InboxNotificationFallbackIconWorkspace, + notifications.TemplateWorkspaceOutOfMemory: codersdk.InboxNotificationFallbackIconWorkspace, + notifications.TemplateWorkspaceOutOfDisk: codersdk.InboxNotificationFallbackIconWorkspace, // account related notifications - notifications.TemplateUserAccountCreated: codersdk.FallbackIconAccount, - notifications.TemplateUserAccountDeleted: codersdk.FallbackIconAccount, - notifications.TemplateUserAccountSuspended: codersdk.FallbackIconAccount, - notifications.TemplateUserAccountActivated: codersdk.FallbackIconAccount, - notifications.TemplateYourAccountSuspended: codersdk.FallbackIconAccount, - notifications.TemplateYourAccountActivated: codersdk.FallbackIconAccount, - notifications.TemplateUserRequestedOneTimePasscode: codersdk.FallbackIconAccount, + notifications.TemplateUserAccountCreated: codersdk.InboxNotificationFallbackIconAccount, + notifications.TemplateUserAccountDeleted: codersdk.InboxNotificationFallbackIconAccount, + notifications.TemplateUserAccountSuspended: codersdk.InboxNotificationFallbackIconAccount, + notifications.TemplateUserAccountActivated: codersdk.InboxNotificationFallbackIconAccount, + notifications.TemplateYourAccountSuspended: codersdk.InboxNotificationFallbackIconAccount, + notifications.TemplateYourAccountActivated: codersdk.InboxNotificationFallbackIconAccount, + notifications.TemplateUserRequestedOneTimePasscode: codersdk.InboxNotificationFallbackIconAccount, // template related notifications - notifications.TemplateTemplateDeleted: codersdk.FallbackIconTemplate, - notifications.TemplateTemplateDeprecated: codersdk.FallbackIconTemplate, - notifications.TemplateWorkspaceBuildsFailedReport: codersdk.FallbackIconTemplate, + notifications.TemplateTemplateDeleted: codersdk.InboxNotificationFallbackIconTemplate, + notifications.TemplateTemplateDeprecated: codersdk.InboxNotificationFallbackIconTemplate, + notifications.TemplateWorkspaceBuildsFailedReport: codersdk.InboxNotificationFallbackIconTemplate, } func ensureNotificationIcon(notif codersdk.InboxNotification) codersdk.InboxNotification { @@ -64,7 +64,7 @@ func ensureNotificationIcon(notif codersdk.InboxNotification) codersdk.InboxNoti fallbackIcon, ok := fallbackIcons[notif.TemplateID] if !ok { - fallbackIcon = codersdk.FallbackIconOther + fallbackIcon = codersdk.InboxNotificationFallbackIconOther } notif.Icon = fallbackIcon @@ -80,7 +80,7 @@ func convertInboxNotificationResponse(ctx context.Context, logger slog.Logger, n Targets: notif.Targets, Title: notif.Title, Content: notif.Content, - Icon: codersdk.InboxNotificationFallbackIcon(notif.Icon), + Icon: notif.Icon, Actions: func() []codersdk.InboxNotificationAction { var actionsList []codersdk.InboxNotificationAction err := json.Unmarshal([]byte(notif.Actions), &actionsList) diff --git a/coderd/inboxnotifications_internal_test.go b/coderd/inboxnotifications_internal_test.go index 126248bc1bdcb..e7d9a85d3e74f 100644 --- a/coderd/inboxnotifications_internal_test.go +++ b/coderd/inboxnotifications_internal_test.go @@ -16,16 +16,16 @@ func TestInboxNotifications_ensureNotificationIcon(t *testing.T) { tests := []struct { name string - icon codersdk.InboxNotificationFallbackIcon + icon string templateID uuid.UUID - expectedIcon codersdk.InboxNotificationFallbackIcon + expectedIcon string }{ - {"WorkspaceCreated", "", notifications.TemplateWorkspaceCreated, codersdk.FallbackIconWorkspace}, - {"UserAccountCreated", "", notifications.TemplateUserAccountCreated, codersdk.FallbackIconAccount}, - {"TemplateDeleted", "", notifications.TemplateTemplateDeleted, codersdk.FallbackIconTemplate}, - {"TestNotification", "", notifications.TemplateTestNotification, codersdk.FallbackIconOther}, + {"WorkspaceCreated", "", notifications.TemplateWorkspaceCreated, codersdk.InboxNotificationFallbackIconWorkspace}, + {"UserAccountCreated", "", notifications.TemplateUserAccountCreated, codersdk.InboxNotificationFallbackIconAccount}, + {"TemplateDeleted", "", notifications.TemplateTemplateDeleted, codersdk.InboxNotificationFallbackIconTemplate}, + {"TestNotification", "", notifications.TemplateTestNotification, codersdk.InboxNotificationFallbackIconOther}, {"TestExistingIcon", "https://cdn.coder.com/icon_notif.png", notifications.TemplateTemplateDeleted, "https://cdn.coder.com/icon_notif.png"}, - {"UnknownTemplate", "", uuid.New(), codersdk.FallbackIconOther}, + {"UnknownTemplate", "", uuid.New(), codersdk.InboxNotificationFallbackIconOther}, } for _, tt := range tests { diff --git a/coderd/inboxnotifications_test.go b/coderd/inboxnotifications_test.go index d9ee0ee936a94..82ae539518ae0 100644 --- a/coderd/inboxnotifications_test.go +++ b/coderd/inboxnotifications_test.go @@ -137,7 +137,7 @@ func TestInboxNotification_Watch(t *testing.T) { require.Equal(t, memberClient.ID, notif.Notification.UserID) // check for the fallback icon logic - require.Equal(t, codersdk.FallbackIconWorkspace, notif.Notification.Icon) + require.Equal(t, codersdk.InboxNotificationFallbackIconWorkspace, notif.Notification.Icon) }) t.Run("OK - change format", func(t *testing.T) { @@ -557,11 +557,11 @@ func TestInboxNotifications_List(t *testing.T) { require.Len(t, notifs.Notifications, 10) require.Equal(t, "https://dev.coder.com/icon.png", notifs.Notifications[0].Icon) - require.Equal(t, codersdk.FallbackIconWorkspace, notifs.Notifications[9].Icon) - require.Equal(t, codersdk.FallbackIconWorkspace, notifs.Notifications[8].Icon) - require.Equal(t, codersdk.FallbackIconAccount, notifs.Notifications[7].Icon) - require.Equal(t, codersdk.FallbackIconTemplate, notifs.Notifications[6].Icon) - require.Equal(t, codersdk.FallbackIconOther, notifs.Notifications[4].Icon) + require.Equal(t, codersdk.InboxNotificationFallbackIconWorkspace, notifs.Notifications[9].Icon) + require.Equal(t, codersdk.InboxNotificationFallbackIconWorkspace, notifs.Notifications[8].Icon) + require.Equal(t, codersdk.InboxNotificationFallbackIconAccount, notifs.Notifications[7].Icon) + require.Equal(t, codersdk.InboxNotificationFallbackIconTemplate, notifs.Notifications[6].Icon) + require.Equal(t, codersdk.InboxNotificationFallbackIconOther, notifs.Notifications[4].Icon) }) t.Run("OK with template filter", func(t *testing.T) { @@ -607,7 +607,7 @@ func TestInboxNotifications_List(t *testing.T) { require.Len(t, notifs.Notifications, 5) require.Equal(t, "Notification 8", notifs.Notifications[0].Title) - require.Equal(t, codersdk.FallbackIconWorkspace, notifs.Notifications[0].Icon) + require.Equal(t, codersdk.InboxNotificationFallbackIconWorkspace, notifs.Notifications[0].Icon) }) t.Run("OK with target filter", func(t *testing.T) { diff --git a/codersdk/inboxnotification.go b/codersdk/inboxnotification.go index 3f968b4acd394..1501f701f4272 100644 --- a/codersdk/inboxnotification.go +++ b/codersdk/inboxnotification.go @@ -10,26 +10,24 @@ import ( "github.com/google/uuid" ) -type InboxNotificationFallbackIcon string - const ( - FallbackIconWorkspace InboxNotificationFallbackIcon = "DEFAULT_ICON_WORKSPACE" - FallbackIconAccount InboxNotificationFallbackIcon = "DEFAULT_ICON_ACCOUNT" - FallbackIconTemplate InboxNotificationFallbackIcon = "DEFAULT_ICON_TEMPLATE" - FallbackIconOther InboxNotificationFallbackIcon = "DEFAULT_ICON_OTHER" + InboxNotificationFallbackIconWorkspace = "DEFAULT_ICON_WORKSPACE" + InboxNotificationFallbackIconAccount = "DEFAULT_ICON_ACCOUNT" + InboxNotificationFallbackIconTemplate = "DEFAULT_ICON_TEMPLATE" + InboxNotificationFallbackIconOther = "DEFAULT_ICON_OTHER" ) type InboxNotification struct { - ID uuid.UUID `json:"id" format:"uuid"` - UserID uuid.UUID `json:"user_id" format:"uuid"` - TemplateID uuid.UUID `json:"template_id" format:"uuid"` - Targets []uuid.UUID `json:"targets" format:"uuid"` - Title string `json:"title"` - Content string `json:"content"` - Icon InboxNotificationFallbackIcon `json:"icon"` - Actions []InboxNotificationAction `json:"actions"` - ReadAt *time.Time `json:"read_at"` - CreatedAt time.Time `json:"created_at" format:"date-time"` + ID uuid.UUID `json:"id" format:"uuid"` + UserID uuid.UUID `json:"user_id" format:"uuid"` + TemplateID uuid.UUID `json:"template_id" format:"uuid"` + Targets []uuid.UUID `json:"targets" format:"uuid"` + Title string `json:"title"` + Content string `json:"content"` + Icon string `json:"icon"` + Actions []InboxNotificationAction `json:"actions"` + ReadAt *time.Time `json:"read_at"` + CreatedAt time.Time `json:"created_at" format:"date-time"` } type InboxNotificationAction struct { diff --git a/docs/reference/api/notifications.md b/docs/reference/api/notifications.md index e298b57046d79..09890d3b17864 100644 --- a/docs/reference/api/notifications.md +++ b/docs/reference/api/notifications.md @@ -84,7 +84,7 @@ curl -X GET http://coder-server:8080/api/v2/notifications/inbox \ ], "content": "string", "created_at": "2019-08-24T14:15:22Z", - "icon": "DEFAULT_ICON_WORKSPACE", + "icon": "string", "id": "497f6eca-6276-4993-bfeb-53cbbbba6f08", "read_at": "string", "targets": [ @@ -171,7 +171,7 @@ curl -X GET http://coder-server:8080/api/v2/notifications/inbox/watch \ ], "content": "string", "created_at": "2019-08-24T14:15:22Z", - "icon": "DEFAULT_ICON_WORKSPACE", + "icon": "string", "id": "497f6eca-6276-4993-bfeb-53cbbbba6f08", "read_at": "string", "targets": [ diff --git a/docs/reference/api/schemas.md b/docs/reference/api/schemas.md index 1386927746e81..4fee5c57d5100 100644 --- a/docs/reference/api/schemas.md +++ b/docs/reference/api/schemas.md @@ -3052,7 +3052,7 @@ Git clone makes use of this by parsing the URL from: 'Username for "https://gith ], "content": "string", "created_at": "2019-08-24T14:15:22Z", - "icon": "DEFAULT_ICON_WORKSPACE", + "icon": "string", "id": "497f6eca-6276-4993-bfeb-53cbbbba6f08", "read_at": "string", "targets": [ @@ -3320,7 +3320,7 @@ Git clone makes use of this by parsing the URL from: 'Username for "https://gith ], "content": "string", "created_at": "2019-08-24T14:15:22Z", - "icon": "DEFAULT_ICON_WORKSPACE", + "icon": "string", "id": "497f6eca-6276-4993-bfeb-53cbbbba6f08", "read_at": "string", "targets": [ @@ -3334,18 +3334,18 @@ Git clone makes use of this by parsing the URL from: 'Username for "https://gith ### Properties -| Name | Type | Required | Restrictions | Description | -|---------------|----------------------------------------------------------------------------------|----------|--------------|-------------| -| `actions` | array of [codersdk.InboxNotificationAction](#codersdkinboxnotificationaction) | false | | | -| `content` | string | false | | | -| `created_at` | string | false | | | -| `icon` | [codersdk.InboxNotificationFallbackIcon](#codersdkinboxnotificationfallbackicon) | false | | | -| `id` | string | false | | | -| `read_at` | string | false | | | -| `targets` | array of string | false | | | -| `template_id` | string | false | | | -| `title` | string | false | | | -| `user_id` | string | false | | | +| Name | Type | Required | Restrictions | Description | +|---------------|-------------------------------------------------------------------------------|----------|--------------|-------------| +| `actions` | array of [codersdk.InboxNotificationAction](#codersdkinboxnotificationaction) | false | | | +| `content` | string | false | | | +| `created_at` | string | false | | | +| `icon` | string | false | | | +| `id` | string | false | | | +| `read_at` | string | false | | | +| `targets` | array of string | false | | | +| `template_id` | string | false | | | +| `title` | string | false | | | +| `user_id` | string | false | | | ## codersdk.InboxNotificationAction @@ -3363,23 +3363,6 @@ Git clone makes use of this by parsing the URL from: 'Username for "https://gith | `label` | string | false | | | | `url` | string | false | | | -## codersdk.InboxNotificationFallbackIcon - -```json -"DEFAULT_ICON_WORKSPACE" -``` - -### Properties - -#### Enumerated Values - -| Value | -|--------------------------| -| `DEFAULT_ICON_WORKSPACE` | -| `DEFAULT_ICON_ACCOUNT` | -| `DEFAULT_ICON_TEMPLATE` | -| `DEFAULT_ICON_OTHER` | - ## codersdk.InsightsReportInterval ```json @@ -3523,7 +3506,7 @@ Git clone makes use of this by parsing the URL from: 'Username for "https://gith ], "content": "string", "created_at": "2019-08-24T14:15:22Z", - "icon": "DEFAULT_ICON_WORKSPACE", + "icon": "string", "id": "497f6eca-6276-4993-bfeb-53cbbbba6f08", "read_at": "string", "targets": [ diff --git a/site/src/api/typesGenerated.ts b/site/src/api/typesGenerated.ts index ee857183bb68a..b812bcb46bc03 100644 --- a/site/src/api/typesGenerated.ts +++ b/site/src/api/typesGenerated.ts @@ -1100,7 +1100,7 @@ export interface InboxNotification { readonly targets: readonly string[]; readonly title: string; readonly content: string; - readonly icon: InboxNotificationFallbackIcon; + readonly icon: string; readonly actions: readonly InboxNotificationAction[]; readonly read_at: string | null; readonly created_at: string; @@ -1113,18 +1113,16 @@ export interface InboxNotificationAction { } // From codersdk/inboxnotification.go -export type InboxNotificationFallbackIcon = - | "DEFAULT_ICON_ACCOUNT" - | "DEFAULT_ICON_OTHER" - | "DEFAULT_ICON_TEMPLATE" - | "DEFAULT_ICON_WORKSPACE"; - -export const InboxNotificationFallbackIcons: InboxNotificationFallbackIcon[] = [ - "DEFAULT_ICON_ACCOUNT", - "DEFAULT_ICON_OTHER", - "DEFAULT_ICON_TEMPLATE", - "DEFAULT_ICON_WORKSPACE", -]; +export const InboxNotificationFallbackIconAccount = "DEFAULT_ICON_ACCOUNT"; + +// From codersdk/inboxnotification.go +export const InboxNotificationFallbackIconOther = "DEFAULT_ICON_OTHER"; + +// From codersdk/inboxnotification.go +export const InboxNotificationFallbackIconTemplate = "DEFAULT_ICON_TEMPLATE"; + +// From codersdk/inboxnotification.go +export const InboxNotificationFallbackIconWorkspace = "DEFAULT_ICON_WORKSPACE"; // From codersdk/insights.go export type InsightsReportInterval = "day" | "week"; diff --git a/site/src/modules/notifications/NotificationsInbox/InboxAvatar.tsx b/site/src/modules/notifications/NotificationsInbox/InboxAvatar.tsx index 5ceb30bbb5b9a..cc95d9096a8a2 100644 --- a/site/src/modules/notifications/NotificationsInbox/InboxAvatar.tsx +++ b/site/src/modules/notifications/NotificationsInbox/InboxAvatar.tsx @@ -1,6 +1,8 @@ import { - type InboxNotificationFallbackIcon, - InboxNotificationFallbackIcons, + InboxNotificationFallbackIconAccount, + InboxNotificationFallbackIconOther, + InboxNotificationFallbackIconTemplate, + InboxNotificationFallbackIconWorkspace, } from "api/typesGenerated"; import { Avatar } from "components/Avatar/Avatar"; import { @@ -12,6 +14,16 @@ import { import type { FC } from "react"; import type React from "react"; +const InboxNotificationFallbackIcons = [ + InboxNotificationFallbackIconAccount, + InboxNotificationFallbackIconWorkspace, + InboxNotificationFallbackIconTemplate, + InboxNotificationFallbackIconOther, +] as const; + +type InboxNotificationFallbackIcon = + (typeof InboxNotificationFallbackIcons)[number]; + const fallbackIcons: Record = { DEFAULT_ICON_WORKSPACE: , DEFAULT_ICON_ACCOUNT: , @@ -34,5 +46,5 @@ export const InboxAvatar: FC = ({ icon }) => { function isInboxNotificationFallbackIcon( icon: string, ): icon is InboxNotificationFallbackIcon { - return (InboxNotificationFallbackIcons as string[]).includes(icon); + return (InboxNotificationFallbackIcons as readonly string[]).includes(icon); } From fb9acf7187cd3c25dbebe46e8a8ee17683ed1188 Mon Sep 17 00:00:00 2001 From: BrunoQuaresma Date: Mon, 31 Mar 2025 12:14:26 +0000 Subject: [PATCH 6/6] Fix avatar for empty icons --- .../NotificationsInbox/InboxAvatar.stories.tsx | 6 ++++++ .../notifications/NotificationsInbox/InboxAvatar.tsx | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/site/src/modules/notifications/NotificationsInbox/InboxAvatar.stories.tsx b/site/src/modules/notifications/NotificationsInbox/InboxAvatar.stories.tsx index 00f7c5cd01f19..85199a335d662 100644 --- a/site/src/modules/notifications/NotificationsInbox/InboxAvatar.stories.tsx +++ b/site/src/modules/notifications/NotificationsInbox/InboxAvatar.stories.tsx @@ -15,6 +15,12 @@ export const Custom: Story = { }, }; +export const EmptyIcon: Story = { + args: { + icon: "", + }, +}; + export const FallbackWorkspace: Story = { args: { icon: "DEFAULT_ICON_WORKSPACE", diff --git a/site/src/modules/notifications/NotificationsInbox/InboxAvatar.tsx b/site/src/modules/notifications/NotificationsInbox/InboxAvatar.tsx index cc95d9096a8a2..9be8e2b9f74ad 100644 --- a/site/src/modules/notifications/NotificationsInbox/InboxAvatar.tsx +++ b/site/src/modules/notifications/NotificationsInbox/InboxAvatar.tsx @@ -36,6 +36,10 @@ type InboxAvatarProps = { }; export const InboxAvatar: FC = ({ icon }) => { + if (icon === "") { + return {fallbackIcons.DEFAULT_ICON_OTHER}; + } + if (isInboxNotificationFallbackIcon(icon)) { return {fallbackIcons[icon]}; }