projectGeneralSettings.tsx 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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: '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. '[strong:Caution]: Enabling auto resolve will immediately resolve anything that has not been seen within this period of time. There is no undo!',
  113. {
  114. strong: <strong />,
  115. }
  116. ),
  117. saveMessageAlertType: 'warning',
  118. },
  119. allowedDomains: {
  120. name: 'allowedDomains',
  121. type: 'string',
  122. multiline: true,
  123. autosize: true,
  124. maxRows: 10,
  125. rows: 1,
  126. placeholder: t('https://example.com or example.com'),
  127. label: t('Allowed Domains'),
  128. help: t(
  129. 'Examples: https://example.com, *, *.example.com, *:80. Separate multiple entries with a newline'
  130. ),
  131. getValue: val => extractMultilineFields(val),
  132. setValue: val => convertMultilineFieldValue(val),
  133. },
  134. scrapeJavaScript: {
  135. name: 'scrapeJavaScript',
  136. type: 'boolean',
  137. // if this is off for the organization, it cannot be enabled for the project
  138. disabled: ({organization, name}) => !organization[name],
  139. disabledReason: ORG_DISABLED_REASON,
  140. // `props` are the props given to FormField
  141. setValue: (val, props) => props.organization?.[props.name] && val,
  142. label: t('Enable JavaScript source fetching'),
  143. help: t('Allow Sentry to scrape missing JavaScript source context when possible'),
  144. },
  145. securityToken: {
  146. name: 'securityToken',
  147. type: 'string',
  148. label: t('Security Token'),
  149. help: t(
  150. 'Outbound requests matching Allowed Domains will have the header "{token_header}: {token}" appended'
  151. ),
  152. setValue: value => getDynamicText({value, fixed: '__SECURITY_TOKEN__'}),
  153. },
  154. securityTokenHeader: {
  155. name: 'securityTokenHeader',
  156. type: 'string',
  157. placeholder: t('X-Sentry-Token'),
  158. label: t('Security Token Header'),
  159. help: t(
  160. 'Outbound requests matching Allowed Domains will have the header "{token_header}: {token}" appended'
  161. ),
  162. },
  163. verifySSL: {
  164. name: 'verifySSL',
  165. type: 'boolean',
  166. label: t('Verify TLS/SSL'),
  167. help: t('Outbound requests will verify TLS (sometimes known as SSL) connections'),
  168. },
  169. };