mirror of
https://github.com/grafana/grafana.git
synced 2025-09-20 05:53:07 +08:00

* 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
43 lines
1.3 KiB
TypeScript
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>
|
|
);
|
|
};
|