replaySearchBar.tsx 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import SmartSearchBar from 'sentry/components/smartSearchBar';
  2. import {MAX_QUERY_LENGTH, NEGATION_OPERATOR, SEARCH_WILDCARD} from 'sentry/constants';
  3. import {t} from 'sentry/locale';
  4. import {Organization, PageFilters, SavedSearchType, TagCollection} from 'sentry/types';
  5. import {getFieldDefinition, REPLAY_FIELDS} from 'sentry/utils/fields';
  6. const SEARCH_SPECIAL_CHARS_REGEXP = new RegExp(
  7. `^${NEGATION_OPERATOR}|\\${SEARCH_WILDCARD}`,
  8. 'g'
  9. );
  10. /**
  11. * Prepare query string (e.g. strip special characters like negation operator)
  12. */
  13. function prepareQuery(searchQuery: string) {
  14. return searchQuery.replace(SEARCH_SPECIAL_CHARS_REGEXP, '');
  15. }
  16. const getReplayFieldDefinition = (key: string) => getFieldDefinition(key, 'replay');
  17. function fieldDefinitionsToTagCollection(fieldKeys: string[]): TagCollection {
  18. return Object.fromEntries(
  19. fieldKeys.map(key => [
  20. key,
  21. {
  22. key,
  23. name: key,
  24. kind: getReplayFieldDefinition(key)?.kind,
  25. },
  26. ])
  27. );
  28. }
  29. const REPLAY_TAGS = fieldDefinitionsToTagCollection(REPLAY_FIELDS);
  30. type Props = React.ComponentProps<typeof SmartSearchBar> & {
  31. organization: Organization;
  32. pageFilters: PageFilters;
  33. };
  34. function SearchBar(props: Props) {
  35. return (
  36. <SmartSearchBar
  37. {...props}
  38. onGetTagValues={undefined}
  39. supportedTags={REPLAY_TAGS}
  40. placeholder={t('Search for users, duration, countErrors, and more')}
  41. prepareQuery={prepareQuery}
  42. maxQueryLength={MAX_QUERY_LENGTH}
  43. searchSource="replay_index"
  44. savedSearchType={SavedSearchType.REPLAY}
  45. maxMenuHeight={500}
  46. hasRecentSearches
  47. highlightUnsupportedTags
  48. fieldDefinitionGetter={getReplayFieldDefinition}
  49. />
  50. );
  51. }
  52. export default SearchBar;