Skip to content
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

Toast notifications: ignore undefined options #126120

Merged
merged 3 commits into from
Feb 22, 2022

Conversation

pgayvallet
Copy link
Contributor

@pgayvallet pgayvallet commented Feb 22, 2022

Summary

Because of the way the notifications service of the useKibana hook from kibana_react uses core's toast API, by passing every properties, even undefined ones instead of excluding them:

title,
body,
color,
iconType,
toastLifeTimeMs,
onClose,
}) => {
if (!services.notifications) {
throw new TypeError('Could not show notification as notifications service is not available.');
}
services.notifications!.toasts.add({
title: toMountPoint(title, { theme$: services.theme?.theme$ }),
text: toMountPoint(<>{body || null}</>, { theme$: services.theme?.theme$ }),
color,
iconType,
toastLifeTimeMs,
onClose,
});

The internal logic of the toast API to add default values for id and toastLifeTimeMs was broken, as

{
  toastLifeTimeMs: 9000,
  ...{ toastLifeTimeMs: undefined },
}

is { toastLifeTimeMs: undefined }

This PR fixes it by removing options having undefined values before performing the spread.

Closes #125582.

@pgayvallet pgayvallet added bug Fixes for quality problems that affect the customer experience release_note:skip Skip the PR/issue when compiling release notes Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc v8.1.0 v8.2.0 labels Feb 22, 2022
@kibana-ci
Copy link
Collaborator

💚 Build Succeeded

Metrics [docs]

Page load bundle

Size of the bundles that are downloaded on every page load. Target size is below 100kb

id before after diff
core 292.7KB 292.7KB +32.0B

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

@pgayvallet pgayvallet marked this pull request as ready for review February 22, 2022 09:55
@pgayvallet pgayvallet requested a review from a team as a code owner February 22, 2022 09:55
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-core (Team:Core)

Copy link
Member

@afharo afharo left a comment

Choose a reason for hiding this comment

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

LGTM

@pgayvallet pgayvallet added the auto-backport Deprecated - use backport:version if exact versions are needed label Feb 22, 2022
@pgayvallet pgayvallet merged commit 2cabe1a into elastic:main Feb 22, 2022
kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Feb 22, 2022
* Toast notifications: ignore undefined options

* just use omitBy

(cherry picked from commit 2cabe1a)
kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Feb 22, 2022
* Toast notifications: ignore undefined options

* just use omitBy

(cherry picked from commit 2cabe1a)
kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Feb 22, 2022
* Toast notifications: ignore undefined options

* just use omitBy

(cherry picked from commit 2cabe1a)
@kibanamachine
Copy link
Contributor

💚 All backports created successfully

Status Branch Result
8.1
8.0
7.17

Note: Successful backport PRs will be merged automatically after passing CI.

Questions ?

Please refer to the Backport tool documentation

kibanamachine added a commit that referenced this pull request Feb 22, 2022
* Toast notifications: ignore undefined options

* just use omitBy

(cherry picked from commit 2cabe1a)

Co-authored-by: Pierre Gayvallet <[email protected]>
kibanamachine added a commit that referenced this pull request Feb 22, 2022
* Toast notifications: ignore undefined options

* just use omitBy

(cherry picked from commit 2cabe1a)

Co-authored-by: Pierre Gayvallet <[email protected]>
kibanamachine added a commit that referenced this pull request Feb 22, 2022
* Toast notifications: ignore undefined options

* just use omitBy

(cherry picked from commit 2cabe1a)

Co-authored-by: Pierre Gayvallet <[email protected]>
lucasfcosta pushed a commit to lucasfcosta/kibana that referenced this pull request Mar 2, 2022
* Toast notifications: ignore undefined options

* just use omitBy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto-backport Deprecated - use backport:version if exact versions are needed bug Fixes for quality problems that affect the customer experience release_note:skip Skip the PR/issue when compiling release notes Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc v7.17.1 v8.0.1 v8.1.0 v8.2.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[APM] Error toast for API request immediately closes
5 participants