spanDetailsControls.tsx 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. import {browserHistory} from 'react-router';
  2. import styled from '@emotion/styled';
  3. import type {Location} from 'history';
  4. import {Button} from 'sentry/components/button';
  5. import SearchBar from 'sentry/components/events/searchBar';
  6. import {DatePageFilter} from 'sentry/components/organizations/datePageFilter';
  7. import {EnvironmentPageFilter} from 'sentry/components/organizations/environmentPageFilter';
  8. import PageFilterBar from 'sentry/components/organizations/pageFilterBar';
  9. import {t} from 'sentry/locale';
  10. import {space} from 'sentry/styles/space';
  11. import type {Organization} from 'sentry/types';
  12. import type 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. relativeOptions={SPAN_RELATIVE_PERIODS}
  51. maxPickableDays={SPAN_RETENTION_DAYS}
  52. />
  53. </PageFilterBar>
  54. <SearchBar
  55. placeholder={t('Filter Transactions')}
  56. organization={organization}
  57. projectIds={eventView.project}
  58. query={query}
  59. fields={eventView.fields}
  60. onSearch={handleSearchQuery}
  61. />
  62. <Button onClick={handleResetView} disabled={!isZoomed()}>
  63. {t('Reset View')}
  64. </Button>
  65. </FilterActions>
  66. );
  67. }
  68. const FilterActions = styled('div')`
  69. display: grid;
  70. gap: ${space(2)};
  71. margin-bottom: ${space(2)};
  72. @media (min-width: ${p => p.theme.breakpoints.small}) {
  73. grid-template-columns: auto 1fr auto;
  74. }
  75. `;