From 9194ae19449d418d4b227a66889d251fb3f3a2e0 Mon Sep 17 00:00:00 2001 From: opoliarush Date: Mon, 2 Sep 2024 23:42:54 +0300 Subject: [PATCH 1/4] Fix insights selection --- src/components/Insights/useInsightsData.ts | 31 +++++++++++++++++----- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/src/components/Insights/useInsightsData.ts b/src/components/Insights/useInsightsData.ts index 6927e479..b9d1d47f 100644 --- a/src/components/Insights/useInsightsData.ts +++ b/src/components/Insights/useInsightsData.ts @@ -227,7 +227,7 @@ export const useInsightsData = ({ useEffect(() => { window.clearTimeout(refreshTimerId.current); refresh(); - }, [backendInfo, environmentId, spanCodeObjectId, refresh]); + }, [backendInfo, environmentId, spanCodeObjectId, insightViewType, refresh]); useEffect(() => { const handleInsightsData = ( @@ -235,6 +235,26 @@ export const useInsightsData = ({ timeStamp: number, error: DigmaMessageError | undefined ) => { + if (insightViewType !== "Analytics") { + return; + } + + if (!error) { + setData(data as InsightsData); + } + setIsLoading(false); + setLastSetDataTimeStamp(timeStamp); + }; + + const handleIssuesData = ( + data: unknown, + timeStamp: number, + error: DigmaMessageError | undefined + ) => { + if (insightViewType !== "Issues") { + return; + } + if (!error) { setData(data as InsightsData); } @@ -243,10 +263,7 @@ export const useInsightsData = ({ }; dispatcher.addActionListener(actions.SET_DATA_LIST, handleInsightsData); - dispatcher.addActionListener( - issuesActions.SET_DATA_LIST, - handleInsightsData - ); + dispatcher.addActionListener(issuesActions.SET_DATA_LIST, handleIssuesData); return () => { dispatcher.removeActionListener( @@ -255,10 +272,10 @@ export const useInsightsData = ({ ); dispatcher.removeActionListener( issuesActions.SET_DATA_LIST, - handleInsightsData + handleIssuesData ); }; - }, [setData, setIsLoading]); + }, [setData, setIsLoading, insightViewType]); useEffect(() => { if (previousLastSetDataTimeStamp !== lastSetDataTimeStamp) { From f4fa40666ab532bf8859a5185e8571a2bed674d8 Mon Sep 17 00:00:00 2001 From: Kyrylo Shmidt <119138536+kshmidt-digma@users.noreply.github.com> Date: Tue, 3 Sep 2024 11:33:13 +0200 Subject: [PATCH 2/4] Update src/components/Insights/useInsightsData.ts --- src/components/Insights/useInsightsData.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/Insights/useInsightsData.ts b/src/components/Insights/useInsightsData.ts index b9d1d47f..d074ff41 100644 --- a/src/components/Insights/useInsightsData.ts +++ b/src/components/Insights/useInsightsData.ts @@ -227,7 +227,7 @@ export const useInsightsData = ({ useEffect(() => { window.clearTimeout(refreshTimerId.current); refresh(); - }, [backendInfo, environmentId, spanCodeObjectId, insightViewType, refresh]); + }, [backendInfo, environmentId, spanCodeObjectId, refresh]); useEffect(() => { const handleInsightsData = ( From 8bbe42c3dbe83701c5207c3caae60579419ccdd6 Mon Sep 17 00:00:00 2001 From: opoliarush Date: Tue, 3 Sep 2024 16:38:54 +0300 Subject: [PATCH 3/4] Fix view --- src/components/Insights/types.ts | 5 ++++ src/components/Insights/useInsightsData.ts | 29 +++++++--------------- 2 files changed, 14 insertions(+), 20 deletions(-) diff --git a/src/components/Insights/types.ts b/src/components/Insights/types.ts index f3427042..afd75275 100644 --- a/src/components/Insights/types.ts +++ b/src/components/Insights/types.ts @@ -65,6 +65,11 @@ export interface Method { name: string; } +export interface WrappedInsightData { + insightsViewMode: string; + data: InsightsData; +} + export interface InsightsData { insights: GenericCodeObjectInsight[]; totalCount: number; diff --git a/src/components/Insights/useInsightsData.ts b/src/components/Insights/useInsightsData.ts index d074ff41..e7044ae6 100644 --- a/src/components/Insights/useInsightsData.ts +++ b/src/components/Insights/useInsightsData.ts @@ -18,7 +18,7 @@ import { InsightFilterType, ViewMode } from "./InsightsCatalog/types"; import { actions as issuesActions } from "./Issues/actions"; import { GetIssuesDataListQuery } from "./Issues/types"; import { actions } from "./actions"; -import { InsightsData, InsightViewType } from "./types"; +import { InsightViewType, WrappedInsightData } from "./types"; interface UseInsightsDataProps { areFiltersRehydrated: boolean; @@ -235,35 +235,24 @@ export const useInsightsData = ({ timeStamp: number, error: DigmaMessageError | undefined ) => { - if (insightViewType !== "Analytics") { - return; - } + const insightsData = data as WrappedInsightData; - if (!error) { - setData(data as InsightsData); - } - setIsLoading(false); - setLastSetDataTimeStamp(timeStamp); - }; - - const handleIssuesData = ( - data: unknown, - timeStamp: number, - error: DigmaMessageError | undefined - ) => { - if (insightViewType !== "Issues") { + if (insightViewType !== insightsData.insightsViewMode) { return; } if (!error) { - setData(data as InsightsData); + setData(insightsData.data); } setIsLoading(false); setLastSetDataTimeStamp(timeStamp); }; dispatcher.addActionListener(actions.SET_DATA_LIST, handleInsightsData); - dispatcher.addActionListener(issuesActions.SET_DATA_LIST, handleIssuesData); + dispatcher.addActionListener( + issuesActions.SET_DATA_LIST, + handleInsightsData + ); return () => { dispatcher.removeActionListener( @@ -272,7 +261,7 @@ export const useInsightsData = ({ ); dispatcher.removeActionListener( issuesActions.SET_DATA_LIST, - handleIssuesData + handleInsightsData ); }; }, [setData, setIsLoading, insightViewType]); From 07929e712367f5e36a903e76baceda52481b051f Mon Sep 17 00:00:00 2001 From: Kyrylo Shmidt <119138536+kshmidt-digma@users.noreply.github.com> Date: Tue, 3 Sep 2024 16:06:50 +0200 Subject: [PATCH 4/4] Update src/components/Insights/useInsightsData.ts --- src/components/Insights/useInsightsData.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/components/Insights/useInsightsData.ts b/src/components/Insights/useInsightsData.ts index e7044ae6..fd76a166 100644 --- a/src/components/Insights/useInsightsData.ts +++ b/src/components/Insights/useInsightsData.ts @@ -237,6 +237,7 @@ export const useInsightsData = ({ ) => { const insightsData = data as WrappedInsightData; + //Do not handle the response message if the view mode has been already changed if (insightViewType !== insightsData.insightsViewMode) { return; }