Skip to content

Commit

Permalink
[8.x] [ES|QL] Make sure that the commands are not overwritten (#204711)…
Browse files Browse the repository at this point in the history
… (#204904)

# Backport

This will backport the following commits from `main` to `8.x`:
- [[ES|QL] Make sure that the commands are not overwritten
(#204711)](#204711)

<!--- Backport version: 9.4.3 -->

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

<!--BACKPORT [{"author":{"name":"Stratoula
Kalafateli","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-12-19T10:16:21Z","message":"[ES|QL]
Make sure that the commands are not overwritten
(#204711)","sha":"76e22f7cbdd1ad1b73ad1d68ec9f0fb835bb44bd","branchLabelMapping":{"^v9.0.0$":"main","^v8.18.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","v9.0.0","Feature:ES|QL","Team:ESQL","backport:version","v8.18.0"],"title":"[ES|QL]
Make sure that the commands are not
overwritten","number":204711,"url":"https://github.com/elastic/kibana/pull/204711","mergeCommit":{"message":"[ES|QL]
Make sure that the commands are not overwritten
(#204711)","sha":"76e22f7cbdd1ad1b73ad1d68ec9f0fb835bb44bd"}},"sourceBranch":"main","suggestedTargetBranches":["8.x"],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/204711","number":204711,"mergeCommit":{"message":"[ES|QL]
Make sure that the commands are not overwritten
(#204711)","sha":"76e22f7cbdd1ad1b73ad1d68ec9f0fb835bb44bd"}},{"branch":"8.x","label":"v8.18.0","branchLabelMappingKey":"^v8.18.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Stratoula Kalafateli <[email protected]>
  • Loading branch information
kibanamachine and stratoula authored Dec 19, 2024
1 parent 129f515 commit f1e12df
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -612,22 +612,30 @@ async function getExpressionSuggestionsByType(
(fragment) => Boolean(getColumnByName(fragment, references)),
(_fragment: string, rangeToReplace?: { start: number; end: number }) => {
// COMMAND fie<suggest>
return fieldSuggestions.map((suggestion) => ({
...suggestion,
text: suggestion.text + (['grok', 'dissect'].includes(command.name) ? ' ' : ''),
command: TRIGGER_SUGGESTION_COMMAND,
rangeToReplace,
}));
return fieldSuggestions.map((suggestion) => {
// if there is already a command, we don't want to override it
if (suggestion.command) return suggestion;
return {
...suggestion,
text: suggestion.text + (['grok', 'dissect'].includes(command.name) ? ' ' : ''),
command: TRIGGER_SUGGESTION_COMMAND,
rangeToReplace,
};
});
},
(fragment: string, rangeToReplace: { start: number; end: number }) => {
// COMMAND field<suggest>
if (['grok', 'dissect'].includes(command.name)) {
return fieldSuggestions.map((suggestion) => ({
...suggestion,
text: suggestion.text + ' ',
command: TRIGGER_SUGGESTION_COMMAND,
rangeToReplace,
}));
return fieldSuggestions.map((suggestion) => {
// if there is already a command, we don't want to override it
if (suggestion.command) return suggestion;
return {
...suggestion,
text: suggestion.text + ' ',
command: TRIGGER_SUGGESTION_COMMAND,
rangeToReplace,
};
});
}

const finalSuggestions = [{ ...pipeCompleteItem, text: ' | ' }];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,16 @@ export async function suggest(
(fragment) => columnExists(fragment),
(_fragment: string, rangeToReplace?: { start: number; end: number }) => {
// KEEP fie<suggest>
return fieldSuggestions.map((suggestion) => ({
...suggestion,
text: suggestion.text,
command: TRIGGER_SUGGESTION_COMMAND,
rangeToReplace,
}));
return fieldSuggestions.map((suggestion) => {
// if there is already a command, we don't want to override it
if (suggestion.command) return suggestion;
return {
...suggestion,
text: suggestion.text,
command: TRIGGER_SUGGESTION_COMMAND,
rangeToReplace,
};
});
},
(fragment: string, rangeToReplace: { start: number; end: number }) => {
// KEEP field<suggest>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,16 @@ export async function suggest(
(fragment) => columnExists(fragment),
(_fragment: string, rangeToReplace?: { start: number; end: number }) => {
// KEEP fie<suggest>
return fieldSuggestions.map((suggestion) => ({
...suggestion,
text: suggestion.text,
command: TRIGGER_SUGGESTION_COMMAND,
rangeToReplace,
}));
return fieldSuggestions.map((suggestion) => {
// if there is already a command, we don't want to override it
if (suggestion.command) return suggestion;
return {
...suggestion,
text: suggestion.text,
command: TRIGGER_SUGGESTION_COMMAND,
rangeToReplace,
};
});
},
(fragment: string, rangeToReplace: { start: number; end: number }) => {
// KEEP field<suggest>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,15 @@ export async function suggest(
// SORT fie<suggest>
return [
...pushItUpInTheList(
fieldSuggestions.map((suggestion) => ({
...suggestion,
command: TRIGGER_SUGGESTION_COMMAND,
rangeToReplace,
})),
fieldSuggestions.map((suggestion) => {
// if there is already a command, we don't want to override it
if (suggestion.command) return suggestion;
return {
...suggestion,
command: TRIGGER_SUGGESTION_COMMAND,
rangeToReplace,
};
}),
true
),
...functionSuggestions,
Expand Down

0 comments on commit f1e12df

Please sign in to comment.