From e63e934d53e7902fde263df4d5efa7f65a61aedf Mon Sep 17 00:00:00 2001 From: stephmilovic Date: Wed, 6 May 2020 08:31:45 -0600 Subject: [PATCH] move reduce --- .../case/use_get_case_user_actions.tsx | 39 +++++++++++-------- 1 file changed, 22 insertions(+), 17 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 db9bbc684e5cc..bb2fdc60d1395 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 @@ -53,20 +53,6 @@ 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[], @@ -102,7 +88,7 @@ export const getPushedInfo = ( [] ); - const caseServices = caseUserActions.reduce((acc, cua, i) => { + let caseServices = caseUserActions.reduce((acc, cua, i) => { if (cua.action !== 'push-to-service') { return acc; } @@ -120,7 +106,7 @@ export const getPushedInfo = ( ...acc[externalService.connectorId], ...externalService, lastPushIndex: i, - commentsToUpdate: buildCommentsToUpdate(commentsAndIndex, i), + commentsToUpdate: [], }, } : { @@ -129,12 +115,31 @@ export const getPushedInfo = ( firstPushIndex: i, lastPushIndex: i, hasDataToPush: hasDataToPushForConnector(externalService.connectorId), - commentsToUpdate: buildCommentsToUpdate(commentsAndIndex, i), + commentsToUpdate: [], }, }), }; }, {}); + caseServices = Object.keys(caseServices).reduce((acc, key) => { + return { + ...acc, + [key]: { + ...caseServices[key], + // if the comment happens after the lastUpdateToCaseIndex, it should be included in commentsToUpdate + commentsToUpdate: commentsAndIndex.reduce( + (bacc, currentComment) => + currentComment.commentIndex > caseServices[key].lastPushIndex + ? bacc.indexOf(currentComment.commentId) > -1 + ? [...bacc.filter(e => e !== currentComment.commentId), currentComment.commentId] + : [...bacc, currentComment.commentId] + : bacc, + [] + ), + }, + }; + }, {}); + const hasDataToPush = caseServices[caseConnectorId] != null ? caseServices[caseConnectorId].hasDataToPush : true; return {