adminSettings.tsx 6.9 KB

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