RevertDashboardModal.tsx 959 B

12345678910111213141516171819202122232425262728293031323334
  1. import React, { useEffect } from 'react';
  2. import { ConfirmModal } from '@grafana/ui';
  3. import { useDashboardRestore } from './useDashboardRestore';
  4. export interface RevertDashboardModalProps {
  5. hideModal: () => void;
  6. version: number;
  7. }
  8. export const RevertDashboardModal: React.FC<RevertDashboardModalProps> = ({ hideModal, version }) => {
  9. // TODO: how should state.error be handled?
  10. const { state, onRestoreDashboard } = useDashboardRestore(version);
  11. useEffect(() => {
  12. if (state.loading === false && state.value) {
  13. hideModal();
  14. }
  15. }, [state, hideModal]);
  16. return (
  17. <ConfirmModal
  18. isOpen={true}
  19. title="Restore Version"
  20. icon="history"
  21. onDismiss={hideModal}
  22. onConfirm={onRestoreDashboard}
  23. body={
  24. <p>Are you sure you want to restore the dashboard to version {version}? All unsaved changes will be lost.</p>
  25. }
  26. confirmText={`Yes, restore to version ${version}`}
  27. />
  28. );
  29. };