-
Notifications
You must be signed in to change notification settings - Fork 22
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
#2174: Replace unmaintained react-toast-notifications
(and use one style for all toasts)
#2836
Conversation
notify.error("Error updating account alias", { | ||
error, | ||
}); | ||
notify.error({ message: "Error updating account alias", error }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
API improvement: Either call it with a plain string or provide a regular Notification
object.
Pros:
- no awkward
{ error }
wrap - simpler types
- safer: no
unknown
as the first parameter ofnotify.error
just to allownotify.error(new Error())
Cons:
- 8 extra characters 😌
message:
if you need to include theerror
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
8 extra characters 😌 message: if you need to include the error
I'm not sure we have the budget for the extra storage
src/contrib/pipedrive/create.ts
Outdated
message: `Error adding ${name} to Pipedrive`, | ||
type: "error", | ||
}); | ||
notify.error(`Error adding ${name} to Pipedrive`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As @twschiller suggested in https://github.com/pixiebrix/pixiebrix-app/pull/1252, errors are automatically reported. This was not the case with the previous showNotification
implementation so let me know if I should set report: false
to some of these.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These should actually be logger statements and BusinessErrors. Will change these
MENU_INSTALL_ERROR_DEBOUNCE_MS, | ||
{ | ||
leading: true, | ||
trailing: false, | ||
} | ||
); | ||
) as typeof notify.error; // `debounce` loses the overloads |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Side note: we might want to use memoize
instead since this debounce
may lump together unrelated errors.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Memoize won't work unless we define a custom equality function (over message). Debounce should be fine here in practice, since having multiple specific errors doesn't help much. This is more about not spamming the end-user with error notifications
src/hooks/useDeployments.ts
Outdated
{ error, report: true } | ||
); | ||
notify.warning({ | ||
message: `Error fetching latest bricks from server: ${getErrorMessage( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"notify.warning" … "Error"
Is it a warning or an error? When should an error be displayed as a warning?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The nuance is that with a warning, the user still might be OK continuing. But with an error, they would expect to no be able to proceed successfully. I'll change the message to clarify
message: | ||
"You must update the PixieBrix browser extension to activate the deployment", | ||
}); | ||
reportEvent("DeploymentRejectVersion"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Error notifications almost always need to be reported and sometimes are reported with the exact same user message.
Events on the other hand have zero data overlap with notifications and so far only appear ~8 times in the whole extension, one of which was actually reported twice. Having events as an optional parameter means that its use must always be deliberate and explicit.
Events may also have additional attached data which would further complicate the notifier for little benefit.
For these reasons I dropped the event
option from the notifier.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For these reasons I dropped the event option from the notifier
Sure, I think this makes sense. We'll give it a try
} else { | ||
const message = `Error handling context menu action: ${getErrorMessage( | ||
error | ||
)}`; | ||
reportError(new Error(message)); | ||
void showNotification(target, { message, type: "error" }); | ||
reportError(error); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we want to report the original error here. The stack trace will point to this block anyway, but its origin will be better defined.
Here it's called explicitly because the messaging API does not automatically serialize errors, especially deep inside other objects.
notify.success(`Removed brick ${getLabel(installable)}`); | ||
reportEvent("ExtensionRemove", { | ||
extensionId: installable.id, | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this case reportEvent
was called implicitly and explicitly
message: | ||
"Error refreshing service configurations, restart the PixieBrix extension", | ||
|
||
error, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
notify.warning
never reported this error. @twschiller Pick one:
- Drop line
- Add
report: true
- Change to
report.error
Same thing for the error below, in the same file
const notify = { | ||
/** | ||
* @example notify.error('User message') | ||
* @example notify.error({error: new Error('Error that can be shown to the user')}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This notifyError({error})
only happens a couple of times in the extension. We should probably not show raw errors to the user without adding some context, so I suggest requiring a message as always and only use error
for the reporting:
} catch (error) {
notifyError({
error,
message: "Stuff failed because: " + getErrorMessage(error)
})
}
appearance: "error", | ||
autoDismiss: true, | ||
notify.success("Cleared the log entries for this extension"); | ||
} catch (error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This error was not reported, now it is.
I'm good with this for now. Future considerations:
In this world, the error detail will probably be less prominent (e.g., smaller font size) |
react-toast-notifications
(and use one style for all toasts) #2174Status: Rrrrrrrrrready
One
notify.*
API to rule them all. It replaces:addToast
showNotification
useNotifications
Also standardizes the
notify.error
=> automaticallyreportError
Currently-supported pages
Demo
Notice:
z-index
that notifications should haveScreen.Recording.3.mov