domainSelector.tsx 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. import {
  10. EMPTY_OPTION_VALUE,
  11. EmptyContainer,
  12. } from 'sentry/views/starfish/views/spans/selectors/emptyOption';
  13. const {SPAN_DOMAIN} = SpanMetricsField;
  14. export function DomainSelector({
  15. value,
  16. defaultResourceTypes,
  17. }: {
  18. defaultResourceTypes?: string[];
  19. value?: string;
  20. }) {
  21. const location = useLocation();
  22. const {data} = useResourceDomainsQuery(defaultResourceTypes);
  23. const options: Option[] = [
  24. {value: '', label: 'All'},
  25. {
  26. value: EMPTY_OPTION_VALUE,
  27. label: <EmptyContainer>{t('No domain')}</EmptyContainer>,
  28. },
  29. ...data.map(domain => ({
  30. value: domain,
  31. label: domain,
  32. })),
  33. ];
  34. return (
  35. <SelectControlWithProps
  36. inFieldLabel={`${t('Domain')}:`}
  37. options={options}
  38. value={value}
  39. onChange={newValue => {
  40. browserHistory.push({
  41. ...location,
  42. query: {
  43. ...location.query,
  44. [SPAN_DOMAIN]: newValue?.value,
  45. cursor: undefined,
  46. },
  47. });
  48. }}
  49. />
  50. );
  51. }
  52. export default DomainSelector;