domainSelector.tsx 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import {browserHistory} from 'react-router';
  2. import {t} from 'sentry/locale';
  3. import {useLocation} from 'sentry/utils/useLocation';
  4. import SelectControlWithProps, {
  5. Option,
  6. } from 'sentry/views/performance/browser/resources/shared/selectControlWithProps';
  7. import {useResourceDomainsQuery} from 'sentry/views/performance/browser/resources/utils/useResourceDomansQuery';
  8. import {SpanMetricsField} from 'sentry/views/starfish/types';
  9. const {SPAN_DOMAIN} = SpanMetricsField;
  10. export function DomainSelector({value}: {value?: string}) {
  11. const location = useLocation();
  12. const {data} = useResourceDomainsQuery();
  13. const options: Option[] = [
  14. {value: '', label: 'All'},
  15. ...data.map(domain => ({
  16. value: domain,
  17. label: domain,
  18. })),
  19. ];
  20. return (
  21. <SelectControlWithProps
  22. inFieldLabel={`${t('Domain')}:`}
  23. options={options}
  24. value={value}
  25. onChange={newValue => {
  26. browserHistory.push({
  27. ...location,
  28. query: {
  29. ...location.query,
  30. [SPAN_DOMAIN]: newValue?.value,
  31. },
  32. });
  33. }}
  34. />
  35. );
  36. }
  37. export default DomainSelector;