Files
grafana/public/app/features/alerting/unified/components/NoAlertManagerWarning.tsx
Konrad Lalik 65d7d466d7 Alerting: Improved RBAC for Alert managers (#48344)
* Initial support for grafana or cloud only alert managers

* Handle missing alert manager

* Refactor code, fix tests

* Fix redirect url

* Bring back the test

* Improve missing alert manager warning, add useAlertManagerSourceName tests

* Fix lint errors

* Rename alert manager hook

* Refactor alert manager label creation

* Improve warnings' messages

* Fix linter

* Fix warning condition in RuleEditor
2022-05-05 13:34:58 +02:00

43 lines
1.3 KiB
TypeScript

import React from 'react';
import { Alert } from '@grafana/ui';
import { useAlertManagerSourceName } from '../hooks/useAlertManagerSourceName';
import { AlertManagerDataSource } from '../utils/datasource';
import { AlertManagerPicker } from './AlertManagerPicker';
interface Props {
availableAlertManagers: AlertManagerDataSource[];
}
const NoAlertManagersAvailable = () => (
<Alert title="No Alertmanager found" severity="warning">
We could not find any external Alertmanagers and you may not have access to the built-in Grafana Alertmanager.
</Alert>
);
const OtherAlertManagersAvailable = () => (
<Alert title="Selected Alertmanager not found. Select a different Alertmanager." severity="warning">
Selected Alertmanager no longer exists or you may not have permission to access it.
</Alert>
);
export const NoAlertManagerWarning = ({ availableAlertManagers }: Props) => {
const [_, setAlertManagerSourceName] = useAlertManagerSourceName(availableAlertManagers);
const hasOtherAMs = availableAlertManagers.length > 0;
return (
<div>
{hasOtherAMs ? (
<>
<AlertManagerPicker onChange={setAlertManagerSourceName} dataSources={availableAlertManagers} />
<OtherAlertManagersAvailable />
</>
) : (
<NoAlertManagersAvailable />
)}
</div>
);
};