tracesSearchBar.tsx 3.2 KB

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