adminSettings.tsx 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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.all.problem-creation',
  20. 'performance.issues.all.early-adopter-rollout',
  21. 'performance.issues.all.general-availability-rollout',
  22. 'performance.issues.all.post-process-group-early-adopter-rollout',
  23. 'performance.issues.all.post-process-group-ga-rollout',
  24. 'performance.issues.n_plus_one_db.problem-creation',
  25. 'performance.issues.n_plus_one_db_ext.problem-creation',
  26. 'performance.issues.n_plus_one_db.count_threshold',
  27. 'performance.issues.n_plus_one_db.duration_threshold',
  28. ];
  29. type Field = ReturnType<typeof getOption>;
  30. type FieldDef = {
  31. field: Field;
  32. value: string | undefined;
  33. };
  34. type State = AsyncView['state'] & {
  35. data: Record<string, FieldDef>;
  36. };
  37. export default class AdminSettings extends AsyncView<{}, State> {
  38. get endpoint() {
  39. return '/internal/options/';
  40. }
  41. getEndpoints(): ReturnType<AsyncView['getEndpoints']> {
  42. return [['data', this.endpoint]];
  43. }
  44. renderBody() {
  45. const {data} = this.state;
  46. const initialData = {};
  47. const fields = {};
  48. for (const key of optionsAvailable) {
  49. // TODO(dcramer): we should not be mutating options
  50. const option = data[key] ?? {field: {}, value: undefined};
  51. if (option.value === undefined || option.value === '') {
  52. const defn = getOption(key);
  53. initialData[key] = defn.defaultValue ? defn.defaultValue() : '';
  54. } else {
  55. initialData[key] = option.value;
  56. }
  57. fields[key] = getOptionField(key, option.field);
  58. }
  59. return (
  60. <div>
  61. <h3>{t('Settings')}</h3>
  62. <Form
  63. apiMethod="PUT"
  64. apiEndpoint={this.endpoint}
  65. initialData={initialData}
  66. saveOnBlur
  67. >
  68. <Panel>
  69. <PanelHeader>General</PanelHeader>
  70. {fields['system.url-prefix']}
  71. {fields['system.admin-email']}
  72. {fields['system.support-email']}
  73. {fields['system.security-email']}
  74. {fields['system.rate-limit']}
  75. </Panel>
  76. <Panel>
  77. <PanelHeader>Security & Abuse</PanelHeader>
  78. {fields['auth.allow-registration']}
  79. {fields['auth.ip-rate-limit']}
  80. {fields['auth.user-rate-limit']}
  81. {fields['api.rate-limit.org-create']}
  82. </Panel>
  83. <Panel>
  84. <PanelHeader>Beacon</PanelHeader>
  85. {fields['beacon.anonymous']}
  86. </Panel>
  87. <Feature features={['organizations:performance-issues-dev']}>
  88. <Panel>
  89. <PanelHeader>Performance Issues - All</PanelHeader>
  90. {fields['performance.issues.all.problem-detection']}
  91. {fields['performance.issues.all.problem-creation']}
  92. {fields['performance.issues.all.early-adopter-rollout']}
  93. {fields['performance.issues.all.general-availability-rollout']}
  94. {fields['performance.issues.all.post-process-group-early-adopter-rollout']}
  95. {fields['performance.issues.all.post-process-group-ga-rollout']}
  96. </Panel>
  97. <Panel>
  98. <PanelHeader>Performance Issues - Detectors</PanelHeader>
  99. {fields['performance.issues.n_plus_one_db.problem-creation']}
  100. {fields['performance.issues.n_plus_one_db_ext.problem-creation']}
  101. {fields['performance.issues.n_plus_one_db.count_threshold']}
  102. {fields['performance.issues.n_plus_one_db.duration_threshold']}
  103. </Panel>
  104. </Feature>
  105. </Form>
  106. </div>
  107. );
  108. }
  109. }