projectGeneralSettings.tsx 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. import {createFilter} from 'react-select';
  2. import styled from '@emotion/styled';
  3. import {PlatformIcon} from 'platformicons';
  4. import {Field} from 'sentry/components/forms/type';
  5. import platforms from 'sentry/data/platforms';
  6. import {t, tct, tn} from 'sentry/locale';
  7. import space from 'sentry/styles/space';
  8. import {convertMultilineFieldValue, extractMultilineFields} from 'sentry/utils';
  9. import getDynamicText from 'sentry/utils/getDynamicText';
  10. import slugify from 'sentry/utils/slugify';
  11. // Export route to make these forms searchable by label/help
  12. export const route = '/settings/:orgId/projects/:projectId/';
  13. const getResolveAgeAllowedValues = () => {
  14. let i = 0;
  15. const values: number[] = [];
  16. while (i <= 720) {
  17. values.push(i);
  18. if (i < 12) {
  19. i += 1;
  20. } else if (i < 24) {
  21. i += 3;
  22. } else if (i < 36) {
  23. i += 6;
  24. } else if (i < 48) {
  25. i += 12;
  26. } else {
  27. i += 24;
  28. }
  29. }
  30. return values;
  31. };
  32. const RESOLVE_AGE_ALLOWED_VALUES = getResolveAgeAllowedValues();
  33. const ORG_DISABLED_REASON = t(
  34. "This option is enforced by your organization's settings and cannot be customized per-project."
  35. );
  36. const PlatformWrapper = styled('div')`
  37. display: flex;
  38. align-items: center;
  39. `;
  40. const StyledPlatformIcon = styled(PlatformIcon)`
  41. margin-right: ${space(1)};
  42. `;
  43. export const fields: Record<string, Field> = {
  44. name: {
  45. name: 'name',
  46. type: 'string',
  47. required: true,
  48. label: t('Name'),
  49. placeholder: t('my-awesome-project'),
  50. help: t('A name for this project'),
  51. transformInput: slugify,
  52. getData: (data: {name?: string}) => {
  53. return {
  54. name: data.name,
  55. slug: data.name,
  56. };
  57. },
  58. saveOnBlur: false,
  59. saveMessageAlertType: 'info',
  60. saveMessage: t('You will be redirected to the new project slug after saving'),
  61. },
  62. platform: {
  63. name: 'platform',
  64. type: 'select',
  65. label: t('Platform'),
  66. options: platforms.map(({id, name}) => ({
  67. value: id,
  68. label: (
  69. <PlatformWrapper key={id}>
  70. <StyledPlatformIcon platform={id} />
  71. {name}
  72. </PlatformWrapper>
  73. ),
  74. })),
  75. help: t('The primary platform for this project'),
  76. filterOption: createFilter({
  77. stringify: option => {
  78. const matchedPlatform = platforms.find(({id}) => id === option.value);
  79. return `${matchedPlatform?.name} ${option.value}`;
  80. },
  81. }),
  82. },
  83. subjectPrefix: {
  84. name: 'subjectPrefix',
  85. type: 'string',
  86. label: t('Subject Prefix'),
  87. placeholder: t('e.g. [my-org]'),
  88. help: t('Choose a custom prefix for emails from this project'),
  89. },
  90. resolveAge: {
  91. name: 'resolveAge',
  92. type: 'range',
  93. allowedValues: RESOLVE_AGE_ALLOWED_VALUES,
  94. label: t('Auto Resolve'),
  95. help: t(
  96. "Automatically resolve an issue if it hasn't been seen for this amount of time"
  97. ),
  98. formatLabel: val => {
  99. val = Number(val);
  100. if (val === 0) {
  101. return t('Disabled');
  102. }
  103. if (val > 23 && val % 24 === 0) {
  104. // Based on allowed values, val % 24 should always be true
  105. val = val / 24;
  106. return tn('%s day', '%s days', val);
  107. }
  108. return tn('%s hour', '%s hours', val);
  109. },
  110. saveOnBlur: false,
  111. saveMessage: tct(
  112. '[Caution]: Enabling auto resolve will immediately resolve anything that has ' +
  113. 'not been seen within this period of time. There is no undo!',
  114. {
  115. Caution: <strong>Caution</strong>,
  116. }
  117. ),
  118. saveMessageAlertType: 'warning',
  119. },
  120. allowedDomains: {
  121. name: 'allowedDomains',
  122. type: 'string',
  123. multiline: true,
  124. autosize: true,
  125. maxRows: 10,
  126. rows: 1,
  127. placeholder: t('https://example.com or example.com'),
  128. label: t('Allowed Domains'),
  129. help: t('Separate multiple entries with a newline'),
  130. getValue: val => extractMultilineFields(val),
  131. setValue: val => convertMultilineFieldValue(val),
  132. },
  133. scrapeJavaScript: {
  134. name: 'scrapeJavaScript',
  135. type: 'boolean',
  136. // if this is off for the organization, it cannot be enabled for the project
  137. disabled: ({organization, name}) => !organization[name],
  138. disabledReason: ORG_DISABLED_REASON,
  139. // `props` are the props given to FormField
  140. setValue: (val, props) => props.organization && props.organization[props.name] && val,
  141. label: t('Enable JavaScript source fetching'),
  142. help: t('Allow Sentry to scrape missing JavaScript source context when possible'),
  143. },
  144. securityToken: {
  145. name: 'securityToken',
  146. type: 'string',
  147. label: t('Security Token'),
  148. help: t(
  149. 'Outbound requests matching Allowed Domains will have the header "{token_header}: {token}" appended'
  150. ),
  151. setValue: value => getDynamicText({value, fixed: '__SECURITY_TOKEN__'}),
  152. },
  153. securityTokenHeader: {
  154. name: 'securityTokenHeader',
  155. type: 'string',
  156. placeholder: t('X-Sentry-Token'),
  157. label: t('Security Token Header'),
  158. help: t(
  159. 'Outbound requests matching Allowed Domains will have the header "{token_header}: {token}" appended'
  160. ),
  161. },
  162. verifySSL: {
  163. name: 'verifySSL',
  164. type: 'boolean',
  165. label: t('Verify TLS/SSL'),
  166. help: t('Outbound requests will verify TLS (sometimes known as SSL) connections'),
  167. },
  168. };