Skip to content

Commit d30f623

Browse files
committed
feat(query-builder): Add a submit button
1 parent d457ede commit d30f623

File tree

2 files changed

+54
-34
lines changed

2 files changed

+54
-34
lines changed

static/app/components/searchQueryBuilder/index.tsx

+53-33
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {forwardRef, useLayoutEffect, useMemo, useRef} from 'react';
2+
import {css} from '@emotion/react';
23
import styled from '@emotion/styled';
34

45
import {Button} from 'sentry/components/core/button';
@@ -151,33 +152,43 @@ function SearchIndicator({
151152
);
152153
}
153154

154-
const ActionButtons = forwardRef<HTMLDivElement, {trailingItems?: React.ReactNode}>(
155-
({trailingItems = null}, ref) => {
156-
const {dispatch, handleSearch, disabled, query} = useSearchQueryBuilder();
155+
const ActionButtons = forwardRef<
156+
HTMLDivElement,
157+
{initialQuery: string; trailingItems?: React.ReactNode}
158+
>(({trailingItems = null, initialQuery}, ref) => {
159+
const {dispatch, handleSearch, disabled, query} = useSearchQueryBuilder();
160+
const unsubmittedChanges = query !== initialQuery;
157161

158-
if (disabled) {
159-
return null;
160-
}
161-
162-
return (
163-
<ButtonsWrapper ref={ref}>
164-
{trailingItems}
165-
{query === '' ? null : (
166-
<ActionButton
167-
aria-label={t('Clear search query')}
168-
size="zero"
169-
icon={<IconClose />}
170-
borderless
171-
onClick={() => {
172-
dispatch({type: 'CLEAR'});
173-
handleSearch('');
174-
}}
175-
/>
176-
)}
177-
</ButtonsWrapper>
178-
);
162+
if (disabled) {
163+
return null;
179164
}
180-
);
165+
166+
return (
167+
<ButtonsWrapper ref={ref}>
168+
{trailingItems}
169+
{query === '' ? null : (
170+
<ActionButton
171+
aria-label={t('Clear search query')}
172+
size="zero"
173+
icon={<IconClose size="sm" />}
174+
borderless
175+
onClick={() => {
176+
dispatch({type: 'CLEAR'});
177+
handleSearch('');
178+
}}
179+
/>
180+
)}
181+
<ActionButton
182+
aria-label={t('Submit search query')}
183+
size="zero"
184+
icon={<IconSearch size="sm" />}
185+
borderless
186+
priority={unsubmittedChanges ? 'primary' : 'default'}
187+
onClick={() => handleSearch(query)}
188+
/>
189+
</ButtonsWrapper>
190+
);
191+
});
181192

182193
export function SearchQueryBuilder({
183194
className,
@@ -312,18 +323,20 @@ export function SearchQueryBuilder({
312323
data-test-id="search-query-builder"
313324
>
314325
<PanelProvider>
315-
<SearchIndicator
326+
{/* <SearchIndicator
316327
initialQuery={initialQuery}
317328
showUnsubmittedIndicator={showUnsubmittedIndicator}
318-
/>
329+
/> */}
319330
{!parsedQuery || queryInterface === QueryInterfaceType.TEXT ? (
320331
<PlainTextQueryInput label={label} />
321332
) : (
322333
<TokenizedQueryGrid label={label} actionBarWidth={actionBarWidth} />
323334
)}
324-
{size !== 'small' && (
325-
<ActionButtons ref={actionBarRef} trailingItems={trailingItems} />
326-
)}
335+
<ActionButtons
336+
ref={actionBarRef}
337+
trailingItems={trailingItems}
338+
initialQuery={initialQuery}
339+
/>
327340
</PanelProvider>
328341
</Wrapper>
329342
</SearchQueryBuilderContext.Provider>
@@ -342,15 +355,22 @@ const Wrapper = styled(Input.withComponent('div'))`
342355

343356
const ButtonsWrapper = styled('div')`
344357
position: absolute;
345-
right: 9px;
346-
top: 9px;
358+
right: 3px;
359+
top: 3px;
347360
display: flex;
348361
align-items: center;
349362
gap: ${space(0.5)};
350363
`;
351364

352365
const ActionButton = styled(Button)`
353-
color: ${p => p.theme.subText};
366+
${p =>
367+
p.priority !== 'primary' &&
368+
css`
369+
color: ${p.theme.subText};
370+
`}
371+
372+
height: 30px;
373+
width: 30px;
354374
`;
355375

356376
const PositionedSearchIconContainer = styled('div')`

static/app/components/searchQueryBuilder/tokenizedQueryGrid.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ export function TokenizedQueryGrid({label, actionBarWidth}: TokenizedQueryGridPr
163163
const SearchQueryGridWrapper = styled('div')`
164164
padding-top: ${space(0.75)};
165165
padding-bottom: ${space(0.75)};
166-
padding-left: 32px;
166+
padding-left: ${space(0.75)};
167167
padding-right: ${space(0.75)};
168168
display: flex;
169169
align-items: stretch;

0 commit comments

Comments
 (0)