tracesSearchBar.tsx 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. import styled from '@emotion/styled';
  2. import {Button} from 'sentry/components/button';
  3. import {SpanSearchQueryBuilder} from 'sentry/components/performance/spanSearchQueryBuilder';
  4. import {IconAdd, IconClose} from 'sentry/icons';
  5. import {t} from 'sentry/locale';
  6. import {space} from 'sentry/styles/space';
  7. import {trackAnalytics} from 'sentry/utils/analytics';
  8. import useOrganization from 'sentry/utils/useOrganization';
  9. import usePageFilters from 'sentry/utils/usePageFilters';
  10. interface TracesSearchBarProps {
  11. handleClearSearch: (index: number) => boolean;
  12. handleSearch: (index: number, query: string) => void;
  13. queries: string[];
  14. }
  15. const getSpanName = (index: number) => {
  16. const spanNames = [
  17. t('Find traces where a span is'),
  18. t('and another span where'),
  19. t('and another span where'),
  20. ];
  21. return spanNames[index];
  22. };
  23. export function TracesSearchBar({
  24. queries,
  25. handleSearch,
  26. handleClearSearch,
  27. }: TracesSearchBarProps) {
  28. const organization = useOrganization();
  29. const {selection} = usePageFilters();
  30. const canAddMoreQueries = queries.length <= 2;
  31. const localQueries = queries.length ? queries : [''];
  32. return (
  33. <TraceSearchBarsContainer>
  34. {localQueries.map((query, index) => (
  35. <TraceBar key={index}>
  36. <SpanLetter>{getSpanName(index)}</SpanLetter>
  37. <SpanSearchQueryBuilder
  38. projects={selection.projects}
  39. initialQuery={query}
  40. onSearch={(queryString: string) => handleSearch(index, queryString)}
  41. searchSource="trace-explorer"
  42. />
  43. <StyledButton
  44. aria-label={t('Remove Span')}
  45. icon={<IconClose size="sm" />}
  46. size="sm"
  47. onClick={() => {
  48. trackAnalytics('trace_explorer.remove_span_condition', {
  49. organization,
  50. });
  51. if (queries.length >= 0) {
  52. handleClearSearch(index);
  53. }
  54. }}
  55. />
  56. </TraceBar>
  57. ))}
  58. {canAddMoreQueries ? (
  59. <Button
  60. aria-label={t('Add Query')}
  61. icon={<IconAdd size="xs" isCircled />}
  62. size="sm"
  63. onClick={() => {
  64. trackAnalytics('trace_explorer.add_span_condition', {
  65. organization,
  66. });
  67. handleSearch(localQueries.length, '');
  68. }}
  69. >
  70. {t('Add Another Span')}
  71. </Button>
  72. ) : null}
  73. </TraceSearchBarsContainer>
  74. );
  75. }
  76. const TraceSearchBarsContainer = styled('div')`
  77. display: flex;
  78. flex-direction: column;
  79. align-items: flex-start;
  80. justify-content: center;
  81. gap: ${space(1)};
  82. `;
  83. const TraceBar = styled('div')`
  84. display: flex;
  85. flex-direction: row;
  86. width: 100%;
  87. gap: ${space(1)};
  88. `;
  89. const SpanLetter = styled('div')`
  90. background-color: ${p => p.theme.purple100};
  91. border-radius: ${p => p.theme.borderRadius};
  92. text-align: center;
  93. min-width: 220px;
  94. color: ${p => p.theme.purple400};
  95. white-space: nowrap;
  96. font-weight: ${p => p.theme.fontWeightBold};
  97. align-content: center;
  98. `;
  99. const StyledButton = styled(Button)`
  100. height: 38px;
  101. `;