Toasts
Extensions can show toasts in Superset's notification area with the toasts API.
import { toasts } from '@apache-superset/core';
toasts.addSuccessToast('Exported to Google Sheets', {
link: { href: 'https://docs.google.com/spreadsheets/d/abc', label: 'Open' },
});
Functions
| Function | Description |
|---|---|
addInfoToast(text, options?) | Shows an informational toast |
addSuccessToast(text, options?) | Shows a success toast |
addWarningToast(text, options?) | Shows a warning toast |
addDangerToast(text, options?) | Shows an error toast |
removeToast(id) | Closes a toast |
Each add*Toast function returns the ID of the toast, which you can pass to removeToast.
Options
interface ToastOptions {
link?: { href: string; label: string };
duration?: number;
}
textis always rendered as plain text, never as HTML.linkadds a button with the givenlabel. Clicking it openshrefin a new tab withnoopenerandnoreferrer. The URL goes through Superset's navigation guard: absolute URLs must usehttp(s),ftp:,mailto:ortel:, other values are treated as paths within Superset, and URLs the guard rejects (for example ones with embedded credentials) are logged instead of opened.durationis the time in milliseconds before the toast closes. The default is 8000.0keeps the toast until the user closes it.- A toast with a
linknever closes on its own, so that keyboard and assistive-technology users are not raced.durationis ignored whenlinkis set.
Example
Show a toast while an export runs, then replace it with the result:
import { toasts } from '@apache-superset/core';
const id = toasts.addInfoToast('Sending to Google Sheets…', { duration: 0 });
try {
const url = await sendToSheets();
toasts.removeToast(id);
toasts.addSuccessToast('Sent to Google Sheets', {
link: { href: url, label: 'Open' },
});
} catch {
toasts.removeToast(id);
toasts.addDangerToast('Sending to Google Sheets failed');
}