grafana/public/app/features/alerting/unified/hooks/useManagedAlertStateHistory.ts

23 lines
692 B
TypeScript
Raw Normal View History

2021-12-14 09:36:54 -06:00
import { useEffect } from 'react';
import { useDispatch } from 'app/types';
import { StateHistoryItem } from 'app/types/unified-alerting';
2021-12-14 09:36:54 -06:00
import { fetchGrafanaAnnotationsAction } from '../state/actions';
import { AsyncRequestState } from '../utils/redux';
2021-12-14 09:36:54 -06:00
import { useUnifiedAlertingSelector } from './useUnifiedAlertingSelector';
export function useManagedAlertStateHistory(alertId: string) {
const dispatch = useDispatch();
const history = useUnifiedAlertingSelector<AsyncRequestState<StateHistoryItem[]>>(
(state) => state.managedAlertStateHistory
);
useEffect(() => {
dispatch(fetchGrafanaAnnotationsAction(alertId));
}, [dispatch, alertId]);
return history;
}