From 5922aa2d58a249e619ecb7e88f7a1420043f3fc7 Mon Sep 17 00:00:00 2001 From: stephmilovic Date: Tue, 5 May 2020 16:39:17 -0600 Subject: [PATCH] pr changeS --- .../case/use_get_case_user_actions.tsx | 51 ++++++++----------- 1 file changed, 21 insertions(+), 30 deletions(-) diff --git a/x-pack/plugins/siem/public/containers/case/use_get_case_user_actions.tsx b/x-pack/plugins/siem/public/containers/case/use_get_case_user_actions.tsx index 97f1d55f822d6..db9bbc684e5cc 100644 --- a/x-pack/plugins/siem/public/containers/case/use_get_case_user_actions.tsx +++ b/x-pack/plugins/siem/public/containers/case/use_get_case_user_actions.tsx @@ -49,6 +49,24 @@ export interface UseGetCaseUserActions extends CaseUserActionsState { const getExternalService = (value: string): CaseExternalService | null => convertToCamelCase(parseString(`${value}`)); +interface CommentsAndIndex { + commentId: string; + commentIndex: number; +} +// if the comment happens after the lastUpdateToCaseIndex, it should be included in commentsToUpdate +const buildCommentsToUpdate = ( + commentsAndIndex: CommentsAndIndex[], + lastUpdateToCaseIndex: number +) => + commentsAndIndex.reduce( + (bacc, currentComment) => + currentComment.commentIndex > lastUpdateToCaseIndex + ? bacc.indexOf(currentComment.commentId) > -1 + ? [...bacc.filter(e => e !== currentComment.commentId), currentComment.commentId] + : [...bacc, currentComment.commentId] + : bacc, + [] + ); export const getPushedInfo = ( caseUserActions: CaseUserActions[], @@ -70,12 +88,7 @@ export const getPushedInfo = ( .action !== 'push-to-service' ); }; - const commentsAndIndex = caseUserActions.reduce< - Array<{ - commentId: string; - commentIndex: number; - }> - >( + const commentsAndIndex = caseUserActions.reduce( (bacc, mua, index) => mua.actionField[0] === 'comment' && mua.commentId != null ? [ @@ -107,18 +120,7 @@ export const getPushedInfo = ( ...acc[externalService.connectorId], ...externalService, lastPushIndex: i, - commentsToUpdate: commentsAndIndex.reduce( - (bacc, currentComment) => - currentComment.commentIndex > i - ? bacc.indexOf(currentComment.commentId) > -1 - ? [ - ...bacc.filter(e => e !== currentComment.commentId), - currentComment.commentId, - ] - : [...bacc, currentComment.commentId] - : bacc, - [] - ), + commentsToUpdate: buildCommentsToUpdate(commentsAndIndex, i), }, } : { @@ -127,18 +129,7 @@ export const getPushedInfo = ( firstPushIndex: i, lastPushIndex: i, hasDataToPush: hasDataToPushForConnector(externalService.connectorId), - commentsToUpdate: commentsAndIndex.reduce( - (bacc, currentComment) => - currentComment.commentIndex > i - ? bacc.indexOf(currentComment.commentId) > -1 - ? [ - ...bacc.filter(e => e !== currentComment.commentId), - currentComment.commentId, - ] - : [...bacc, currentComment.commentId] - : bacc, - [] - ), + commentsToUpdate: buildCommentsToUpdate(commentsAndIndex, i), }, }), };