adminSettings.tsx 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. import Feature from 'sentry/components/acl/feature';
  2. import {Form} from 'sentry/components/forms';
  3. import {Panel, PanelHeader} from 'sentry/components/panels';
  4. import {t} from 'sentry/locale';
  5. import AsyncView from 'sentry/views/asyncView';
  6. import {getOption, getOptionField} from './options';
  7. const optionsAvailable = [
  8. 'system.url-prefix',
  9. 'system.admin-email',
  10. 'system.support-email',
  11. 'system.security-email',
  12. 'system.rate-limit',
  13. 'auth.allow-registration',
  14. 'auth.ip-rate-limit',
  15. 'auth.user-rate-limit',
  16. 'api.rate-limit.org-create',
  17. 'beacon.anonymous',
  18. 'performance.issues.n_plus_one_db.problem-creation',
  19. 'performance.issues.n_plus_one_db_ext.problem-creation',
  20. 'performance.issues.n_plus_one_db.count_threshold',
  21. 'performance.issues.n_plus_one_db.duration_threshold',
  22. 'performance.issues.consecutive_db.problem-creation',
  23. 'performance.issues.consecutive_db.la-rollout',
  24. 'performance.issues.consecutive_db.ea-rollout',
  25. 'performance.issues.consecutive_db.ga-rollout',
  26. 'performance.issues.n_plus_one_api_calls.problem-creation',
  27. 'performance.issues.n_plus_one_api_calls.la-rollout',
  28. 'performance.issues.n_plus_one_api_calls.ea-rollout',
  29. 'performance.issues.n_plus_one_api_calls.ga-rollout',
  30. 'performance.issues.compressed_assets.problem-creation',
  31. 'performance.issues.compressed_assets.la-rollout',
  32. 'performance.issues.compressed_assets.ea-rollout',
  33. 'performance.issues.compressed_assets.ga-rollout',
  34. 'performance.issues.file_io_main_thread.problem-creation',
  35. 'performance.issues.slow_db_query.problem-creation',
  36. 'performance.issues.slow_db_query.la-rollout',
  37. 'performance.issues.slow_db_query.ea-rollout',
  38. 'performance.issues.slow_db_query.ga-rollout',
  39. ];
  40. type Field = ReturnType<typeof getOption>;
  41. type FieldDef = {
  42. field: Field;
  43. value: string | undefined;
  44. };
  45. type State = AsyncView['state'] & {
  46. data: Record<string, FieldDef>;
  47. };
  48. export default class AdminSettings extends AsyncView<{}, State> {
  49. get endpoint() {
  50. return '/internal/options/';
  51. }
  52. getEndpoints(): ReturnType<AsyncView['getEndpoints']> {
  53. return [['data', this.endpoint]];
  54. }
  55. renderBody() {
  56. const {data} = this.state;
  57. const initialData = {};
  58. const fields = {};
  59. for (const key of optionsAvailable) {
  60. // TODO(dcramer): we should not be mutating options
  61. const option = data[key] ?? {field: {}, value: undefined};
  62. if (option.value === undefined || option.value === '') {
  63. const defn = getOption(key);
  64. initialData[key] = defn.defaultValue ? defn.defaultValue() : '';
  65. } else {
  66. initialData[key] = option.value;
  67. }
  68. fields[key] = getOptionField(key, option.field);
  69. }
  70. return (
  71. <div>
  72. <h3>{t('Settings')}</h3>
  73. <Form
  74. apiMethod="PUT"
  75. apiEndpoint={this.endpoint}
  76. initialData={initialData}
  77. saveOnBlur
  78. >
  79. <Panel>
  80. <PanelHeader>General</PanelHeader>
  81. {fields['system.url-prefix']}
  82. {fields['system.admin-email']}
  83. {fields['system.support-email']}
  84. {fields['system.security-email']}
  85. {fields['system.rate-limit']}
  86. </Panel>
  87. <Panel>
  88. <PanelHeader>Security & Abuse</PanelHeader>
  89. {fields['auth.allow-registration']}
  90. {fields['auth.ip-rate-limit']}
  91. {fields['auth.user-rate-limit']}
  92. {fields['api.rate-limit.org-create']}
  93. </Panel>
  94. <Panel>
  95. <PanelHeader>Beacon</PanelHeader>
  96. {fields['beacon.anonymous']}
  97. </Panel>
  98. <Feature features={['organizations:performance-issues-dev']}>
  99. <Panel>
  100. <PanelHeader>Performance Issues - Detectors</PanelHeader>
  101. {fields['performance.issues.n_plus_one_db.problem-creation']}
  102. {fields['performance.issues.n_plus_one_db_ext.problem-creation']}
  103. {fields['performance.issues.n_plus_one_db.count_threshold']}
  104. {fields['performance.issues.n_plus_one_db.duration_threshold']}
  105. </Panel>
  106. <Panel>
  107. <PanelHeader>Performance Issues - Consecutive DB Detector</PanelHeader>
  108. {fields['performance.issues.consecutive_db.problem-creation']}
  109. {fields['performance.issues.consecutive_db.la-rollout']}
  110. {fields['performance.issues.consecutive_db.ea-rollout']}
  111. {fields['performance.issues.consecutive_db.ga-rollout']}
  112. </Panel>
  113. <Panel>
  114. <PanelHeader>Performance Issues - N+1 API Calls Detector</PanelHeader>
  115. {fields['performance.issues.n_plus_one_api_calls.problem-creation']}
  116. {fields['performance.issues.n_plus_one_api_calls.la-rollout']}
  117. {fields['performance.issues.n_plus_one_api_calls.ea-rollout']}
  118. {fields['performance.issues.n_plus_one_api_calls.ga-rollout']}
  119. </Panel>
  120. <Panel>
  121. <PanelHeader>Performance Issues - Compressed Assets Detector</PanelHeader>
  122. {fields['performance.issues.compressed_assets.problem-creation']}
  123. {fields['performance.issues.compressed_assets.la-rollout']}
  124. {fields['performance.issues.compressed_assets.ea-rollout']}
  125. {fields['performance.issues.compressed_assets.ga-rollout']}
  126. </Panel>
  127. <Panel>
  128. <PanelHeader>Performance Issues - File IO on Main Thread</PanelHeader>
  129. {fields['performance.issues.file_io_main_thread.problem-creation']}
  130. </Panel>
  131. <Panel>
  132. <PanelHeader>Performance Issues - Slow DB Span Detector</PanelHeader>
  133. {fields['performance.issues.slow_db_query.problem-creation']}
  134. {fields['performance.issues.slow_db_query.la-rollout']}
  135. {fields['performance.issues.slow_db_query.ea-rollout']}
  136. {fields['performance.issues.slow_db_query.ga-rollout']}
  137. </Panel>
  138. </Feature>
  139. </Form>
  140. </div>
  141. );
  142. }
  143. }