Skip to content

fix: add fallback icons for notifications #17013

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Mar 28, 2025
Merged

Conversation

defelmnq
Copy link
Contributor

@defelmnq defelmnq commented Mar 20, 2025

@defelmnq defelmnq changed the title work on fallback icons fix: add fallback icons for notifications Mar 26, 2025
Comment on lines 39 to 69
var fallbackIcons = map[uuid.UUID]string{
// workspace related notifications
notifications.TemplateWorkspaceCreated: FallbackIconWorkspace,
notifications.TemplateWorkspaceCreated: FallbackIconWorkspace,
notifications.TemplateWorkspaceManuallyUpdated: FallbackIconWorkspace,
notifications.TemplateWorkspaceDeleted: FallbackIconWorkspace,
notifications.TemplateWorkspaceAutobuildFailed: FallbackIconWorkspace,
notifications.TemplateWorkspaceDormant: FallbackIconWorkspace,
notifications.TemplateWorkspaceAutoUpdated: FallbackIconWorkspace,
notifications.TemplateWorkspaceMarkedForDeletion: FallbackIconWorkspace,
notifications.TemplateWorkspaceManualBuildFailed: FallbackIconWorkspace,
notifications.TemplateWorkspaceOutOfMemory: FallbackIconWorkspace,
notifications.TemplateWorkspaceOutOfDisk: FallbackIconWorkspace,

// account related notifications
notifications.TemplateUserAccountCreated: FallbackIconAccount,
notifications.TemplateUserAccountDeleted: FallbackIconAccount,
notifications.TemplateUserAccountSuspended: FallbackIconAccount,
notifications.TemplateUserAccountActivated: FallbackIconAccount,
notifications.TemplateYourAccountSuspended: FallbackIconAccount,
notifications.TemplateYourAccountActivated: FallbackIconAccount,
notifications.TemplateUserRequestedOneTimePasscode: FallbackIconAccount,

// template related notifications
notifications.TemplateTemplateDeleted: FallbackIconTemplate,
notifications.TemplateTemplateDeprecated: FallbackIconTemplate,
notifications.TemplateWorkspaceBuildsFailedReport: FallbackIconTemplate,

// other related notifications
notifications.TemplateTestNotification: FallbackIconOther,
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a test to ensure that each notification template type has a fallback icon associated with it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added some tests 👀

Comment on lines 196 to 197
payload.InboxNotification.Icon = fallbackIcons[payload.InboxNotification.TemplateID]
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, we should check that there is a fallback icon defined.

Thoought: would it make sense to encapsulate this logic in a function InboxNotification.Icon()?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I created an util function to have only one place on the which we change it.

I was willing to do it as a method for the codersdk.InboxNotification receiver, but can't as it generates import cycle with the templates. :(

Comment on lines 67 to 68
// other related notifications
notifications.TemplateTestNotification: FallbackIconOther,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WDYT about returning FallbackIconOther if fallbackIcons[notif.TemplateID] does not exist? so eventually the order would be:

  1. Custom notif icon.
  2. fallbackIcons[notif.TemplateID]
  3. FallbackIconOther

In this case we won't need to add entries to fallbackIcons if FallbackIconOther is fine, including TemplateTestNotification.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the idea, like it and will make it more reliable. I added a fallback logic, please tell me if that's what you had in mind.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, thank you!

@defelmnq defelmnq requested review from mtojek and johnstcn March 27, 2025 15:02
@defelmnq defelmnq marked this pull request as ready for review March 27, 2025 15:54
Copy link
Member

@mtojek mtojek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@defelmnq is it still a draft PR?

Comment on lines 33 to 36
FallbackIconWorkspace = "DEFAULT_WORKSPACE_ICON"
FallbackIconAccount = "DEFAULT_ACCOUNT_ICON"
FallbackIconTemplate = "DEFAULT_TEMPLATE_ICON"
FallbackIconOther = "DEFAULT_OTHER_ICON"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If these are values processed by "site", you should place them in codersdk as Enum, so they will be generated to TS.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a really good idea, thanks for that - I moved it.

cc @BrunoQuaresma you would be able to use it now.

FallbackIconOther = "DEFAULT_OTHER_ICON"
)

var fallbackIcons = map[uuid.UUID]string{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alternative data structure:

fallbackIcons = map[NotificationIcon][]uuid.UUID

not a must, just a preference

@defelmnq defelmnq requested a review from mtojek March 28, 2025 09:37
Copy link
Member

@mtojek mtojek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!!

Comment on lines 67 to 68
// other related notifications
notifications.TemplateTestNotification: FallbackIconOther,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, thank you!

@defelmnq defelmnq merged commit 148dae1 into main Mar 28, 2025
31 of 33 checks passed
@defelmnq defelmnq deleted the notif-inbox/internal-522 branch March 28, 2025 11:21
@github-actions github-actions bot locked and limited conversation to collaborators Mar 28, 2025
@matifali
Copy link
Member

/cherry-pick release/2.21

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants