-
Notifications
You must be signed in to change notification settings - Fork 914
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
Adds toast ID to toast api #3752
Changes from all commits
69985a2
257a1d0
aa0c126
ee961d7
81a136c
92ccc30
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,12 +42,10 @@ import { I18nStart } from '../../i18n'; | |
/** | ||
* Allowed fields for {@link ToastInput}. | ||
* | ||
* @remarks | ||
* `id` cannot be specified. | ||
* | ||
* @public | ||
*/ | ||
export type ToastInputFields = Pick<EuiToast, Exclude<keyof EuiToast, 'id' | 'text' | 'title'>> & { | ||
id?: string; | ||
title?: string | MountPoint; | ||
text?: string | MountPoint; | ||
}; | ||
|
@@ -143,6 +141,16 @@ export class ToastsApi implements IToasts { | |
* @returns a {@link Toast} | ||
*/ | ||
public add(toastOrTitle: ToastInput) { | ||
if (typeof toastOrTitle !== 'string') { | ||
const toastObject = toastOrTitle; | ||
const list = this.toasts$.getValue(); | ||
const existingToast = list.find((toast) => toast.id === toastObject.id); | ||
|
||
if (existingToast) { | ||
return existingToast; | ||
} | ||
} | ||
|
||
const toast: Toast = { | ||
id: String(this.idCounter++), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if it's somewhat surprising that we still increment the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We dont still increment, if an existing toast is found, we exit this function when we return the existing toast. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right, I'm talking about the case where an |
||
toastLifeTimeMs: this.uiSettings.get('notifications:lifetime:info'), | ||
|
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.
do we know the historical reason why?
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 looked at the git history but as far as I can tell, there isn't a good reason. That's why I kept the default behavior as is. Only if you explicitly pass an id does the behavior change
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.
After reviewing, my understanding is that it was just intended to be an internal property, that simply auto-increments with each new toast. Ashwin's change here changes the purpose and usage of the property a bit (for example, passing string ids instead of a number), but not in a way that affects the historical usage. So I don't think it was intended as "specifying id is prohibited" and instead meant "specifying id is not necessary".