1import { StateHistoryItem } from 'app/types/unified-alerting';
2import { useEffect } from 'react';
3import { useDispatch } from 'react-redux';
4import { fetchGrafanaAnnotationsAction } from '../state/actions';
5import { AsyncRequestState } from '../utils/redux';
6import { useUnifiedAlertingSelector } from './useUnifiedAlertingSelector';
7
8export function useManagedAlertStateHistory(alertId: string) {
9  const dispatch = useDispatch();
10  const history = useUnifiedAlertingSelector<AsyncRequestState<StateHistoryItem[]>>(
11    (state) => state.managedAlertStateHistory
12  );
13
14  useEffect(() => {
15    dispatch(fetchGrafanaAnnotationsAction(alertId));
16  }, [dispatch, alertId]);
17
18  return history;
19}
20