From c4a4b88328351ca8d5116a45c63d72d13d8aec0d Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Fri, 20 Sep 2024 23:32:11 +0000 Subject: [PATCH] Fix running recent query button (#8252) * Fix click on recent query switching language Signed-off-by: abbyhu2000 * change to use uuid as identifier Signed-off-by: abbyhu2000 * Changeset file for PR #8252 created/updated --------- Signed-off-by: abbyhu2000 Co-authored-by: opensearch-changeset-bot[bot] <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com> (cherry picked from commit 2f36eaf6d6d3fa2aa3343f1e5c9e298b286ec030) Signed-off-by: github-actions[bot] --- changelogs/fragments/8252.yml | 2 ++ .../query_string/language_service/lib/recent_query.tsx | 9 ++++++--- .../public/query/query_string/language_service/types.ts | 1 + .../data/public/query/query_string/query_history.ts | 2 ++ 4 files changed, 11 insertions(+), 3 deletions(-) create mode 100644 changelogs/fragments/8252.yml diff --git a/changelogs/fragments/8252.yml b/changelogs/fragments/8252.yml new file mode 100644 index 000000000000..f612ecc2b2f8 --- /dev/null +++ b/changelogs/fragments/8252.yml @@ -0,0 +1,2 @@ +fix: +- Run recent query button work properly ([#8252](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/8252)) \ No newline at end of file diff --git a/src/plugins/data/public/query/query_string/language_service/lib/recent_query.tsx b/src/plugins/data/public/query/query_string/language_service/lib/recent_query.tsx index 2e3fdb7f55aa..0b58f0413966 100644 --- a/src/plugins/data/public/query/query_string/language_service/lib/recent_query.tsx +++ b/src/plugins/data/public/query/query_string/language_service/lib/recent_query.tsx @@ -51,7 +51,10 @@ export function RecentQueriesTable({ icon: 'play', type: 'icon', onClick: (item: RecentQueryTableItem) => { - onClickRecentQuery(recentQueries[item.id].query, recentQueries[item.id].timeRange); + onClickRecentQuery( + recentQueries.find((recentQuery) => recentQuery.id === item.id)?.query!, + recentQueries.find((recentQuery) => recentQuery.id === item.id)?.timeRange + ); }, 'data-test-subj': 'action-run', }, @@ -76,8 +79,8 @@ export function RecentQueriesTable({ const recentQueryItems: RecentQueryTableItem[] = recentQueries .filter((item, idx) => idx < MAX_RECENT_QUERY_SIZE) .filter((item) => item.query.language === currentLanguage) - .map((query, idx) => ({ - id: idx, + .map((query) => ({ + id: query.id, query: query.query.query, timeRange: query.timeRange, time: moment(query.time).format('MMM D, YYYY HH:mm:ss'), diff --git a/src/plugins/data/public/query/query_string/language_service/types.ts b/src/plugins/data/public/query/query_string/language_service/types.ts index e82e12f95ec9..dff25464db08 100644 --- a/src/plugins/data/public/query/query_string/language_service/types.ts +++ b/src/plugins/data/public/query/query_string/language_service/types.ts @@ -13,6 +13,7 @@ import { import { EditorInstance } from '../../../ui/query_editor/editors'; export interface RecentQueryItem { + id: number; query: Query; time: number; timeRange?: TimeRange; diff --git a/src/plugins/data/public/query/query_string/query_history.ts b/src/plugins/data/public/query/query_string/query_history.ts index 277287ee09d8..48dbf3511744 100644 --- a/src/plugins/data/public/query/query_string/query_history.ts +++ b/src/plugins/data/public/query/query_string/query_history.ts @@ -3,6 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ +import uuid from 'uuid'; import { BehaviorSubject } from 'rxjs'; import { DataStorage } from '../../../common'; import { Query, TimeRange } from '../..'; @@ -61,6 +62,7 @@ export class QueryHistory { time: timestamp, query, dateRange, + id: uuid.v4(), }; this.storage.set(newKey, newItem);