adminSettings.tsx 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  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, isPending, isError} = useApiQuery<Record<string, FieldDef>>(
  69. ['/internal/options/'],
  70. {
  71. staleTime: 0,
  72. }
  73. );
  74. if (isError) {
  75. return <LoadingError />;
  76. }
  77. if (isPending) {
  78. return <LoadingIndicator />;
  79. }
  80. const initialData: Record<string, React.ReactNode> = {};
  81. const fields: Record<string, React.ReactNode> = {};
  82. for (const key of optionsAvailable) {
  83. const option = data[key] ?? ({field: {}, value: undefined} as FieldDef);
  84. if (option.value === undefined || option.value === '') {
  85. const defn = getOption(key);
  86. initialData[key] = defn.defaultValue ? defn.defaultValue() : '';
  87. } else {
  88. initialData[key] = option.value;
  89. }
  90. fields[key] = getOptionField(key, option.field);
  91. }
  92. return (
  93. <div>
  94. <h3>{t('Settings')}</h3>
  95. <Form
  96. apiMethod="PUT"
  97. apiEndpoint={'/internal/options/'}
  98. initialData={initialData}
  99. saveOnBlur
  100. >
  101. <Panel>
  102. <PanelHeader>{t('General')}</PanelHeader>
  103. {fields['system.url-prefix']}
  104. {fields['system.admin-email']}
  105. {fields['system.support-email']}
  106. {fields['system.security-email']}
  107. {fields['system.rate-limit']}
  108. </Panel>
  109. <Panel>
  110. <PanelHeader>{t('Security & Abuse')}</PanelHeader>
  111. {fields['auth.allow-registration']}
  112. {fields['auth.ip-rate-limit']}
  113. {fields['auth.user-rate-limit']}
  114. {fields['api.rate-limit.org-create']}
  115. </Panel>
  116. <Panel>
  117. <PanelHeader>{t('Beacon')}</PanelHeader>
  118. {fields['beacon.anonymous']}
  119. </Panel>
  120. <Feature features="organizations:performance-issues-dev">
  121. <Panel>
  122. <PanelHeader>{t('Performance Issues - All')}</PanelHeader>
  123. {fields['performance.issues.all.problem-detection']}
  124. </Panel>
  125. <Panel>
  126. <PanelHeader>{t('Performance Issues - Detectors')}</PanelHeader>
  127. {fields['performance.issues.n_plus_one_db.problem-creation']}
  128. {fields['performance.issues.n_plus_one_db_ext.problem-creation']}
  129. {fields['performance.issues.n_plus_one_db.count_threshold']}
  130. {fields['performance.issues.n_plus_one_db.duration_threshold']}
  131. </Panel>
  132. <Panel>
  133. <PanelHeader>{t('Performance Issues - Consecutive DB Detector')}</PanelHeader>
  134. {fields['performance.issues.consecutive_db.problem-creation']}
  135. {fields['performance.issues.consecutive_db.la-rollout']}
  136. {fields['performance.issues.consecutive_db.ea-rollout']}
  137. {fields['performance.issues.consecutive_db.ga-rollout']}
  138. </Panel>
  139. <Panel>
  140. <PanelHeader>{t('Performance Issues - N+1 API Calls Detector')}</PanelHeader>
  141. {fields['performance.issues.n_plus_one_api_calls.problem-creation']}
  142. {fields['performance.issues.n_plus_one_api_calls.la-rollout']}
  143. {fields['performance.issues.n_plus_one_api_calls.ea-rollout']}
  144. {fields['performance.issues.n_plus_one_api_calls.ga-rollout']}
  145. </Panel>
  146. <Panel>
  147. <PanelHeader>
  148. {t('Performance Issues - Compressed Assets Detector')}
  149. </PanelHeader>
  150. {fields['performance.issues.compressed_assets.problem-creation']}
  151. {fields['performance.issues.compressed_assets.la-rollout']}
  152. {fields['performance.issues.compressed_assets.ea-rollout']}
  153. {fields['performance.issues.compressed_assets.ga-rollout']}
  154. </Panel>
  155. <Panel>
  156. <PanelHeader>{t('Performance Issues - File IO on Main Thread')}</PanelHeader>
  157. {fields['performance.issues.file_io_main_thread.problem-creation']}
  158. </Panel>
  159. <Panel>
  160. <PanelHeader>{t('Performance Issues - Slow DB Span Detector')}</PanelHeader>
  161. {fields['performance.issues.slow_db_query.problem-creation']}
  162. {fields['performance.issues.slow_db_query.la-rollout']}
  163. {fields['performance.issues.slow_db_query.ea-rollout']}
  164. {fields['performance.issues.slow_db_query.ga-rollout']}
  165. </Panel>
  166. <Panel>
  167. <PanelHeader>
  168. {t('Performance Issues - Large Render Blocking Asset Detector')}
  169. </PanelHeader>
  170. {fields['performance.issues.render_blocking_assets.problem-creation']}
  171. {fields['performance.issues.render_blocking_assets.la-rollout']}
  172. {fields['performance.issues.render_blocking_assets.ea-rollout']}
  173. {fields['performance.issues.render_blocking_assets.ga-rollout']}
  174. </Panel>
  175. <Panel>
  176. <PanelHeader>{t('Performance Issues - MN+1 DB Detector')}</PanelHeader>
  177. {fields['performance.issues.m_n_plus_one_db.problem-creation']}
  178. {fields['performance.issues.m_n_plus_one_db.la-rollout']}
  179. {fields['performance.issues.m_n_plus_one_db.ea-rollout']}
  180. {fields['performance.issues.m_n_plus_one_db.ga-rollout']}
  181. </Panel>
  182. <Panel>
  183. <PanelHeader>
  184. {t('Performance Issues - Consecutive HTTP Span Detector')}
  185. </PanelHeader>
  186. {fields['performance.issues.consecutive_http.max_duration_between_spans']}
  187. {fields['performance.issues.consecutive_http.consecutive_count_threshold']}
  188. {fields['performance.issues.consecutive_http.span_duration_threshold']}
  189. </Panel>
  190. <Panel>
  191. <PanelHeader>
  192. {t('Performance Issues - Large HTTP Payload Detector')}
  193. </PanelHeader>
  194. {fields['performance.issues.large_http_payload.size_threshold']}
  195. </Panel>
  196. <Panel>
  197. <PanelHeader>
  198. {t('Profiling Issues - Block Main Thread Detector Ingest')}
  199. </PanelHeader>
  200. {fields['profile.issues.blocked_main_thread-ingest.la-rollout']}
  201. {fields['profile.issues.blocked_main_thread-ingest.ea-rollout']}
  202. {fields['profile.issues.blocked_main_thread-ingest.ga-rollout']}
  203. </Panel>
  204. <Panel>
  205. <PanelHeader>
  206. {t('Profiling Issues - Block Main Thread Detector Post Process Group')}
  207. </PanelHeader>
  208. {fields['profile.issues.blocked_main_thread-ppg.la-rollout']}
  209. {fields['profile.issues.blocked_main_thread-ppg.ea-rollout']}
  210. {fields['profile.issues.blocked_main_thread-ppg.ga-rollout']}
  211. </Panel>
  212. </Feature>
  213. <Feature features="organizations:view-hierarchies-options-dev">
  214. <Panel>
  215. <PanelHeader>{t('View Hierarchy')}</PanelHeader>
  216. </Panel>
  217. </Feature>
  218. </Form>
  219. </div>
  220. );
  221. }