Skip to content

Commit

Permalink
Merge pull request #875 from digma-ai/fix/highlights-refresh
Browse files Browse the repository at this point in the history
Fix highlights refresh
  • Loading branch information
kshmidt-digma committed May 28, 2024
2 parents 5fc1fa6 + ab7f50a commit 38dd996
Show file tree
Hide file tree
Showing 9 changed files with 120 additions and 68 deletions.
41 changes: 34 additions & 7 deletions src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,25 @@ import { sendMessageToWebService } from "./web/sendMessageToWebService";
const isDigmaMessageEvent = (e: MessageEvent): e is DigmaMessageEvent =>
isObject(e.data) && e.data.type === "digma";

const OUTGOING_MESSAGE_ACTION_ID_CONSOLE_STYLE =
"color: blue; font-weight: bold";
const FAILED_OUTGOING_MESSAGE_ACTION_ID_CONSOLE_STYLE =
"color: red; font-weight: bold";
const INCOMING_MESSAGE_ACTION_ID_CONSOLE_STYLE =
"color: green; font-weight: bold";

export const initializeDigmaMessageListener = (
dispatcher: ActionDispatcher
) => {
const handleDigmaMessage = (e: MessageEvent) => {
if (isDigmaMessageEvent(e)) {
console.debug("Digma message received: ", e);
console.debug(

Check warning on line 22 in src/api/index.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Unexpected console statement

Check warning on line 22 in src/api/index.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

Unexpected console statement
`Digma message received: %c${e.data.action}
%cRaw message: %O`,
INCOMING_MESSAGE_ACTION_ID_CONSOLE_STYLE,
null,
e.data
);
dispatcher.dispatch(e.timeStamp, e.data.action, e.data.payload);
}
};
Expand All @@ -27,16 +40,20 @@ export const initializeDigmaMessageListener = (
export const sendMessage = <T>(
message: DigmaOutgoingMessageData<T>
): string | undefined => {
console.debug("Digma message to send:", message);

switch (platform) {
case "Web":
sendMessageToWebService(message);
break;
case "VS Code":
if (window.sendMessageToVSCode) {
window.sendMessageToVSCode(message);
console.debug("Digma message has been sent to VS Code: ", message);
console.debug(

Check warning on line 50 in src/api/index.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Unexpected console statement

Check warning on line 50 in src/api/index.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

Unexpected console statement
`Digma message has been successfully sent to VS Code: %c${message.action}
%cRaw message: %O`,
OUTGOING_MESSAGE_ACTION_ID_CONSOLE_STYLE,
null,
message
);
}
break;
case "JetBrains":
Expand All @@ -45,13 +62,23 @@ export const sendMessage = <T>(
request: JSON.stringify(message),
onSuccess: function (response) {
console.debug(

Check warning on line 64 in src/api/index.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Unexpected console statement

Check warning on line 64 in src/api/index.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

Unexpected console statement
"Digma message cefQuery has been successfully sent: %s",
`Digma message has been successfully handled by JCEF: %c${message.action}
%cRaw message: %O
Response: %O`,
OUTGOING_MESSAGE_ACTION_ID_CONSOLE_STYLE,
null,
message,
response
);
},
onFailure: function (error_code, error_message) {
onFailure: function (error_code: number, error_message: string) {
console.error(

Check warning on line 75 in src/api/index.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Unexpected console statement

Check warning on line 75 in src/api/index.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

Unexpected console statement
" Digma message failed to send cefQuery: %d, %s",
`Digma message has failed to be handled by JCEF: %c${message.action}
%cRaw message: %O
%cError code: %d
Error message: %s`,
FAILED_OUTGOING_MESSAGE_ACTION_ID_CONSOLE_STYLE,
null,
error_code,
error_message
);
Expand Down
29 changes: 17 additions & 12 deletions src/components/Highlights/Impact/useImpactData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,21 @@ export const useImpactData = () => {
const refreshTimerId = useRef<number>();

const getData = useCallback(() => {
window.sendMessageToDigma<GetHighlightsImpactDataPayload>({
action: mainActions.GET_HIGHLIGHTS_IMPACT_DATA,
payload: {
query: {
scopedSpanCodeObjectId: config.scope?.span?.spanCodeObjectId || null,
environments: config.environments?.map((x) => x.id) || []
if (
config.scope?.span?.spanCodeObjectId &&
config.environments &&
config.environments.length > 0
) {
window.sendMessageToDigma<GetHighlightsImpactDataPayload>({
action: mainActions.GET_HIGHLIGHTS_IMPACT_DATA,
payload: {
query: {
scopedSpanCodeObjectId: config.scope.span.spanCodeObjectId,
environments: config.environments.map((x) => x.id)
}
}
}
});
});
}
}, [config.scope?.span?.spanCodeObjectId, config.environments]);
const previousGetData = usePrevious(getData);

Expand All @@ -36,10 +42,8 @@ export const useImpactData = () => {
}, [previousGetData, getData]);

useEffect(() => {
if (
previousLastSetDataTimeStamp &&
previousLastSetDataTimeStamp !== lastSetDataTimeStamp
) {
if (previousLastSetDataTimeStamp !== lastSetDataTimeStamp) {
window.clearTimeout(refreshTimerId.current);
refreshTimerId.current = window.setTimeout(() => {
getData();
}, REFRESH_INTERVAL);
Expand All @@ -58,6 +62,7 @@ export const useImpactData = () => {
);

return () => {
window.clearTimeout(refreshTimerId.current);
dispatcher.removeActionListener(
mainActions.SET_HIGHLIGHTS_IMPACT_DATA,
handleImpactData
Expand Down
29 changes: 17 additions & 12 deletions src/components/Highlights/Performance/usePerformanceData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,21 @@ export const usePerformanceData = () => {
const refreshTimerId = useRef<number>();

const getData = useCallback(() => {
window.sendMessageToDigma<GetHighlightsPerformanceDataPayload>({
action: mainActions.GET_HIGHLIGHTS_PERFORMANCE_DATA,
payload: {
query: {
scopedSpanCodeObjectId: config.scope?.span?.spanCodeObjectId || null,
environments: config.environments?.map((x) => x.id) || []
if (
config.scope?.span?.spanCodeObjectId &&
config.environments &&
config.environments.length > 0
) {
window.sendMessageToDigma<GetHighlightsPerformanceDataPayload>({
action: mainActions.GET_HIGHLIGHTS_PERFORMANCE_DATA,
payload: {
query: {
scopedSpanCodeObjectId: config.scope.span.spanCodeObjectId,
environments: config.environments.map((x) => x.id)
}
}
}
});
});
}
}, [config.scope?.span?.spanCodeObjectId, config.environments]);
const previousGetData = usePrevious(getData);

Expand All @@ -36,10 +42,8 @@ export const usePerformanceData = () => {
}, [previousGetData, getData]);

useEffect(() => {
if (
previousLastSetDataTimeStamp &&
previousLastSetDataTimeStamp !== lastSetDataTimeStamp
) {
if (previousLastSetDataTimeStamp !== lastSetDataTimeStamp) {
window.clearTimeout(refreshTimerId.current);
refreshTimerId.current = window.setTimeout(() => {
getData();
}, REFRESH_INTERVAL);
Expand All @@ -58,6 +62,7 @@ export const usePerformanceData = () => {
);

return () => {
window.clearTimeout(refreshTimerId.current);
dispatcher.removeActionListener(
mainActions.SET_HIGHLIGHTS_PERFORMANCE_DATA,
handlePerformanceData
Expand Down
29 changes: 17 additions & 12 deletions src/components/Highlights/Scaling/useScalingData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,21 @@ export const useScalingData = () => {
const refreshTimerId = useRef<number>();

const getData = useCallback(() => {
window.sendMessageToDigma<GetHighlightsScalingDataPayload>({
action: mainActions.GET_HIGHLIGHTS_SCALING_DATA,
payload: {
query: {
scopedSpanCodeObjectId: config.scope?.span?.spanCodeObjectId || null,
environments: config.environments?.map((x) => x.id) || []
if (
config.scope?.span?.spanCodeObjectId &&
config.environments &&
config.environments.length > 0
) {
window.sendMessageToDigma<GetHighlightsScalingDataPayload>({
action: mainActions.GET_HIGHLIGHTS_SCALING_DATA,
payload: {
query: {
scopedSpanCodeObjectId: config.scope.span.spanCodeObjectId,
environments: config.environments.map((x) => x.id)
}
}
}
});
});
}
}, [config.scope?.span?.spanCodeObjectId, config.environments]);
const previousGetData = usePrevious(getData);

Expand All @@ -36,10 +42,8 @@ export const useScalingData = () => {
}, [previousGetData, getData]);

useEffect(() => {
if (
previousLastSetDataTimeStamp &&
previousLastSetDataTimeStamp !== lastSetDataTimeStamp
) {
if (previousLastSetDataTimeStamp !== lastSetDataTimeStamp) {
window.clearTimeout(refreshTimerId.current);
refreshTimerId.current = window.setTimeout(() => {
getData();
}, REFRESH_INTERVAL);
Expand All @@ -58,6 +62,7 @@ export const useScalingData = () => {
);

return () => {
window.clearTimeout(refreshTimerId.current);
dispatcher.removeActionListener(
mainActions.SET_HIGHLIGHTS_SCALING_DATA,
handleScalingData
Expand Down
23 changes: 12 additions & 11 deletions src/components/Highlights/SpanInfo/useSpanInfoData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,16 @@ export const useSpanInfoData = () => {
const refreshTimerId = useRef<number>();

const getData = useCallback(() => {
window.sendMessageToDigma<GetHighlightsSpanInfoDataPayload>({
action: mainActions.GET_HIGHLIGHTS_SPAN_INFO_DATA,
payload: {
query: {
spanCodeObjectId: config.scope?.span?.spanCodeObjectId || null
if (config.scope?.span?.spanCodeObjectId) {
window.sendMessageToDigma<GetHighlightsSpanInfoDataPayload>({
action: mainActions.GET_HIGHLIGHTS_SPAN_INFO_DATA,
payload: {
query: {
spanCodeObjectId: config.scope?.span?.spanCodeObjectId
}
}
}
});
});
}
}, [config.scope?.span?.spanCodeObjectId]);
const previousGetData = usePrevious(getData);

Expand All @@ -35,10 +37,8 @@ export const useSpanInfoData = () => {
}, [previousGetData, getData]);

useEffect(() => {
if (
previousLastSetDataTimeStamp &&
previousLastSetDataTimeStamp !== lastSetDataTimeStamp
) {
if (previousLastSetDataTimeStamp !== lastSetDataTimeStamp) {
window.clearTimeout(refreshTimerId.current);
refreshTimerId.current = window.setTimeout(() => {
getData();
}, REFRESH_INTERVAL);
Expand All @@ -57,6 +57,7 @@ export const useSpanInfoData = () => {
);

return () => {
window.clearTimeout(refreshTimerId.current);
dispatcher.removeActionListener(
mainActions.SET_HIGHLIGHTS_SPAN_INFO_DATA,
handleSpanInfoData
Expand Down
30 changes: 18 additions & 12 deletions src/components/Highlights/TopIssues/useTopIssuesData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,21 @@ export const useTopIssuesData = () => {
const refreshTimerId = useRef<number>();

const getData = useCallback(() => {
window.sendMessageToDigma<GetHighlightsTopIssuesDataPayload>({
action: mainActions.GET_HIGHLIGHTS_TOP_ISSUES_DATA,
payload: {
query: {
scopedCodeObjectId: config.scope?.span?.spanCodeObjectId || null,
environments: config.environments?.map((env) => env.id) || []
if (
config.scope?.span?.spanCodeObjectId &&
config.environments &&
config.environments.length > 0
) {
window.sendMessageToDigma<GetHighlightsTopIssuesDataPayload>({
action: mainActions.GET_HIGHLIGHTS_TOP_ISSUES_DATA,
payload: {
query: {
scopedCodeObjectId: config.scope?.span?.spanCodeObjectId,
environments: config.environments?.map((env) => env.id)
}
}
}
});
});
}
}, [config.scope?.span?.spanCodeObjectId, config.environments]);
const previousGetData = usePrevious(getData);

Expand All @@ -37,10 +43,9 @@ export const useTopIssuesData = () => {
}, [previousGetData, getData]);

useEffect(() => {
if (
previousLastSetDataTimeStamp &&
previousLastSetDataTimeStamp !== lastSetDataTimeStamp
) {
if (previousLastSetDataTimeStamp !== lastSetDataTimeStamp) {
window.clearTimeout(refreshTimerId.current);

refreshTimerId.current = window.setTimeout(() => {
getData();
}, REFRESH_INTERVAL);
Expand All @@ -59,6 +64,7 @@ export const useTopIssuesData = () => {
);

return () => {
window.clearTimeout(refreshTimerId.current);
dispatcher.removeActionListener(
mainActions.SET_HIGHLIGHTS_TOP_ISSUES_DATA,
handleTopIssuesData
Expand Down
1 change: 1 addition & 0 deletions src/components/Insights/useInsightsData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ export const useInsightsData = ({
actions.SET_DATA_LIST,
handleInsightsData
);
window.clearTimeout(refreshTimerId.current);
};
}, []);

Expand Down
4 changes: 3 additions & 1 deletion src/components/Navigation/ScopeBar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,9 @@ export const ScopeBar = (props: ScopeBarProps) => {
</s.ScopeBarButton>
<s.ScopeBarDivider />
<s.ScopeNameContainer>
<s.ScopeName>{scopeDisplayName}</s.ScopeName>
<Tooltip title={scopeDisplayName}>
<s.ScopeName>{scopeDisplayName}</s.ScopeName>
</Tooltip>
{isActive && <s.StyledCopyButton text={scopeDisplayName} />}
</s.ScopeNameContainer>
<s.ScopeBarDivider />
Expand Down
2 changes: 1 addition & 1 deletion src/components/common/v3/Tooltip/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const Tooltip = styled.div<TooltipComponentProps>`
padding: 4px;
border-radius: 4px;
box-shadow: 0 0 6px 0 rgb(0 0 0 / 15%);
word-break: keep-all;
word-wrap: break-word;
color: ${({ theme }) => theme.colors.v3.text.primary};
background: ${({ theme }) => theme.colors.v3.surface.primary};
border: 1px solid ${({ theme }) => theme.colors.v3.stroke.tertiary};
Expand Down

0 comments on commit 38dd996

Please sign in to comment.