statusToggleButton.tsx 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import type {BaseButtonProps} from 'sentry/components/button';
  2. import {Button} from 'sentry/components/button';
  3. import {IconPause, IconPlay} from 'sentry/icons';
  4. import {t} from 'sentry/locale';
  5. import type {ObjectStatus} from 'sentry/types/core';
  6. import type {UptimeRule} from './types';
  7. interface StatusToggleButtonProps extends Omit<BaseButtonProps, 'onClick'> {
  8. onToggleStatus: (status: ObjectStatus) => Promise<void>;
  9. uptimeRule: UptimeRule;
  10. }
  11. export function StatusToggleButton({
  12. uptimeRule,
  13. onToggleStatus,
  14. ...props
  15. }: StatusToggleButtonProps) {
  16. const {status} = uptimeRule;
  17. const isDisabled = status === 'disabled';
  18. const Icon = isDisabled ? IconPlay : IconPause;
  19. const label = isDisabled
  20. ? t('Enable this uptime rule')
  21. : t('Disable this uptime rule and stop performing checks');
  22. return (
  23. <Button
  24. icon={<Icon />}
  25. aria-label={label}
  26. title={label}
  27. onClick={async () => {
  28. await onToggleStatus(isDisabled ? 'active' : 'disabled');
  29. // TODO(epurkhiser): We'll need a hook here to trigger subscription
  30. // refesh in getsentry when toggling uptime monitors since it will
  31. // consume quota.
  32. }}
  33. {...props}
  34. />
  35. );
  36. }