Rename ToastMessage into ToastApiMessage
Signed-off-by: Charles de Dreuille <charles.dedreuille@gmail.com>
This commit is contained in:
committed by
Patrik Oldsberg
parent
e0b7eb0b64
commit
aa1d73a798
@@ -1937,12 +1937,26 @@ export const swappableComponentsApiRef: ApiRef_2<SwappableComponentsApi>;
|
||||
|
||||
// @public
|
||||
export type ToastApi = {
|
||||
post(toast: ToastMessage): string;
|
||||
post(toast: ToastApiMessage): string;
|
||||
close(key: string): void;
|
||||
toast$(): Observable<ToastMessageWithKey>;
|
||||
toast$(): Observable<ToastApiMessageWithKey>;
|
||||
close$(): Observable<string>;
|
||||
};
|
||||
|
||||
// @public
|
||||
export type ToastApiMessage = {
|
||||
title: ReactNode;
|
||||
description?: ReactNode;
|
||||
status?: 'neutral' | 'info' | 'success' | 'warning' | 'danger';
|
||||
links?: ToastLink[];
|
||||
timeout?: number;
|
||||
};
|
||||
|
||||
// @public
|
||||
export type ToastApiMessageWithKey = ToastApiMessage & {
|
||||
key: string;
|
||||
};
|
||||
|
||||
// @public
|
||||
export const toastApiRef: ApiRef<ToastApi>;
|
||||
|
||||
@@ -1952,20 +1966,6 @@ export type ToastLink = {
|
||||
href: string;
|
||||
};
|
||||
|
||||
// @public
|
||||
export type ToastMessage = {
|
||||
title: ReactNode;
|
||||
description?: ReactNode;
|
||||
status?: 'neutral' | 'info' | 'success' | 'warning' | 'danger';
|
||||
links?: ToastLink[];
|
||||
timeout?: number;
|
||||
};
|
||||
|
||||
// @public
|
||||
export type ToastMessageWithKey = ToastMessage & {
|
||||
key: string;
|
||||
};
|
||||
|
||||
// @public (undocumented)
|
||||
export type TranslationApi = {
|
||||
getTranslation<
|
||||
|
||||
@@ -21,7 +21,7 @@ import { Observable } from '@backstage/types';
|
||||
* Message handled by the {@link AlertApi}.
|
||||
*
|
||||
* @public
|
||||
* @deprecated Use {@link ToastMessage} from {@link ToastApi} instead. AlertApi will be removed in a future release.
|
||||
* @deprecated Use {@link ToastApiMessage} from {@link ToastApi} instead. AlertApi will be removed in a future release.
|
||||
*
|
||||
* Migration guide:
|
||||
* - `message` becomes `title`
|
||||
|
||||
@@ -35,7 +35,7 @@ export type ToastLink = {
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export type ToastMessage = {
|
||||
export type ToastApiMessage = {
|
||||
/** Title of the toast (required) */
|
||||
title: ReactNode;
|
||||
/** Optional description text */
|
||||
@@ -53,7 +53,7 @@ export type ToastMessage = {
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export type ToastMessageWithKey = ToastMessage & {
|
||||
export type ToastApiMessageWithKey = ToastApiMessage & {
|
||||
/** Unique key for the toast, used for programmatic dismiss */
|
||||
key: string;
|
||||
};
|
||||
@@ -96,7 +96,7 @@ export type ToastApi = {
|
||||
* @param toast - The toast message to display
|
||||
* @returns A unique key that can be used to programmatically dismiss the toast
|
||||
*/
|
||||
post(toast: ToastMessage): string;
|
||||
post(toast: ToastApiMessage): string;
|
||||
|
||||
/**
|
||||
* Programmatically close/dismiss a toast by its key.
|
||||
@@ -108,7 +108,7 @@ export type ToastApi = {
|
||||
/**
|
||||
* Observe toasts posted by other parts of the application.
|
||||
*/
|
||||
toast$(): Observable<ToastMessageWithKey>;
|
||||
toast$(): Observable<ToastApiMessageWithKey>;
|
||||
|
||||
/**
|
||||
* Observe close events for programmatic toast dismissal.
|
||||
|
||||
@@ -20,9 +20,7 @@
|
||||
"directory": "plugins/app"
|
||||
},
|
||||
"license": "Apache-2.0",
|
||||
"sideEffects": [
|
||||
"*.css"
|
||||
],
|
||||
"sideEffects": false,
|
||||
"exports": {
|
||||
".": "./src/index.ts",
|
||||
"./alpha": "./src/alpha/index.ts",
|
||||
|
||||
@@ -1020,14 +1020,6 @@ const appPlugin: OverridableFrontendPlugin<
|
||||
>;
|
||||
export default appPlugin;
|
||||
|
||||
// @public
|
||||
export interface ToastContent {
|
||||
description?: ReactNode;
|
||||
links?: ToastLink[];
|
||||
status?: 'neutral' | 'info' | 'success' | 'warning' | 'danger';
|
||||
title: ReactNode;
|
||||
}
|
||||
|
||||
// @public
|
||||
export function ToastDisplay(props: ToastDisplayProps): JSX_3.Element;
|
||||
|
||||
@@ -1041,11 +1033,5 @@ export interface ToastDisplayProps {
|
||||
transientTimeoutMs?: number;
|
||||
}
|
||||
|
||||
// @public
|
||||
export interface ToastLink {
|
||||
href: string;
|
||||
label: string;
|
||||
}
|
||||
|
||||
// (No @packageDocumentation comment for this package)
|
||||
```
|
||||
|
||||
@@ -16,8 +16,8 @@
|
||||
|
||||
import {
|
||||
ToastApi,
|
||||
ToastMessage,
|
||||
ToastMessageWithKey,
|
||||
ToastApiMessage,
|
||||
ToastApiMessageWithKey,
|
||||
} from '@backstage/frontend-plugin-api';
|
||||
import { Observable } from '@backstage/types';
|
||||
import ObservableImpl from 'zen-observable';
|
||||
@@ -85,15 +85,15 @@ class PublishSubject<T> {
|
||||
* @internal
|
||||
*/
|
||||
export class ToastApiForwarder implements ToastApi {
|
||||
private readonly subject = new PublishSubject<ToastMessageWithKey>();
|
||||
private readonly subject = new PublishSubject<ToastApiMessageWithKey>();
|
||||
private readonly closeSubject = new PublishSubject<string>();
|
||||
private readonly recentToasts: ToastMessageWithKey[] = [];
|
||||
private readonly recentToasts: ToastApiMessageWithKey[] = [];
|
||||
private readonly closedKeys = new Set<string>();
|
||||
private readonly maxBufferSize = 10;
|
||||
|
||||
post(toast: ToastMessage): string {
|
||||
post(toast: ToastApiMessage): string {
|
||||
const key = generateToastKey();
|
||||
const toastWithKey: ToastMessageWithKey = { ...toast, key };
|
||||
const toastWithKey: ToastApiMessageWithKey = { ...toast, key };
|
||||
|
||||
this.recentToasts.push(toastWithKey);
|
||||
if (this.recentToasts.length > this.maxBufferSize) {
|
||||
@@ -121,7 +121,7 @@ export class ToastApiForwarder implements ToastApi {
|
||||
}
|
||||
}
|
||||
|
||||
toast$(): Observable<ToastMessageWithKey> {
|
||||
toast$(): Observable<ToastApiMessageWithKey> {
|
||||
// Filter out any toasts that were closed to handle race conditions
|
||||
const activeToasts = this.recentToasts.filter(
|
||||
t => !this.closedKeys.has(t.key),
|
||||
|
||||
@@ -16,9 +16,9 @@
|
||||
|
||||
// Public exports
|
||||
export { ToastDisplay } from './ToastDisplay';
|
||||
export type { ToastContent, ToastLink, ToastDisplayProps } from './types';
|
||||
export type { ToastDisplayProps } from './types';
|
||||
|
||||
// Internal exports (used within the plugin only)
|
||||
export { ToastContainer } from './ToastContainer';
|
||||
export { toastQueue } from './ToastQueue';
|
||||
export type { ToastContainerProps } from './types';
|
||||
export type { ToastContent, ToastLink, ToastContainerProps } from './types';
|
||||
|
||||
@@ -19,7 +19,7 @@ import type { ToastQueue, ToastState, QueuedToast } from 'react-stately';
|
||||
|
||||
/**
|
||||
* Link item for toast notifications
|
||||
* @public
|
||||
* @internal
|
||||
*/
|
||||
export interface ToastLink {
|
||||
/** Display text for the link */
|
||||
@@ -30,7 +30,7 @@ export interface ToastLink {
|
||||
|
||||
/**
|
||||
* Content for a toast notification
|
||||
* @public
|
||||
* @internal
|
||||
*/
|
||||
export interface ToastContent {
|
||||
/** Title of the toast (required) */
|
||||
@@ -72,7 +72,7 @@ export interface ToastProps {
|
||||
|
||||
/**
|
||||
* Props for the ToastContainer component
|
||||
* @public
|
||||
* @internal
|
||||
*/
|
||||
export interface ToastContainerProps {
|
||||
/** Toast queue instance */
|
||||
|
||||
@@ -18,8 +18,4 @@ export { appPlugin as default } from './plugin';
|
||||
|
||||
// Toast components for alert display
|
||||
export { ToastDisplay } from './components/Toast';
|
||||
export type {
|
||||
ToastContent,
|
||||
ToastLink,
|
||||
ToastDisplayProps,
|
||||
} from './components/Toast';
|
||||
export type { ToastDisplayProps } from './components/Toast';
|
||||
|
||||
Reference in New Issue
Block a user