Skip to content

Commit

Permalink
pr changeS
Browse files Browse the repository at this point in the history
  • Loading branch information
stephmilovic committed May 5, 2020
1 parent 1dbd61c commit 5922aa2
Showing 1 changed file with 21 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,24 @@ export interface UseGetCaseUserActions extends CaseUserActionsState {

const getExternalService = (value: string): CaseExternalService | null =>
convertToCamelCase<CaseFullExternalService, CaseExternalService>(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<string[]>(
(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[],
Expand All @@ -70,12 +88,7 @@ export const getPushedInfo = (
.action !== 'push-to-service'
);
};
const commentsAndIndex = caseUserActions.reduce<
Array<{
commentId: string;
commentIndex: number;
}>
>(
const commentsAndIndex = caseUserActions.reduce<CommentsAndIndex[]>(
(bacc, mua, index) =>
mua.actionField[0] === 'comment' && mua.commentId != null
? [
Expand Down Expand Up @@ -107,18 +120,7 @@ export const getPushedInfo = (
...acc[externalService.connectorId],
...externalService,
lastPushIndex: i,
commentsToUpdate: commentsAndIndex.reduce<string[]>(
(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),
},
}
: {
Expand All @@ -127,18 +129,7 @@ export const getPushedInfo = (
firstPushIndex: i,
lastPushIndex: i,
hasDataToPush: hasDataToPushForConnector(externalService.connectorId),
commentsToUpdate: commentsAndIndex.reduce<string[]>(
(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),
},
}),
};
Expand Down

0 comments on commit 5922aa2

Please sign in to comment.