Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 7 additions & 12 deletions static/app/components/searchQueryBuilder/index.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,7 @@ describe('SearchQueryBuilder', () => {
expect(await screen.findByRole('button', {name: 'All'})).toBeInTheDocument();
expect(screen.getByRole('button', {name: 'Category 1'})).toBeInTheDocument();
expect(screen.getByRole('button', {name: 'Category 2'})).toBeInTheDocument();
expect(screen.getByRole('button', {name: 'Logic'})).toBeInTheDocument();

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

describe('logic category', () => {
it('does not render logic category when on first input', async () => {
it('renders conditional and parenthetical filters', async () => {
render(<SearchQueryBuilder {...defaultProps} initialQuery="" />, {
organization: {features: ['search-query-builder-conditionals-combobox-menus']},
});

await userEvent.click(getLastInput());
expect(await screen.findByRole('button', {name: 'All'})).toBeInTheDocument();

expect(screen.queryByRole('button', {name: 'Logic'})).not.toBeInTheDocument();
});

it('renders logic category when not on first input', async () => {
render(<SearchQueryBuilder {...defaultProps} initialQuery="span.op:test" />, {
organization: {features: ['search-query-builder-conditionals-combobox-menus']},
});

await userEvent.click(getLastInput());
// Should show conditionals button
expect(await screen.findByRole('button', {name: 'Logic'})).toBeInTheDocument();
await userEvent.click(screen.getByRole('button', {name: 'Logic'}));
expect(await screen.findByRole('option', {name: '('})).toBeInTheDocument();
expect(screen.getByRole('option', {name: ')'})).toBeInTheDocument();
expect(screen.getByRole('option', {name: 'AND'})).toBeInTheDocument();
expect(screen.getByRole('option', {name: 'OR'})).toBeInTheDocument();
});
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,7 @@ import {
} from 'sentry/components/searchQueryBuilder/tokens/filterKeyListBox/utils';
import {itemIsSection} from 'sentry/components/searchQueryBuilder/tokens/utils';
import type {FieldDefinitionGetter} from 'sentry/components/searchQueryBuilder/types';
import type {
ParseResultToken,
Token,
TokenResult,
} from 'sentry/components/searchSyntax/parser';
import type {Token, TokenResult} from 'sentry/components/searchSyntax/parser';
import {getKeyName} from 'sentry/components/searchSyntax/utils';
import type {RecentSearch, TagCollection} from 'sentry/types/group';
import {trackAnalytics} from 'sentry/utils/analytics';
Expand Down Expand Up @@ -134,9 +130,7 @@ function useFilterKeyItems() {

function useFilterKeySections({
recentSearches,
filterItem,
}: {
filterItem: Node<ParseResultToken>;
recentSearches: RecentSearch[] | undefined;
}) {
const {filterKeySections, query, disallowLogicalOperators} = useSearchQueryBuilder();
Expand All @@ -155,22 +149,21 @@ function useFilterKeySections({
return [];
}

const isFirstItem = filterItem.key.toString().endsWith(':0');
if (recentSearches?.length && !query) {
const recentSearchesSections: Section[] = [
RECENT_SEARCH_CATEGORY,
ALL_CATEGORY,
...definedSections,
];

if (!disallowLogicalOperators && !isFirstItem && hasConditionalsInCombobox) {
if (!disallowLogicalOperators && hasConditionalsInCombobox) {
recentSearchesSections.push(LOGIC_CATEGORY);
}
return recentSearchesSections;
}

const customSections: Section[] = [ALL_CATEGORY, ...definedSections];
if (!disallowLogicalOperators && !isFirstItem && hasConditionalsInCombobox) {
if (!disallowLogicalOperators && hasConditionalsInCombobox) {
customSections.push(LOGIC_CATEGORY);
}

Expand All @@ -179,7 +172,6 @@ function useFilterKeySections({
disallowLogicalOperators,
filterKeySections,
hasConditionalsInCombobox,
filterItem.key,
query,
recentSearches?.length,
]);
Expand All @@ -200,19 +192,18 @@ function useFilterKeySections({
return {sections, selectedSection, setSelectedSection};
}

const conditionalFilterItems = [
const logicFilterItems = [
createLogicFilterItem({value: 'AND'}),
createLogicFilterItem({value: 'OR'}),
createLogicFilterItem({value: '('}),
createLogicFilterItem({value: ')'}),
];

interface UseFilterKeyListBoxArgs {
filterItem: Node<ParseResultToken>;
filterValue: string;
}

export function useFilterKeyListBox({filterValue, filterItem}: UseFilterKeyListBoxArgs) {
export function useFilterKeyListBox({filterValue}: UseFilterKeyListBoxArgs) {
const {
filterKeys,
getFieldDefinition,
Expand All @@ -228,7 +219,6 @@ export function useFilterKeyListBox({filterValue, filterItem}: UseFilterKeyListB
const {data: recentSearches} = useRecentSearches();
const {sections, selectedSection, setSelectedSection} = useFilterKeySections({
recentSearches,
filterItem,
});

const organization = useOrganization();
Expand Down Expand Up @@ -270,7 +260,7 @@ export function useFilterKeyListBox({filterValue, filterItem}: UseFilterKeyListB
selectedSection === LOGIC_CATEGORY_VALUE &&
hasConditionalsInCombobox
) {
return [...askSeerItem, ...conditionalFilterItems];
return [...askSeerItem, ...logicFilterItems];
}

const filteredByCategory = sectionedItems.filter(item => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,6 @@ function SearchQueryBuilderInputInternal({

const {customMenu, sectionItems, maxOptions, onKeyDownCapture, handleOptionSelected} =
useFilterKeyListBox({
filterItem: item,
filterValue,
});
const sortedFilteredItems = useSortedFilterKeyItems({
Expand Down
Loading