adminSettings.tsx 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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. 'performance.issues.m_n_plus_one_db.problem-creation',
  45. 'performance.issues.m_n_plus_one_db.la-rollout',
  46. 'performance.issues.m_n_plus_one_db.ea-rollout',
  47. 'performance.issues.m_n_plus_one_db.ga-rollout',
  48. 'profile.issues.blocked_main_thread-ingest.la-rollout',
  49. 'profile.issues.blocked_main_thread-ingest.ea-rollout',
  50. 'profile.issues.blocked_main_thread-ingest.ga-rollout',
  51. 'profile.issues.blocked_main_thread-ppg.la-rollout',
  52. 'profile.issues.blocked_main_thread-ppg.ea-rollout',
  53. 'profile.issues.blocked_main_thread-ppg.ga-rollout',
  54. ];
  55. type Field = ReturnType<typeof getOption>;
  56. type FieldDef = {
  57. field: Field;
  58. value: string | undefined;
  59. };
  60. type State = AsyncView['state'] & {
  61. data: Record<string, FieldDef>;
  62. };
  63. export default class AdminSettings extends AsyncView<{}, State> {
  64. get endpoint() {
  65. return '/internal/options/';
  66. }
  67. getEndpoints(): ReturnType<AsyncView['getEndpoints']> {
  68. return [['data', this.endpoint]];
  69. }
  70. renderBody() {
  71. const {data} = this.state;
  72. const initialData = {};
  73. const fields = {};
  74. for (const key of optionsAvailable) {
  75. // TODO(dcramer): we should not be mutating options
  76. const option = data[key] ?? {field: {}, value: undefined};
  77. if (option.value === undefined || option.value === '') {
  78. const defn = getOption(key);
  79. initialData[key] = defn.defaultValue ? defn.defaultValue() : '';
  80. } else {
  81. initialData[key] = option.value;
  82. }
  83. fields[key] = getOptionField(key, option.field);
  84. }
  85. return (
  86. <div>
  87. <h3>{t('Settings')}</h3>
  88. <Form
  89. apiMethod="PUT"
  90. apiEndpoint={this.endpoint}
  91. initialData={initialData}
  92. saveOnBlur
  93. >
  94. <Panel>
  95. <PanelHeader>General</PanelHeader>
  96. {fields['system.url-prefix']}
  97. {fields['system.admin-email']}
  98. {fields['system.support-email']}
  99. {fields['system.security-email']}
  100. {fields['system.rate-limit']}
  101. </Panel>
  102. <Panel>
  103. <PanelHeader>Security & Abuse</PanelHeader>
  104. {fields['auth.allow-registration']}
  105. {fields['auth.ip-rate-limit']}
  106. {fields['auth.user-rate-limit']}
  107. {fields['api.rate-limit.org-create']}
  108. </Panel>
  109. <Panel>
  110. <PanelHeader>Beacon</PanelHeader>
  111. {fields['beacon.anonymous']}
  112. </Panel>
  113. <Feature features={['organizations:performance-issues-dev']}>
  114. <Panel>
  115. <PanelHeader>Performance Issues - All</PanelHeader>
  116. {fields['performance.issues.all.problem-detection']}
  117. </Panel>
  118. <Panel>
  119. <PanelHeader>Performance Issues - Detectors</PanelHeader>
  120. {fields['performance.issues.n_plus_one_db.problem-creation']}
  121. {fields['performance.issues.n_plus_one_db_ext.problem-creation']}
  122. {fields['performance.issues.n_plus_one_db.count_threshold']}
  123. {fields['performance.issues.n_plus_one_db.duration_threshold']}
  124. </Panel>
  125. <Panel>
  126. <PanelHeader>Performance Issues - Consecutive DB Detector</PanelHeader>
  127. {fields['performance.issues.consecutive_db.problem-creation']}
  128. {fields['performance.issues.consecutive_db.la-rollout']}
  129. {fields['performance.issues.consecutive_db.ea-rollout']}
  130. {fields['performance.issues.consecutive_db.ga-rollout']}
  131. </Panel>
  132. <Panel>
  133. <PanelHeader>Performance Issues - N+1 API Calls Detector</PanelHeader>
  134. {fields['performance.issues.n_plus_one_api_calls.problem-creation']}
  135. {fields['performance.issues.n_plus_one_api_calls.la-rollout']}
  136. {fields['performance.issues.n_plus_one_api_calls.ea-rollout']}
  137. {fields['performance.issues.n_plus_one_api_calls.ga-rollout']}
  138. </Panel>
  139. <Panel>
  140. <PanelHeader>Performance Issues - Compressed Assets Detector</PanelHeader>
  141. {fields['performance.issues.compressed_assets.problem-creation']}
  142. {fields['performance.issues.compressed_assets.la-rollout']}
  143. {fields['performance.issues.compressed_assets.ea-rollout']}
  144. {fields['performance.issues.compressed_assets.ga-rollout']}
  145. </Panel>
  146. <Panel>
  147. <PanelHeader>Performance Issues - File IO on Main Thread</PanelHeader>
  148. {fields['performance.issues.file_io_main_thread.problem-creation']}
  149. </Panel>
  150. <Panel>
  151. <PanelHeader>Performance Issues - Slow DB Span Detector</PanelHeader>
  152. {fields['performance.issues.slow_db_query.problem-creation']}
  153. {fields['performance.issues.slow_db_query.la-rollout']}
  154. {fields['performance.issues.slow_db_query.ea-rollout']}
  155. {fields['performance.issues.slow_db_query.ga-rollout']}
  156. </Panel>
  157. <Panel>
  158. <PanelHeader>
  159. Performance Issues - Large Render Blocking Asset Detector
  160. </PanelHeader>
  161. {fields['performance.issues.render_blocking_assets.problem-creation']}
  162. {fields['performance.issues.render_blocking_assets.la-rollout']}
  163. {fields['performance.issues.render_blocking_assets.ea-rollout']}
  164. {fields['performance.issues.render_blocking_assets.ga-rollout']}
  165. </Panel>
  166. <Panel>
  167. <PanelHeader>Performance Issues - MN+1 DB Detector</PanelHeader>
  168. {fields['performance.issues.m_n_plus_one_db.problem-creation']}
  169. {fields['performance.issues.m_n_plus_one_db.la-rollout']}
  170. {fields['performance.issues.m_n_plus_one_db.ea-rollout']}
  171. {fields['performance.issues.m_n_plus_one_db.ga-rollout']}
  172. </Panel>
  173. <Panel>
  174. <PanelHeader>
  175. Profiling Issues - Block Main Thread Detector Ingest
  176. </PanelHeader>
  177. {fields['profile.issues.blocked_main_thread-ingest.la-rollout']}
  178. {fields['profile.issues.blocked_main_thread-ingest.ea-rollout']}
  179. {fields['profile.issues.blocked_main_thread-ingest.ga-rollout']}
  180. </Panel>
  181. <Panel>
  182. <PanelHeader>
  183. Profiling Issues - Block Main Thread Detector Post Process Group
  184. </PanelHeader>
  185. {fields['profile.issues.blocked_main_thread-ppg.la-rollout']}
  186. {fields['profile.issues.blocked_main_thread-ppg.ea-rollout']}
  187. {fields['profile.issues.blocked_main_thread-ppg.ga-rollout']}
  188. </Panel>
  189. </Feature>
  190. <Feature features={['organizations:view-hierarchies-options-dev']}>
  191. <Panel>
  192. <PanelHeader>View Hierarchy</PanelHeader>
  193. </Panel>
  194. </Feature>
  195. </Form>
  196. </div>
  197. );
  198. }
  199. }