useManagedAlertStateHistory.ts 694 B

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