adminSettings.tsx 5.1 KB

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