2021-04-26 00:18:46 -05:00
|
|
|
import { Alert, Field, LoadingPlaceholder } from '@grafana/ui';
|
2021-04-07 00:42:43 -05:00
|
|
|
import React, { FC, useEffect } from 'react';
|
|
|
|
import { useDispatch } from 'react-redux';
|
|
|
|
import { AlertingPageWrapper } from './components/AlertingPageWrapper';
|
|
|
|
import { AlertManagerPicker } from './components/AlertManagerPicker';
|
|
|
|
import { useAlertManagerSourceName } from './hooks/useAlertManagerSourceName';
|
|
|
|
import { useUnifiedAlertingSelector } from './hooks/useUnifiedAlertingSelector';
|
|
|
|
import { fetchAlertManagerConfigAction } from './state/actions';
|
|
|
|
import { initialAsyncRequestState } from './utils/redux';
|
|
|
|
|
|
|
|
const AmRoutes: FC = () => {
|
|
|
|
const [alertManagerSourceName, setAlertManagerSourceName] = useAlertManagerSourceName();
|
|
|
|
const dispatch = useDispatch();
|
|
|
|
|
|
|
|
const amConfigs = useUnifiedAlertingSelector((state) => state.amConfigs);
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
dispatch(fetchAlertManagerConfigAction(alertManagerSourceName));
|
|
|
|
}, [alertManagerSourceName, dispatch]);
|
|
|
|
|
|
|
|
const { result, loading, error } = amConfigs[alertManagerSourceName] || initialAsyncRequestState;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<AlertingPageWrapper pageId="am-routes">
|
2021-04-19 05:02:58 -05:00
|
|
|
<Field label="Choose alert manager">
|
|
|
|
<AlertManagerPicker current={alertManagerSourceName} onChange={setAlertManagerSourceName} />
|
|
|
|
</Field>
|
2021-04-07 00:42:43 -05:00
|
|
|
<br />
|
|
|
|
<br />
|
|
|
|
{error && !loading && (
|
2021-04-26 00:18:46 -05:00
|
|
|
<Alert severity="error" title="Error loading alert manager config">
|
2021-04-07 00:42:43 -05:00
|
|
|
{error.message || 'Unknown error.'}
|
2021-04-26 00:18:46 -05:00
|
|
|
</Alert>
|
2021-04-07 00:42:43 -05:00
|
|
|
)}
|
|
|
|
{loading && <LoadingPlaceholder text="loading alert manager config..." />}
|
|
|
|
{result && !loading && !error && <pre>{JSON.stringify(result, null, 2)}</pre>}
|
|
|
|
</AlertingPageWrapper>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default AmRoutes;
|