Skip to content
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 21 additions & 50 deletions src/platform/packages/private/kbn-esql-editor/src/esql_editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -309,56 +309,27 @@ const ESQLEditorInternal = function ESQLEditor({
openTimePickerPopover();
});

monaco.editor.registerCommand('esql.control.time_literal.create', async (...args) => {
const position = editor1.current?.getPosition();
await triggerControl(
fixedQuery,
ESQLVariableType.TIME_LITERAL,
position,
uiActions,
esqlVariables,
controlsContext?.onSaveControl,
controlsContext?.onCancelControl
);
});

monaco.editor.registerCommand('esql.control.fields.create', async (...args) => {
const position = editor1.current?.getPosition();
await triggerControl(
fixedQuery,
ESQLVariableType.FIELDS,
position,
uiActions,
esqlVariables,
controlsContext?.onSaveControl,
controlsContext?.onCancelControl
);
});

monaco.editor.registerCommand('esql.control.values.create', async (...args) => {
const position = editor1.current?.getPosition();
await triggerControl(
fixedQuery,
ESQLVariableType.VALUES,
position,
uiActions,
esqlVariables,
controlsContext?.onSaveControl,
controlsContext?.onCancelControl
);
});

monaco.editor.registerCommand('esql.control.functions.create', async (...args) => {
const position = editor1.current?.getPosition();
await triggerControl(
fixedQuery,
ESQLVariableType.FUNCTIONS,
position,
uiActions,
esqlVariables,
controlsContext?.onSaveControl,
controlsContext?.onCancelControl
);
const controlCommands = [
{ command: 'esql.control.multi_values.create', variableType: ESQLVariableType.MULTI_VALUES },
{ command: 'esql.control.time_literal.create', variableType: ESQLVariableType.TIME_LITERAL },
{ command: 'esql.control.fields.create', variableType: ESQLVariableType.FIELDS },
{ command: 'esql.control.values.create', variableType: ESQLVariableType.VALUES },
{ command: 'esql.control.functions.create', variableType: ESQLVariableType.FUNCTIONS },
];

controlCommands.forEach(({ command, variableType }) => {
monaco.editor.registerCommand(command, async (...args) => {
const position = editor1.current?.getPosition();
await triggerControl(
fixedQuery,
variableType,
position,
uiActions,
esqlVariables,
controlsContext?.onSaveControl,
controlsContext?.onCancelControl
);
});
});

editor1.current?.addCommand(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,7 @@ export const getDocLinks = ({ kibanaBranch, buildFlavor }: GetDocLinkOptions): D
queryDsl: `${ELASTIC_DOCS}explore-analyze/query-filter/languages/querydsl`,
queryESQL: `${ELASTIC_DOCS}explore-analyze/query-filter/languages/esql`,
queryESQLExamples: `${ELASTIC_DOCS}explore-analyze/query-filter/languages/esql`,
queryESQLMultiValueControls: `${ELASTIC_DOCS}explore-analyze/dashboards/add-controls#add-esql-control`,
},
search: {
sessions: `${ELASTIC_DOCS}explore-analyze/discover/search-sessions`,
Expand Down
1 change: 1 addition & 0 deletions src/platform/packages/shared/kbn-doc-links/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,7 @@ export interface DocLinks {
readonly queryDsl: string;
readonly queryESQL: string;
readonly queryESQLExamples: string;
readonly queryESQLMultiValueControls: string;
};
readonly date: {
readonly dateMath: string;
Expand Down
7 changes: 6 additions & 1 deletion src/platform/packages/shared/kbn-es-types/src/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -686,5 +686,10 @@ export interface ESQLSearchParams {
dropNullColumns?: boolean;
params?:
| estypes.ScalarValue[]
| Array<Record<string, string | number | Record<string, string | number> | undefined>>;
| Array<
Record<
string,
string | number | (string | number)[] | Record<string, string | number> | undefined
>
>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,12 @@ export function enrichFunctionParameters(functionDefinition: FunctionDefinition)
});
}

if (functionDefinition.name === 'mv_contains') {
return enrichFunctionSignatures(functionDefinition, 'superset', {
supportsMultiValues: true,
});
}

if (functionDefinition.name === 'qstr') {
return {
...functionDefinition,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7435,6 +7435,7 @@ const mvContainsDefinition: FunctionDefinition = {
name: 'superset',
type: 'boolean',
optional: false,
supportsMultiValues: true,
},
{
name: 'subset',
Expand All @@ -7450,6 +7451,7 @@ const mvContainsDefinition: FunctionDefinition = {
name: 'superset',
type: 'cartesian_point',
optional: false,
supportsMultiValues: true,
},
{
name: 'subset',
Expand All @@ -7465,6 +7467,7 @@ const mvContainsDefinition: FunctionDefinition = {
name: 'superset',
type: 'cartesian_shape',
optional: false,
supportsMultiValues: true,
},
{
name: 'subset',
Expand All @@ -7480,6 +7483,7 @@ const mvContainsDefinition: FunctionDefinition = {
name: 'superset',
type: 'date',
optional: false,
supportsMultiValues: true,
},
{
name: 'subset',
Expand All @@ -7495,6 +7499,7 @@ const mvContainsDefinition: FunctionDefinition = {
name: 'superset',
type: 'date_nanos',
optional: false,
supportsMultiValues: true,
},
{
name: 'subset',
Expand All @@ -7510,6 +7515,7 @@ const mvContainsDefinition: FunctionDefinition = {
name: 'superset',
type: 'double',
optional: false,
supportsMultiValues: true,
},
{
name: 'subset',
Expand All @@ -7525,6 +7531,7 @@ const mvContainsDefinition: FunctionDefinition = {
name: 'superset',
type: 'geo_point',
optional: false,
supportsMultiValues: true,
},
{
name: 'subset',
Expand All @@ -7540,6 +7547,7 @@ const mvContainsDefinition: FunctionDefinition = {
name: 'superset',
type: 'geo_shape',
optional: false,
supportsMultiValues: true,
},
{
name: 'subset',
Expand All @@ -7555,6 +7563,7 @@ const mvContainsDefinition: FunctionDefinition = {
name: 'superset',
type: 'geohash',
optional: false,
supportsMultiValues: true,
},
{
name: 'subset',
Expand All @@ -7570,6 +7579,7 @@ const mvContainsDefinition: FunctionDefinition = {
name: 'superset',
type: 'geohex',
optional: false,
supportsMultiValues: true,
},
{
name: 'subset',
Expand All @@ -7585,6 +7595,7 @@ const mvContainsDefinition: FunctionDefinition = {
name: 'superset',
type: 'geotile',
optional: false,
supportsMultiValues: true,
},
{
name: 'subset',
Expand All @@ -7600,6 +7611,7 @@ const mvContainsDefinition: FunctionDefinition = {
name: 'superset',
type: 'integer',
optional: false,
supportsMultiValues: true,
},
{
name: 'subset',
Expand All @@ -7615,6 +7627,7 @@ const mvContainsDefinition: FunctionDefinition = {
name: 'superset',
type: 'ip',
optional: false,
supportsMultiValues: true,
},
{
name: 'subset',
Expand All @@ -7630,6 +7643,7 @@ const mvContainsDefinition: FunctionDefinition = {
name: 'superset',
type: 'keyword',
optional: false,
supportsMultiValues: true,
},
{
name: 'subset',
Expand All @@ -7645,6 +7659,7 @@ const mvContainsDefinition: FunctionDefinition = {
name: 'superset',
type: 'keyword',
optional: false,
supportsMultiValues: true,
},
{
name: 'subset',
Expand All @@ -7660,6 +7675,7 @@ const mvContainsDefinition: FunctionDefinition = {
name: 'superset',
type: 'long',
optional: false,
supportsMultiValues: true,
},
{
name: 'subset',
Expand All @@ -7675,6 +7691,7 @@ const mvContainsDefinition: FunctionDefinition = {
name: 'superset',
type: 'text',
optional: false,
supportsMultiValues: true,
},
{
name: 'subset',
Expand All @@ -7690,6 +7707,7 @@ const mvContainsDefinition: FunctionDefinition = {
name: 'superset',
type: 'text',
optional: false,
supportsMultiValues: true,
},
{
name: 'subset',
Expand All @@ -7705,6 +7723,7 @@ const mvContainsDefinition: FunctionDefinition = {
name: 'superset',
type: 'unsigned_long',
optional: false,
supportsMultiValues: true,
},
{
name: 'subset',
Expand All @@ -7720,6 +7739,7 @@ const mvContainsDefinition: FunctionDefinition = {
name: 'superset',
type: 'version',
optional: false,
supportsMultiValues: true,
},
{
name: 'subset',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,11 @@ export interface FunctionParameter {
suggestedValues?: string[];

mapParams?: string;

/** If true, this parameter supports multiple values (arrays). Default is false.
* This indicates that the parameter can accept multiple values, which will be passed as an array.
*/
supportsMultiValues?: boolean;
}

export interface ElasticsearchCommandDefinition {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import type { LicenseType } from '@kbn/licensing-types';

import { uniq } from 'lodash';
import type { PricingProduct } from '@kbn/core-pricing-common/src/types';
import { ESQLVariableType } from '@kbn/esql-types';
import { getLocationInfo } from '../../../commands_registry/location';
import {
isAssignment,
Expand Down Expand Up @@ -190,6 +191,10 @@ export async function getFunctionArgsSuggestions(
// If the type is explicitly a boolean condition
typesToSuggestNext.some((t) => t && t.type === 'boolean' && t.name === 'condition');

const canBeMultiValue = typesToSuggestNext.some(
(t) => t && (t.supportsMultiValues === true || t.name === 'values')
);

const shouldAddComma =
hasMoreMandatoryArgs &&
fnDefinition.type !== FunctionDefinitionTypes.OPERATOR &&
Expand Down Expand Up @@ -334,6 +339,7 @@ export async function getFunctionArgsSuggestions(
addComma: shouldAddComma,
advanceCursor: shouldAdvanceCursor,
openSuggestions: shouldAdvanceCursor,
...(canBeMultiValue && { variableType: ESQLVariableType.MULTI_VALUES }),
}
),
true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,7 @@ export const buildColumnSuggestions = (
addComma?: boolean;
variableType?: ESQLVariableType;
supportsControls?: boolean;
supportsMultiValue?: boolean;
},
variables?: ESQLControlVariable[]
): ISuggestionItem[] => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export enum ESQLVariableType {
TIME_LITERAL = 'time_literal',
FIELDS = 'fields',
VALUES = 'values',
MULTI_VALUES = 'multi_values',
FUNCTIONS = 'functions',
}

Expand All @@ -35,7 +36,7 @@ export enum EsqlControlType {

export interface ESQLControlVariable {
key: string;
value: string | number;
value: string | number | (string | number)[];
type: ESQLVariableType;
}

Expand All @@ -48,6 +49,7 @@ export type ControlWidthOptions = 'small' | 'medium' | 'large';
export interface ESQLControlState {
grow?: boolean;
width?: ControlWidthOptions;
singleSelect?: boolean;
title: string;
selectedOptions: string[];
variableName: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,39 @@ describe('autocomplete.suggest', () => {
});
});

test('suggests `?multiValue` option', async () => {
const { suggest } = await setup();

const suggestions = await suggest('FROM index_a | WHERE MV_CONTAINS(/', {
callbacks: {
canSuggestVariables: () => true,
getVariables: () => [
{
key: 'interval',
value: '1 hour',
type: ESQLVariableType.TIME_LITERAL,
},
{
key: 'multiValue',
value: ['value1', 'value2'],
type: ESQLVariableType.MULTI_VALUES,
},
],
getColumnsFor: () =>
Promise.resolve([{ name: '@timestamp', type: 'date', userDefined: false }]),
},
});

expect(suggestions).toContainEqual({
label: '?multiValue',
text: '?multiValue',
kind: 'Constant',
detail: 'Named parameter',
command: undefined,
sortText: '11A',
});
});

test('suggests `Create control` option when ? is being typed', async () => {
const { suggest } = await setup();

Expand Down
Loading