projectGeneralSettings.tsx 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. import {createFilter} from 'react-select';
  2. import styled from '@emotion/styled';
  3. import {PlatformIcon} from 'platformicons';
  4. import type {Field} from 'sentry/components/forms/types';
  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: 'warning',
  60. saveMessage: t(
  61. "Changing a project's name will also change the project slug. This can break your build scripts! Please proceed carefully."
  62. ),
  63. },
  64. platform: {
  65. name: 'platform',
  66. type: 'select',
  67. label: t('Platform'),
  68. options: platforms.map(({id, name}) => ({
  69. value: id,
  70. label: (
  71. <PlatformWrapper key={id}>
  72. <StyledPlatformIcon platform={id} />
  73. {name}
  74. </PlatformWrapper>
  75. ),
  76. })),
  77. help: t('The primary platform for this project'),
  78. filterOption: createFilter({
  79. stringify: option => {
  80. const matchedPlatform = platforms.find(({id}) => id === option.value);
  81. return `${matchedPlatform?.name} ${option.value}`;
  82. },
  83. }),
  84. },
  85. subjectPrefix: {
  86. name: 'subjectPrefix',
  87. type: 'string',
  88. label: t('Subject Prefix'),
  89. placeholder: t('e.g. [my-org]'),
  90. help: t('Choose a custom prefix for emails from this project'),
  91. },
  92. resolveAge: {
  93. name: 'resolveAge',
  94. type: 'range',
  95. allowedValues: RESOLVE_AGE_ALLOWED_VALUES,
  96. label: t('Auto Resolve'),
  97. help: t(
  98. "Automatically resolve an issue if it hasn't been seen for this amount of time"
  99. ),
  100. formatLabel: val => {
  101. val = Number(val);
  102. if (val === 0) {
  103. return t('Disabled');
  104. }
  105. if (val > 23 && val % 24 === 0) {
  106. // Based on allowed values, val % 24 should always be true
  107. val = val / 24;
  108. return tn('%s day', '%s days', val);
  109. }
  110. return tn('%s hour', '%s hours', val);
  111. },
  112. saveOnBlur: false,
  113. saveMessage: tct(
  114. '[strong:Caution]: Enabling auto resolve will immediately resolve anything that has not been seen within this period of time. There is no undo!',
  115. {
  116. strong: <strong />,
  117. }
  118. ),
  119. saveMessageAlertType: 'warning',
  120. },
  121. allowedDomains: {
  122. name: 'allowedDomains',
  123. type: 'string',
  124. multiline: true,
  125. autosize: true,
  126. maxRows: 10,
  127. rows: 1,
  128. placeholder: t('https://example.com or example.com'),
  129. label: t('Allowed Domains'),
  130. help: t(
  131. 'Examples: https://example.com, *, *.example.com, *:80. Separate multiple entries with a newline'
  132. ),
  133. getValue: val => extractMultilineFields(val),
  134. setValue: val => convertMultilineFieldValue(val),
  135. },
  136. scrapeJavaScript: {
  137. name: 'scrapeJavaScript',
  138. type: 'boolean',
  139. // if this is off for the organization, it cannot be enabled for the project
  140. disabled: ({organization, name}) => !organization[name],
  141. disabledReason: ORG_DISABLED_REASON,
  142. // `props` are the props given to FormField
  143. setValue: (val, props) => props.organization?.[props.name] && val,
  144. label: t('Enable JavaScript source fetching'),
  145. help: t('Allow Sentry to scrape missing JavaScript source context when possible'),
  146. },
  147. securityToken: {
  148. name: 'securityToken',
  149. type: 'string',
  150. label: t('Security Token'),
  151. help: t(
  152. 'Outbound requests matching Allowed Domains will have the header "{token_header}: {token}" appended'
  153. ),
  154. setValue: value => getDynamicText({value, fixed: '__SECURITY_TOKEN__'}),
  155. },
  156. securityTokenHeader: {
  157. name: 'securityTokenHeader',
  158. type: 'string',
  159. placeholder: t('X-Sentry-Token'),
  160. label: t('Security Token Header'),
  161. help: t(
  162. 'Outbound requests matching Allowed Domains will have the header "{token_header}: {token}" appended'
  163. ),
  164. },
  165. verifySSL: {
  166. name: 'verifySSL',
  167. type: 'boolean',
  168. label: t('Verify TLS/SSL'),
  169. help: t('Outbound requests will verify TLS (sometimes known as SSL) connections'),
  170. },
  171. };