subscriptionBox.tsx 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. import styled from '@emotion/styled';
  2. import Checkbox from 'sentry/components/checkbox';
  3. import FeatureBadge from 'sentry/components/featureBadge';
  4. import {Tooltip} from 'sentry/components/tooltip';
  5. import {t} from 'sentry/locale';
  6. import {space} from 'sentry/styles/space';
  7. import {Organization} from 'sentry/types';
  8. import withOrganization from 'sentry/utils/withOrganization';
  9. import {
  10. EVENT_CHOICES,
  11. PERMISSIONS_MAP,
  12. } from 'sentry/views/settings/organizationDeveloperSettings/constants';
  13. type Resource = (typeof EVENT_CHOICES)[number];
  14. type Props = {
  15. checked: boolean;
  16. disabledFromPermissions: boolean;
  17. isNew: boolean;
  18. onChange: (resource: Resource, checked: boolean) => void;
  19. organization: Organization;
  20. resource: Resource;
  21. webhookDisabled?: boolean;
  22. };
  23. function SubscriptionBox({
  24. checked,
  25. disabledFromPermissions,
  26. isNew,
  27. onChange,
  28. organization,
  29. resource,
  30. webhookDisabled = false,
  31. }: Props) {
  32. const {features} = organization;
  33. let disabled = disabledFromPermissions || webhookDisabled;
  34. let message = t(
  35. "Must have at least 'Read' permissions enabled for %s",
  36. PERMISSIONS_MAP[resource]
  37. );
  38. if (resource === 'error' && !features.includes('integrations-event-hooks')) {
  39. disabled = true;
  40. message = t(
  41. 'Your organization does not have access to the error subscription resource.'
  42. );
  43. }
  44. if (webhookDisabled) {
  45. message = t('Cannot enable webhook subscription without specifying a webhook url');
  46. }
  47. const DESCRIPTIONS: Record<(typeof EVENT_CHOICES)[number], string> = {
  48. // Swap ignored for archived if the feature is enabled
  49. issue: `created, resolved, assigned, ${
  50. features.includes('escalating-issues') ? 'archived' : 'ignored'
  51. }`,
  52. error: 'created',
  53. comment: 'created, edited, deleted',
  54. };
  55. return (
  56. <Tooltip disabled={!disabled} title={message} key={resource}>
  57. <SubscriptionGridItem disabled={disabled}>
  58. <SubscriptionInfo>
  59. <SubscriptionTitle>
  60. {resource}
  61. {isNew && <FeatureBadge type="new" />}
  62. </SubscriptionTitle>
  63. <SubscriptionDescription>{DESCRIPTIONS[resource]}</SubscriptionDescription>
  64. </SubscriptionInfo>
  65. <Checkbox
  66. key={`${resource}${checked}`}
  67. aria-label={resource}
  68. disabled={disabled}
  69. id={resource}
  70. value={resource}
  71. checked={checked}
  72. onChange={evt => onChange(resource, evt.target.checked)}
  73. />
  74. </SubscriptionGridItem>
  75. </Tooltip>
  76. );
  77. }
  78. export default withOrganization(SubscriptionBox);
  79. const SubscriptionGridItem = styled('div')<{disabled: boolean}>`
  80. display: flex;
  81. justify-content: space-between;
  82. background: ${p => p.theme.backgroundSecondary};
  83. opacity: ${p => (p.disabled ? 0.3 : 1)};
  84. border-radius: ${p => p.theme.borderRadius};
  85. margin: ${space(1.5)};
  86. padding: ${space(1.5)};
  87. box-sizing: border-box;
  88. `;
  89. const SubscriptionInfo = styled('div')`
  90. display: flex;
  91. flex-direction: column;
  92. align-self: center;
  93. `;
  94. const SubscriptionDescription = styled('div')`
  95. font-size: ${p => p.theme.fontSizeMedium};
  96. line-height: 1;
  97. color: ${p => p.theme.gray300};
  98. `;
  99. const SubscriptionTitle = styled('div')`
  100. font-size: ${p => p.theme.fontSizeLarge};
  101. line-height: 1;
  102. color: ${p => p.theme.textColor};
  103. white-space: nowrap;
  104. margin-bottom: ${space(0.75)};
  105. `;