2021-04-26 00:18:46 -05:00
|
|
|
import { Field, Alert, LoadingPlaceholder } from '@grafana/ui';
|
2021-04-09 05:44:26 -05:00
|
|
|
import React, { FC, useEffect } from 'react';
|
|
|
|
import { useDispatch } from 'react-redux';
|
2021-04-27 08:28:53 -05:00
|
|
|
import { Redirect } from 'react-router-dom';
|
2021-04-09 05:44:26 -05:00
|
|
|
import { AlertingPageWrapper } from './components/AlertingPageWrapper';
|
|
|
|
import { AlertManagerPicker } from './components/AlertManagerPicker';
|
|
|
|
import { useAlertManagerSourceName } from './hooks/useAlertManagerSourceName';
|
|
|
|
import { useUnifiedAlertingSelector } from './hooks/useUnifiedAlertingSelector';
|
|
|
|
import { fetchSilencesAction } from './state/actions';
|
|
|
|
import { initialAsyncRequestState } from './utils/redux';
|
|
|
|
|
|
|
|
const Silences: FC = () => {
|
|
|
|
const [alertManagerSourceName, setAlertManagerSourceName] = useAlertManagerSourceName();
|
|
|
|
const dispatch = useDispatch();
|
|
|
|
|
|
|
|
const silences = useUnifiedAlertingSelector((state) => state.silences);
|
|
|
|
|
|
|
|
useEffect(() => {
|
2021-04-27 08:28:53 -05:00
|
|
|
if (alertManagerSourceName) {
|
|
|
|
dispatch(fetchSilencesAction(alertManagerSourceName));
|
|
|
|
}
|
2021-04-09 05:44:26 -05:00
|
|
|
}, [alertManagerSourceName, dispatch]);
|
|
|
|
|
2021-04-27 08:28:53 -05:00
|
|
|
const { result, loading, error } =
|
|
|
|
(alertManagerSourceName && silences[alertManagerSourceName]) || initialAsyncRequestState;
|
|
|
|
|
|
|
|
if (!alertManagerSourceName) {
|
|
|
|
return <Redirect to="/alerting/silences" />;
|
|
|
|
}
|
2021-04-09 05:44:26 -05:00
|
|
|
|
|
|
|
return (
|
|
|
|
<AlertingPageWrapper pageId="silences">
|
2021-04-19 05:02:58 -05:00
|
|
|
<Field label="Choose alert manager">
|
|
|
|
<AlertManagerPicker current={alertManagerSourceName} onChange={setAlertManagerSourceName} />
|
|
|
|
</Field>
|
2021-04-09 05:44:26 -05:00
|
|
|
<br />
|
|
|
|
<br />
|
|
|
|
{error && !loading && (
|
2021-04-26 00:18:46 -05:00
|
|
|
<Alert severity="error" title="Error loading silences">
|
2021-04-09 05:44:26 -05:00
|
|
|
{error.message || 'Unknown error.'}
|
2021-04-26 00:18:46 -05:00
|
|
|
</Alert>
|
2021-04-09 05:44:26 -05:00
|
|
|
)}
|
|
|
|
{loading && <LoadingPlaceholder text="loading silences..." />}
|
|
|
|
{result && !loading && !error && <pre>{JSON.stringify(result, null, 2)}</pre>}
|
|
|
|
</AlertingPageWrapper>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default Silences;
|