Skip to content

Commit 498dbfc

Browse files
authored
feat(search-bar): Tweak logic category (#103465)
This PR removes the first item checks, and will display all logic operators at all times.
1 parent db8dc3d commit 498dbfc

File tree

3 files changed

+13
-29
lines changed

3 files changed

+13
-29
lines changed

static/app/components/searchQueryBuilder/index.spec.tsx

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,7 @@ describe('SearchQueryBuilder', () => {
434434
expect(await screen.findByRole('button', {name: 'All'})).toBeInTheDocument();
435435
expect(screen.getByRole('button', {name: 'Category 1'})).toBeInTheDocument();
436436
expect(screen.getByRole('button', {name: 'Category 2'})).toBeInTheDocument();
437+
expect(screen.getByRole('button', {name: 'Logic'})).toBeInTheDocument();
437438

438439
const menu = screen.getByRole('listbox');
439440
const groups = within(menu).getAllByRole('group');
@@ -717,25 +718,19 @@ describe('SearchQueryBuilder', () => {
717718
});
718719

719720
describe('logic category', () => {
720-
it('does not render logic category when on first input', async () => {
721+
it('renders conditional and parenthetical filters', async () => {
721722
render(<SearchQueryBuilder {...defaultProps} initialQuery="" />, {
722723
organization: {features: ['search-query-builder-conditionals-combobox-menus']},
723724
});
724-
725725
await userEvent.click(getLastInput());
726-
expect(await screen.findByRole('button', {name: 'All'})).toBeInTheDocument();
727-
728-
expect(screen.queryByRole('button', {name: 'Logic'})).not.toBeInTheDocument();
729-
});
730726

731-
it('renders logic category when not on first input', async () => {
732-
render(<SearchQueryBuilder {...defaultProps} initialQuery="span.op:test" />, {
733-
organization: {features: ['search-query-builder-conditionals-combobox-menus']},
734-
});
735-
736-
await userEvent.click(getLastInput());
737727
// Should show conditionals button
738728
expect(await screen.findByRole('button', {name: 'Logic'})).toBeInTheDocument();
729+
await userEvent.click(screen.getByRole('button', {name: 'Logic'}));
730+
expect(await screen.findByRole('option', {name: '('})).toBeInTheDocument();
731+
expect(screen.getByRole('option', {name: ')'})).toBeInTheDocument();
732+
expect(screen.getByRole('option', {name: 'AND'})).toBeInTheDocument();
733+
expect(screen.getByRole('option', {name: 'OR'})).toBeInTheDocument();
739734
});
740735
});
741736
});

static/app/components/searchQueryBuilder/tokens/filterKeyListBox/useFilterKeyListBox.tsx

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,7 @@ import {
3131
} from 'sentry/components/searchQueryBuilder/tokens/filterKeyListBox/utils';
3232
import {itemIsSection} from 'sentry/components/searchQueryBuilder/tokens/utils';
3333
import type {FieldDefinitionGetter} from 'sentry/components/searchQueryBuilder/types';
34-
import type {
35-
ParseResultToken,
36-
Token,
37-
TokenResult,
38-
} from 'sentry/components/searchSyntax/parser';
34+
import type {Token, TokenResult} from 'sentry/components/searchSyntax/parser';
3935
import {getKeyName} from 'sentry/components/searchSyntax/utils';
4036
import type {RecentSearch, TagCollection} from 'sentry/types/group';
4137
import {trackAnalytics} from 'sentry/utils/analytics';
@@ -134,9 +130,7 @@ function useFilterKeyItems() {
134130

135131
function useFilterKeySections({
136132
recentSearches,
137-
filterItem,
138133
}: {
139-
filterItem: Node<ParseResultToken>;
140134
recentSearches: RecentSearch[] | undefined;
141135
}) {
142136
const {filterKeySections, query, disallowLogicalOperators} = useSearchQueryBuilder();
@@ -155,22 +149,21 @@ function useFilterKeySections({
155149
return [];
156150
}
157151

158-
const isFirstItem = filterItem.key.toString().endsWith(':0');
159152
if (recentSearches?.length && !query) {
160153
const recentSearchesSections: Section[] = [
161154
RECENT_SEARCH_CATEGORY,
162155
ALL_CATEGORY,
163156
...definedSections,
164157
];
165158

166-
if (!disallowLogicalOperators && !isFirstItem && hasConditionalsInCombobox) {
159+
if (!disallowLogicalOperators && hasConditionalsInCombobox) {
167160
recentSearchesSections.push(LOGIC_CATEGORY);
168161
}
169162
return recentSearchesSections;
170163
}
171164

172165
const customSections: Section[] = [ALL_CATEGORY, ...definedSections];
173-
if (!disallowLogicalOperators && !isFirstItem && hasConditionalsInCombobox) {
166+
if (!disallowLogicalOperators && hasConditionalsInCombobox) {
174167
customSections.push(LOGIC_CATEGORY);
175168
}
176169

@@ -179,7 +172,6 @@ function useFilterKeySections({
179172
disallowLogicalOperators,
180173
filterKeySections,
181174
hasConditionalsInCombobox,
182-
filterItem.key,
183175
query,
184176
recentSearches?.length,
185177
]);
@@ -200,19 +192,18 @@ function useFilterKeySections({
200192
return {sections, selectedSection, setSelectedSection};
201193
}
202194

203-
const conditionalFilterItems = [
195+
const logicFilterItems = [
204196
createLogicFilterItem({value: 'AND'}),
205197
createLogicFilterItem({value: 'OR'}),
206198
createLogicFilterItem({value: '('}),
207199
createLogicFilterItem({value: ')'}),
208200
];
209201

210202
interface UseFilterKeyListBoxArgs {
211-
filterItem: Node<ParseResultToken>;
212203
filterValue: string;
213204
}
214205

215-
export function useFilterKeyListBox({filterValue, filterItem}: UseFilterKeyListBoxArgs) {
206+
export function useFilterKeyListBox({filterValue}: UseFilterKeyListBoxArgs) {
216207
const {
217208
filterKeys,
218209
getFieldDefinition,
@@ -228,7 +219,6 @@ export function useFilterKeyListBox({filterValue, filterItem}: UseFilterKeyListB
228219
const {data: recentSearches} = useRecentSearches();
229220
const {sections, selectedSection, setSelectedSection} = useFilterKeySections({
230221
recentSearches,
231-
filterItem,
232222
});
233223

234224
const organization = useOrganization();
@@ -270,7 +260,7 @@ export function useFilterKeyListBox({filterValue, filterItem}: UseFilterKeyListB
270260
selectedSection === LOGIC_CATEGORY_VALUE &&
271261
hasConditionalsInCombobox
272262
) {
273-
return [...askSeerItem, ...conditionalFilterItems];
263+
return [...askSeerItem, ...logicFilterItems];
274264
}
275265

276266
const filteredByCategory = sectionedItems.filter(item => {

static/app/components/searchQueryBuilder/tokens/freeText.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,6 @@ function SearchQueryBuilderInputInternal({
301301

302302
const {customMenu, sectionItems, maxOptions, onKeyDownCapture, handleOptionSelected} =
303303
useFilterKeyListBox({
304-
filterItem: item,
305304
filterValue,
306305
});
307306
const sortedFilteredItems = useSortedFilterKeyItems({

0 commit comments

Comments
 (0)