adminSettings.tsx 5.3 KB

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