[8.8] [Controls] Add query settings to ES query (#157923) (#158023)

# Backport

This will backport the following commits from `main` to `8.8`:
- [[Controls] Add query settings to ES query
(#157923)](https://github.com/elastic/kibana/pull/157923)

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

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

<!--BACKPORT [{"author":{"name":"Hannah
Mudge","email":"Heenawter@users.noreply.github.com"},"sourceCommit":{"committedDate":"2023-05-17T18:49:49Z","message":"[Controls]
Add query settings to ES query (#157923)\n\nCloses
https://github.com/elastic/kibana/issues/157411\r\n\r\n##
Summary\r\n\r\nThis PR sends the Kibana query settings to the controls
ES query so that\r\nthings like leading wildcard queries in the query
bar no longer break\r\nthem.\r\n\r\n**Before:**\r\n\r\n![Screenshot
2023-05-17 at 12 25
20\r\nPM](9deca883-6251-49f4-954b-7ffd7e418255)\r\n\r\nAs
a follow up, we need to
address\r\nhttps://github.com/elastic/kibana/issues/156430 so that, if a
user has\r\nthe wrong query setting and ends up in an error state from
something\r\nlike a leading wildcard query, they can recover without
hard refreshing\r\nthe page.\r\n\r\n### Checklist\r\n\r\n- [x] This was
checked for
[cross-browser\r\ncompatibility](https://www.elastic.co/support/matrix#matrix_browsers)\r\n\r\n\r\n###
For maintainers\r\n\r\n- [ ] This was checked for breaking API changes
and was
[labeled\r\nappropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)","sha":"70407d6b19c6092427d9af10b48a183209dc682d","branchLabelMapping":{"^v8.9.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix","Team:Presentation","loe:hours","impact:high","Project:Controls","backport:prev-minor","v8.9.0"],"number":157923,"url":"https://github.com/elastic/kibana/pull/157923","mergeCommit":{"message":"[Controls]
Add query settings to ES query (#157923)\n\nCloses
https://github.com/elastic/kibana/issues/157411\r\n\r\n##
Summary\r\n\r\nThis PR sends the Kibana query settings to the controls
ES query so that\r\nthings like leading wildcard queries in the query
bar no longer break\r\nthem.\r\n\r\n**Before:**\r\n\r\n![Screenshot
2023-05-17 at 12 25
20\r\nPM](9deca883-6251-49f4-954b-7ffd7e418255)\r\n\r\nAs
a follow up, we need to
address\r\nhttps://github.com/elastic/kibana/issues/156430 so that, if a
user has\r\nthe wrong query setting and ends up in an error state from
something\r\nlike a leading wildcard query, they can recover without
hard refreshing\r\nthe page.\r\n\r\n### Checklist\r\n\r\n- [x] This was
checked for
[cross-browser\r\ncompatibility](https://www.elastic.co/support/matrix#matrix_browsers)\r\n\r\n\r\n###
For maintainers\r\n\r\n- [ ] This was checked for breaking API changes
and was
[labeled\r\nappropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)","sha":"70407d6b19c6092427d9af10b48a183209dc682d"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v8.9.0","labelRegex":"^v8.9.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/157923","number":157923,"mergeCommit":{"message":"[Controls]
Add query settings to ES query (#157923)\n\nCloses
https://github.com/elastic/kibana/issues/157411\r\n\r\n##
Summary\r\n\r\nThis PR sends the Kibana query settings to the controls
ES query so that\r\nthings like leading wildcard queries in the query
bar no longer break\r\nthem.\r\n\r\n**Before:**\r\n\r\n![Screenshot
2023-05-17 at 12 25
20\r\nPM](9deca883-6251-49f4-954b-7ffd7e418255)\r\n\r\nAs
a follow up, we need to
address\r\nhttps://github.com/elastic/kibana/issues/156430 so that, if a
user has\r\nthe wrong query setting and ends up in an error state from
something\r\nlike a leading wildcard query, they can recover without
hard refreshing\r\nthe page.\r\n\r\n### Checklist\r\n\r\n- [x] This was
checked for
[cross-browser\r\ncompatibility](https://www.elastic.co/support/matrix#matrix_browsers)\r\n\r\n\r\n###
For maintainers\r\n\r\n- [ ] This was checked for breaking API changes
and was
[labeled\r\nappropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)","sha":"70407d6b19c6092427d9af10b48a183209dc682d"}}]}]
BACKPORT-->

Co-authored-by: Hannah Mudge <Heenawter@users.noreply.github.com>
This commit is contained in:
Kibana Machine 2023-05-17 16:03:47 -04:00 committed by GitHub
parent 0d0bf8afc4
commit 7117cc902c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -9,6 +9,8 @@
import { memoize } from 'lodash';
import dateMath from '@kbn/datemath';
import { CoreStart } from '@kbn/core/public';
import { getEsQueryConfig } from '@kbn/data-plugin/common';
import { buildEsQuery, type TimeRange } from '@kbn/es-query';
import { KibanaPluginServiceFactory } from '@kbn/presentation-util-plugin/public';
@ -24,10 +26,12 @@ import { ControlsPluginStartDeps } from '../../types';
import { ControlsOptionsListService } from './types';
class OptionsListService implements ControlsOptionsListService {
private core: CoreStart;
private data: ControlsDataService;
private http: ControlsHTTPService;
constructor(requiredServices: OptionsListServiceRequiredServices) {
constructor(core: CoreStart, requiredServices: OptionsListServiceRequiredServices) {
this.core = core;
({ data: this.data, http: this.http } = requiredServices);
}
@ -85,7 +89,8 @@ class OptionsListService implements ControlsOptionsListService {
const { query, filters, dataView, timeRange, field, ...passThroughProps } = request;
const timeFilter = timeRange ? timeService.createFilter(dataView, timeRange) : undefined;
const filtersToUse = [...(filters ?? []), ...(timeFilter ? [timeFilter] : [])];
const esFilters = [buildEsQuery(dataView, query ?? [], filtersToUse ?? [])];
const config = getEsQueryConfig(this.core.uiSettings);
const esFilters = [buildEsQuery(dataView, query ?? [], filtersToUse ?? [], config)];
return {
...passThroughProps,
@ -145,5 +150,5 @@ export type OptionsListServiceFactory = KibanaPluginServiceFactory<
>;
export const optionsListServiceFactory: OptionsListServiceFactory = (core, requiredServices) => {
return new OptionsListService(requiredServices);
return new OptionsListService(core.coreStart, requiredServices);
};