From 0b1ad4d52170e7d21fafe9eb749fe858c3e31d47 Mon Sep 17 00:00:00 2001 From: sareyu Date: Fri, 16 Aug 2024 16:56:38 +0300 Subject: [PATCH] fix: proper dispatch action --- src/containers/Tenant/Query/QueryEditor/QueryEditor.tsx | 7 ------- src/store/reducers/executeQuery.ts | 8 +++++--- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/src/containers/Tenant/Query/QueryEditor/QueryEditor.tsx b/src/containers/Tenant/Query/QueryEditor/QueryEditor.tsx index ac21ed2c1..030c1da14 100644 --- a/src/containers/Tenant/Query/QueryEditor/QueryEditor.tsx +++ b/src/containers/Tenant/Query/QueryEditor/QueryEditor.tsx @@ -16,7 +16,6 @@ import { goToPreviousQuery, saveQueryToHistory, setTenantPath, - updateQueryInHistory, } from '../../../../store/reducers/executeQuery'; import {explainQueryApi} from '../../../../store/reducers/explainQuery/explainQuery'; import type {PreparedExplainResponse} from '../../../../store/reducers/explainQuery/types'; @@ -85,7 +84,6 @@ interface QueryEditorProps { showPreview: boolean; setShowPreview: (...args: Parameters) => void; saveQueryToHistory: (...args: Parameters) => void; - updateQueryInHistory: (...args: Parameters) => void; } function QueryEditor(props: QueryEditorProps) { @@ -172,10 +170,6 @@ function QueryEditor(props: QueryEditorProps) { schema, enableTracingLevel, queryId, - }).then((res) => { - if ('data' in res) { - props.updateQueryInHistory(res.data.stats, queryId); - } }); setIsResultLoaded(true); props.setShowPreview(false); @@ -419,7 +413,6 @@ const mapStateToProps = (state: RootState) => { const mapDispatchToProps = { saveQueryToHistory, - updateQueryInHistory, goToPreviousQuery, goToNextQuery, setShowPreview, diff --git a/src/store/reducers/executeQuery.ts b/src/store/reducers/executeQuery.ts index 093eb693e..ea3732cdd 100644 --- a/src/store/reducers/executeQuery.ts +++ b/src/store/reducers/executeQuery.ts @@ -195,7 +195,7 @@ export const executeQueryApi = api.injectEndpoints({ enableTracingLevel, queryId, }, - {signal}, + {signal, dispatch}, ) => { let action: ExecuteActions = 'execute'; let syntax: QuerySyntax = QUERY_SYNTAX.yql; @@ -234,6 +234,8 @@ export const executeQueryApi = api.injectEndpoints({ } const data = parseQueryAPIExecuteResponse(response); + + dispatch(updateQueryInHistory(data.stats, queryId)); return {data}; } catch (error) { return {error}; @@ -251,12 +253,12 @@ export const saveQueryToHistory = (queryText: string, queryId: string) => { } as const; }; -export const updateQueryInHistory = (stats: IQueryResult['stats'], queryId: string) => { +export function updateQueryInHistory(stats: IQueryResult['stats'], queryId: string) { return { type: UPDATE_QUERY_IN_HISTORY, data: {queryId, stats}, } as const; -}; +} export const goToPreviousQuery = () => { return {