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
50 changes: 9 additions & 41 deletions static/app/components/searchQueryBuilder/index.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1068,9 +1068,7 @@ describe('SearchQueryBuilder', () => {

it('can add a new token by clicking a key suggestion', async () => {
const mockOnChange = jest.fn();
render(<SearchQueryBuilder {...defaultProps} onChange={mockOnChange} />, {
organization: {features: ['search-query-builder-input-flow-changes']},
});
render(<SearchQueryBuilder {...defaultProps} onChange={mockOnChange} />);

await userEvent.click(screen.getByRole('combobox', {name: 'Add a search term'}));
await userEvent.click(screen.getByRole('option', {name: 'browser.name'}));
Expand All @@ -1082,11 +1080,6 @@ describe('SearchQueryBuilder', () => {
// onChange should not be called until exiting edit mode
expect(mockOnChange).not.toHaveBeenCalled();

// Should have focus on the operator option
const operatorOption = await screen.findByRole('option', {name: 'contains'});
expect(operatorOption).toHaveFocus();
await userEvent.click(operatorOption);

await userEvent.click(await screen.findByRole('option', {name: 'Firefox'}));

// New token should have a value, and selecting from dropdown switches operator to "is"
Expand All @@ -1109,8 +1102,7 @@ describe('SearchQueryBuilder', () => {
<SearchQueryBuilder
{...defaultProps}
initialQuery={`browser.name:${WildcardOperators.CONTAINS}firefox`}
/>,
{organization: {features: ['search-query-builder-input-flow-changes']}}
/>
);

await userEvent.click(
Expand Down Expand Up @@ -1142,9 +1134,7 @@ describe('SearchQueryBuilder', () => {
});

it('can add a filter after some free text', async () => {
render(<SearchQueryBuilder {...defaultProps} />, {
organization: {features: ['search-query-builder-input-flow-changes']},
});
render(<SearchQueryBuilder {...defaultProps} />);

await userEvent.click(getLastInput());

Expand All @@ -1156,11 +1146,6 @@ describe('SearchQueryBuilder', () => {
await userEvent.click(screen.getByRole('option', {name: 'browser.name'}));
jest.restoreAllMocks();

// Should have focus on the operator option
const operatorOption = await screen.findByRole('option', {name: 'contains'});
expect(operatorOption).toHaveFocus();
await userEvent.click(operatorOption);

// Filter value should have focus
expect(await screen.findByLabelText('Edit filter value')).toHaveFocus();
await userEvent.keyboard('foo{enter}');
Expand Down Expand Up @@ -1244,9 +1229,7 @@ describe('SearchQueryBuilder', () => {
});

it('converts text to filter when typing <filter>:', async () => {
render(<SearchQueryBuilder {...defaultProps} />, {
organization: {features: ['search-query-builder-input-flow-changes']},
});
render(<SearchQueryBuilder {...defaultProps} />);
await userEvent.click(getLastInput());

await userEvent.type(
Expand Down Expand Up @@ -1276,16 +1259,13 @@ describe('SearchQueryBuilder', () => {
});

it('selects [Filtered] from dropdown', async () => {
render(<SearchQueryBuilder {...defaultProps} />, {
organization: {features: ['search-query-builder-input-flow-changes']},
});
render(<SearchQueryBuilder {...defaultProps} />);
await userEvent.click(getLastInput());

await userEvent.type(
screen.getByRole('combobox', {name: 'Add a search term'}),
'message:'
);
await userEvent.keyboard('{enter}');
await userEvent.click(screen.getByRole('option', {name: '[Filtered]'}));

// Selecting from dropdown switches operator from contains to "is"
Expand Down Expand Up @@ -4197,36 +4177,24 @@ describe('SearchQueryBuilder', () => {
});

it('focuses on the filter value when user selects an aggregate filter with no arguments', async () => {
render(<SearchQueryBuilder {...aggregateDefaultProps} />, {
organization: {features: ['search-query-builder-input-flow-changes']},
});
render(<SearchQueryBuilder {...aggregateDefaultProps} />);

await userEvent.click(getLastInput());
await userEvent.keyboard('count');
await userEvent.click(screen.getByRole('option', {name: 'count()'}));
expect(screen.getByLabelText('count():>100')).toBeInTheDocument();

const gtOption = screen.getByRole('option', {name: '>'});
expect(gtOption).toHaveFocus();
await userEvent.click(gtOption);

expect(screen.getByLabelText('Edit filter value')).toHaveFocus();
expect(await screen.findByLabelText('Edit filter value')).toHaveFocus();
});

it('focuses on the filter value when user input looks like an aggregate filter with no arguments', async () => {
render(<SearchQueryBuilder {...aggregateDefaultProps} />, {
organization: {features: ['search-query-builder-input-flow-changes']},
});
render(<SearchQueryBuilder {...aggregateDefaultProps} />);

await userEvent.click(getLastInput());
await userEvent.keyboard('count(');
expect(screen.getByLabelText('count():>100')).toBeInTheDocument();

const gtOption = screen.getByRole('option', {name: '>'});
expect(gtOption).toHaveFocus();
await userEvent.click(gtOption);

expect(screen.getByLabelText('Edit filter value')).toHaveFocus();
expect(await screen.findByLabelText('Edit filter value')).toHaveFocus();
});

it('focuses on the filter value after only argument is specified', async () => {
Expand Down
36 changes: 5 additions & 31 deletions static/app/components/searchQueryBuilder/tokens/freeText.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import type {KeyboardEvent, Node} from '@react-types/shared';
import {useSearchQueryBuilder} from 'sentry/components/searchQueryBuilder/context';
import {useQueryBuilderGridItem} from 'sentry/components/searchQueryBuilder/hooks/useQueryBuilderGridItem';
import {SearchQueryBuilderCombobox} from 'sentry/components/searchQueryBuilder/tokens/combobox';
import {areWildcardOperatorsAllowed} from 'sentry/components/searchQueryBuilder/tokens/filter/utils';
import {useFilterKeyListBox} from 'sentry/components/searchQueryBuilder/tokens/filterKeyListBox/useFilterKeyListBox';
import {InvalidTokenTooltip} from 'sentry/components/searchQueryBuilder/tokens/invalidTokenTooltip';
import {useSortedFilterKeyItems} from 'sentry/components/searchQueryBuilder/tokens/useSortedFilterKeyItems';
Expand All @@ -27,7 +26,6 @@ import {
recentSearchTypeToLabel,
} from 'sentry/components/searchQueryBuilder/utils';
import {
FilterType,
InvalidReason,
parseSearch,
Token,
Expand Down Expand Up @@ -134,25 +132,13 @@ function countPreviousItemsOfType({

function calculateNextFocusForFilter(
state: ListState<ParseResultToken>,
definition: FieldDefinition | null,
key: string | null,
hasInputChangeFlows: boolean
definition: FieldDefinition | null
): FocusOverride {
const numPreviousFilterItems = countPreviousItemsOfType({state, type: Token.FILTER});

const isNumericValueType =
definition?.valueType === FieldValueType.NUMBER ||
definition?.valueType === FieldValueType.INTEGER;

let part: FocusOverride['part'] =
hasInputChangeFlows && (isNumericValueType || areWildcardOperatorsAllowed(definition))
? 'op'
: 'value';

let part: FocusOverride['part'] = 'value';
if (definition?.kind === FieldKind.FUNCTION && definition.parameters?.length) {
part = 'key';
} else if (key === FilterType.IS || key === FilterType.HAS) {
part = 'value';
}

return {
Expand Down Expand Up @@ -265,9 +251,6 @@ function SearchQueryBuilderInputInternal({
const [selectionIndex, setSelectionIndex] = useState(0);

const organization = useOrganization();
const hasInputChangeFlows = organization.features.includes(
'search-query-builder-input-flow-changes'
);

const updateSelectionIndex = useCallback(() => {
setSelectionIndex(inputRef.current?.selectionStart ?? 0);
Expand Down Expand Up @@ -512,12 +495,7 @@ function SearchQueryBuilderInputInternal({
value,
getFieldDefinition
),
focusOverride: calculateNextFocusForFilter(
state,
getFieldDefinition(value),
value,
hasInputChangeFlows
),
focusOverride: calculateNextFocusForFilter(state, getFieldDefinition(value)),
shouldCommitQuery: false,
});
resetInputValue();
Expand Down Expand Up @@ -617,9 +595,7 @@ function SearchQueryBuilderInputInternal({
),
focusOverride: calculateNextFocusForFilter(
state,
getFieldDefinition(filterValue),
null,
hasInputChangeFlows
getFieldDefinition(filterValue)
),
shouldCommitQuery: false,
});
Expand Down Expand Up @@ -660,9 +636,7 @@ function SearchQueryBuilderInputInternal({
),
focusOverride: calculateNextFocusForFilter(
state,
getFieldDefinition(filterKey),
filterKey,
hasInputChangeFlows
getFieldDefinition(filterKey)
),
shouldCommitQuery: false,
});
Expand Down
4 changes: 1 addition & 3 deletions static/app/views/automations/list.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import AutomationsList from 'sentry/views/automations/list';

describe('AutomationsList', () => {
const organization = OrganizationFixture({
features: ['workflow-engine-ui', 'search-query-builder-input-flow-changes'],
features: ['workflow-engine-ui'],
});
const project = ProjectFixture({id: '1', slug: 'project-1'});
const detector = MetricDetectorFixture({
Expand Down Expand Up @@ -180,7 +180,6 @@ describe('AutomationsList', () => {
// Click through menus to select action:slack
await userEvent.click(screen.getByRole('combobox', {name: 'Add a search term'}));
await userEvent.click(await screen.findByRole('option', {name: 'action'}));
await userEvent.click(await screen.findByRole('option', {name: 'is'}));
await userEvent.click(await screen.findByRole('option', {name: 'slack'}));

await screen.findByText('Slack Automation');
Expand Down Expand Up @@ -433,7 +432,6 @@ describe('AutomationsList', () => {
// Click through menus to select action:slack
await userEvent.click(screen.getByRole('combobox', {name: 'Add a search term'}));
await userEvent.click(await screen.findByRole('option', {name: 'action'}));
await userEvent.click(await screen.findByRole('option', {name: 'is'}));
await userEvent.click(await screen.findByRole('option', {name: 'slack'}));

// Wait for filtered results to load
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function renderWithProvider({
}: ComponentProps<typeof SpansSearchBar>) {
return render(
<SpansSearchBar widgetQuery={widgetQuery} onSearch={onSearch} onClose={onClose} />,
{organization: {features: ['search-query-builder-input-flow-changes']}}
{}
);
}

Expand Down Expand Up @@ -135,7 +135,6 @@ describe('SpansSearchBar', () => {
name: 'Add a search term',
});
await userEvent.type(searchInput, 'span.op:', {delay: null});
await userEvent.keyboard('{enter}');
await userEvent.keyboard('function', {delay: null});
await userEvent.keyboard('{enter}');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ jest.mock('sentry/views/issueDetails/utils', () => ({
}));

describe('EventDetailsHeader', () => {
const organization = OrganizationFixture({
features: ['search-query-builder-input-flow-changes'],
});
const organization = OrganizationFixture();
const project = ProjectFixture({
environments: ['production', 'staging', 'development'],
});
Expand Down Expand Up @@ -139,8 +137,7 @@ describe('EventDetailsHeader', () => {

const search = await screen.findByPlaceholderText('Filter events\u2026');
await userEvent.type(search, `${tagKey}:`, {delay: null});
await userEvent.click(screen.getByRole('option', {name: 'is'}));
await userEvent.keyboard(`${tagValue}{enter}`, {delay: null});
await userEvent.click(await screen.findByRole('option', {name: tagValue}));
await waitFor(() => {
expect(mockUseNavigate).toHaveBeenCalledWith(
expect.objectContaining(locationQuery),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ import {EventSearch} from 'sentry/views/issueDetails/streamline/eventSearch';
const mockHandleSearch = jest.fn();

describe('EventSearch', () => {
const organization = OrganizationFixture({
features: ['search-query-builder-input-flow-changes'],
});
const organization = OrganizationFixture();
const project = ProjectFixture({
environments: ['production', 'staging', 'developement'],
});
Expand Down Expand Up @@ -53,8 +51,8 @@ describe('EventSearch', () => {
const search = screen.getByRole('combobox', {name: 'Add a search term'});
expect(search).toBeInTheDocument();
await userEvent.type(search, `${tagKey}:`);
await userEvent.click(screen.getByRole('option', {name: 'is'}));
await userEvent.keyboard(`${tagValue}{enter}{enter}`);
await userEvent.click(await screen.findByRole('option', {name: tagValue}));
await userEvent.keyboard('{enter}');

await waitFor(() => {
expect(mockTagKeyQuery).toHaveBeenCalled();
Expand Down
2 changes: 1 addition & 1 deletion static/app/views/releases/list/index.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {ReleasesStatusOption} from 'sentry/views/releases/list/releasesStatusOpt

describe('ReleasesList', () => {
const organization = OrganizationFixture({
features: ['search-query-builder-input-flow-changes', 'preprod-frontend-routes'],
features: ['preprod-frontend-routes'],
});
const projects = [ProjectFixture({features: ['releases']})];
const semverVersionInfo = {
Expand Down
Loading