Skip to content

Commit

Permalink
Fix running recent query button (opensearch-project#8252) (opensearch…
Browse files Browse the repository at this point in the history
…-project#8280)

* Fix click on recent query switching language



* change to use uuid as identifier



* Changeset file for PR opensearch-project#8252 created/updated

---------



(cherry picked from commit 2f36eaf)

Signed-off-by: abbyhu2000 <[email protected]>
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: opensearch-changeset-bot[bot] <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored and SuZhou-Joe committed Oct 3, 2024
1 parent 6902000 commit 13d59c8
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 3 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/8252.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
fix:
- Run recent query button work properly ([#8252](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/8252))
Original file line number Diff line number Diff line change
Expand Up @@ -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',
},
Expand All @@ -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'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
import { EditorInstance } from '../../../ui/query_editor/editors';

export interface RecentQueryItem {
id: number;
query: Query;
time: number;
timeRange?: TimeRange;
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/data/public/query/query_string/query_history.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 '../..';
Expand Down Expand Up @@ -61,6 +62,7 @@ export class QueryHistory {
time: timestamp,
query,
dateRange,
id: uuid.v4(),
};
this.storage.set(newKey, newItem);

Expand Down

0 comments on commit 13d59c8

Please sign in to comment.