databaseSystemSelector.tsx 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. return (
  17. <CompactSelect
  18. onChange={option => {
  19. setSelectedSystem(option.value);
  20. navigate({
  21. ...location,
  22. query: {
  23. ...location.query,
  24. [SPAN_SYSTEM]: option.value,
  25. // Reset the table and command since they won't be valid if the DB system changes
  26. [SPAN_DOMAIN]: undefined,
  27. [SPAN_ACTION]: undefined,
  28. },
  29. });
  30. }}
  31. options={options}
  32. triggerProps={{prefix: t('System')}}
  33. loading={isLoading}
  34. disabled={isError || isLoading || options.length <= 1}
  35. value={systemQueryParam ?? selectedSystem}
  36. />
  37. );
  38. }