Skip to content

Commit

Permalink
Fix view
Browse files Browse the repository at this point in the history
  • Loading branch information
opoliarush committed Sep 3, 2024
1 parent f4fa406 commit 8bbe42c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 20 deletions.
5 changes: 5 additions & 0 deletions src/components/Insights/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ export interface Method {
name: string;
}

export interface WrappedInsightData {
insightsViewMode: string;
data: InsightsData;
}

export interface InsightsData {
insights: GenericCodeObjectInsight[];
totalCount: number;
Expand Down
29 changes: 9 additions & 20 deletions src/components/Insights/useInsightsData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(
Expand All @@ -272,7 +261,7 @@ export const useInsightsData = ({
);
dispatcher.removeActionListener(
issuesActions.SET_DATA_LIST,
handleIssuesData
handleInsightsData
);
};
}, [setData, setIsLoading, insightViewType]);
Expand Down

0 comments on commit 8bbe42c

Please sign in to comment.