useStateHistoryModal.tsx 783 B

1234567891011121314151617181920212223242526272829303132
  1. import React, { useMemo, useState } from 'react';
  2. import { Modal } from '@grafana/ui';
  3. import { StateHistory } from '../components/rules/StateHistory';
  4. function useStateHistoryModal(alertId: string) {
  5. const [showModal, setShowModal] = useState<boolean>(false);
  6. const StateHistoryModal = useMemo(
  7. () => (
  8. <Modal
  9. isOpen={showModal}
  10. onDismiss={() => setShowModal(false)}
  11. closeOnBackdropClick={true}
  12. closeOnEscape={true}
  13. title="State history"
  14. >
  15. <StateHistory alertId={alertId} />
  16. </Modal>
  17. ),
  18. [alertId, showModal]
  19. );
  20. return {
  21. StateHistoryModal,
  22. showStateHistoryModal: () => setShowModal(true),
  23. hideStateHistoryModal: () => setShowModal(false),
  24. };
  25. }
  26. export { useStateHistoryModal };