Skip to content

Commit bda84c2

Browse files
Migrate Errors tab to REST API (#1356)
* Migrate Errors tab to REST API * Reenable Open In IDE in Sandbox --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent 99cb1a0 commit bda84c2

File tree

49 files changed

+759
-944
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+759
-944
lines changed

eslint.config.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export default tseslint.config(
1717
parserOptions: {
1818
project: "./tsconfig.eslint.json",
1919
tsconfigRootDir: import.meta.dirname,
20-
ecmaVersion: 2022
20+
ecmaVersion: 2023
2121
}
2222
},
2323
rules: {

src/components/Errors/ErrorCard/mockData.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
import type { Error } from "../types";
1+
import type { Error } from "../../../redux/services/types";
22

33
export const mockedError: Error = {
44
uid: "1",
55
name: "Very long long long long long long long error name",
66
scoreInfo: {
77
score: 100,
88
scoreParams: {
9-
param1: "value1",
10-
param2: "value2"
9+
param1: 1,
10+
param2: 2
1111
}
1212
},
1313
codeObjectId: "codeObjectId1",

src/components/Errors/ErrorCard/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Error } from "../types";
1+
import type { Error } from "../../../redux/services/types";
22

33
export interface ErrorCardProps {
44
data: Error;

src/components/Errors/ErrorDetails/ErrorDetails.stories.tsx

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import type { Meta, StoryObj } from "@storybook/react";
22
import { ErrorDetails } from ".";
33
import { actions } from "../actions";
4-
import { mockedErrorDetails } from "./mockData";
54

65
// More on how to set up stories at: https://storybook.js.org/docs/react/writing-stories/introduction
76
const meta: Meta<typeof ErrorDetails> = {
@@ -20,13 +19,6 @@ type Story = StoryObj<typeof ErrorDetails>;
2019
// More on writing stories with args: https://storybook.js.org/docs/react/writing-stories/args
2120
export const Default: Story = {
2221
play: () => {
23-
window.setTimeout(() => {
24-
window.postMessage({
25-
type: "digma",
26-
action: actions.SET_ERROR_DETAILS,
27-
payload: mockedErrorDetails
28-
});
29-
}, 1000);
3022
window.setTimeout(() => {
3123
window.postMessage({
3224
type: "digma",

src/components/Errors/ErrorDetails/ErrorDetailsCardContent/FlowStack/SpanFrameGroup/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
import type { MouseEvent } from "react";
22
import { v4 as uuidv4 } from "uuid";
3+
import type { ErrorFlowFrame } from "../../../../../../redux/services/types";
34
import { isString } from "../../../../../../typeGuards/isString";
45
import { sendUserActionTrackingEvent } from "../../../../../../utils/actions/sendUserActionTrackingEvent";
56
import { CodeIcon } from "../../../../../common/icons/12px/CodeIcon";
67
import { OpenTelemetryLogoIcon } from "../../../../../common/icons/12px/OpenTelemetryLogoIcon";
78
import { Tooltip } from "../../../../../common/v3/Tooltip";
89
import { trackingEvents } from "../../../../tracking";
9-
import type { Frame } from "../../../types";
1010
import * as s from "./styles";
1111
import type { FrameItemCodeLocation, SpanFrameGroupProps } from "./types";
1212

13-
const getFrameItemText = (frame: Frame) => {
13+
const getFrameItemText = (frame: ErrorFlowFrame) => {
1414
if (window.ide === "PyCharm" && frame.executedCode) {
1515
return frame.executedCode;
1616
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1+
import type { ErrorOriginService } from "../../../../../../redux/services/types";
12
import { isObject } from "../../../../../../typeGuards/isObject";
23
import { isString } from "../../../../../../typeGuards/isString";
3-
import type { ServiceInfo } from "../../../types";
44

55
export const isServiceInfoWithName = (
6-
x: ServiceInfo | null
7-
): x is Omit<ServiceInfo, "serviceName"> & { serviceName: string } =>
6+
x: ErrorOriginService
7+
): x is Omit<ErrorOriginService, "serviceName"> & { serviceName: string } =>
88
isObject(x) && isString(x.serviceName);
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import type { FilesURIsMap, Frame } from "../../../types";
1+
import type { ErrorFlowFrame } from "../../../../../../redux/services/types";
2+
import type { FilesURIsMap } from "../../../types";
23

34
export interface FrameItemCodeLocation {
45
URI: string;
@@ -7,7 +8,7 @@ export interface FrameItemCodeLocation {
78

89
export interface SpanFrameGroupProps {
910
spanName: string;
10-
frames: Frame[];
11+
frames: ErrorFlowFrame[];
1112
filesURIs: FilesURIsMap;
1213
onGoCodeLocation: (location: FrameItemCodeLocation) => void;
1314
}

src/components/Errors/ErrorDetails/ErrorDetailsCardContent/FlowStack/index.tsx

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { useEffect, useMemo, useRef } from "react";
22
import { v4 as uuidv4 } from "uuid";
33
import type { DataFetcherConfiguration } from "../../../../../hooks/useFetchData";
44
import { useFetchData } from "../../../../../hooks/useFetchData";
5+
import type { ErrorFlowFrame } from "../../../../../redux/services/types";
56
import { useErrorsSelector } from "../../../../../store/errors/useErrorsSelector";
67
import { useStore } from "../../../../../store/useStore";
78
import { isNull } from "../../../../../typeGuards/isNull";
@@ -15,8 +16,6 @@ import { actions } from "../../../actions";
1516
import { trackingEvents } from "../../../tracking";
1617
import type {
1718
FilesURIsMap,
18-
Frame,
19-
FrameStack,
2019
GetFilesURIsPayload,
2120
GoToCodeLocationPayload,
2221
GoToTracePayload,
@@ -40,15 +39,12 @@ export const FlowStack = ({ data }: FlowStackProps) => {
4039
const { setErrorDetailsWorkspaceItemsOnly } = useStore.getState();
4140
const stacksContainerRef = useRef<HTMLDivElement>(null);
4241

43-
const frameStacks = useMemo(
44-
() => data.frameStacks.filter(Boolean) as FrameStack[],
45-
[data]
46-
);
42+
const frameStacks = useMemo(() => data.frameStacks ?? [], [data]);
4743

4844
const filesURIsPayload = useMemo(
4945
() => ({
5046
codeObjectIds: frameStacks
51-
.map((stack) => stack.frames.map((x) => x?.codeObjectId))
47+
.map((stack) => stack.frames?.map((x) => x?.codeObjectId) ?? [])
5248
.flat()
5349
.filter(isString)
5450
}),
@@ -83,9 +79,10 @@ export const FlowStack = ({ data }: FlowStackProps) => {
8379
payload: {
8480
traceId,
8581
spanName:
86-
frameStacks[0].frames[0]?.spanName ??
82+
frameStacks[0].frames?.[0]?.spanName ??
8783
`Sample trace for error ${exceptionType ?? ""}`.trim(),
88-
spanCodeObjectId: frameStacks[0].frames[0]?.codeObjectId ?? undefined
84+
spanCodeObjectId:
85+
frameStacks[0].frames?.[0]?.codeObjectId ?? undefined
8986
}
9087
});
9188
}
@@ -131,7 +128,7 @@ export const FlowStack = ({ data }: FlowStackProps) => {
131128
<s.Container>
132129
<s.StacksContainer ref={stacksContainerRef}>
133130
{frameStacks.map((x) => {
134-
const frames = x.frames.filter(Boolean) as Frame[];
131+
const frames = x.frames ?? [];
135132
const visibleFrames = showWorkspaceOnly
136133
? frames.filter((x) => x.codeObjectId && filesURIs[x.codeObjectId])
137134
: frames;
@@ -143,7 +140,7 @@ export const FlowStack = ({ data }: FlowStackProps) => {
143140
acc[acc.length - 1].push(frame);
144141
}
145142
return acc;
146-
}, [] as Frame[][]);
143+
}, [] as ErrorFlowFrame[][]);
147144

148145
return (
149146
<s.StackContainer key={uuidv4()}>

src/components/Errors/ErrorDetails/ErrorDetailsCardContent/FlowStack/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import type { FlowInfo } from "../../types";
1+
import type { ErrorFlowInfo } from "../../../../../redux/services/types";
22

33
export interface FlowProps {
4-
data: FlowInfo;
4+
data: ErrorFlowInfo;
55
}
66

77
export interface ShowOnlyWorkspaceErrorStackTraceItemsPayload {

src/components/Errors/ErrorDetails/ErrorDetailsCardContent/index.tsx

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { useEffect, useState } from "react";
22
import { useNow } from "../../../../hooks/useNow";
33
import { usePrevious } from "../../../../hooks/usePrevious";
4-
import { isNull } from "../../../../typeGuards/isNull";
54
import { isNumber } from "../../../../typeGuards/isNumber";
65
import { isString } from "../../../../typeGuards/isString";
76
import { sendUserActionTrackingEvent } from "../../../../utils/actions/sendUserActionTrackingEvent";
@@ -33,20 +32,21 @@ export const ErrorDetailsCardContent = ({
3332
}
3433
}, [previousId, id]);
3534

36-
const services = data.originServices
37-
.filter(isServiceInfoWithName)
38-
.map((x) => x.serviceName);
35+
const services =
36+
data.originServices
37+
?.filter(isServiceInfoWithName)
38+
.map((x) => x.serviceName) ?? [];
3939
const startedTooltip = new Date(data.firstOccurenceTime).toString();
4040
const startedString = formatTimeDistance(data.firstOccurenceTime, now);
4141
const lastTooltip = new Date(data.lastOccurenceTime).toString();
4242
const lastString = formatTimeDistance(data.lastOccurenceTime, now);
4343
const avgPerDay = data.dayAvg;
4444

45-
const flows = data.errors.filter((x) => !isNull(x));
45+
const flows = data.errors ?? [];
4646
const currentFlow = flows[currentFlowStack];
4747

4848
const isPreviousFlowButtonDisabled = currentFlowStack === 0;
49-
const isNextFlowButtonDisabled = currentFlowStack === flows.length - 1;
49+
const isNextFlowButtonDisabled = currentFlowStack >= flows.length - 1;
5050

5151
const handleFlowPaginationButtonClick = (flowNumber: number) => () => {
5252
sendUserActionTrackingEvent(trackingEvents.FLOW_PAGINATION_BUTTON_CLICKED);
@@ -101,8 +101,10 @@ export const ErrorDetailsCardContent = ({
101101
<span>
102102
Flow Stacks{" "}
103103
<s.FlowsCountNumber>
104-
<s.CurrentFlowNumber>{currentFlowStack + 1}</s.CurrentFlowNumber>/
105-
{data.errors.length}
104+
<s.CurrentFlowNumber>
105+
{flows.length > 0 ? currentFlowStack + 1 : 0}
106+
</s.CurrentFlowNumber>
107+
/{flows.length}
106108
</s.FlowsCountNumber>
107109
</span>
108110
<s.IconButton
@@ -116,7 +118,9 @@ export const ErrorDetailsCardContent = ({
116118
/>
117119
</s.IconButton>
118120
</s.FlowPagination>
119-
<FlowStack data={currentFlow} key={currentFlowStack} />
121+
{flows.length > 0 && (
122+
<FlowStack data={currentFlow} key={currentFlowStack} />
123+
)}
120124
</s.FlowsContainer>
121125
</s.Container>
122126
);

0 commit comments

Comments
 (0)