Skip to content

Commit f82a862

Browse files
stratoulakibanamachineHeenawterdavismcpheelukasolson
authored
[ES|QL][Discover] Supports controls (elastic#229598)
## Summary Part of elastic#225948 Enables controls in Discover from the editor. <img width="1252" height="122" alt="image" src="https://github.com/user-attachments/assets/76792f2e-abd0-406b-8a9f-84c53a06dfc4" /> The users can save the charts with variables in a dashboard but the controls are not been transferred. We will deal with it on a follow up PR. The same behavior is on dashboards too so there is a consistency there 😄. Flaky tests runner elastic#229598 (comment) Note: The Expand width to fit available space is not working but I will hide it for Discover only in a follow up PR ### Checklist Check the PR satisfies following conditions. Reviewers should verify this PR satisfies this list as well. - [x] Any text added follows [EUI's writing guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses sentence case text and includes [i18n support](https://github.com/elastic/kibana/blob/main/src/platform/packages/shared/kbn-i18n/README.md) - [x] [Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html) was added for features that require explanation or tutorials - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios - [x] [Flaky Test Runner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was used on any tests changed --------- Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com> Co-authored-by: Hannah Mudge <hannah.wright@elastic.co> Co-authored-by: Davis McPhee <davis.mcphee@elastic.co> Co-authored-by: Lukas Olson <lukas@elastic.co>
1 parent 227f1d3 commit f82a862

61 files changed

Lines changed: 1258 additions & 106 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

packages/kbn-optimizer/limits.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ pageLoadAssetSize:
175175
uiActions: 24712
176176
uiActionsEnhanced: 20189
177177
unifiedDocViewer: 14513
178-
unifiedSearch: 23000
178+
unifiedSearch: 24000
179179
upgradeAssistant: 6898
180180
uptime: 48184
181181
urlDrilldown: 21563

src/core/server/integration_tests/ci_checks/saved_objects/check_registered_types.test.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ describe('checking migration metadata changes on all registered SO types', () =>
162162
"risk-engine-configuration": "533a0a3f2dbef1c95129146ec4d5714de305be1a",
163163
"rules-settings": "53f94e5ce61f5e75d55ab8adbc1fb3d0937d2e0b",
164164
"sample-data-telemetry": "c38daf1a49ed24f2a4fb091e6e1e833fccf19935",
165-
"search": "5078b5f3bc5ed31cd8c16317f17100637734ea2b",
165+
"search": "c0e733a8dca9f8d6bca139d29f0eeb084e2963c6",
166166
"search-session": "fae0dfc63274d6a3b90ca583802c48cab8760637",
167167
"search-telemetry": "1bbaf2db531b97fa04399440fa52d46e86d54dd8",
168168
"search_playground": "3eba7e7c4563f03f76aea02f5dd3a7a739bf51a3",
@@ -1006,6 +1006,7 @@ describe('checking migration metadata changes on all registered SO types', () =>
10061006
"search|global: ce649a79d99c5ff5eb68d544635428ef87946d84",
10071007
"search|mappings: 432d4dfdb5a33ce29d00ccdcfcda70d7c5f94b52",
10081008
"search|schemas: 8d6477e08dfdf20335752a69994646f9da90741f",
1009+
"search|10.8.0: e9b8e7a06ce8c93bc1480859d82a018a29a85ff4",
10091010
"search|10.7.0: 5d15a12f9c024d225ccff3d77a8116b43fc8d8b0",
10101011
"search|10.6.0: 6ffb6b8b9bf540ea70d22447182eea0f3725afc7",
10111012
"search|10.5.0: 08da62a471e520af9d201342ff275e1d20513175",
@@ -1336,7 +1337,7 @@ describe('checking migration metadata changes on all registered SO types', () =>
13361337
"risk-engine-configuration": "10.2.0",
13371338
"rules-settings": "10.1.0",
13381339
"sample-data-telemetry": "10.0.0",
1339-
"search": "10.7.0",
1340+
"search": "10.8.0",
13401341
"search-session": "10.0.0",
13411342
"search-telemetry": "10.0.0",
13421343
"search_playground": "10.1.0",
@@ -1483,7 +1484,7 @@ describe('checking migration metadata changes on all registered SO types', () =>
14831484
"risk-engine-configuration": "10.2.0",
14841485
"rules-settings": "10.1.0",
14851486
"sample-data-telemetry": "0.0.0",
1486-
"search": "10.7.0",
1487+
"search": "10.8.0",
14871488
"search-session": "8.6.0",
14881489
"search-telemetry": "7.12.0",
14891490
"search_playground": "10.1.0",

src/platform/packages/shared/kbn-unified-histogram/components/chart/chart.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import type { DataView, DataViewField } from '@kbn/data-views-plugin/public';
2828
import type { TimeRange } from '@kbn/es-query';
2929
import type { PublishingSubject } from '@kbn/presentation-publishing';
3030
import type { RequestStatus } from '@kbn/inspector-plugin/public';
31+
import type { ESQLControlVariable } from '@kbn/esql-types';
3132
import type { IKibanaSearchResponse } from '@kbn/search-types';
3233
import type { estypes } from '@elastic/elasticsearch';
3334
import { Histogram } from './histogram';
@@ -90,6 +91,7 @@ export interface UnifiedHistogramChartProps {
9091
onBrushEnd?: LensEmbeddableInput['onBrushEnd'];
9192
withDefaultActions?: EmbeddableComponentProps['withDefaultActions'];
9293
columns?: DatatableColumn[];
94+
esqlVariables?: ESQLControlVariable[];
9395
}
9496

9597
const RequestStatusError: typeof RequestStatus.ERROR = 2;

src/platform/packages/shared/kbn-unified-histogram/components/chart/histogram.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { css } from '@emotion/react';
1212
import React from 'react';
1313
import type { DataView } from '@kbn/data-views-plugin/public';
1414
import type { TimeRange } from '@kbn/es-query';
15+
import type { ESQLControlVariable } from '@kbn/esql-types';
1516
import type { EmbeddableComponentProps, LensEmbeddableInput } from '@kbn/lens-plugin/public';
1617
import type {
1718
UnifiedHistogramBucketInterval,
@@ -38,6 +39,7 @@ export interface HistogramProps {
3839
onFilter?: LensEmbeddableInput['onFilter'];
3940
onBrushEnd?: LensEmbeddableInput['onBrushEnd'];
4041
withDefaultActions?: EmbeddableComponentProps['withDefaultActions'];
42+
esqlVariables?: ESQLControlVariable[];
4143
}
4244

4345
export function Histogram({
@@ -56,6 +58,7 @@ export function Histogram({
5658
onBrushEnd,
5759
withDefaultActions,
5860
abortController,
61+
esqlVariables,
5962
}: HistogramProps) {
6063
const { timeRangeText, timeRangeDisplay } = useTimeRange({
6164
uiSettings,
@@ -98,7 +101,6 @@ export function Histogram({
98101
transform: translate(-50%, -50%);
99102
}
100103
`;
101-
102104
return (
103105
<>
104106
<div
@@ -119,6 +121,7 @@ export function Histogram({
119121
onFilter={onFilter}
120122
onBrushEnd={onBrushEnd}
121123
withDefaultActions={withDefaultActions}
124+
esqlVariables={esqlVariables}
122125
/>
123126
</div>
124127
{timeRangeDisplay}

src/platform/packages/shared/kbn-unified-histogram/hooks/use_unified_histogram.test.tsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
*/
99

1010
import { RequestAdapter } from '@kbn/inspector-plugin/common';
11+
import type { ESQLControlVariable } from '@kbn/esql-types';
1112
import { act } from 'react-dom/test-utils';
1213
import { dataViewWithTimefieldMock } from '../__mocks__/data_view_with_timefield';
1314
import { unifiedHistogramServicesMock } from '../__mocks__/services';
@@ -26,6 +27,13 @@ describe('useUnifiedHistogram', () => {
2627
requestAdapter: new RequestAdapter(),
2728
searchSessionId: '123',
2829
timeRange: { from: 'now-15m', to: 'now' },
30+
esqlVariables: [
31+
{
32+
key: 'agent_keyword',
33+
value: 'Mozilla/5.0 (X11; Linux x86_64; rv:6.0a1) Gecko/20110421 Firefox/6.0a1',
34+
type: 'values',
35+
},
36+
] as ESQLControlVariable[],
2937
})
3038
);
3139
expect(hook.result.current.isInitialized).toBe(false);
@@ -37,6 +45,13 @@ describe('useUnifiedHistogram', () => {
3745
});
3846
expect(hook.result.current.api).toBeDefined();
3947
expect(hook.result.current.chartProps?.chart?.timeInterval).toBe('42s');
48+
expect(hook.result.current.chartProps?.esqlVariables).toEqual([
49+
{
50+
key: 'agent_keyword',
51+
value: 'Mozilla/5.0 (X11; Linux x86_64; rv:6.0a1) Gecko/20110421 Firefox/6.0a1',
52+
type: 'values',
53+
},
54+
]);
4055
expect(hook.result.current.layoutProps).toBeDefined();
4156
});
4257

src/platform/packages/shared/kbn-unified-histogram/hooks/use_unified_histogram.ts

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { useEffect, useMemo, useState } from 'react';
1818
import type { Observable } from 'rxjs';
1919
import { of } from 'rxjs';
2020
import useMount from 'react-use/lib/useMount';
21+
import type { ESQLControlVariable } from '@kbn/esql-types';
2122
import { cloneDeep } from 'lodash';
2223
import type { DataView } from '@kbn/data-views-plugin/common';
2324
import useObservable from 'react-use/lib/useObservable';
@@ -73,6 +74,10 @@ export type UseUnifiedHistogramProps = Omit<UnifiedHistogramStateOptions, 'servi
7374
* The current breakdown field
7475
*/
7576
breakdownField?: string;
77+
/**
78+
* The ES|QL variables to use for the chart
79+
*/
80+
esqlVariables?: ESQLControlVariable[];
7681
/**
7782
* The external custom Lens vis
7883
*/
@@ -172,8 +177,16 @@ export const useUnifiedHistogram = (props: UseUnifiedHistogramProps): UseUnified
172177
setLensVisService(new LensVisService({ services, lensSuggestionsApi: apiHelper.suggestions }));
173178
});
174179

175-
const { services, dataView, columns, isChartLoading, timeRange, table, externalVisContext } =
176-
props;
180+
const {
181+
services,
182+
dataView,
183+
columns,
184+
isChartLoading,
185+
timeRange,
186+
table,
187+
externalVisContext,
188+
esqlVariables,
189+
} = props;
177190

178191
const columnsMap = useMemo(() => {
179192
return columns?.reduce<Record<string, DatatableColumn>>((acc, column) => {
@@ -246,14 +259,24 @@ export const useUnifiedHistogram = (props: UseUnifiedHistogramProps): UseUnified
246259
? {
247260
...props,
248261
...stateProps,
262+
esqlVariables,
249263
input$,
250264
chart,
251265
isChartAvailable,
252266
requestParams,
253267
lensVisService,
254268
}
255269
: undefined;
256-
}, [chart, input$, isChartAvailable, lensVisService, props, requestParams, stateProps]);
270+
}, [
271+
chart,
272+
input$,
273+
isChartAvailable,
274+
lensVisService,
275+
props,
276+
requestParams,
277+
stateProps,
278+
esqlVariables,
279+
]);
257280
const layoutProps = useMemo<UnifiedHistogramPartialLayoutProps>(
258281
() => ({
259282
chart,

src/platform/packages/shared/kbn-unified-histogram/tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
"@kbn/visualizations-plugin",
3535
"@kbn/kibana-utils-plugin",
3636
"@kbn/lens-embeddable-utils",
37+
"@kbn/esql-types",
3738
"@kbn/data-views-plugin"
3839
]
3940
}

src/platform/plugins/shared/controls/public/control_group/components/floating_actions.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ export const FloatingActions: FC<FloatingActionsProps> = ({
133133
}`}
134134
className={classNames(
135135
'presentationUtil__floatingActions',
136+
'controlFrameFloatingActions',
136137
`controlFrameFloatingActions--${isTwoLine ? 'twoLine' : 'oneLine'}`,
137138
className
138139
)}

src/platform/plugins/shared/discover/kibana.jsonc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@
5757
"kibanaUtils",
5858
"kibanaReact",
5959
"unifiedSearch",
60-
"savedObjects"
60+
"savedObjects",
61+
"controls",
6162
],
6263
"extraPublicDirs": [
6364
"common"
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the "Elastic License
4+
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
5+
* Public License v 1"; you may not use this file except in compliance with, at
6+
* your election, the "Elastic License 2.0", the "GNU Affero General Public
7+
* License v3.0 only", or the "Server Side Public License, v 1".
8+
*/
9+
10+
import type { ControlPanelsState } from '@kbn/controls-plugin/public';
11+
import type { ESQLControlState, ESQLVariableType, EsqlControlType } from '@kbn/esql-types';
12+
13+
export const mockControlState: ControlPanelsState<ESQLControlState> = {
14+
panel1: {
15+
type: 'esqlControl',
16+
availableOptions: ['bar', 'baz'],
17+
variableType: 'values' as ESQLVariableType,
18+
variableName: 'foo',
19+
title: 'Panel 1',
20+
selectedOptions: ['bar'],
21+
esqlQuery: '',
22+
controlType: 'STATIC_VALUES' as EsqlControlType,
23+
order: 0,
24+
},
25+
};

0 commit comments

Comments
 (0)