Skip to content

Commit 753c994

Browse files
committed
Fix types
1 parent 0c3c4d5 commit 753c994

File tree

4 files changed

+26
-27
lines changed

4 files changed

+26
-27
lines changed

src/components/Errors/ErrorDetails/ErrorDetailsCardContent/FlowStack/SpanFrameGroup/typeGuards.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ import { isObject } from "../../../../../../typeGuards/isObject";
33
import { isString } from "../../../../../../typeGuards/isString";
44

55
export const isServiceInfoWithName = (
6-
x: ErrorOriginService | null
6+
x: ErrorOriginService
77
): x is Omit<ErrorOriginService, "serviceName"> & { serviceName: string } =>
88
isObject(x) && isString(x.serviceName);

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

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +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 {
6-
ErrorFlowFrame,
7-
ErrorFlowFrameStack
8-
} from "../../../../../redux/services/types";
5+
import type { ErrorFlowFrame } from "../../../../../redux/services/types";
96
import { useErrorsSelector } from "../../../../../store/errors/useErrorsSelector";
107
import { useStore } from "../../../../../store/useStore";
118
import { isNull } from "../../../../../typeGuards/isNull";
@@ -42,15 +39,12 @@ export const FlowStack = ({ data }: FlowStackProps) => {
4239
const { setErrorDetailsWorkspaceItemsOnly } = useStore.getState();
4340
const stacksContainerRef = useRef<HTMLDivElement>(null);
4441

45-
const frameStacks = useMemo(
46-
() => data.frameStacks.filter(Boolean) as ErrorFlowFrameStack[],
47-
[data]
48-
);
42+
const frameStacks = useMemo(() => data.frameStacks ?? [], [data]);
4943

5044
const filesURIsPayload = useMemo(
5145
() => ({
5246
codeObjectIds: frameStacks
53-
.map((stack) => stack.frames.map((x) => x?.codeObjectId))
47+
.map((stack) => stack.frames?.map((x) => x?.codeObjectId) ?? [])
5448
.flat()
5549
.filter(isString)
5650
}),
@@ -85,9 +79,10 @@ export const FlowStack = ({ data }: FlowStackProps) => {
8579
payload: {
8680
traceId,
8781
spanName:
88-
frameStacks[0].frames[0]?.spanName ??
82+
frameStacks[0].frames?.[0]?.spanName ??
8983
`Sample trace for error ${exceptionType ?? ""}`.trim(),
90-
spanCodeObjectId: frameStacks[0].frames[0]?.codeObjectId ?? undefined
84+
spanCodeObjectId:
85+
frameStacks[0].frames?.[0]?.codeObjectId ?? undefined
9186
}
9287
});
9388
}
@@ -133,7 +128,7 @@ export const FlowStack = ({ data }: FlowStackProps) => {
133128
<s.Container>
134129
<s.StacksContainer ref={stacksContainerRef}>
135130
{frameStacks.map((x) => {
136-
const frames = x.frames.filter(Boolean) as ErrorFlowFrame[];
131+
const frames = x.frames ?? [];
137132
const visibleFrames = showWorkspaceOnly
138133
? frames.filter((x) => x.codeObjectId && filesURIs[x.codeObjectId])
139134
: frames;

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

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { useEffect, useState } from "react";
22
import { usePrevious } from "../../../../hooks/usePrevious";
3-
import { isNull } from "../../../../typeGuards/isNull";
43
import { isNumber } from "../../../../typeGuards/isNumber";
54
import { isString } from "../../../../typeGuards/isString";
65
import { sendUserActionTrackingEvent } from "../../../../utils/actions/sendUserActionTrackingEvent";
@@ -31,20 +30,21 @@ export const ErrorDetailsCardContent = ({
3130
}
3231
}, [previousId, id]);
3332

34-
const services = data.originServices
35-
.filter(isServiceInfoWithName)
36-
.map((x) => x.serviceName);
33+
const services =
34+
data.originServices
35+
?.filter(isServiceInfoWithName)
36+
.map((x) => x.serviceName) ?? [];
3737
const startedTooltip = new Date(data.firstOccurenceTime).toString();
3838
const startedString = formatTimeDistance(data.firstOccurenceTime);
3939
const lastTooltip = new Date(data.lastOccurenceTime).toString();
4040
const lastString = formatTimeDistance(data.lastOccurenceTime);
4141
const avgPerDay = data.dayAvg;
4242

43-
const flows = data.errors.filter((x) => !isNull(x));
43+
const flows = data.errors ?? [];
4444
const currentFlow = flows[currentFlowStack];
4545

4646
const isPreviousFlowButtonDisabled = currentFlowStack === 0;
47-
const isNextFlowButtonDisabled = currentFlowStack === flows.length - 1;
47+
const isNextFlowButtonDisabled = currentFlowStack >= flows.length - 1;
4848

4949
const handleFlowPaginationButtonClick = (flowNumber: number) => () => {
5050
sendUserActionTrackingEvent(trackingEvents.FLOW_PAGINATION_BUTTON_CLICKED);
@@ -99,8 +99,10 @@ export const ErrorDetailsCardContent = ({
9999
<span>
100100
Flow Stacks{" "}
101101
<s.FlowsCountNumber>
102-
<s.CurrentFlowNumber>{currentFlowStack + 1}</s.CurrentFlowNumber>/
103-
{data.errors.length}
102+
<s.CurrentFlowNumber>
103+
{flows.length > 0 ? currentFlowStack + 1 : 0}
104+
</s.CurrentFlowNumber>
105+
/{flows.length}
104106
</s.FlowsCountNumber>
105107
</span>
106108
<s.IconButton
@@ -114,7 +116,9 @@ export const ErrorDetailsCardContent = ({
114116
/>
115117
</s.IconButton>
116118
</s.FlowPagination>
117-
<FlowStack data={currentFlow} key={currentFlowStack} />
119+
{flows.length > 0 && (
120+
<FlowStack data={currentFlow} key={currentFlowStack} />
121+
)}
118122
</s.FlowsContainer>
119123
</s.Container>
120124
);

src/redux/services/types.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -812,7 +812,7 @@ export interface ErrorFlowFrame {
812812
lineNumber: number;
813813
executedCode: string | null;
814814
codeObjectId: string | null;
815-
parameters: (ParamStats | null)[]; // TODO: check if this is correct
815+
parameters: ParamStats[] | null;
816816
repeat: number;
817817
spanName: string | null;
818818
spanKind: string | null;
@@ -823,12 +823,12 @@ export interface ErrorFlowFrame {
823823

824824
export interface ErrorFlowFrameStack {
825825
exceptionType: string | null;
826-
frames: (ErrorFlowFrame | null)[]; // TODO: check if this is correct
826+
frames: ErrorFlowFrame[] | null;
827827
exceptionMessage: string | null;
828828
}
829829

830830
export interface ErrorFlowInfo {
831-
frameStacks: (ErrorFlowFrameStack | null)[]; // TODO: check if this is correct
831+
frameStacks: ErrorFlowFrameStack[] | null;
832832
stackTrace: string | null;
833833
lastInstanceCommitId: string | null;
834834
latestTraceId: string | null;
@@ -846,8 +846,8 @@ export interface GetErrorResponse {
846846
lastOccurenceTime: string;
847847
dayAvg: number | null;
848848
scoreInfo: ScoreInfo;
849-
errors: (ErrorFlowInfo | null)[]; // TODO: check if this is correct
850-
originServices: (ErrorOriginService | null)[]; // TODO: check if this is correct
849+
errors: ErrorFlowInfo[] | null;
850+
originServices: ErrorOriginService[] | null;
851851
}
852852

853853
export enum GlobalErrorsSortingCriterion {

0 commit comments

Comments
 (0)