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]);