@@ -17,13 +17,12 @@ import Panel from 'sentry/components/panels/panel';
1717import PanelHeader from 'sentry/components/panels/panelHeader' ;
1818import PanelItem from 'sentry/components/panels/panelItem' ;
1919import PerformanceDuration from 'sentry/components/performanceDuration' ;
20- import type { SmartSearchBarProps } from 'sentry/components/smartSearchBar' ;
2120import { IconChevron } from 'sentry/icons/iconChevron' ;
2221import { t } from 'sentry/locale' ;
2322import { space } from 'sentry/styles/space' ;
2423import type { PageFilters } from 'sentry/types/core' ;
2524import { useApiQuery } from 'sentry/utils/queryClient' ;
26- import { decodeInteger , decodeScalar } from 'sentry/utils/queryString' ;
25+ import { decodeInteger , decodeList } from 'sentry/utils/queryString' ;
2726import { useLocation } from 'sentry/utils/useLocation' ;
2827import useOrganization from 'sentry/utils/useOrganization' ;
2928import usePageFilters from 'sentry/utils/usePageFilters' ;
@@ -46,26 +45,52 @@ const DEFAULT_PER_PAGE = 20;
4645export function Content ( ) {
4746 const location = useLocation ( ) ;
4847
49- const query = useMemo ( ( ) => {
50- return decodeScalar ( location . query . query , '' ) ;
48+ const queries = useMemo ( ( ) => {
49+ return decodeList ( location . query . query ) ;
5150 } , [ location . query . query ] ) ;
5251
5352 const limit = useMemo ( ( ) => {
5453 return decodeInteger ( location . query . perPage , DEFAULT_PER_PAGE ) ;
5554 } , [ location . query . perPage ] ) ;
5655
57- const handleSearch : SmartSearchBarProps [ 'onSearch' ] = useCallback (
58- ( searchQuery : string ) => {
56+ const handleSearch = useCallback (
57+ ( searchIndex : number , searchQuery : string ) => {
58+ const newQueries = [ ...queries ] ;
59+ if ( newQueries . length === 0 ) {
60+ // In the odd case someone wants to add search bars before any query has been made, we add both the default one shown and a new one.
61+ newQueries [ 0 ] = '' ;
62+ }
63+ newQueries [ searchIndex ] = searchQuery ;
5964 browserHistory . push ( {
6065 ...location ,
6166 query : {
6267 ...location . query ,
6368 cursor : undefined ,
64- query : searchQuery || undefined ,
69+ query : typeof searchQuery === 'string' ? newQueries : queries ,
6570 } ,
6671 } ) ;
6772 } ,
68- [ location ]
73+ [ location , queries ]
74+ ) ;
75+
76+ const handleClearSearch = useCallback (
77+ ( searchIndex : number ) => {
78+ const newQueries = [ ...queries ] ;
79+ if ( typeof newQueries [ searchIndex ] !== undefined ) {
80+ delete newQueries [ searchIndex ] ;
81+ browserHistory . push ( {
82+ ...location ,
83+ query : {
84+ ...location . query ,
85+ cursor : undefined ,
86+ query : newQueries ,
87+ } ,
88+ } ) ;
89+ return true ;
90+ }
91+ return false ;
92+ } ,
93+ [ location , queries ]
6994 ) ;
7095
7196 const traces = useTraces < Field > ( {
@@ -76,7 +101,7 @@ export function Content() {
76101 ) ,
77102 ] ,
78103 limit,
79- query,
104+ query : queries ,
80105 sort : SORTS ,
81106 } ) ;
82107
@@ -92,7 +117,11 @@ export function Content() {
92117 < EnvironmentPageFilter />
93118 < DatePageFilter />
94119 </ PageFilterBar >
95- < TracesSearchBar query = { query } handleSearch = { handleSearch } />
120+ < TracesSearchBar
121+ queries = { queries }
122+ handleSearch = { handleSearch }
123+ handleClearSearch = { handleClearSearch }
124+ />
96125 < StyledPanel >
97126 < TracePanelContent >
98127 < StyledPanelHeader align = "right" lightText >
@@ -292,7 +321,7 @@ interface UseTracesOptions<F extends string> {
292321 datetime ?: PageFilters [ 'datetime' ] ;
293322 enabled ?: boolean ;
294323 limit ?: number ;
295- query ?: string ;
324+ query ?: string | string [ ] ;
296325 sort ?: string [ ] ;
297326 suggestedQuery ?: string ;
298327}
0 commit comments