adminSettings.tsx 3.6 KB

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