-
Notifications
You must be signed in to change notification settings - Fork 726
CONSOLE-5424: Add minimize action for toast notifications #16762
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
Open
galkremer1
wants to merge
3
commits into
openshift:main
Choose a base branch
from
galkremer1:CONSOLE-5424-add-minimize-to-toast-messages
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -61,34 +61,63 @@ The UI displays tabs in priority order from highest to lowest. Default built-in | |
|
|
||
| ### Improved control over toast notifications | ||
|
|
||
| When displaying toast notifications using `useToast` hook, Console supports persisting toasts in the | ||
| notification drawer with read/unread state and management actions. Toast notifications that opt in to | ||
| drawer persistence are subject to a visible cap (default 3) with an overflow link to the notification | ||
| drawer. Existing toast consumers are unaffected — by default, toasts remain on-screen only. | ||
| When displaying toast notifications using the `useToast` hook, Console supports persisting toasts in the | ||
| notification drawer with read/unread state, management actions, and minimizing toasts back to the | ||
| drawer. Toast notifications that opt in to drawer persistence are subject to a visible cap (default 3) | ||
| with an overflow link to the notification drawer. Existing toast consumers are unaffected: by default, | ||
| toasts remain on-screen only. | ||
|
|
||
| `ToastOptions` supports optional properties for this control: | ||
|
Member
Author
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. @jseseCCS can you please review this section again? |
||
|
|
||
| - `persistInDrawer` (default `false`) to persist the toast in the notification drawer with read/unread | ||
| state. Drawer-persisted toasts default to counting toward the visible cap and overflow link. | ||
| - `skipOverflow` (default `true`) to exclude the toast from the visible cap (default 3) and overflow | ||
| link. Defaults to `false` when `persistInDrawer` is `true`, unless set explicitly. Combine | ||
| `persistInDrawer: true` with `skipOverflow: true` for always-visible drawer-persisted toasts. | ||
| - `drawerGroup` to group the toast into a named drawer section. Omitted toasts use the built-in group, | ||
| displayed as "Other Alerts" (translated by Console). Custom values are shown as-is; plugins are | ||
| responsible for translating their own group names. | ||
| - `minimizable` (default `false`) to add a Minus icon button, for toasts that aren't `dismissible`, that | ||
| minimizes the toast: hides it on-screen and keeps it unread in the drawer, without invoking `onClose`. | ||
| Requires `persistInDrawer: true`. | ||
| - `actions` to add buttons or links to the toast, each with a `label` and `callback`. Set `dismiss: true` | ||
| on an action to also dismiss the toast when clicked, or `minimize: true` to minimize it instead. A | ||
| `minimize: true` action renders as a text link at its position in the array, useful for `dismissible` | ||
| toasts where the Minus icon isn't shown. | ||
|
|
||
| `useToast` also returns `minimizeToast(id)` for minimizing a toast programmatically. | ||
|
|
||
| #### Example: Persist, group, and minimize a toast | ||
|
|
||
| `ToastOptions` supports new optional properties for better control over toast notifications: | ||
| ```tsx | ||
| const { addToast } = useToast(); | ||
|
|
||
| - `persistInDrawer` (default `false`) to persist the toast in the notification drawer when set to `true`. | ||
| Drawer-persisted toasts default to participating in the visible toast cap and overflow link. | ||
| - `skipOverflow` (default `true`) to control whether a toast participates in the visible toast cap. | ||
| When `persistInDrawer` is `true`, defaults to `false` unless explicitly set to `true`. | ||
| Use `persistInDrawer: true` with `skipOverflow: true` for always-visible drawer-persisted toasts | ||
| (e.g. long-running upload progress). | ||
| - `drawerGroup` to group toast notifications into named sections in the notification drawer. When omitted, | ||
| toasts appear in the built-in default group, displayed as "Other Alerts" (translated by Console). Custom | ||
| `drawerGroup` values are shown as-is; plugins are responsible for translating their own group names if needed. | ||
| addToast({ | ||
| title: 'Uploading disk.img', | ||
| variant: 'info', | ||
| content: <UploadProgressContent />, | ||
| dismissible: false, | ||
| timeout: false, | ||
| persistInDrawer: true, | ||
| skipOverflow: true, | ||
| drawerGroup: 'Uploads', // translate custom group names in your own plugin, e.g. t('Uploads') | ||
| minimizable: true, | ||
| }); | ||
| ``` | ||
|
|
||
| ### Example: persisting and grouping toasts in the notification drawer | ||
| #### Example: Order a minimize action for a dismissible toast | ||
|
|
||
| ```tsx | ||
| const { addToast } = useToast(); | ||
|
|
||
| addToast({ | ||
| title: 'Upload complete', | ||
| variant: 'success', | ||
| content: 'disk.img uploaded successfully.', | ||
| title: 'Import failed', | ||
| variant: 'danger', | ||
| content: 'disk.img could not be imported.', | ||
| dismissible: true, | ||
| persistInDrawer: true, | ||
| drawerGroup: 'Uploads', | ||
| actions: [ | ||
| { label: 'Retry', callback: retryImport }, | ||
| { label: 'Minimize', minimize: true, callback: () => {} }, | ||
| ], | ||
| }); | ||
| ``` | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -998,7 +998,9 @@ export const useActivePerspective: UseActivePerspective = require('@console/dyna | |
|
|
||
| /** | ||
| * Hook that provides toast functionality for displaying alerts. | ||
| * @returns A toast context object with an `addToast` function for adding a toast to the screen and a `removeToast` function for removing a toast from the screen. | ||
| * @returns A context object with an addToast function for adding a toast to the screen, a | ||
| * removeToast function for removing it from the screen, and a minimizeToast function for | ||
| * hiding a drawer-persisted toast from the screen while keeping it unread in the notification drawer. | ||
|
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. same comment as in api.md line 3213 |
||
| * @example | ||
| * ```tsx | ||
| * const Component: React.FC = (props) => { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 breaks have to stay @galkremer1 ?
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.
Yes, they are auto-generated by the content of
frontend/packages/console-dynamic-plugin-sdk/src/api/core-api.ts