forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[8.x] [ES|QL] Recommended queries (elastic#194418) (elastic#195442)
# Backport This will backport the following commits from `main` to `8.x`: - [[ES|QL] Recommended queries (elastic#194418)](elastic#194418) <!--- 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-10-08T14:52:21Z","message":"[ES|QL] Recommended queries (elastic#194418)\n\n## Summary\r\n\r\nCloses https://github.com/elastic/kibana/issues/187325\r\n\r\n<img width=\"927\" alt=\"image\"\r\nsrc=\"https://github.com/user-attachments/assets/46220c26-f54c-4bd7-9a8b-d1d29591dc68\">\r\n\r\n<img width=\"539\" alt=\"image\"\r\nsrc=\"https://github.com/user-attachments/assets/f4d938af-f2b6-400d-918f-3dcf1d22618f\">\r\n\r\n\r\nThis is the first iteration of this feature. We want to help the users\r\nfamiliarize themselves with popular operations. This PR:\r\n- adds the recommended queries list in the help menu of unified search\r\n- adds the list after the users select a datasource with the from\r\ncommand\r\n- adds the list in the editor's empty state\r\n\r\n### Checklist\r\n\r\n- [ ]\r\n[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\r\nwas added for features that require explanation or tutorials\r\n- [ ] [Unit or functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere updated or added to match the most common scenarios","sha":"149e801109d7c9edf2d6eef41ebb0e281314a19f","branchLabelMapping":{"^v9.0.0$":"main","^v8.16.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["v9.0.0","release_note:feature","backport:prev-minor","Feature:ES|QL","Team:ESQL","v8.16.0"],"title":"[ES|QL] Recommended queries","number":194418,"url":"https://github.com/elastic/kibana/pull/194418","mergeCommit":{"message":"[ES|QL] Recommended queries (elastic#194418)\n\n## Summary\r\n\r\nCloses https://github.com/elastic/kibana/issues/187325\r\n\r\n<img width=\"927\" alt=\"image\"\r\nsrc=\"https://github.com/user-attachments/assets/46220c26-f54c-4bd7-9a8b-d1d29591dc68\">\r\n\r\n<img width=\"539\" alt=\"image\"\r\nsrc=\"https://github.com/user-attachments/assets/f4d938af-f2b6-400d-918f-3dcf1d22618f\">\r\n\r\n\r\nThis is the first iteration of this feature. We want to help the users\r\nfamiliarize themselves with popular operations. This PR:\r\n- adds the recommended queries list in the help menu of unified search\r\n- adds the list after the users select a datasource with the from\r\ncommand\r\n- adds the list in the editor's empty state\r\n\r\n### Checklist\r\n\r\n- [ ]\r\n[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\r\nwas added for features that require explanation or tutorials\r\n- [ ] [Unit or functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere updated or added to match the most common scenarios","sha":"149e801109d7c9edf2d6eef41ebb0e281314a19f"}},"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/194418","number":194418,"mergeCommit":{"message":"[ES|QL] Recommended queries (elastic#194418)\n\n## Summary\r\n\r\nCloses https://github.com/elastic/kibana/issues/187325\r\n\r\n<img width=\"927\" alt=\"image\"\r\nsrc=\"https://github.com/user-attachments/assets/46220c26-f54c-4bd7-9a8b-d1d29591dc68\">\r\n\r\n<img width=\"539\" alt=\"image\"\r\nsrc=\"https://github.com/user-attachments/assets/f4d938af-f2b6-400d-918f-3dcf1d22618f\">\r\n\r\n\r\nThis is the first iteration of this feature. We want to help the users\r\nfamiliarize themselves with popular operations. This PR:\r\n- adds the recommended queries list in the help menu of unified search\r\n- adds the list after the users select a datasource with the from\r\ncommand\r\n- adds the list in the editor's empty state\r\n\r\n### Checklist\r\n\r\n- [ ]\r\n[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\r\nwas added for features that require explanation or tutorials\r\n- [ ] [Unit or functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere updated or added to match the most common scenarios","sha":"149e801109d7c9edf2d6eef41ebb0e281314a19f"}},{"branch":"8.x","label":"v8.16.0","branchLabelMappingKey":"^v8.16.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}] BACKPORT--> Co-authored-by: Stratoula Kalafateli <[email protected]>
- Loading branch information
1 parent
9bd5789
commit ba2ecd5
Showing
16 changed files
with
424 additions
and
122 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
...ages/kbn-esql-validation-autocomplete/src/autocomplete/recommended_queries/suggestions.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the "Elastic License | ||
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
* Public License v 1"; you may not use this file except in compliance with, at | ||
* your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
* License v3.0 only", or the "Server Side Public License, v 1". | ||
*/ | ||
|
||
import type { SuggestionRawDefinition, GetFieldsByTypeFn } from '../types'; | ||
import { getRecommendedQueries } from './templates'; | ||
|
||
export const getRecommendedQueriesSuggestions = async ( | ||
getFieldsByType: GetFieldsByTypeFn, | ||
fromCommand: string = '' | ||
): Promise<SuggestionRawDefinition[]> => { | ||
const fieldSuggestions = await getFieldsByType('date', [], { | ||
openSuggestions: true, | ||
}); | ||
let timeField = ''; | ||
if (fieldSuggestions.length) { | ||
timeField = | ||
fieldSuggestions?.find((field) => field.label === '@timestamp')?.label || | ||
fieldSuggestions[0].label; | ||
} | ||
|
||
const recommendedQueries = getRecommendedQueries({ fromCommand, timeField }); | ||
|
||
const suggestions: SuggestionRawDefinition[] = recommendedQueries.map((query) => { | ||
return { | ||
label: query.label, | ||
text: query.queryString, | ||
kind: 'Issue', | ||
detail: query.description, | ||
sortText: 'D', | ||
}; | ||
}); | ||
|
||
return suggestions; | ||
}; |
Oops, something went wrong.