databaseSystemSelector.tsx 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import {CompactSelect} from 'sentry/components/compactSelect';
  2. import {t} from 'sentry/locale';
  3. import {decodeScalar} from 'sentry/utils/queryString';
  4. import {useLocation} from 'sentry/utils/useLocation';
  5. import {useNavigate} from 'sentry/utils/useNavigate';
  6. import {useSystemSelectorOptions} from 'sentry/views/insights/database/components/useSystemSelectorOptions';
  7. import {SpanMetricsField} from 'sentry/views/insights/types';
  8. const {SPAN_SYSTEM, SPAN_DOMAIN, SPAN_ACTION} = SpanMetricsField;
  9. export function DatabaseSystemSelector() {
  10. const location = useLocation();
  11. const navigate = useNavigate();
  12. // If there is no query parameter for the system, retrieve the current value from the hook instead
  13. const systemQueryParam = decodeScalar(location.query?.[SPAN_SYSTEM]);
  14. const {selectedSystem, setSelectedSystem, options, isLoading, isError} =
  15. useSystemSelectorOptions();
  16. const system = systemQueryParam ?? selectedSystem;
  17. return (
  18. <CompactSelect
  19. onChange={option => {
  20. setSelectedSystem(option.value);
  21. navigate({
  22. ...location,
  23. query: {
  24. ...location.query,
  25. [SPAN_SYSTEM]: option.value,
  26. // Reset the table and command since they won't be valid if the DB system changes
  27. [SPAN_DOMAIN]: undefined,
  28. [SPAN_ACTION]: undefined,
  29. },
  30. });
  31. }}
  32. options={options}
  33. triggerProps={{prefix: t('System')}}
  34. loading={isLoading}
  35. disabled={isError || isLoading || options.length <= 1}
  36. value={system}
  37. />
  38. );
  39. }