adminSettings.tsx 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. import Feature from 'sentry/components/acl/feature';
  2. import Form from 'sentry/components/forms/form';
  3. import LoadingError from 'sentry/components/loadingError';
  4. import LoadingIndicator from 'sentry/components/loadingIndicator';
  5. import Panel from 'sentry/components/panels/panel';
  6. import PanelHeader from 'sentry/components/panels/panelHeader';
  7. import {t} from 'sentry/locale';
  8. import {useApiQuery} from 'sentry/utils/queryClient';
  9. import {getOption, getOptionField} from './options';
  10. const optionsAvailable = [
  11. 'system.url-prefix',
  12. 'system.admin-email',
  13. 'system.support-email',
  14. 'system.security-email',
  15. 'system.rate-limit',
  16. 'auth.allow-registration',
  17. 'auth.ip-rate-limit',
  18. 'auth.user-rate-limit',
  19. 'api.rate-limit.org-create',
  20. 'beacon.anonymous',
  21. 'performance.issues.all.problem-detection',
  22. 'performance.issues.n_plus_one_db.problem-creation',
  23. 'performance.issues.n_plus_one_db_ext.problem-creation',
  24. 'performance.issues.n_plus_one_db.count_threshold',
  25. 'performance.issues.n_plus_one_db.duration_threshold',
  26. 'performance.issues.consecutive_db.problem-creation',
  27. 'performance.issues.consecutive_db.la-rollout',
  28. 'performance.issues.consecutive_db.ea-rollout',
  29. 'performance.issues.consecutive_db.ga-rollout',
  30. 'performance.issues.n_plus_one_api_calls.problem-creation',
  31. 'performance.issues.n_plus_one_api_calls.la-rollout',
  32. 'performance.issues.n_plus_one_api_calls.ea-rollout',
  33. 'performance.issues.n_plus_one_api_calls.ga-rollout',
  34. 'performance.issues.compressed_assets.problem-creation',
  35. 'performance.issues.compressed_assets.la-rollout',
  36. 'performance.issues.compressed_assets.ea-rollout',
  37. 'performance.issues.compressed_assets.ga-rollout',
  38. 'performance.issues.file_io_main_thread.problem-creation',
  39. 'performance.issues.slow_db_query.problem-creation',
  40. 'performance.issues.slow_db_query.la-rollout',
  41. 'performance.issues.slow_db_query.ea-rollout',
  42. 'performance.issues.slow_db_query.ga-rollout',
  43. 'performance.issues.render_blocking_assets.problem-creation',
  44. 'performance.issues.render_blocking_assets.la-rollout',
  45. 'performance.issues.render_blocking_assets.ea-rollout',
  46. 'performance.issues.render_blocking_assets.ga-rollout',
  47. 'performance.issues.m_n_plus_one_db.problem-creation',
  48. 'performance.issues.m_n_plus_one_db.la-rollout',
  49. 'performance.issues.m_n_plus_one_db.ea-rollout',
  50. 'performance.issues.m_n_plus_one_db.ga-rollout',
  51. 'performance.issues.consecutive_http.max_duration_between_spans',
  52. 'performance.issues.consecutive_http.consecutive_count_threshold',
  53. 'performance.issues.consecutive_http.span_duration_threshold',
  54. 'performance.issues.large_http_payload.size_threshold',
  55. 'profile.issues.blocked_main_thread-ingest.la-rollout',
  56. 'profile.issues.blocked_main_thread-ingest.ea-rollout',
  57. 'profile.issues.blocked_main_thread-ingest.ga-rollout',
  58. 'profile.issues.blocked_main_thread-ppg.la-rollout',
  59. 'profile.issues.blocked_main_thread-ppg.ea-rollout',
  60. 'profile.issues.blocked_main_thread-ppg.ga-rollout',
  61. ];
  62. type Field = ReturnType<typeof getOption>;
  63. type FieldDef = {
  64. field: Field;
  65. value: string | undefined;
  66. };
  67. export default function AdminSettings() {
  68. const {data, isLoading, isError} = useApiQuery<Record<string, FieldDef>>(
  69. ['/internal/options/'],
  70. {
  71. staleTime: 0,
  72. }
  73. );
  74. if (isError) {
  75. return <LoadingError />;
  76. }
  77. if (isLoading) {
  78. return <LoadingIndicator />;
  79. }
  80. const initialData = {};
  81. const fields = {};
  82. for (const key of optionsAvailable) {
  83. // TODO(dcramer): we should not be mutating options
  84. const option = data[key] ?? {field: {}, value: undefined};
  85. if (option.value === undefined || option.value === '') {
  86. const defn = getOption(key);
  87. initialData[key] = defn.defaultValue ? defn.defaultValue() : '';
  88. } else {
  89. initialData[key] = option.value;
  90. }
  91. fields[key] = getOptionField(key, option.field);
  92. }
  93. return (
  94. <div>
  95. <h3>{t('Settings')}</h3>
  96. <Form
  97. apiMethod="PUT"
  98. apiEndpoint={'/internal/options/'}
  99. initialData={initialData}
  100. saveOnBlur
  101. >
  102. <Panel>
  103. <PanelHeader>{t('General')}</PanelHeader>
  104. {fields['system.url-prefix']}
  105. {fields['system.admin-email']}
  106. {fields['system.support-email']}
  107. {fields['system.security-email']}
  108. {fields['system.rate-limit']}
  109. </Panel>
  110. <Panel>
  111. <PanelHeader>{t('Security & Abuse')}</PanelHeader>
  112. {fields['auth.allow-registration']}
  113. {fields['auth.ip-rate-limit']}
  114. {fields['auth.user-rate-limit']}
  115. {fields['api.rate-limit.org-create']}
  116. </Panel>
  117. <Panel>
  118. <PanelHeader>{t('Beacon')}</PanelHeader>
  119. {fields['beacon.anonymous']}
  120. </Panel>
  121. <Feature features="organizations:performance-issues-dev">
  122. <Panel>
  123. <PanelHeader>{t('Performance Issues - All')}</PanelHeader>
  124. {fields['performance.issues.all.problem-detection']}
  125. </Panel>
  126. <Panel>
  127. <PanelHeader>{t('Performance Issues - Detectors')}</PanelHeader>
  128. {fields['performance.issues.n_plus_one_db.problem-creation']}
  129. {fields['performance.issues.n_plus_one_db_ext.problem-creation']}
  130. {fields['performance.issues.n_plus_one_db.count_threshold']}
  131. {fields['performance.issues.n_plus_one_db.duration_threshold']}
  132. </Panel>
  133. <Panel>
  134. <PanelHeader>{t('Performance Issues - Consecutive DB Detector')}</PanelHeader>
  135. {fields['performance.issues.consecutive_db.problem-creation']}
  136. {fields['performance.issues.consecutive_db.la-rollout']}
  137. {fields['performance.issues.consecutive_db.ea-rollout']}
  138. {fields['performance.issues.consecutive_db.ga-rollout']}
  139. </Panel>
  140. <Panel>
  141. <PanelHeader>{t('Performance Issues - N+1 API Calls Detector')}</PanelHeader>
  142. {fields['performance.issues.n_plus_one_api_calls.problem-creation']}
  143. {fields['performance.issues.n_plus_one_api_calls.la-rollout']}
  144. {fields['performance.issues.n_plus_one_api_calls.ea-rollout']}
  145. {fields['performance.issues.n_plus_one_api_calls.ga-rollout']}
  146. </Panel>
  147. <Panel>
  148. <PanelHeader>
  149. {t('Performance Issues - Compressed Assets Detector')}
  150. </PanelHeader>
  151. {fields['performance.issues.compressed_assets.problem-creation']}
  152. {fields['performance.issues.compressed_assets.la-rollout']}
  153. {fields['performance.issues.compressed_assets.ea-rollout']}
  154. {fields['performance.issues.compressed_assets.ga-rollout']}
  155. </Panel>
  156. <Panel>
  157. <PanelHeader>{t('Performance Issues - File IO on Main Thread')}</PanelHeader>
  158. {fields['performance.issues.file_io_main_thread.problem-creation']}
  159. </Panel>
  160. <Panel>
  161. <PanelHeader>{t('Performance Issues - Slow DB Span Detector')}</PanelHeader>
  162. {fields['performance.issues.slow_db_query.problem-creation']}
  163. {fields['performance.issues.slow_db_query.la-rollout']}
  164. {fields['performance.issues.slow_db_query.ea-rollout']}
  165. {fields['performance.issues.slow_db_query.ga-rollout']}
  166. </Panel>
  167. <Panel>
  168. <PanelHeader>
  169. {t('Performance Issues - Large Render Blocking Asset Detector')}
  170. </PanelHeader>
  171. {fields['performance.issues.render_blocking_assets.problem-creation']}
  172. {fields['performance.issues.render_blocking_assets.la-rollout']}
  173. {fields['performance.issues.render_blocking_assets.ea-rollout']}
  174. {fields['performance.issues.render_blocking_assets.ga-rollout']}
  175. </Panel>
  176. <Panel>
  177. <PanelHeader>{t('Performance Issues - MN+1 DB Detector')}</PanelHeader>
  178. {fields['performance.issues.m_n_plus_one_db.problem-creation']}
  179. {fields['performance.issues.m_n_plus_one_db.la-rollout']}
  180. {fields['performance.issues.m_n_plus_one_db.ea-rollout']}
  181. {fields['performance.issues.m_n_plus_one_db.ga-rollout']}
  182. </Panel>
  183. <Panel>
  184. <PanelHeader>
  185. {t('Performance Issues - Consecutive HTTP Span Detector')}
  186. </PanelHeader>
  187. {fields['performance.issues.consecutive_http.max_duration_between_spans']}
  188. {fields['performance.issues.consecutive_http.consecutive_count_threshold']}
  189. {fields['performance.issues.consecutive_http.span_duration_threshold']}
  190. </Panel>
  191. <Panel>
  192. <PanelHeader>
  193. {t('Performance Issues - Large HTTP Payload Detector')}
  194. </PanelHeader>
  195. {fields['performance.issues.large_http_payload.size_threshold']}
  196. </Panel>
  197. <Panel>
  198. <PanelHeader>
  199. {t('Profiling Issues - Block Main Thread Detector Ingest')}
  200. </PanelHeader>
  201. {fields['profile.issues.blocked_main_thread-ingest.la-rollout']}
  202. {fields['profile.issues.blocked_main_thread-ingest.ea-rollout']}
  203. {fields['profile.issues.blocked_main_thread-ingest.ga-rollout']}
  204. </Panel>
  205. <Panel>
  206. <PanelHeader>
  207. {t('Profiling Issues - Block Main Thread Detector Post Process Group')}
  208. </PanelHeader>
  209. {fields['profile.issues.blocked_main_thread-ppg.la-rollout']}
  210. {fields['profile.issues.blocked_main_thread-ppg.ea-rollout']}
  211. {fields['profile.issues.blocked_main_thread-ppg.ga-rollout']}
  212. </Panel>
  213. </Feature>
  214. <Feature features="organizations:view-hierarchies-options-dev">
  215. <Panel>
  216. <PanelHeader>{t('View Hierarchy')}</PanelHeader>
  217. </Panel>
  218. </Feature>
  219. </Form>
  220. </div>
  221. );
  222. }