Skip to content

Commit f00c888

Browse files
Set method id to the search on Hotspot code lens navigation (#1354)
* Set method id to the search on Hotspot code lens navigation * Clear recent activity data on backend change, fix navigation from code lens
1 parent c871dbd commit f00c888

File tree

7 files changed

+109
-47
lines changed

7 files changed

+109
-47
lines changed

dependencies.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"jetBrainsPluginVersion": "2.0.411",
2+
"jetBrainsPluginVersion": "2.0.414",
33
"visualStudioExtensionVersion": "1.2.11",
44
"jaegerUIVersion": "1.29.1-digma.1.2.0",
55
"jaegerVersion": "1.45.0"

src/components/Main/index.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ const getURLToNavigateOnCodeLensClick = (scope: Scope): string | undefined => {
4545
return;
4646
}
4747

48+
if (codeLens.lensTitle.toLocaleLowerCase().includes("error hotspot")) {
49+
return `/${TAB_IDS.ERRORS}`;
50+
}
51+
4852
if (codeLens.importance <= 4) {
4953
return `/${TAB_IDS.ISSUES}`;
5054
}

src/components/RecentActivity/index.tsx

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -174,18 +174,6 @@ export const RecentActivity = () => {
174174
);
175175
}, [recentActivityData.environments]);
176176

