Skip to content

Commit f9cea28

Browse files
authored
feat(issues): Allow search suggestion to filter when selected (#51564)
1 parent bd41029 commit f9cea28

File tree

4 files changed

+51
-9
lines changed

4 files changed

+51
-9
lines changed

static/app/components/smartSearchBar/index.spec.jsx

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1084,11 +1084,7 @@ describe('SmartSearchBar', function () {
10841084
});
10851085
it('hides the default group after typing', async function () {
10861086
render(
1087-
<SmartSearchBar
1088-
{...defaultProps}
1089-
defaultSearchGroup={defaultSearchGroup}
1090-
query=""
1091-
/>
1087+
<SmartSearchBar {...defaultProps} defaultSearchGroup={defaultSearchGroup} />
10921088
);
10931089

10941090
const textbox = screen.getByRole('textbox');
@@ -1102,5 +1098,33 @@ describe('SmartSearchBar', function () {
11021098
screen.queryByTestId('default-search-group-wrapper')
11031099
).not.toBeInTheDocument();
11041100
});
1101+
1102+
it('hides the default group after picking item with applyFilter', async function () {
1103+
render(
1104+
<SmartSearchBar
1105+
{...defaultProps}
1106+
defaultSearchGroup={{
1107+
...defaultSearchGroup,
1108+
children: [
1109+
{
1110+
type: ItemType.RECOMMENDED,
1111+
title: 'Custom Tags',
1112+
// Filter is applied to all search items when picked
1113+
applyFilter: item => item.title === 'device',
1114+
},
1115+
],
1116+
}}
1117+
/>
1118+
);
1119+
1120+
const textbox = screen.getByRole('textbox');
1121+
await userEvent.click(textbox);
1122+
expect(await screen.findByText('User identification value')).toBeInTheDocument();
1123+
await userEvent.click(screen.getByText('Custom Tags'));
1124+
1125+
expect(screen.queryByText('Custom Tags')).not.toBeInTheDocument();
1126+
expect(screen.queryByText('User identification value')).not.toBeInTheDocument();
1127+
expect(screen.getByText('device')).toBeInTheDocument();
1128+
});
11051129
});
11061130
});

static/app/components/smartSearchBar/index.tsx

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1562,12 +1562,14 @@ class SmartSearchBar extends Component<DefaultProps & Props, State> {
15621562
* @param recentSearchItems List of recent search items, same format as searchItem
15631563
* @param tagName The current tag name in scope
15641564
* @param type Defines the type/state of the dropdown menu items
1565+
* @param skipDefaultGroup Force hide the default group even without a query
15651566
*/
15661567
updateAutoCompleteState(
15671568
searchItems: SearchItem[],
15681569
recentSearchItems: SearchItem[],
15691570
tagName: string,
1570-
type: ItemType
1571+
type: ItemType,
1572+
skipDefaultGroup = false
15711573
) {
15721574
const {
15731575
fieldDefinitionGetter,
@@ -1589,7 +1591,7 @@ class SmartSearchBar extends Component<DefaultProps & Props, State> {
15891591
maxSearchItems,
15901592
queryCharsLeft,
15911593
true,
1592-
defaultSearchGroup,
1594+
skipDefaultGroup ? undefined : defaultSearchGroup,
15931595
fieldDefinitionGetter
15941596
);
15951597

@@ -1781,6 +1783,18 @@ class SmartSearchBar extends Component<DefaultProps & Props, State> {
17811783
});
17821784
}
17831785

1786+
if (item.applyFilter) {
1787+
const [tagKeys, tagType] = this.getTagKeys('');
1788+
this.updateAutoCompleteState(
1789+
tagKeys.filter(item.applyFilter),
1790+
[],
1791+
'',
1792+
tagType,
1793+
true
1794+
);
1795+
return;
1796+
}
1797+
17841798
this.onAutoCompleteFromAst(replaceText, item);
17851799
};
17861800

static/app/components/smartSearchBar/types.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ export type SearchGroup = {
3434

3535
export type SearchItem = {
3636
active?: boolean;
37+
/**
38+
* When this item is selected, apply a filter to the search query
39+
*/
40+
applyFilter?: (item: SearchItem) => void;
3741
/**
3842
* Call a callback instead of setting a value in the search query
3943
*/

static/app/views/issueList/searchBar.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,8 @@ function IssueListSearchBar({organization, tags, ...props}: Props) {
133133
type: ItemType.RECOMMENDED,
134134
title: t('Custom Tags'),
135135
desc: t('Filter events by custom tags.'),
136-
// TODO(scttcper): handle custom tags
137-
value: 'url:',
136+
// Shows only tags when clicked
137+
applyFilter: item => item.kind === FieldKind.TAG,
138138
},
139139
],
140140
};

0 commit comments

Comments
 (0)