statusToggleButton.tsx 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import {BaseButtonProps, Button} from 'sentry/components/button';
  2. import HookOrDefault from 'sentry/components/hookOrDefault';
  3. import {IconPause, IconPlay} from 'sentry/icons';
  4. import {t} from 'sentry/locale';
  5. import {ObjectStatus} from 'sentry/types';
  6. import {Monitor} from 'sentry/views/monitors/types';
  7. interface StatusToggleButtonProps extends Omit<BaseButtonProps, 'onClick'> {
  8. monitor: Monitor;
  9. onToggleStatus: (status: ObjectStatus) => void;
  10. }
  11. function SimpleStatusToggle({
  12. monitor,
  13. onToggleStatus,
  14. ...props
  15. }: StatusToggleButtonProps) {
  16. const {status} = monitor;
  17. const isDisabeld = status === 'disabled';
  18. const Icon = isDisabeld ? IconPlay : IconPause;
  19. const label = isDisabeld
  20. ? t('Reactive this monitor')
  21. : t('Disable this monitor and discard incoming check-ins');
  22. return (
  23. <Button
  24. icon={<Icon />}
  25. aria-label={label}
  26. title={label}
  27. onClick={() => onToggleStatus(isDisabeld ? 'active' : 'disabled')}
  28. {...props}
  29. />
  30. );
  31. }
  32. const StatusToggleButton = HookOrDefault({
  33. hookName: 'component:monitor-status-toggle',
  34. defaultComponent: SimpleStatusToggle,
  35. });
  36. export {StatusToggleButton, StatusToggleButtonProps};