databaseSystemSelector.tsx 1.3 KB

123456789101112131415161718192021222324252627282930313233
  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} = 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({...location, query: {...location.query, [SPAN_SYSTEM]: option.value}});
  21. }}
  22. options={options}
  23. triggerProps={{prefix: t('DB System')}}
  24. loading={isLoading}
  25. disabled={isError || isLoading || options.length <= 1}
  26. value={systemQueryParam ?? selectedSystem}
  27. />
  28. );
  29. }