NoAlertManagerWarning.tsx 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import React from 'react';
  2. import { Alert } from '@grafana/ui';
  3. import { useAlertManagerSourceName } from '../hooks/useAlertManagerSourceName';
  4. import { AlertManagerDataSource } from '../utils/datasource';
  5. import { AlertManagerPicker } from './AlertManagerPicker';
  6. interface Props {
  7. availableAlertManagers: AlertManagerDataSource[];
  8. }
  9. const NoAlertManagersAvailable = () => (
  10. <Alert title="No Alertmanager found" severity="warning">
  11. We could not find any external Alertmanagers and you may not have access to the built-in Grafana Alertmanager.
  12. </Alert>
  13. );
  14. const OtherAlertManagersAvailable = () => (
  15. <Alert title="Selected Alertmanager not found. Select a different Alertmanager." severity="warning">
  16. Selected Alertmanager no longer exists or you may not have permission to access it.
  17. </Alert>
  18. );
  19. export const NoAlertManagerWarning = ({ availableAlertManagers }: Props) => {
  20. const [_, setAlertManagerSourceName] = useAlertManagerSourceName(availableAlertManagers);
  21. const hasOtherAMs = availableAlertManagers.length > 0;
  22. return (
  23. <div>
  24. {hasOtherAMs ? (
  25. <>
  26. <AlertManagerPicker onChange={setAlertManagerSourceName} dataSources={availableAlertManagers} />
  27. <OtherAlertManagersAvailable />
  28. </>
  29. ) : (
  30. <NoAlertManagersAvailable />
  31. )}
  32. </div>
  33. );
  34. };