Skip to content

Commit

Permalink
[8.6] Fixes auto suggest in security solution (#145924) (#146439)
Browse files Browse the repository at this point in the history
# Backport

This will backport the following commits from `main` to `8.6`:
- [Fixes auto suggest in security solution
(#145924)](#145924)

<!--- Backport version: 8.9.7 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Steph
Milovic","email":"[email protected]"},"sourceCommit":{"committedDate":"2022-11-28T16:52:03Z","message":"Fixes
auto suggest in security solution
(#145924)","sha":"3a6825cf47e80dab9aeae373a1a93ab740e733eb","branchLabelMapping":{"^v8.7.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","Team:
SecuritySolution","Team:Security Solution
Platform","v8.6.0","v8.7.0"],"number":145924,"url":"https://github.com/elastic/kibana/pull/145924","mergeCommit":{"message":"Fixes
auto suggest in security solution
(#145924)","sha":"3a6825cf47e80dab9aeae373a1a93ab740e733eb"}},"sourceBranch":"main","suggestedTargetBranches":["8.6"],"targetPullRequestStates":[{"branch":"8.6","label":"v8.6.0","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v8.7.0","labelRegex":"^v8.7.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/145924","number":145924,"mergeCommit":{"message":"Fixes
auto suggest in security solution
(#145924)","sha":"3a6825cf47e80dab9aeae373a1a93ab740e733eb"}}]}]
BACKPORT-->

Co-authored-by: Steph Milovic <[email protected]>
  • Loading branch information
kibanamachine and stephmilovic authored Nov 28, 2022
1 parent d00d67d commit 3dbe456
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,7 @@ import { compact, debounce, isEmpty, isEqual, isFunction, partition } from 'loda
import { CoreStart, DocLinksStart, Toast } from '@kbn/core/public';
import type { Query } from '@kbn/es-query';
import { DataPublicPluginStart, getQueryLog } from '@kbn/data-plugin/public';
import {
type DataView,
DataView as KibanaDataView,
DataViewsPublicPluginStart,
} from '@kbn/data-views-plugin/public';
import { type DataView, DataViewsPublicPluginStart } from '@kbn/data-views-plugin/public';
import type { PersistedLog } from '@kbn/data-plugin/public';
import { getFieldSubtypeNested, KIBANA_USER_QUERY_LANGUAGE_KEY } from '@kbn/data-plugin/common';
import { toMountPoint } from '@kbn/kibana-react-plugin/public';
Expand Down Expand Up @@ -188,7 +184,7 @@ export default class QueryStringInputUI extends PureComponent<QueryStringInputPr
QueryStringInputProps['indexPatterns'][number],
DataView
>(this.props.indexPatterns || [], (indexPattern): indexPattern is DataView => {
return indexPattern instanceof KibanaDataView;
return indexPattern.hasOwnProperty('fields') && indexPattern.hasOwnProperty('title');
});
const idOrTitlePatterns = stringPatterns.map((sp) =>
typeof sp === 'string' ? { type: 'title', value: sp } : sp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,17 @@
*/

import { login, visit } from '../../tasks/login';
import { openAddFilterPopover, fillAddFilterForm } from '../../tasks/search_bar';
import { GLOBAL_SEARCH_BAR_FILTER_ITEM } from '../../screens/search_bar';
import {
openAddFilterPopover,
fillAddFilterForm,
openKqlQueryBar,
fillKqlQueryBar,
} from '../../tasks/search_bar';
import {
AUTO_SUGGEST_AGENT_NAME,
AUTO_SUGGEST_HOST_NAME_VALUE,
GLOBAL_SEARCH_BAR_FILTER_ITEM,
} from '../../screens/search_bar';
import { getHostIpFilter } from '../../objects/filter';

import { HOSTS_URL } from '../../urls/navigation';
Expand All @@ -29,4 +38,11 @@ describe('SearchBar', () => {
`${getHostIpFilter().key}: ${getHostIpFilter().value}`
);
});

it('auto suggests fields from the data view and auto completes available field values', () => {
openKqlQueryBar();
cy.get(AUTO_SUGGEST_AGENT_NAME).should('be.visible');
fillKqlQueryBar(`host.name:`);
cy.get(AUTO_SUGGEST_HOST_NAME_VALUE).should('be.visible');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,10 @@ export const GLOBAL_SEARCH_BAR_FILTER_ITEM = '#popoverFor_filter0';
export const GLOBAL_SEARCH_BAR_FILTER_ITEM_AT = (value: number) => `#popoverFor_filter${value}`;

export const GLOBAL_SEARCH_BAR_PINNED_FILTER = '.globalFilterItem-isPinned';

export const GLOBAL_KQL_INPUT =
'[data-test-subj="filters-global-container"] [data-test-subj="unifiedQueryInput"] textarea';

export const AUTO_SUGGEST_AGENT_NAME = `[data-test-subj="autocompleteSuggestion-field-agent.name-"]`;

export const AUTO_SUGGEST_HOST_NAME_VALUE = `[data-test-subj='autocompleteSuggestion-value-"siem-kibana"-']`;
11 changes: 11 additions & 0 deletions x-pack/plugins/security_solution/cypress/tasks/search_bar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
ADD_FILTER_FORM_OPERATOR_FIELD,
ADD_FILTER_FORM_FIELD_OPTION,
ADD_FILTER_FORM_FILTER_VALUE_INPUT,
GLOBAL_KQL_INPUT,
} from '../screens/search_bar';

export const openAddFilterPopover = () => {
Expand All @@ -24,6 +25,16 @@ export const openAddFilterPopover = () => {
cy.get(GLOBAL_SEARCH_BAR_ADD_FILTER).click();
};

export const openKqlQueryBar = () => {
cy.get(GLOBAL_KQL_INPUT).should('be.visible');
cy.get(GLOBAL_KQL_INPUT).click();
};

export const fillKqlQueryBar = (query: string) => {
cy.get(GLOBAL_KQL_INPUT).should('be.visible');
cy.get(GLOBAL_KQL_INPUT).type(query);
};

export const fillAddFilterForm = ({ key, value, operator }: SearchBarFilter) => {
cy.get(ADD_FILTER_FORM_FIELD_INPUT).should('exist');
cy.get(ADD_FILTER_FORM_FIELD_INPUT).should('be.visible');
Expand Down

0 comments on commit 3dbe456

Please sign in to comment.