Files
grafana/public/app/core/components/AppNotifications/AppNotificationItem.tsx
Hugo Häggmark 119d5897ea i18n: imports use @grafana/i18n (#105177)
* i18n: everything should target @grafana/i18n

* wip

* chore: updates after PR feedback

* Trigger build

* Trigger build

* Trigger build

* chore: skip flaky tests

* chore: skip flaky tests

* chore: skip flaky tests

* chore: skip flaky tests

* chore: skip flaky tests

* chore: skip flaky tests

* chore: revert all flaky tests

* chore: some incorrect usages of useTranslate
2025-05-15 09:17:14 +02:00

58 lines
1.5 KiB
TypeScript

import { css } from '@emotion/css';
import { useEffectOnce } from 'react-use';
import { GrafanaTheme2 } from '@grafana/data';
import { Trans } from '@grafana/i18n';
import { Alert, useStyles2 } from '@grafana/ui';
import { AppNotification, timeoutMap } from 'app/types';
interface Props {
appNotification: AppNotification;
onClearNotification: (id: string) => void;
}
export default function AppNotificationItem({ appNotification, onClearNotification }: Props) {
const styles = useStyles2(getStyles);
useEffectOnce(() => {
setTimeout(() => {
onClearNotification(appNotification.id);
}, timeoutMap[appNotification.severity]);
});
const hasBody = appNotification.component || appNotification.text || appNotification.traceId;
const traceId = appNotification.traceId;
return (
<Alert
severity={appNotification.severity}
title={appNotification.title}
onRemove={() => onClearNotification(appNotification.id)}
elevated
>
{hasBody && (
<div className={styles.wrapper}>
<span>{appNotification.component || appNotification.text}</span>
{traceId && (
<span className={styles.trace}>
<Trans i18nKey="app-notification.item.trace-id">Trace ID: {{ traceId }}</Trans>
</span>
)}
</div>
)}
</Alert>
);
}
function getStyles(theme: GrafanaTheme2) {
return {
wrapper: css({
display: 'flex',
flexDirection: 'column',
}),
trace: css({
fontSize: theme.typography.pxToRem(10),
}),
};
}