spanDetailsControls.tsx 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. import {browserHistory} from 'react-router';
  2. import styled from '@emotion/styled';
  3. import {Location} from 'history';
  4. import Button from 'sentry/components/button';
  5. import DatePageFilter from 'sentry/components/datePageFilter';
  6. import EnvironmentPageFilter from 'sentry/components/environmentPageFilter';
  7. import SearchBar from 'sentry/components/events/searchBar';
  8. import PageFilterBar from 'sentry/components/organizations/pageFilterBar';
  9. import {t} from 'sentry/locale';
  10. import space from 'sentry/styles/space';
  11. import {Organization} from 'sentry/types';
  12. import EventView from 'sentry/utils/discover/eventView';
  13. import {removeHistogramQueryStrings} from 'sentry/utils/performance/histogram';
  14. import {decodeScalar} from 'sentry/utils/queryString';
  15. import {SPAN_RELATIVE_PERIODS, SPAN_RETENTION_DAYS} from '../utils';
  16. import {ZoomKeys} from './utils';
  17. interface SpanDetailsControlsProps {
  18. eventView: EventView;
  19. location: Location;
  20. organization: Organization;
  21. }
  22. export default function SpanDetailsControls({
  23. organization,
  24. eventView,
  25. location,
  26. }: SpanDetailsControlsProps) {
  27. const query = decodeScalar(location.query.query, '');
  28. const handleSearchQuery = (searchQuery: string): void => {
  29. browserHistory.push({
  30. pathname: location.pathname,
  31. query: {
  32. ...location.query,
  33. cursor: undefined,
  34. query: String(searchQuery).trim() || undefined,
  35. },
  36. });
  37. };
  38. const handleResetView = () => {
  39. browserHistory.push({
  40. pathname: location.pathname,
  41. query: removeHistogramQueryStrings(location, Object.values(ZoomKeys)),
  42. });
  43. };
  44. const isZoomed = () => Object.values(ZoomKeys).some(key => location.query[key]);
  45. return (
  46. <FilterActions>
  47. <PageFilterBar condensed>
  48. <EnvironmentPageFilter />
  49. <DatePageFilter
  50. alignDropdown="left"
  51. relativeOptions={SPAN_RELATIVE_PERIODS}
  52. maxPickableDays={SPAN_RETENTION_DAYS}
  53. />
  54. </PageFilterBar>
  55. <SearchBar
  56. placeholder={t('Filter Transactions')}
  57. organization={organization}
  58. projectIds={eventView.project}
  59. query={query}
  60. fields={eventView.fields}
  61. onSearch={handleSearchQuery}
  62. />
  63. <Button onClick={handleResetView} disabled={!isZoomed()}>
  64. {t('Reset View')}
  65. </Button>
  66. </FilterActions>
  67. );
  68. }
  69. const FilterActions = styled('div')`
  70. display: grid;
  71. gap: ${space(2)};
  72. margin-bottom: ${space(2)};
  73. @media (min-width: ${p => p.theme.breakpoints.small}) {
  74. grid-template-columns: auto 1fr auto;
  75. }
  76. `;