Skip to content

Commit 5922aa2

Browse files
committed
pr changeS
1 parent 1dbd61c commit 5922aa2

File tree

1 file changed

+21
-30
lines changed

1 file changed

+21
-30
lines changed

x-pack/plugins/siem/public/containers/case/use_get_case_user_actions.tsx

Lines changed: 21 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,24 @@ export interface UseGetCaseUserActions extends CaseUserActionsState {
4949

5050
const getExternalService = (value: string): CaseExternalService | null =>
5151
convertToCamelCase<CaseFullExternalService, CaseExternalService>(parseString(`${value}`));
52+
interface CommentsAndIndex {
53+
commentId: string;
54+
commentIndex: number;
55+
}
56+
// if the comment happens after the lastUpdateToCaseIndex, it should be included in commentsToUpdate
57+
const buildCommentsToUpdate = (
58+
commentsAndIndex: CommentsAndIndex[],
59+
lastUpdateToCaseIndex: number
60+
) =>
61+
commentsAndIndex.reduce<string[]>(
62+
(bacc, currentComment) =>
63+
currentComment.commentIndex > lastUpdateToCaseIndex
64+
? bacc.indexOf(currentComment.commentId) > -1
65+
? [...bacc.filter(e => e !== currentComment.commentId), currentComment.commentId]
66+
: [...bacc, currentComment.commentId]
67+
: bacc,
68+
[]
69+
);
5270

5371
export const getPushedInfo = (
5472
caseUserActions: CaseUserActions[],
@@ -70,12 +88,7 @@ export const getPushedInfo = (
7088
.action !== 'push-to-service'
7189
);
7290
};
73-
const commentsAndIndex = caseUserActions.reduce<
74-
Array<{
75-
commentId: string;
76-
commentIndex: number;
77-
}>
78-
>(
91+
const commentsAndIndex = caseUserActions.reduce<CommentsAndIndex[]>(
7992
(bacc, mua, index) =>
8093
mua.actionField[0] === 'comment' && mua.commentId != null
8194
? [
@@ -107,18 +120,7 @@ export const getPushedInfo = (
107120
...acc[externalService.connectorId],
108121
...externalService,
109122
lastPushIndex: i,
110-
commentsToUpdate: commentsAndIndex.reduce<string[]>(
111-
(bacc, currentComment) =>
112-
currentComment.commentIndex > i
113-
? bacc.indexOf(currentComment.commentId) > -1
114-
? [
115-
...bacc.filter(e => e !== currentComment.commentId),
116-
currentComment.commentId,
117-
]
118-
: [...bacc, currentComment.commentId]
119-
: bacc,
120-
[]
121-
),
123+
commentsToUpdate: buildCommentsToUpdate(commentsAndIndex, i),
122124
},
123125
}
124126
: {
@@ -127,18 +129,7 @@ export const getPushedInfo = (
127129
firstPushIndex: i,
128130
lastPushIndex: i,
129131
hasDataToPush: hasDataToPushForConnector(externalService.connectorId),
130-
commentsToUpdate: commentsAndIndex.reduce<string[]>(
131-
(bacc, currentComment) =>
132-
currentComment.commentIndex > i
133-
? bacc.indexOf(currentComment.commentId) > -1
134-
? [
135-
...bacc.filter(e => e !== currentComment.commentId),
136-
currentComment.commentId,
137-
]
138-
: [...bacc, currentComment.commentId]
139-
: bacc,
140-
[]
141-
),
132+
commentsToUpdate: buildCommentsToUpdate(commentsAndIndex, i),
142133
},
143134
}),
144135
};

0 commit comments

Comments
 (0)