Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -336,56 +336,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 @@ -511,6 +511,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/query-filter/languages/esql-kibana#esql-multi-values-controls`,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just an anchor now. Florent will release the updated docs in the next serverless release

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For traceability, this is the PR that will add the docs (and that link will then lead to corresponding content) elastic/docs-content#3529

It'll be merged on release day

},
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 @@ -368,6 +368,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 @@ -7582,6 +7582,7 @@ const mvContainsDefinition: FunctionDefinition = {
name: 'superset',
type: 'boolean',
optional: false,
supportsMultiValues: true,
},
{
name: 'subset',
Expand All @@ -7597,6 +7598,7 @@ const mvContainsDefinition: FunctionDefinition = {
name: 'superset',
type: 'cartesian_point',
optional: false,
supportsMultiValues: true,
},
{
name: 'subset',
Expand All @@ -7612,6 +7614,7 @@ const mvContainsDefinition: FunctionDefinition = {
name: 'superset',
type: 'cartesian_shape',
optional: false,
supportsMultiValues: true,
},
{
name: 'subset',
Expand All @@ -7627,6 +7630,7 @@ const mvContainsDefinition: FunctionDefinition = {
name: 'superset',
type: 'date',
optional: false,
supportsMultiValues: true,
},
{
name: 'subset',
Expand All @@ -7642,6 +7646,7 @@ const mvContainsDefinition: FunctionDefinition = {
name: 'superset',
type: 'date_nanos',
optional: false,
supportsMultiValues: true,
},
{
name: 'subset',
Expand All @@ -7657,6 +7662,7 @@ const mvContainsDefinition: FunctionDefinition = {
name: 'superset',
type: 'double',
optional: false,
supportsMultiValues: true,
},
{
name: 'subset',
Expand All @@ -7672,6 +7678,7 @@ const mvContainsDefinition: FunctionDefinition = {
name: 'superset',
type: 'geo_point',
optional: false,
supportsMultiValues: true,
},
{
name: 'subset',
Expand All @@ -7687,6 +7694,7 @@ const mvContainsDefinition: FunctionDefinition = {
name: 'superset',
type: 'geo_shape',
optional: false,
supportsMultiValues: true,
},
{
name: 'subset',
Expand All @@ -7702,6 +7710,7 @@ const mvContainsDefinition: FunctionDefinition = {
name: 'superset',
type: 'geohash',
optional: false,
supportsMultiValues: true,
},
{
name: 'subset',
Expand All @@ -7717,6 +7726,7 @@ const mvContainsDefinition: FunctionDefinition = {
name: 'superset',
type: 'geohex',
optional: false,
supportsMultiValues: true,
},
{
name: 'subset',
Expand All @@ -7732,6 +7742,7 @@ const mvContainsDefinition: FunctionDefinition = {
name: 'superset',
type: 'geotile',
optional: false,
supportsMultiValues: true,
},
{
name: 'subset',
Expand All @@ -7747,6 +7758,7 @@ const mvContainsDefinition: FunctionDefinition = {
name: 'superset',
type: 'integer',
optional: false,
supportsMultiValues: true,
},
{
name: 'subset',
Expand All @@ -7762,6 +7774,7 @@ const mvContainsDefinition: FunctionDefinition = {
name: 'superset',
type: 'ip',
optional: false,
supportsMultiValues: true,
},
{
name: 'subset',
Expand All @@ -7777,6 +7790,7 @@ const mvContainsDefinition: FunctionDefinition = {
name: 'superset',
type: 'keyword',
optional: false,
supportsMultiValues: true,
},
{
name: 'subset',
Expand All @@ -7792,6 +7806,7 @@ const mvContainsDefinition: FunctionDefinition = {
name: 'superset',
type: 'keyword',
optional: false,
supportsMultiValues: true,
},
{
name: 'subset',
Expand All @@ -7807,6 +7822,7 @@ const mvContainsDefinition: FunctionDefinition = {
name: 'superset',
type: 'long',
optional: false,
supportsMultiValues: true,
},
{
name: 'subset',
Expand All @@ -7822,6 +7838,7 @@ const mvContainsDefinition: FunctionDefinition = {
name: 'superset',
type: 'text',
optional: false,
supportsMultiValues: true,
},
{
name: 'subset',
Expand All @@ -7837,6 +7854,7 @@ const mvContainsDefinition: FunctionDefinition = {
name: 'superset',
type: 'text',
optional: false,
supportsMultiValues: true,
},
{
name: 'subset',
Expand All @@ -7852,6 +7870,7 @@ const mvContainsDefinition: FunctionDefinition = {
name: 'superset',
type: 'unsigned_long',
optional: false,
supportsMultiValues: true,
},
{
name: 'subset',
Expand All @@ -7867,6 +7886,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 @@ -183,6 +183,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 @@ -206,11 +206,15 @@ async function buildFieldAndFunctionSuggestions(
const hasNonConstantParam = paramDefinitions.some(({ constantOnly }) => !constantOnly);
const isVariadicOrUnknownPosition = paramDefinitions.length === 0;
if (hasNonConstantParam || isVariadicOrUnknownPosition) {
const canBeMultiValue = paramDefinitions.some(
(t) => t && (t.supportsMultiValues === true || t.name === 'values')
);
await builder.addFields({
types: config.acceptedTypes,
ignoredColumns,
addComma: config.shouldAddComma,
promoteToTop: true,
canBeMultiValue,
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export class SuggestionBuilder {
promoteToTop?: boolean;
openSuggestions?: boolean;
values?: boolean;
canBeMultiValue?: boolean;
}): Promise<this> {
const types = options?.types ?? ['any'];
const addComma = options?.addComma ?? false;
Expand All @@ -40,6 +41,7 @@ export class SuggestionBuilder {
const ignoredColumns = options?.ignoredColumns ?? [];
const openSuggestions = options?.openSuggestions ?? (addSpaceAfterField || addComma);
const values = options?.values;
const canBeMultiValue = options?.canBeMultiValue ?? false;

const getByType = this.context.callbacks?.getByType ?? (() => Promise.resolve([]));

Expand All @@ -50,6 +52,7 @@ export class SuggestionBuilder {
addComma,
promoteToTop,
values,
canBeMultiValue,
});

this.suggestions.push(...fieldSuggestions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ interface FieldSuggestionsOptions {
openSuggestions?: boolean;
addComma?: boolean;
promoteToTop?: boolean;
canBeMultiValue?: boolean;
}

export async function getFieldsSuggestions(
Expand All @@ -156,13 +157,20 @@ export async function getFieldsSuggestions(
openSuggestions = false,
addComma = false,
promoteToTop = true,
canBeMultiValue = false,
} = options;

const variableType = (() => {
if (canBeMultiValue) return ESQLVariableType.MULTI_VALUES;
if (values) return ESQLVariableType.VALUES;
return ESQLVariableType.FIELDS;
})();

const suggestions = await getFieldsByType(types, ignoreColumns, {
advanceCursor: addSpaceAfterField,
openSuggestions,
addComma,
variableType: values ? ESQLVariableType.VALUES : ESQLVariableType.FIELDS,
variableType,
});

return pushItUpInTheList(suggestions as ISuggestionItem[], promoteToTop);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,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
Loading