monitorHeaderActions.tsx 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. import {browserHistory} from 'react-router';
  2. import {deleteMonitor, updateMonitor} from 'sentry/actionCreators/monitors';
  3. import {Button} from 'sentry/components/button';
  4. import ButtonBar from 'sentry/components/buttonBar';
  5. import Confirm from 'sentry/components/confirm';
  6. import {IconDelete, IconEdit, IconPause, IconPlay} from 'sentry/icons';
  7. import {t} from 'sentry/locale';
  8. import useApi from 'sentry/utils/useApi';
  9. import {normalizeUrl} from 'sentry/utils/withDomainRequired';
  10. import {Monitor, MonitorStatus} from '../types';
  11. import CronsFeedbackButton from './cronsFeedbackButton';
  12. type Props = {
  13. monitor: Monitor;
  14. onUpdate: (data: Monitor) => void;
  15. orgId: string;
  16. };
  17. const MonitorHeaderActions = ({monitor, orgId, onUpdate}: Props) => {
  18. const api = useApi();
  19. const handleDelete = async () => {
  20. await deleteMonitor(api, orgId, monitor.slug);
  21. browserHistory.push(normalizeUrl(`/organizations/${orgId}/crons/`));
  22. };
  23. const handleUpdate = async (data: Partial<Monitor>) => {
  24. const resp = await updateMonitor(api, orgId, monitor.slug, data);
  25. onUpdate?.(resp);
  26. };
  27. const toggleStatus = () =>
  28. handleUpdate({
  29. status:
  30. monitor.status === MonitorStatus.DISABLED
  31. ? MonitorStatus.ACTIVE
  32. : MonitorStatus.DISABLED,
  33. });
  34. return (
  35. <ButtonBar gap={1}>
  36. <CronsFeedbackButton />
  37. <Confirm
  38. onConfirm={handleDelete}
  39. message={t('Are you sure you want to permanently delete this cron monitor?')}
  40. >
  41. <Button size="sm" icon={<IconDelete size="xs" />}>
  42. {t('Delete')}
  43. </Button>
  44. </Confirm>
  45. <Button
  46. size="sm"
  47. icon={
  48. monitor.status !== 'disabled' ? <IconPause size="xs" /> : <IconPlay size="xs" />
  49. }
  50. onClick={toggleStatus}
  51. >
  52. {monitor.status !== 'disabled' ? t('Pause') : t('Resume')}
  53. </Button>
  54. <Button
  55. priority="primary"
  56. size="sm"
  57. icon={<IconEdit size="xs" />}
  58. to={`/organizations/${orgId}/crons/${monitor.slug}/edit/`}
  59. >
  60. {t('Edit')}
  61. </Button>
  62. </ButtonBar>
  63. );
  64. };
  65. export default MonitorHeaderActions;