tracesSearchBar.tsx 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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 useOrganization from 'sentry/utils/useOrganization';
  8. interface TracesSearchBarProps {
  9. handleClearSearch: (index: number) => boolean;
  10. handleSearch: (index: number, query: string) => void;
  11. queries: string[];
  12. }
  13. const getSpanName = (index: number) => {
  14. const spanNames = [t('Span A'), t('Span B'), t('Span C')];
  15. return spanNames[index];
  16. };
  17. export function TracesSearchBar({
  18. queries,
  19. handleSearch,
  20. handleClearSearch,
  21. }: TracesSearchBarProps) {
  22. // TODO: load tags for autocompletion
  23. const organization = useOrganization();
  24. const canAddMoreQueries = queries.length <= 2;
  25. const localQueries = queries.length ? queries : [''];
  26. return (
  27. <TraceSearchBarsContainer>
  28. {localQueries.map((query, index) => (
  29. <TraceBar key={index}>
  30. <SpanLetter>{getSpanName(index)}</SpanLetter>
  31. <StyledSearchBar
  32. query={query}
  33. onSearch={(queryString: string) => handleSearch(index, queryString)}
  34. placeholder={t(
  35. 'Search for traces containing a span matching these attributes'
  36. )}
  37. organization={organization}
  38. />
  39. <StyledButton
  40. aria-label={t('Remove span')}
  41. icon={<IconClose size="sm" />}
  42. size="sm"
  43. onClick={() => (queries.length === 0 ? false : handleClearSearch(index))}
  44. />
  45. </TraceBar>
  46. ))}
  47. {canAddMoreQueries ? (
  48. <Button
  49. aria-label={t('Add query')}
  50. icon={<IconAdd size="xs" isCircled />}
  51. size="sm"
  52. onClick={() => handleSearch(localQueries.length, '')}
  53. >
  54. {t('Add Span')}
  55. </Button>
  56. ) : null}
  57. </TraceSearchBarsContainer>
  58. );
  59. }
  60. const TraceSearchBarsContainer = styled('div')`
  61. display: flex;
  62. flex-direction: column;
  63. align-items: flex-start;
  64. justify-content: center;
  65. gap: ${space(1)};
  66. `;
  67. const TraceBar = styled('div')`
  68. display: flex;
  69. flex-direction: row;
  70. align-items: center;
  71. justify-content: flex-start;
  72. width: 100%;
  73. gap: ${space(1)};
  74. `;
  75. const SpanLetter = styled('div')`
  76. background-color: ${p => p.theme.purple100};
  77. border-radius: ${p => p.theme.borderRadius};
  78. padding: ${space(1)} ${space(2)};
  79. color: ${p => p.theme.purple400};
  80. white-space: nowrap;
  81. font-weight: 800;
  82. `;
  83. const StyledSearchBar = styled(SearchBar)`
  84. width: 100%;
  85. `;
  86. const StyledButton = styled(Button)`
  87. height: 38px;
  88. `;