![Jon Koops](/assets/img/avatar_default.png)
Closes #30705 Signed-off-by: Jon Koops <jonkoops@gmail.com> Signed-off-by: Erik Jan de Wit <erikjan.dewit@gmail.com> Co-authored-by: Erik Jan de Wit <erikjan.dewit@gmail.com>
43 lines
1 KiB
TypeScript
43 lines
1 KiB
TypeScript
import {
|
|
AlertGroup,
|
|
Alert,
|
|
AlertActionCloseButton,
|
|
AlertVariant,
|
|
} from "@patternfly/react-core";
|
|
|
|
import type { AlertEntry } from "./Alerts";
|
|
|
|
export type AlertPanelProps = {
|
|
alerts: AlertEntry[];
|
|
onCloseAlert: (id: number) => void;
|
|
};
|
|
|
|
export function AlertPanel({ alerts, onCloseAlert }: AlertPanelProps) {
|
|
return (
|
|
<AlertGroup
|
|
data-testid="global-alerts"
|
|
isToast
|
|
style={{ whiteSpace: "pre-wrap" }}
|
|
>
|
|
{alerts.map(({ id, variant, message, description }, index) => (
|
|
<Alert
|
|
key={id}
|
|
data-testid={index === 0 ? "last-alert" : undefined}
|
|
isLiveRegion
|
|
variant={AlertVariant[variant]}
|
|
component="p"
|
|
variantLabel=""
|
|
title={message}
|
|
actionClose={
|
|
<AlertActionCloseButton
|
|
title={message}
|
|
onClose={() => onCloseAlert(id)}
|
|
/>
|
|
}
|
|
>
|
|
{description && <p>{description}</p>}
|
|
</Alert>
|
|
))}
|
|
</AlertGroup>
|
|
);
|
|
}
|