177-
useEffect(() => {
178-
if (!config.userInfo?.id && config.backendInfo?.centralize) {
179-
void toggleRecentIndicator({
180-
status: false
181-
});
182-
}
183-
}, [
184-
config.backendInfo?.centralize,
185-
config.userInfo?.id,
186-
toggleRecentIndicator
187-
]);
188-
189177
useEffect(() => {
190178
const isAnyRecentActivity = environments.some(
191179
(environment) => environment.hasRecentActivity

src/components/RecentActivity/useRecentActivityData.ts

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
1-
import { useEffect, useState } from "react";
1+
import { useCallback, useContext, useEffect, useState } from "react";
2+
import { useRecentActivityDispatch } from "../../containers/RecentActivity/hooks";
3+
import { usePrevious } from "../../hooks/usePrevious";
24
import {
5+
digmaApi,
36
useGetEnvironmentsQuery,
47
useGetRecentActivityQuery
58
} from "../../redux/services/digma";
9+
import { useToggleRecentIndicatorMutation } from "../../redux/services/plugin";
610
import type {
711
Environment,
812
RecentActivityEntry
913
} from "../../redux/services/types";
14+
import { areBackendInfosEqual } from "../../utils/areBackendInfosEqual";
15+
import { ConfigContext } from "../common/App/ConfigContext";
1016

1117
const REFRESH_INTERVAL = 10 * 1000; // in milliseconds
1218

@@ -18,6 +24,11 @@ interface RecentActivityData {
1824
}
1925

2026
export const useRecentActivityData = (environmentId: string | undefined) => {
27+
const { backendInfo, userInfo } = useContext(ConfigContext);
28+
const previousBackendInfo = usePrevious(backendInfo);
29+
const [toggleRecentIndicator] = useToggleRecentIndicatorMutation();
30+
const dispatch = useRecentActivityDispatch();
31+
2132
const [data, setData] = useState<RecentActivityData>({
2233
environments: undefined,
2334
entries: undefined,
@@ -27,7 +38,8 @@ export const useRecentActivityData = (environmentId: string | undefined) => {
2738

2839
const { data: environments, isFetching: areEnvironmentsFetching } =
2940
useGetEnvironmentsQuery(undefined, {
30-
pollingInterval: REFRESH_INTERVAL
41+
pollingInterval: REFRESH_INTERVAL,
42+
skip: !userInfo?.id && backendInfo?.centralize
3143
});
3244

3345
const { data: recentActivityData, isFetching: isRecentActivityDataFetching } =
@@ -41,14 +53,43 @@ export const useRecentActivityData = (environmentId: string | undefined) => {
4153
}
4254
);
4355

56+
const clearData = useCallback(() => {
57+
setData((prevData) => ({
58+
...prevData,
59+
environments: undefined,
60+
entries: undefined
61+
}));
62+
void toggleRecentIndicator({
63+
status: false
64+
});
65+
dispatch(digmaApi.util.invalidateTags(["Environment", "RecentActivity"]));
66+
}, [toggleRecentIndicator, dispatch]);
67+
68+
// Clear data on backend change
69+
useEffect(() => {
70+
if (
71+
previousBackendInfo &&
72+
backendInfo &&
73+
!areBackendInfosEqual(previousBackendInfo, backendInfo)
74+
) {
75+
clearData();
76+
}
77+
}, [previousBackendInfo, backendInfo, clearData]);
78+
79+
// Clear data on user change
80+
useEffect(() => {
81+
clearData();
82+
}, [userInfo?.id, clearData]);
83+
84+
// Clear recent activity data on environment change
4485
useEffect(() => {
4586
if (environmentId) {
4687
setData((prevData) => ({
4788
...prevData,
4889
entries: undefined
4990
}));
5091
}
51-
}, [environmentId]);
92+
}, [environmentId, dispatch]);
5293

5394
useEffect(() => {
5495
setData((prevData) => ({

src/components/common/App/index.tsx

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ import { isNumber } from "../../../typeGuards/isNumber";
1717
import { isObject } from "../../../typeGuards/isObject";
1818
import { isString } from "../../../typeGuards/isString";
1919
import { sendErrorTrackingEvent } from "../../../utils/actions/sendErrorTrackingEvent";
20-
import { isScopeWithMetricsReportContext } from "../../Main/typeGuards";
20+
import {
21+
isScopeWithCodeLensContext,
22+
isScopeWithMetricsReportContext
23+
} from "../../Main/typeGuards";
2124
import { ErrorScreen } from "../ErrorScreen";
2225
import { ConfigContext } from "./ConfigContext";
2326
import { getStyledComponentsTheme } from "./getTheme";
@@ -29,6 +32,7 @@ import type {
2932
PersistedState,
3033
RunConfiguration,
3134
Scope,
35+
ScopeWithCodeLensContext,
3236
UserInfo
3337
} from "./types";
3438

@@ -102,7 +106,8 @@ export const App = ({ theme, children, id }: AppProps) => {
102106
setInsightsFilteredCriticalityLevels:
103107
setInsightsFilteredCriticalityLevelsInSpanScope,
104108
setInsightsFilteredCriticalityLevelsInGlobalScope,
105-
setInsightsLastDays
109+
setInsightsLastDays,
110+
setGlobalErrorsSearch
106111
} = useStore.getState();
107112

108113
const handleError = (error: Error, info: ErrorInfo) => {
@@ -309,11 +314,27 @@ export const App = ({ theme, children, id }: AppProps) => {
309314

310315
const handleSetScope = (data: unknown) => {
311316
setConfig((config) => {
312-
const scope = data as Scope;
317+
let scope = data as Scope;
313318
const environment = scope.environmentId
314319
? config.environments?.find((x) => x.id === scope.environmentId)
315320
: config.environment;
316321

322+
// Change scope to the global one if "Error Hotspot" code lens click is the trigger
323+
if (
324+
isScopeWithCodeLensContext(scope) &&
325+
scope.context.payload.codeLens.lensTitle
326+
.toLocaleLowerCase()
327+
.includes("error hotspot")
328+
) {
329+
const newScope: ScopeWithCodeLensContext = {
330+
...scope,
331+
span: null
332+
};
333+
scope = newScope;
334+
335+
setGlobalErrorsSearch(newScope.context.payload.codeLens.codeMethod);
336+
}
337+
317338
setScope(scope);
318339
setEnvironment(environment ?? null);
319340

@@ -642,7 +663,8 @@ export const App = ({ theme, children, id }: AppProps) => {
642663
setInsightsFilteredInsightTypesInGlobalScope,
643664
setInsightsFilteredCriticalityLevelsInSpanScope,
644665
setInsightsFilteredCriticalityLevelsInGlobalScope,
645-
setInsightsLastDays
666+
setInsightsLastDays,
667+
setGlobalErrorsSearch
646668
]);
647669

648670
const styledComponentsTheme = getStyledComponentsTheme(
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { useDispatch, useSelector } from "react-redux";
2+
import type { RecentActivityDispatch, RecentActivityRootState } from "./store";
3+
4+
export const useRecentActivityDispatch =
5+
useDispatch.withTypes<RecentActivityDispatch>();
6+
export const useRecentActivitySelector =
7+
useSelector.withTypes<RecentActivityRootState>();

0 commit comments

Comments
 (0)