Skip to content

Commit

Permalink
[RAM] Alert search bar only KQL (#155947)
Browse files Browse the repository at this point in the history
## Summary

Adding the props `showQueryInput` is fixing the layout of of the
filters. We also wanted to make sure that our alert search bar can only
work with KQL because we need to do some kind of validation on the field
used in the search bar, therefore it will be easier to just use
KueryNode for now.

### Before:
<img width="754" alt="Screenshot 2023-04-26 at 1 52 44 PM"
src="https://user-images.githubusercontent.com/189600/234698078-612f03be-3331-41ab-a2d9-80f6cd767043.png">


### After:
<img width="749" alt="image"
src="https://user-images.githubusercontent.com/189600/234697735-abafc15f-5562-42a0-aeb9-638129d70120.png">

---------

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
  • Loading branch information
XavierM and kibanamachine authored May 5, 2023
1 parent dd1fd26 commit af7e34a
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,11 @@ storiesOf('SearchBar', module)
},
} as unknown as SearchBarProps)
)
.add('without switch query language', () =>
wrapSearchBarInContext({
disableQueryLanguageSwitcher: true,
} as SearchBarProps)
)
.add('show only query bar without submit', () =>
wrapSearchBarInContext({
showDatePicker: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export interface QueryBarMenuProps extends WithCloseFilterEditorConfirmModalProp
toggleFilterBarMenuPopover: (value: boolean) => void;
openQueryBarMenu: boolean;
nonKqlMode?: 'lucene' | 'text';
disableQueryLanguageSwitcher?: boolean;
dateRangeFrom?: string;
dateRangeTo?: string;
savedQueryService: SavedQueryService;
Expand All @@ -72,6 +73,7 @@ export interface QueryBarMenuProps extends WithCloseFilterEditorConfirmModalProp
function QueryBarMenuComponent({
language,
nonKqlMode,
disableQueryLanguageSwitcher,
dateRangeFrom,
dateRangeTo,
onQueryChange,
Expand Down Expand Up @@ -158,6 +160,7 @@ function QueryBarMenuComponent({
manageFilterSetComponent,
hiddenPanelOptions,
nonKqlMode,
disableQueryLanguageSwitcher,
closePopover: plainClosePopover,
onQueryBarSubmit,
onFiltersUpdated,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ export interface QueryBarMenuPanelsProps {
manageFilterSetComponent?: JSX.Element;
hiddenPanelOptions?: FilterPanelOption[];
nonKqlMode?: 'lucene' | 'text';
disableQueryLanguageSwitcher?: boolean;
closePopover: () => void;
onQueryBarSubmit: (payload: { dateRange: TimeRange; query?: Query }) => void;
onFiltersUpdated?: (filters: Filter[]) => void;
Expand All @@ -170,6 +171,7 @@ export function QueryBarMenuPanels({
manageFilterSetComponent,
hiddenPanelOptions,
nonKqlMode,
disableQueryLanguageSwitcher = false,
closePopover,
onQueryBarSubmit,
onFiltersUpdated,
Expand Down Expand Up @@ -384,7 +386,7 @@ export function QueryBarMenuPanels({
}

// language menu appears when the showQueryInput is true
if (showQueryInput) {
if (showQueryInput && !disableQueryLanguageSwitcher) {
items.push({
name: `Language: ${language === 'kuery' ? kqlLabel : luceneLabel}`,
panel: 3,
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/unified_search/public/search_bar/search_bar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ export interface SearchBarOwnProps<QT extends AggregateQuery | Query = Query> {
isClearable?: boolean;
iconType?: EuiIconProps['type'];
nonKqlMode?: 'lucene' | 'text';
disableQueryLanguageSwitcher?: boolean;
// defines padding and border; use 'inPage' to avoid any padding or border;
// use 'detached' if the searchBar appears at the very top of the view, without any wrapper
displayStyle?: 'inPage' | 'detached';
Expand Down Expand Up @@ -472,6 +473,7 @@ class SearchBarUI<QT extends (Query | AggregateQuery) | Query = Query> extends C
const queryBarMenu = this.props.showQueryMenu ? (
<QueryBarMenu
nonKqlMode={this.props.nonKqlMode}
disableQueryLanguageSwitcher={this.props.disableQueryLanguageSwitcher}
language={
this.state.query && isOfQueryType(this.state?.query)
? this.state?.query?.language
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export const ActionAlertsFilterQuery: React.FC<ActionAlertsFilterQueryProps> = (
<EuiSpacer size="s" />
<AlertsSearchBar
appName="siem"
disableQueryLanguageSwitcher={true}
featureIds={['siem']}
query={query.kql}
filters={query.filters ?? []}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { TriggersAndActionsUiServices } from '../../..';
// TODO Share buildEsQuery to be used between AlertsSearchBar and AlertsStateTable component https://github.com/elastic/kibana/issues/144615
export function AlertsSearchBar({
appName,
disableQueryLanguageSwitcher = false,
featureIds,
query,
filters,
Expand Down Expand Up @@ -70,6 +71,7 @@ export function AlertsSearchBar({
return (
<SearchBar
appName={appName}
disableQueryLanguageSwitcher={disableQueryLanguageSwitcher}
indexPatterns={loading || error ? NO_INDEX_PATTERNS : [dataView!]}
placeholder={placeholder}
query={{ query: query ?? '', language: queryLanguage }}
Expand All @@ -82,6 +84,8 @@ export function AlertsSearchBar({
onFiltersUpdated={onFiltersUpdated}
onRefresh={onRefresh}
showDatePicker={showDatePicker}
showQueryInput={true}
showSaveQuery={true}
showSubmitButton={showSubmitButton}
submitOnBlur={submitOnBlur}
onQueryChange={onSearchQueryChange}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export type QueryLanguageType = 'lucene' | 'kuery';

export interface AlertsSearchBarProps {
appName: string;
disableQueryLanguageSwitcher?: boolean;
featureIds: ValidFeatureId[];
rangeFrom?: string;
rangeTo?: string;
Expand Down

0 comments on commit af7e34a

Please sign in to comment.