box-ui-elements 16.0.0 → 16.0.1-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/explorer.js +2 -2
- package/dist/openwith.js +1 -1
- package/dist/picker.js +9 -9
- package/dist/preview.js +2 -2
- package/dist/sharing.js +15 -15
- package/dist/sidebar.js +2 -2
- package/dist/uploader.js +9 -9
- package/es/api/Feed.js +67 -22
- package/es/api/Feed.js.flow +52 -6
- package/es/api/Feed.js.map +1 -1
- package/es/elements/content-sidebar/withSidebarAnnotations.js +6 -10
- package/es/elements/content-sidebar/withSidebarAnnotations.js.flow +5 -5
- package/es/elements/content-sidebar/withSidebarAnnotations.js.map +1 -1
- package/package.json +1 -1
- package/src/api/Feed.js +52 -6
- package/src/api/__tests__/Feed.test.js +130 -5
- package/src/elements/content-sidebar/__tests__/withSidebarAnnotations.test.js +4 -2
- package/src/elements/content-sidebar/withSidebarAnnotations.js +5 -5
|
@@ -281,9 +281,7 @@ export default function withSidebarAnnotations(WrappedComponent) {
|
|
|
281
281
|
return;
|
|
282
282
|
}
|
|
283
283
|
|
|
284
|
-
feedAPI.
|
|
285
|
-
total_reply_count: annotationItem.total_reply_count + 1
|
|
286
|
-
}, annotationId);
|
|
284
|
+
feedAPI.modifyFeedItemRepliesCountBy(annotationId, 1);
|
|
287
285
|
feedAPI.updateReplyItem(_objectSpread({}, annotationReply, {
|
|
288
286
|
isPending: false
|
|
289
287
|
}), annotationId, requestId);
|
|
@@ -342,7 +340,7 @@ export default function withSidebarAnnotations(WrappedComponent) {
|
|
|
342
340
|
|
|
343
341
|
if (!annotationItem) {
|
|
344
342
|
return;
|
|
345
|
-
} // Check if the parent annotation has the reply currently visible
|
|
343
|
+
} // Check if the parent annotation has the reply currently visible and if so, remove it
|
|
346
344
|
|
|
347
345
|
|
|
348
346
|
var replyItem = annotationItem.replies.find(function (_ref7) {
|
|
@@ -352,12 +350,10 @@ export default function withSidebarAnnotations(WrappedComponent) {
|
|
|
352
350
|
|
|
353
351
|
if (replyItem) {
|
|
354
352
|
feedAPI.deleteReplyItem(replyId, annotationId);
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
}, annotationId);
|
|
360
|
-
}
|
|
353
|
+
} // Decrease the amount of replies by 1
|
|
354
|
+
|
|
355
|
+
|
|
356
|
+
feedAPI.modifyFeedItemRepliesCountBy(annotationId, -1);
|
|
361
357
|
}
|
|
362
358
|
|
|
363
359
|
this.refreshActivitySidebar();
|
|
@@ -173,7 +173,7 @@ export default function withSidebarAnnotations(
|
|
|
173
173
|
return;
|
|
174
174
|
}
|
|
175
175
|
|
|
176
|
-
feedAPI.
|
|
176
|
+
feedAPI.modifyFeedItemRepliesCountBy(annotationId, 1);
|
|
177
177
|
feedAPI.updateReplyItem({ ...annotationReply, isPending: false }, annotationId, requestId);
|
|
178
178
|
}
|
|
179
179
|
|
|
@@ -223,14 +223,14 @@ export default function withSidebarAnnotations(
|
|
|
223
223
|
return;
|
|
224
224
|
}
|
|
225
225
|
|
|
226
|
-
// Check if the parent annotation has the reply currently visible
|
|
226
|
+
// Check if the parent annotation has the reply currently visible and if so, remove it
|
|
227
227
|
const replyItem = annotationItem.replies.find(({ id }) => id === replyId);
|
|
228
228
|
if (replyItem) {
|
|
229
229
|
feedAPI.deleteReplyItem(replyId, annotationId);
|
|
230
|
-
} else if (annotationItem.total_reply_count > 0) {
|
|
231
|
-
// Decrease the amount of replies by 1
|
|
232
|
-
feedAPI.updateFeedItem({ total_reply_count: annotationItem.total_reply_count - 1 }, annotationId);
|
|
233
230
|
}
|
|
231
|
+
|
|
232
|
+
// Decrease the amount of replies by 1
|
|
233
|
+
feedAPI.modifyFeedItemRepliesCountBy(annotationId, -1);
|
|
234
234
|
}
|
|
235
235
|
|
|
236
236
|
this.refreshActivitySidebar();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/elements/content-sidebar/withSidebarAnnotations.js"],"names":["React","getProp","noop","matchPath","FEED_ITEM_TYPE_VERSION","getBadUserError","withSidebarAnnotations","WrappedComponent","WithSidebarAnnotations","props","createRef","file","getAnnotationsPath","getAnnotationsMatchPath","history","location","match","annotationId","currentFileVersionId","fileVersionId","replace","annotatorState","activeAnnotationFileVersionId","activeAnnotationId","defaultFileVersionId","newLocationState","open","state","push","pathname","api","fileId","onVersionChange","feedAPI","getFeedAPI","getCachedItems","items","feedItems","version","filter","item","type","find","id","currentVersionId","updateVersionToCurrent","isOpen","isActivity","current","sidebarPanels","refresh","redirectDeeplinkedAnnotation","prevProps","prevAnnotatorState","prevFileId","prevLocation","action","annotation","prevActiveAnnotationId","prevAnnotation","prevMatch","hasActiveAnnotationChanged","isAnnotationsPath","isTransitioningToAnnotationPath","prevFileVersionId","addAnnotationReply","deleteAnnotationReply","updateAnnotationReply","updateAnnotation","deleteAnnotation","addAnnotation","updateActiveAnnotation","updateActiveVersion","meta","requestId","currentUser","isPending","hasItems","refreshActivitySidebar","annotationReply","addPendingReply","annotationItem","updateFeedItem","total_reply_count","updateReplyItem","deleteFeedItem","replyId","replyItem","replies","deleteReplyItem","Component","displayName","name"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AACA,OAAO,KAAKA,KAAZ,MAAuB,OAAvB;AACA,OAAOC,OAAP,MAAoB,YAApB;AACA,OAAOC,IAAP,MAAiB,aAAjB;AACA,SAASC,SAAT,QAA8C,kBAA9C;AACA,SAASC,sBAAT,QAAuC,iBAAvC;AACA,SAASC,eAAT,QAAgC,mBAAhC;AAiBA,eAAe,SAASC,sBAAT,CACXC,gBADW,EAEe;AAAA,MACpBC,sBADoB;AAAA;AAAA;AAAA;;AAetB,oCAAYC,KAAZ,EAAmB;AAAA;;AAAA;;AACf,kGAAMA,KAAN;;AADe,sEAFuCT,KAAK,CAACU,SAAN,EAEvC;;AAAA,qFAMY,YAAM;AAAA,0BACgD,MAAKD,KADrD;AAAA,YACzBE,IADyB,eACzBA,IADyB;A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KhB,KAAKrE,KALW;AAAA,kDAEhBY,cAFgB;AAAA,YAEEmC,MAFF,yBAEEA,MAFF;AAAA,YAEUC,UAFV,yBAEUA,UAFV;AAAA,YAEsBsB,eAFtB,yBAEsBA,eAFtB;AAAA,YAGhBjD,GAHgB,iBAGhBA,GAHgB;AAAA,YAIhBnB,IAJgB,iBAIhBA,IAJgB;AAOpB,YAAMsB,OAAO,GAAGH,GAAG,CAACI,UAAJ,CAAe,KAAf,CAAhB;AACA,YAAM0C,SAAS,GAAGpB,MAAM,KAAK,oBAA7B;AACAvB,QAAAA,OAAO,CAACtB,IAAR,GAAeA,IAAf;AAEAsB,QAAAA,OAAO,CAACmD,eAAR,mBAA6BL,eAA7B;AAA8CH,UAAAA,SAAS,EAATA;AAA9C,YAA2DnB,UAAU,CAACd,EAAtE,EAA0EoC,eAAe,CAACpC,EAA1F;AAEA,aAAKmC,sBAAL;AACH;AAnPqB;AAAA;AAAA,+BAoTb;AACL,eAAO,oBAAC,gBAAD;AAAkB,UAAA,GAAG,EAAE,KAAK7B;AAA5B,WAA+C,KAAKxC,KAApD,EAAP;AACH;AAtTqB;;AAAA;AAAA,IACWT,KAAK,CAAC0F,SADjB;;AAAA,kBACpBlF,sBADoB,kBAEA;AAClBa,IAAAA,cAAc,EAAE,EADE;AAElBR,IAAAA,uBAAuB,EAAEX,IAFP;AAGlBU,IAAAA,kBAAkB,EAAEV,IAHF;AAIlB8B,IAAAA,eAAe,EAAE9B;AAJC,GAFA;;AAyT1B,MAAMyF,WAAW,GAAGpF,gBAAgB,CAACoF,WAAjB,IAAgCpF,gBAAgB,CAACqF,IAAjD,IAAyD,WAA7E;AACApF,EAAAA,sBAAsB,CAACmF,WAAvB,oCAA+DA,WAA/D;AAEA,SAAOnF,sBAAP;AACH","sourcesContent":["// @flow\nimport * as React from 'react';\nimport getProp from 'lodash/get';\nimport noop from 'lodash/noop';\nimport { matchPath, type ContextRouter } from 'react-router-dom';\nimport { FEED_ITEM_TYPE_VERSION } from '../../constants';\nimport { getBadUserError } from '../../utils/error';\nimport type { WithAnnotatorContextProps } from '../common/annotator-context';\nimport type { BoxItem, User } from '../../common/types/core';\n\ntype Props = {\n ...ContextRouter,\n currentUser?: User,\n file: BoxItem,\n fileId: string,\n isOpen: boolean,\n onVersionChange: Function,\n} & WithAnnotatorContextProps;\n\ntype SidebarPanelsRefType = {\n refresh: (shouldRefreshCache?: boolean) => void,\n};\n\nexport default function withSidebarAnnotations(\n WrappedComponent: React.ComponentType<Props>,\n): React.ComponentType<Props> {\n class WithSidebarAnnotations extends React.Component<Props> {\n static defaultProps = {\n annotatorState: {},\n getAnnotationsMatchPath: noop,\n getAnnotationsPath: noop,\n onVersionChange: noop,\n };\n\n static displayName: ?string;\n\n props: Props;\n\n sidebarPanels: { current: SidebarPanelsRefType | null } = React.createRef();\n\n constructor(props) {\n super(props);\n\n this.redirectDeeplinkedAnnotation();\n }\n\n redirectDeeplinkedAnnotation = () => {\n const { file, getAnnotationsPath, getAnnotationsMatchPath, history, location } = this.props;\n const match = getAnnotationsMatchPath(location);\n const annotationId = getProp(match, 'params.annotationId');\n const currentFileVersionId = getProp(file, 'file_version.id');\n const fileVersionId = getProp(match, 'params.fileVersionId');\n\n if (fileVersionId && fileVersionId !== currentFileVersionId) {\n history.replace(getAnnotationsPath(currentFileVersionId, annotationId));\n }\n };\n\n componentDidUpdate(prevProps: Props) {\n const { annotatorState, fileId, getAnnotationsMatchPath, location, onVersionChange }: Props = this.props;\n const { annotatorState: prevAnnotatorState, fileId: prevFileId, location: prevLocation }: Props = prevProps;\n const { action, activeAnnotationId, annotation } = annotatorState;\n const { activeAnnotationId: prevActiveAnnotationId, annotation: prevAnnotation } = prevAnnotatorState;\n\n const match = getAnnotationsMatchPath(location);\n const prevMatch = getAnnotationsMatchPath(prevLocation);\n const fileVersionId = getProp(match, 'params.fileVersionId');\n const hasActiveAnnotationChanged = prevActiveAnnotationId !== activeAnnotationId;\n const isAnnotationsPath = !!match;\n const isTransitioningToAnnotationPath = activeAnnotationId && !isAnnotationsPath;\n const prevFileVersionId = getProp(prevMatch, 'params.fileVersionId');\n\n if (action === 'reply_create_start' || action === 'reply_create_end') {\n this.addAnnotationReply();\n }\n\n if (action === 'reply_delete_start' || action === 'reply_delete_end') {\n this.deleteAnnotationReply();\n }\n\n if (action === 'reply_update_start' || action === 'reply_update_end') {\n this.updateAnnotationReply();\n }\n\n if (action === 'update_start' || action === 'update_end') {\n this.updateAnnotation();\n }\n\n if (action === 'delete_start' || action === 'delete_end') {\n this.deleteAnnotation();\n }\n\n if ((action === 'create_start' || action === 'create_end') && annotation && prevAnnotation !== annotation) {\n this.addAnnotation();\n }\n\n // Active annotation id changed. If location is currently an annotation path or\n // if location is not currently an annotation path but the active annotation id\n // transitioned from falsy to truthy, update the location accordingly\n if (hasActiveAnnotationChanged && (isAnnotationsPath || isTransitioningToAnnotationPath)) {\n this.updateActiveAnnotation();\n }\n\n if (fileVersionId && prevFileVersionId !== fileVersionId) {\n this.updateActiveVersion();\n }\n\n if (prevFileId !== fileId) {\n // If the file id has changed, reset the current version id since the previous (possibly versioned)\n // location is no longer active\n onVersionChange(null);\n }\n }\n\n addAnnotation() {\n const {\n annotatorState: { action, annotation, meta: { requestId } = {} },\n api,\n currentUser,\n file,\n fileId,\n } = this.props;\n\n if (!requestId) {\n return;\n }\n\n // TODO: need to address in follow on -- currentUser may be undefined here but is never fetched for sure until ActivitySidebar\n if (!currentUser) {\n throw getBadUserError();\n }\n\n const feedAPI = api.getFeedAPI(false);\n const isPending = action === 'create_start';\n const { items: hasItems } = feedAPI.getCachedItems(fileId) || {};\n\n // If there are existing items in the cache for this file, then patch the cache with the new annotation\n // If there are no cache entry for feeditems, then it is assumed that it has not yet been fetched.\n if (hasItems) {\n feedAPI.addAnnotation(file, currentUser, annotation, requestId, isPending);\n }\n\n this.refreshActivitySidebar();\n }\n\n addAnnotationReply() {\n const {\n annotatorState: {\n action,\n annotation: { id: annotationId },\n annotationReply,\n meta: { requestId },\n },\n api,\n currentUser,\n file,\n } = this.props;\n\n if (!currentUser) {\n throw getBadUserError();\n }\n\n const feedAPI = api.getFeedAPI(false);\n feedAPI.file = file;\n\n if (action === 'reply_create_start') {\n feedAPI.addPendingReply(annotationId, currentUser, { ...annotationReply, id: requestId });\n } else {\n const { items: feedItems = [] } = feedAPI.getCachedItems(file.id) || {};\n const annotationItem = feedItems.find(({ id }) => id === annotationId);\n\n if (!annotationItem) {\n return;\n }\n\n feedAPI.updateFeedItem({ total_reply_count: annotationItem.total_reply_count + 1 }, annotationId);\n feedAPI.updateReplyItem({ ...annotationReply, isPending: false }, annotationId, requestId);\n }\n\n this.refreshActivitySidebar();\n }\n\n deleteAnnotation() {\n const {\n annotatorState: { action, annotation },\n api,\n file,\n } = this.props;\n\n const feedAPI = api.getFeedAPI(false);\n feedAPI.file = file;\n\n if (action === 'delete_start') {\n feedAPI.updateFeedItem({ isPending: true }, annotation.id);\n } else {\n feedAPI.deleteFeedItem(annotation.id);\n }\n\n this.refreshActivitySidebar();\n }\n\n deleteAnnotationReply() {\n const {\n annotatorState: {\n action,\n annotation: { id: annotationId },\n annotationReply: { id: replyId },\n },\n api,\n file,\n } = this.props;\n\n const feedAPI = api.getFeedAPI(false);\n feedAPI.file = file;\n\n if (action === 'reply_delete_start') {\n feedAPI.updateReplyItem({ isPending: true }, annotationId, replyId);\n } else {\n const { items: feedItems = [] } = feedAPI.getCachedItems(file.id) || {};\n const annotationItem = feedItems.find(({ id }) => id === annotationId);\n\n if (!annotationItem) {\n return;\n }\n\n // Check if the parent annotation has the reply currently visible\n const replyItem = annotationItem.replies.find(({ id }) => id === replyId);\n if (replyItem) {\n feedAPI.deleteReplyItem(replyId, annotationId);\n } else if (annotationItem.total_reply_count > 0) {\n // Decrease the amount of replies by 1\n feedAPI.updateFeedItem({ total_reply_count: annotationItem.total_reply_count - 1 }, annotationId);\n }\n }\n\n this.refreshActivitySidebar();\n }\n\n updateAnnotation() {\n const {\n annotatorState: { action, annotation },\n api,\n file,\n } = this.props;\n\n const feedAPI = api.getFeedAPI(false);\n const isPending = action === 'update_start';\n feedAPI.file = file;\n\n feedAPI.updateFeedItem({ ...annotation, isPending }, annotation.id);\n\n this.refreshActivitySidebar();\n }\n\n updateAnnotationReply() {\n const {\n annotatorState: { action, annotation, annotationReply },\n api,\n file,\n } = this.props;\n\n const feedAPI = api.getFeedAPI(false);\n const isPending = action === 'reply_update_start';\n feedAPI.file = file;\n\n feedAPI.updateReplyItem({ ...annotationReply, isPending }, annotation.id, annotationReply.id);\n\n this.refreshActivitySidebar();\n }\n\n updateActiveAnnotation = () => {\n const {\n annotatorState: { activeAnnotationFileVersionId, activeAnnotationId },\n file,\n getAnnotationsMatchPath,\n getAnnotationsPath,\n history,\n location,\n } = this.props;\n const match = getAnnotationsMatchPath(location);\n const currentFileVersionId = getProp(file, 'file_version.id');\n const defaultFileVersionId = activeAnnotationFileVersionId || currentFileVersionId;\n const fileVersionId = getProp(match, 'params.fileVersionId', defaultFileVersionId);\n const newLocationState = activeAnnotationId ? { open: true } : location.state;\n\n // Update the location pathname and open state if transitioning to an active annotation id, force the sidebar open\n history.push({\n pathname: getAnnotationsPath(fileVersionId, activeAnnotationId),\n state: newLocationState,\n });\n };\n\n updateActiveVersion = () => {\n const {\n api,\n file,\n fileId,\n getAnnotationsMatchPath,\n getAnnotationsPath,\n history,\n location,\n onVersionChange,\n } = this.props;\n const feedAPI = api.getFeedAPI(false);\n const match = getAnnotationsMatchPath(location);\n const currentFileVersionId = getProp(file, 'file_version.id');\n const fileVersionId = getProp(match, 'params.fileVersionId');\n const { items: feedItems = [] } = feedAPI.getCachedItems(fileId) || {};\n const version = feedItems\n .filter(item => item.type === FEED_ITEM_TYPE_VERSION)\n .find(item => item.id === fileVersionId);\n\n if (version) {\n onVersionChange(version, {\n currentVersionId: currentFileVersionId,\n updateVersionToCurrent: () => history.push(getAnnotationsPath(currentFileVersionId)),\n });\n }\n };\n\n refreshActivitySidebar = () => {\n const { isOpen, location } = this.props;\n\n const pathname = getProp(location, 'pathname', '');\n const isActivity = matchPath(pathname, '/activity');\n const { current } = this.sidebarPanels;\n\n // If the activity sidebar is currently open, then force it to refresh with the updated data\n if (current && isActivity && isOpen) {\n current.refresh(false);\n }\n };\n\n render() {\n return <WrappedComponent ref={this.sidebarPanels} {...this.props} />;\n }\n }\n\n const displayName = WrappedComponent.displayName || WrappedComponent.name || 'Component';\n WithSidebarAnnotations.displayName = `WithSidebarAnnotations(${displayName})`;\n\n return WithSidebarAnnotations;\n}\n"],"file":"withSidebarAnnotations.js"}
|
|
1
|
+
{"version":3,"sources":["../../../src/elements/content-sidebar/withSidebarAnnotations.js"],"names":["React","getProp","noop","matchPath","FEED_ITEM_TYPE_VERSION","getBadUserError","withSidebarAnnotations","WrappedComponent","WithSidebarAnnotations","props","createRef","file","getAnnotationsPath","getAnnotationsMatchPath","history","location","match","annotationId","currentFileVersionId","fileVersionId","replace","annotatorState","activeAnnotationFileVersionId","activeAnnotationId","defaultFileVersionId","newLocationState","open","state","push","pathname","api","fileId","onVersionChange","feedAPI","getFeedAPI","getCachedItems","items","feedItems","version","filter","item","type","find","id","currentVersionId","updateVersionToCurrent","isOpen","isActivity","current","sidebarPanels","refresh","redirectDeeplinkedAnnotation","prevProps","prevAnnotatorState","prevFileId","prevLocation","action","annotation","prevActiveAnnotationId","prevAnnotation","prevMatch","hasActiveAnnotationChanged","isAnnotationsPath","isTransitioningToAnnotationPath","prevFileVersionId","addAnnotationReply","deleteAnnotationReply","updateAnnotationReply","updateAnnotation","deleteAnnotation","addAnnotation","updateActiveAnnotation","updateActiveVersion","meta","requestId","currentUser","isPending","hasItems","refreshActivitySidebar","annotationReply","addPendingReply","annotationItem","modifyFeedItemRepliesCountBy","updateReplyItem","updateFeedItem","deleteFeedItem","replyId","replyItem","replies","deleteReplyItem","Component","displayName","name"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AACA,OAAO,KAAKA,KAAZ,MAAuB,OAAvB;AACA,OAAOC,OAAP,MAAo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jD,IAAyD,WAA7E;AACApF,EAAAA,sBAAsB,CAACmF,WAAvB,oCAA+DA,WAA/D;AAEA,SAAOnF,sBAAP;AACH","sourcesContent":["// @flow\nimport * as React from 'react';\nimport getProp from 'lodash/get';\nimport noop from 'lodash/noop';\nimport { matchPath, type ContextRouter } from 'react-router-dom';\nimport { FEED_ITEM_TYPE_VERSION } from '../../constants';\nimport { getBadUserError } from '../../utils/error';\nimport type { WithAnnotatorContextProps } from '../common/annotator-context';\nimport type { BoxItem, User } from '../../common/types/core';\n\ntype Props = {\n ...ContextRouter,\n currentUser?: User,\n file: BoxItem,\n fileId: string,\n isOpen: boolean,\n onVersionChange: Function,\n} & WithAnnotatorContextProps;\n\ntype SidebarPanelsRefType = {\n refresh: (shouldRefreshCache?: boolean) => void,\n};\n\nexport default function withSidebarAnnotations(\n WrappedComponent: React.ComponentType<Props>,\n): React.ComponentType<Props> {\n class WithSidebarAnnotations extends React.Component<Props> {\n static defaultProps = {\n annotatorState: {},\n getAnnotationsMatchPath: noop,\n getAnnotationsPath: noop,\n onVersionChange: noop,\n };\n\n static displayName: ?string;\n\n props: Props;\n\n sidebarPanels: { current: SidebarPanelsRefType | null } = React.createRef();\n\n constructor(props) {\n super(props);\n\n this.redirectDeeplinkedAnnotation();\n }\n\n redirectDeeplinkedAnnotation = () => {\n const { file, getAnnotationsPath, getAnnotationsMatchPath, history, location } = this.props;\n const match = getAnnotationsMatchPath(location);\n const annotationId = getProp(match, 'params.annotationId');\n const currentFileVersionId = getProp(file, 'file_version.id');\n const fileVersionId = getProp(match, 'params.fileVersionId');\n\n if (fileVersionId && fileVersionId !== currentFileVersionId) {\n history.replace(getAnnotationsPath(currentFileVersionId, annotationId));\n }\n };\n\n componentDidUpdate(prevProps: Props) {\n const { annotatorState, fileId, getAnnotationsMatchPath, location, onVersionChange }: Props = this.props;\n const { annotatorState: prevAnnotatorState, fileId: prevFileId, location: prevLocation }: Props = prevProps;\n const { action, activeAnnotationId, annotation } = annotatorState;\n const { activeAnnotationId: prevActiveAnnotationId, annotation: prevAnnotation } = prevAnnotatorState;\n\n const match = getAnnotationsMatchPath(location);\n const prevMatch = getAnnotationsMatchPath(prevLocation);\n const fileVersionId = getProp(match, 'params.fileVersionId');\n const hasActiveAnnotationChanged = prevActiveAnnotationId !== activeAnnotationId;\n const isAnnotationsPath = !!match;\n const isTransitioningToAnnotationPath = activeAnnotationId && !isAnnotationsPath;\n const prevFileVersionId = getProp(prevMatch, 'params.fileVersionId');\n\n if (action === 'reply_create_start' || action === 'reply_create_end') {\n this.addAnnotationReply();\n }\n\n if (action === 'reply_delete_start' || action === 'reply_delete_end') {\n this.deleteAnnotationReply();\n }\n\n if (action === 'reply_update_start' || action === 'reply_update_end') {\n this.updateAnnotationReply();\n }\n\n if (action === 'update_start' || action === 'update_end') {\n this.updateAnnotation();\n }\n\n if (action === 'delete_start' || action === 'delete_end') {\n this.deleteAnnotation();\n }\n\n if ((action === 'create_start' || action === 'create_end') && annotation && prevAnnotation !== annotation) {\n this.addAnnotation();\n }\n\n // Active annotation id changed. If location is currently an annotation path or\n // if location is not currently an annotation path but the active annotation id\n // transitioned from falsy to truthy, update the location accordingly\n if (hasActiveAnnotationChanged && (isAnnotationsPath || isTransitioningToAnnotationPath)) {\n this.updateActiveAnnotation();\n }\n\n if (fileVersionId && prevFileVersionId !== fileVersionId) {\n this.updateActiveVersion();\n }\n\n if (prevFileId !== fileId) {\n // If the file id has changed, reset the current version id since the previous (possibly versioned)\n // location is no longer active\n onVersionChange(null);\n }\n }\n\n addAnnotation() {\n const {\n annotatorState: { action, annotation, meta: { requestId } = {} },\n api,\n currentUser,\n file,\n fileId,\n } = this.props;\n\n if (!requestId) {\n return;\n }\n\n // TODO: need to address in follow on -- currentUser may be undefined here but is never fetched for sure until ActivitySidebar\n if (!currentUser) {\n throw getBadUserError();\n }\n\n const feedAPI = api.getFeedAPI(false);\n const isPending = action === 'create_start';\n const { items: hasItems } = feedAPI.getCachedItems(fileId) || {};\n\n // If there are existing items in the cache for this file, then patch the cache with the new annotation\n // If there are no cache entry for feeditems, then it is assumed that it has not yet been fetched.\n if (hasItems) {\n feedAPI.addAnnotation(file, currentUser, annotation, requestId, isPending);\n }\n\n this.refreshActivitySidebar();\n }\n\n addAnnotationReply() {\n const {\n annotatorState: {\n action,\n annotation: { id: annotationId },\n annotationReply,\n meta: { requestId },\n },\n api,\n currentUser,\n file,\n } = this.props;\n\n if (!currentUser) {\n throw getBadUserError();\n }\n\n const feedAPI = api.getFeedAPI(false);\n feedAPI.file = file;\n\n if (action === 'reply_create_start') {\n feedAPI.addPendingReply(annotationId, currentUser, { ...annotationReply, id: requestId });\n } else {\n const { items: feedItems = [] } = feedAPI.getCachedItems(file.id) || {};\n const annotationItem = feedItems.find(({ id }) => id === annotationId);\n\n if (!annotationItem) {\n return;\n }\n\n feedAPI.modifyFeedItemRepliesCountBy(annotationId, 1);\n feedAPI.updateReplyItem({ ...annotationReply, isPending: false }, annotationId, requestId);\n }\n\n this.refreshActivitySidebar();\n }\n\n deleteAnnotation() {\n const {\n annotatorState: { action, annotation },\n api,\n file,\n } = this.props;\n\n const feedAPI = api.getFeedAPI(false);\n feedAPI.file = file;\n\n if (action === 'delete_start') {\n feedAPI.updateFeedItem({ isPending: true }, annotation.id);\n } else {\n feedAPI.deleteFeedItem(annotation.id);\n }\n\n this.refreshActivitySidebar();\n }\n\n deleteAnnotationReply() {\n const {\n annotatorState: {\n action,\n annotation: { id: annotationId },\n annotationReply: { id: replyId },\n },\n api,\n file,\n } = this.props;\n\n const feedAPI = api.getFeedAPI(false);\n feedAPI.file = file;\n\n if (action === 'reply_delete_start') {\n feedAPI.updateReplyItem({ isPending: true }, annotationId, replyId);\n } else {\n const { items: feedItems = [] } = feedAPI.getCachedItems(file.id) || {};\n const annotationItem = feedItems.find(({ id }) => id === annotationId);\n\n if (!annotationItem) {\n return;\n }\n\n // Check if the parent annotation has the reply currently visible and if so, remove it\n const replyItem = annotationItem.replies.find(({ id }) => id === replyId);\n if (replyItem) {\n feedAPI.deleteReplyItem(replyId, annotationId);\n }\n\n // Decrease the amount of replies by 1\n feedAPI.modifyFeedItemRepliesCountBy(annotationId, -1);\n }\n\n this.refreshActivitySidebar();\n }\n\n updateAnnotation() {\n const {\n annotatorState: { action, annotation },\n api,\n file,\n } = this.props;\n\n const feedAPI = api.getFeedAPI(false);\n const isPending = action === 'update_start';\n feedAPI.file = file;\n\n feedAPI.updateFeedItem({ ...annotation, isPending }, annotation.id);\n\n this.refreshActivitySidebar();\n }\n\n updateAnnotationReply() {\n const {\n annotatorState: { action, annotation, annotationReply },\n api,\n file,\n } = this.props;\n\n const feedAPI = api.getFeedAPI(false);\n const isPending = action === 'reply_update_start';\n feedAPI.file = file;\n\n feedAPI.updateReplyItem({ ...annotationReply, isPending }, annotation.id, annotationReply.id);\n\n this.refreshActivitySidebar();\n }\n\n updateActiveAnnotation = () => {\n const {\n annotatorState: { activeAnnotationFileVersionId, activeAnnotationId },\n file,\n getAnnotationsMatchPath,\n getAnnotationsPath,\n history,\n location,\n } = this.props;\n const match = getAnnotationsMatchPath(location);\n const currentFileVersionId = getProp(file, 'file_version.id');\n const defaultFileVersionId = activeAnnotationFileVersionId || currentFileVersionId;\n const fileVersionId = getProp(match, 'params.fileVersionId', defaultFileVersionId);\n const newLocationState = activeAnnotationId ? { open: true } : location.state;\n\n // Update the location pathname and open state if transitioning to an active annotation id, force the sidebar open\n history.push({\n pathname: getAnnotationsPath(fileVersionId, activeAnnotationId),\n state: newLocationState,\n });\n };\n\n updateActiveVersion = () => {\n const {\n api,\n file,\n fileId,\n getAnnotationsMatchPath,\n getAnnotationsPath,\n history,\n location,\n onVersionChange,\n } = this.props;\n const feedAPI = api.getFeedAPI(false);\n const match = getAnnotationsMatchPath(location);\n const currentFileVersionId = getProp(file, 'file_version.id');\n const fileVersionId = getProp(match, 'params.fileVersionId');\n const { items: feedItems = [] } = feedAPI.getCachedItems(fileId) || {};\n const version = feedItems\n .filter(item => item.type === FEED_ITEM_TYPE_VERSION)\n .find(item => item.id === fileVersionId);\n\n if (version) {\n onVersionChange(version, {\n currentVersionId: currentFileVersionId,\n updateVersionToCurrent: () => history.push(getAnnotationsPath(currentFileVersionId)),\n });\n }\n };\n\n refreshActivitySidebar = () => {\n const { isOpen, location } = this.props;\n\n const pathname = getProp(location, 'pathname', '');\n const isActivity = matchPath(pathname, '/activity');\n const { current } = this.sidebarPanels;\n\n // If the activity sidebar is currently open, then force it to refresh with the updated data\n if (current && isActivity && isOpen) {\n current.refresh(false);\n }\n };\n\n render() {\n return <WrappedComponent ref={this.sidebarPanels} {...this.props} />;\n }\n }\n\n const displayName = WrappedComponent.displayName || WrappedComponent.name || 'Component';\n WithSidebarAnnotations.displayName = `WithSidebarAnnotations(${displayName})`;\n\n return WithSidebarAnnotations;\n}\n"],"file":"withSidebarAnnotations.js"}
|
package/package.json
CHANGED
package/src/api/Feed.js
CHANGED
|
@@ -221,9 +221,11 @@ class Feed extends Base {
|
|
|
221
221
|
permissions,
|
|
222
222
|
feedItemChanges,
|
|
223
223
|
(annotation: Annotation) => {
|
|
224
|
+
const { replies, total_reply_count, ...annotationBase } = annotation;
|
|
224
225
|
this.updateFeedItem(
|
|
225
226
|
{
|
|
226
|
-
|
|
227
|
+
// Do not update replies and total_reply_count props as their current values are not included in the response
|
|
228
|
+
...annotationBase,
|
|
227
229
|
isPending: false,
|
|
228
230
|
},
|
|
229
231
|
annotationId,
|
|
@@ -505,9 +507,12 @@ class Feed extends Base {
|
|
|
505
507
|
|
|
506
508
|
this.updateFeedItem({ isRepliesLoading: true }, commentFeedItemId);
|
|
507
509
|
|
|
508
|
-
const successCallbackFn = (
|
|
509
|
-
this.updateFeedItem(
|
|
510
|
-
|
|
510
|
+
const successCallbackFn = ({ entries }: ThreadedCommentsType) => {
|
|
511
|
+
this.updateFeedItem(
|
|
512
|
+
{ isRepliesLoading: false, replies: entries, total_reply_count: entries.length },
|
|
513
|
+
commentFeedItemId,
|
|
514
|
+
);
|
|
515
|
+
successCallback(entries);
|
|
511
516
|
};
|
|
512
517
|
const errorCallbackFn = (error: ErrorResponseData, code: string) => {
|
|
513
518
|
this.fetchRepliesErrorCallback(error, code, commentFeedItemId);
|
|
@@ -898,13 +903,26 @@ class Feed extends Base {
|
|
|
898
903
|
fileId: file.id,
|
|
899
904
|
commentId: id,
|
|
900
905
|
permissions,
|
|
901
|
-
successCallback: this.
|
|
906
|
+
successCallback: this.deleteReplySuccessCallback.bind(this, id, parentId, successCallback),
|
|
902
907
|
errorCallback: (e: ElementsXhrError, code: string) => {
|
|
903
908
|
this.deleteReplyErrorCallback(e, code, id, parentId);
|
|
904
909
|
},
|
|
905
910
|
});
|
|
906
911
|
};
|
|
907
912
|
|
|
913
|
+
/**
|
|
914
|
+
* Callback for successful deletion of a reply.
|
|
915
|
+
*
|
|
916
|
+
* @param {string} id - ID of the reply
|
|
917
|
+
* @param {string} parentId - ID of the parent feed item
|
|
918
|
+
* @param {Function} successCallback - success callback
|
|
919
|
+
* @return {void}
|
|
920
|
+
*/
|
|
921
|
+
deleteReplySuccessCallback = (id: string, parentId: string, successCallback: Function): void => {
|
|
922
|
+
this.deleteReplyItem(id, parentId, successCallback);
|
|
923
|
+
this.modifyFeedItemRepliesCountBy(parentId, -1);
|
|
924
|
+
};
|
|
925
|
+
|
|
908
926
|
/**
|
|
909
927
|
* Error callback for deleting a comment
|
|
910
928
|
*
|
|
@@ -1727,6 +1745,7 @@ class Feed extends Base {
|
|
|
1727
1745
|
this.file = file;
|
|
1728
1746
|
this.errorCallback = errorCallback;
|
|
1729
1747
|
this.addPendingReply(parentId, currentUser, commentData);
|
|
1748
|
+
this.modifyFeedItemRepliesCountBy(parentId, 1);
|
|
1730
1749
|
|
|
1731
1750
|
const successCallbackFn = (comment: Comment) => {
|
|
1732
1751
|
this.createReplySuccessCallback(comment, parentId, uuid, successCallback);
|
|
@@ -1877,9 +1896,11 @@ class Feed extends Base {
|
|
|
1877
1896
|
message: text,
|
|
1878
1897
|
status,
|
|
1879
1898
|
successCallback: (comment: Comment) => {
|
|
1899
|
+
const { replies, total_reply_count, ...commentBase } = comment;
|
|
1880
1900
|
this.updateFeedItem(
|
|
1881
1901
|
{
|
|
1882
|
-
|
|
1902
|
+
// Do not update replies and total_reply_count props as their current values are not included in the response
|
|
1903
|
+
...commentBase,
|
|
1883
1904
|
isPending: false,
|
|
1884
1905
|
},
|
|
1885
1906
|
commentId,
|
|
@@ -1950,6 +1971,31 @@ class Feed extends Base {
|
|
|
1950
1971
|
});
|
|
1951
1972
|
};
|
|
1952
1973
|
|
|
1974
|
+
/**
|
|
1975
|
+
* Modify feed item replies count
|
|
1976
|
+
*
|
|
1977
|
+
* @param {string} id - id of the item
|
|
1978
|
+
* @param {number} n - number to modify the count by
|
|
1979
|
+
* @return {void}
|
|
1980
|
+
*/
|
|
1981
|
+
modifyFeedItemRepliesCountBy = (id: string, n: number) => {
|
|
1982
|
+
if (!this.file.id) {
|
|
1983
|
+
throw getBadItemError();
|
|
1984
|
+
}
|
|
1985
|
+
|
|
1986
|
+
const { items: feedItems = [] } = this.getCachedItems(this.file.id) || {};
|
|
1987
|
+
const feedItem = feedItems.find(({ id: itemId }) => itemId === id);
|
|
1988
|
+
|
|
1989
|
+
if (!feedItem || (feedItem.type !== 'annotation' && feedItem.type !== 'comment')) {
|
|
1990
|
+
return;
|
|
1991
|
+
}
|
|
1992
|
+
|
|
1993
|
+
const newReplyCount = (feedItem.total_reply_count || 0) + n;
|
|
1994
|
+
if (newReplyCount >= 0) {
|
|
1995
|
+
this.updateFeedItem({ total_reply_count: newReplyCount }, id);
|
|
1996
|
+
}
|
|
1997
|
+
};
|
|
1998
|
+
|
|
1953
1999
|
destroyTaskCollaborators() {
|
|
1954
2000
|
if (Array.isArray(this.taskCollaboratorsAPI)) {
|
|
1955
2001
|
this.taskCollaboratorsAPI.forEach(api => api.destroy());
|
|
@@ -12,7 +12,9 @@ import {
|
|
|
12
12
|
IS_ERROR_DISPLAYED,
|
|
13
13
|
TASK_MAX_GROUP_ASSIGNEES,
|
|
14
14
|
} from '../../constants';
|
|
15
|
+
import AnnotationsAPI from '../Annotations';
|
|
15
16
|
import Feed from '../Feed';
|
|
17
|
+
import ThreadedCommentsAPI from '../ThreadedComments';
|
|
16
18
|
import { annotation as mockAnnotation } from '../../__mocks__/annotations';
|
|
17
19
|
import { task as mockTask, threadedComments as mockThreadedComments, threadedCommentsFormatted } from '../fixtures';
|
|
18
20
|
|
|
@@ -66,6 +68,8 @@ const threadedComments = {
|
|
|
66
68
|
next_marker: null,
|
|
67
69
|
};
|
|
68
70
|
|
|
71
|
+
const mockReplies = mockThreadedComments[0].replies;
|
|
72
|
+
|
|
69
73
|
jest.mock('lodash/uniqueId', () => () => 'uniqueId');
|
|
70
74
|
|
|
71
75
|
const mockCreateTaskWithDeps = jest.fn().mockImplementation(({ successCallback }) => {
|
|
@@ -206,7 +210,7 @@ jest.mock('../ThreadedComments', () =>
|
|
|
206
210
|
}),
|
|
207
211
|
getCommentReplies: jest.fn().mockImplementation(({ successCallback }) => {
|
|
208
212
|
successCallback({
|
|
209
|
-
entries:
|
|
213
|
+
entries: mockReplies,
|
|
210
214
|
limit: 1000,
|
|
211
215
|
next_marker: null,
|
|
212
216
|
});
|
|
@@ -215,7 +219,7 @@ jest.mock('../ThreadedComments', () =>
|
|
|
215
219
|
successCallback();
|
|
216
220
|
}),
|
|
217
221
|
updateComment: jest.fn().mockImplementation(({ successCallback }) => {
|
|
218
|
-
successCallback();
|
|
222
|
+
successCallback({});
|
|
219
223
|
}),
|
|
220
224
|
createComment: jest.fn().mockImplementation(({ successCallback }) => {
|
|
221
225
|
successCallback();
|
|
@@ -239,12 +243,12 @@ jest.mock('../Annotations', () =>
|
|
|
239
243
|
successCallback();
|
|
240
244
|
}),
|
|
241
245
|
updateAnnotation: jest.fn().mockImplementation((file, id, payload, permissions, successCallback) => {
|
|
242
|
-
successCallback();
|
|
246
|
+
successCallback({});
|
|
243
247
|
}),
|
|
244
248
|
getAnnotations: jest.fn(),
|
|
245
249
|
getAnnotationReplies: jest.fn().mockImplementation((fileId, annotationId, permissions, successCallback) => {
|
|
246
250
|
successCallback({
|
|
247
|
-
entries:
|
|
251
|
+
entries: mockReplies,
|
|
248
252
|
limit: 1000,
|
|
249
253
|
next_marker: null,
|
|
250
254
|
});
|
|
@@ -676,8 +680,8 @@ describe('api/Feed', () => {
|
|
|
676
680
|
const annotationId = '1234';
|
|
677
681
|
const successCallback = jest.fn();
|
|
678
682
|
const errorCallback = jest.fn();
|
|
683
|
+
|
|
679
684
|
feed.fetchReplies(file, annotationId, FEED_ITEM_TYPE_ANNOTATION, successCallback, errorCallback);
|
|
680
|
-
expect(feed.updateFeedItem).toBeCalledWith({ isRepliesLoading: true }, annotationId);
|
|
681
685
|
expect(feed.annotationsAPI.getAnnotationReplies).toBeCalledWith(
|
|
682
686
|
feed.file.id,
|
|
683
687
|
annotationId,
|
|
@@ -685,6 +689,16 @@ describe('api/Feed', () => {
|
|
|
685
689
|
expect.any(Function),
|
|
686
690
|
expect.any(Function),
|
|
687
691
|
);
|
|
692
|
+
expect(feed.updateFeedItem).toHaveBeenNthCalledWith(1, { isRepliesLoading: true }, annotationId);
|
|
693
|
+
expect(feed.updateFeedItem).toHaveBeenNthCalledWith(
|
|
694
|
+
2,
|
|
695
|
+
{
|
|
696
|
+
isRepliesLoading: false,
|
|
697
|
+
replies: mockReplies,
|
|
698
|
+
total_reply_count: mockReplies.length,
|
|
699
|
+
},
|
|
700
|
+
annotationId,
|
|
701
|
+
);
|
|
688
702
|
expect(successCallback).toBeCalled();
|
|
689
703
|
});
|
|
690
704
|
});
|
|
@@ -1094,6 +1108,39 @@ describe('api/Feed', () => {
|
|
|
1094
1108
|
expect(successCallback).toBeCalled();
|
|
1095
1109
|
});
|
|
1096
1110
|
});
|
|
1111
|
+
|
|
1112
|
+
test('should call updateFeedItem without the replies and total_reply_count properties', () => {
|
|
1113
|
+
const commentId = '1';
|
|
1114
|
+
const text = 'abc';
|
|
1115
|
+
const permissions = { can_edit: true };
|
|
1116
|
+
const updatedCommentResult = {
|
|
1117
|
+
id: commentId,
|
|
1118
|
+
permissions,
|
|
1119
|
+
replies: [],
|
|
1120
|
+
tagged_message: text,
|
|
1121
|
+
total_reply_count: 0,
|
|
1122
|
+
};
|
|
1123
|
+
ThreadedCommentsAPI.mockReturnValueOnce({
|
|
1124
|
+
updateComment: jest.fn().mockImplementation(({ successCallback }) => {
|
|
1125
|
+
successCallback(updatedCommentResult);
|
|
1126
|
+
}),
|
|
1127
|
+
});
|
|
1128
|
+
|
|
1129
|
+
feed.updateThreadedComment(file, commentId, text, undefined, permissions, jest.fn(), jest.fn());
|
|
1130
|
+
|
|
1131
|
+
const expectedUpdateFeedItemCommentData = {
|
|
1132
|
+
id: commentId,
|
|
1133
|
+
isPending: false,
|
|
1134
|
+
permissions,
|
|
1135
|
+
tagged_message: text,
|
|
1136
|
+
};
|
|
1137
|
+
expect(feed.updateFeedItem).toHaveBeenNthCalledWith(
|
|
1138
|
+
1,
|
|
1139
|
+
{ tagged_message: text, isPending: true },
|
|
1140
|
+
commentId,
|
|
1141
|
+
);
|
|
1142
|
+
expect(feed.updateFeedItem).toHaveBeenNthCalledWith(2, expectedUpdateFeedItemCommentData, commentId);
|
|
1143
|
+
});
|
|
1097
1144
|
});
|
|
1098
1145
|
|
|
1099
1146
|
describe('updateReply()', () => {
|
|
@@ -1218,6 +1265,19 @@ describe('api/Feed', () => {
|
|
|
1218
1265
|
});
|
|
1219
1266
|
});
|
|
1220
1267
|
|
|
1268
|
+
describe('deleteReplySuccessCallback()', () => {
|
|
1269
|
+
test('should remove the reply from feed and update parent item', () => {
|
|
1270
|
+
feed.deleteReplyItem = jest.fn();
|
|
1271
|
+
feed.modifyFeedItemRepliesCountBy = jest.fn();
|
|
1272
|
+
const id = '123';
|
|
1273
|
+
const parentId = '456';
|
|
1274
|
+
const successCallback = jest.fn();
|
|
1275
|
+
feed.deleteReplySuccessCallback(id, parentId, successCallback);
|
|
1276
|
+
expect(feed.deleteReplyItem).toBeCalledWith(id, parentId, successCallback);
|
|
1277
|
+
expect(feed.modifyFeedItemRepliesCountBy).toBeCalledWith(parentId, -1);
|
|
1278
|
+
});
|
|
1279
|
+
});
|
|
1280
|
+
|
|
1221
1281
|
describe('deleteCommentErrorCallback()', () => {
|
|
1222
1282
|
const e = new Error('foo');
|
|
1223
1283
|
|
|
@@ -1695,6 +1755,22 @@ describe('api/Feed', () => {
|
|
|
1695
1755
|
});
|
|
1696
1756
|
});
|
|
1697
1757
|
|
|
1758
|
+
test('should increment the number of replies of parent item', () => {
|
|
1759
|
+
feed.modifyFeedItemRepliesCountBy = jest.fn();
|
|
1760
|
+
const successCb = jest.fn();
|
|
1761
|
+
const errorCb = jest.fn();
|
|
1762
|
+
const parentId = '123';
|
|
1763
|
+
const parentType = FEED_ITEM_TYPE_COMMENT;
|
|
1764
|
+
const text = 'abc';
|
|
1765
|
+
const currentUser = {
|
|
1766
|
+
id: '123',
|
|
1767
|
+
};
|
|
1768
|
+
|
|
1769
|
+
feed.createReply(file, currentUser, parentId, parentType, text, successCb, errorCb);
|
|
1770
|
+
|
|
1771
|
+
expect(feed.modifyFeedItemRepliesCountBy).toBeCalledWith(parentId, 1);
|
|
1772
|
+
});
|
|
1773
|
+
|
|
1698
1774
|
test('given parentType=annotation, should create the reply using annotationsAPI and invoke the success callback', done => {
|
|
1699
1775
|
feed.createReplySuccessCallback = jest.fn();
|
|
1700
1776
|
feed.createReplyErrorCallback = jest.fn();
|
|
@@ -1975,6 +2051,34 @@ describe('api/Feed', () => {
|
|
|
1975
2051
|
expect(successCallback).toBeCalled();
|
|
1976
2052
|
});
|
|
1977
2053
|
});
|
|
2054
|
+
|
|
2055
|
+
test('should call updateFeedItem without the replies and total_reply_count properties', () => {
|
|
2056
|
+
const status = 'open';
|
|
2057
|
+
const updatedAnnotationResult = {
|
|
2058
|
+
id: annotationId,
|
|
2059
|
+
permissions,
|
|
2060
|
+
replies: [],
|
|
2061
|
+
status,
|
|
2062
|
+
total_reply_count: 0,
|
|
2063
|
+
};
|
|
2064
|
+
AnnotationsAPI.mockReturnValueOnce({
|
|
2065
|
+
updateAnnotation: jest.fn().mockImplementation((f, id, payload, p, callback) => {
|
|
2066
|
+
callback(updatedAnnotationResult);
|
|
2067
|
+
}),
|
|
2068
|
+
});
|
|
2069
|
+
feed.updateFeedItem = jest.fn();
|
|
2070
|
+
|
|
2071
|
+
feed.updateAnnotation(file, annotationId, undefined, status, permissions, jest.fn(), jest.fn());
|
|
2072
|
+
|
|
2073
|
+
const expectedUpdateFeedItemCommentData = {
|
|
2074
|
+
id: annotationId,
|
|
2075
|
+
isPending: false,
|
|
2076
|
+
permissions,
|
|
2077
|
+
status,
|
|
2078
|
+
};
|
|
2079
|
+
expect(feed.updateFeedItem).toHaveBeenNthCalledWith(1, { status, isPending: true }, annotationId);
|
|
2080
|
+
expect(feed.updateFeedItem).toHaveBeenNthCalledWith(2, expectedUpdateFeedItemCommentData, annotationId);
|
|
2081
|
+
});
|
|
1978
2082
|
});
|
|
1979
2083
|
|
|
1980
2084
|
describe('updateCommentErrorCallback()', () => {
|
|
@@ -2062,4 +2166,25 @@ describe('api/Feed', () => {
|
|
|
2062
2166
|
expect(successCallback).toBeCalled();
|
|
2063
2167
|
});
|
|
2064
2168
|
});
|
|
2169
|
+
|
|
2170
|
+
describe('modifyFeedItemRepliesCountBy()', () => {
|
|
2171
|
+
test('should throw if no file id', () => {
|
|
2172
|
+
feed.file = {};
|
|
2173
|
+
expect(() => feed.modifyFeedItemRepliesCountBy('123', 1)).toThrow(fileError);
|
|
2174
|
+
});
|
|
2175
|
+
|
|
2176
|
+
test('should call updateFeedItem if item is in cache', () => {
|
|
2177
|
+
const cachedItems = cloneDeep(mockThreadedComments);
|
|
2178
|
+
const { id, total_reply_count } = cachedItems[0];
|
|
2179
|
+
feed.file = file;
|
|
2180
|
+
feed.updateFeedItem = jest.fn();
|
|
2181
|
+
feed.getCachedItems = jest.fn().mockReturnValue({
|
|
2182
|
+
errors: [],
|
|
2183
|
+
items: cachedItems,
|
|
2184
|
+
});
|
|
2185
|
+
|
|
2186
|
+
feed.modifyFeedItemRepliesCountBy(id, 1);
|
|
2187
|
+
expect(feed.updateFeedItem).toBeCalledWith({ total_reply_count: total_reply_count + 1 }, id);
|
|
2188
|
+
});
|
|
2189
|
+
});
|
|
2065
2190
|
});
|
|
@@ -32,6 +32,7 @@ describe('elements/content-sidebar/withSidebarAnnotations', () => {
|
|
|
32
32
|
deleteAnnotation: jest.fn(),
|
|
33
33
|
deleteFeedItem: jest.fn(),
|
|
34
34
|
deleteReplyItem: jest.fn(),
|
|
35
|
+
modifyFeedItemRepliesCountBy: jest.fn(),
|
|
35
36
|
updateFeedItem: jest.fn(),
|
|
36
37
|
updateReplyItem: jest.fn(),
|
|
37
38
|
};
|
|
@@ -337,7 +338,7 @@ describe('elements/content-sidebar/withSidebarAnnotations', () => {
|
|
|
337
338
|
instance.addAnnotationReply();
|
|
338
339
|
|
|
339
340
|
const expectedReplyData = { ...annotationReply, isPending: false };
|
|
340
|
-
expect(feedAPI.
|
|
341
|
+
expect(feedAPI.modifyFeedItemRepliesCountBy).toBeCalledWith(annotation.id, 1);
|
|
341
342
|
expect(feedAPI.updateReplyItem).toBeCalledWith(expectedReplyData, annotation.id, requestId);
|
|
342
343
|
});
|
|
343
344
|
});
|
|
@@ -415,7 +416,7 @@ describe('elements/content-sidebar/withSidebarAnnotations', () => {
|
|
|
415
416
|
|
|
416
417
|
instance.deleteAnnotationReply();
|
|
417
418
|
|
|
418
|
-
expect(feedAPI.
|
|
419
|
+
expect(feedAPI.modifyFeedItemRepliesCountBy).toBeCalledWith(annotation.id, -1);
|
|
419
420
|
});
|
|
420
421
|
|
|
421
422
|
test('should delete appropriate reply from the feed if it is currently in the feed given action = reply_delete_end', () => {
|
|
@@ -442,6 +443,7 @@ describe('elements/content-sidebar/withSidebarAnnotations', () => {
|
|
|
442
443
|
instance.deleteAnnotationReply();
|
|
443
444
|
|
|
444
445
|
expect(feedAPI.deleteReplyItem).toBeCalledWith(annotationReply.id, annotation.id);
|
|
446
|
+
expect(feedAPI.modifyFeedItemRepliesCountBy).toBeCalledWith(annotation.id, -1);
|
|
445
447
|
});
|
|
446
448
|
});
|
|
447
449
|
|
|
@@ -173,7 +173,7 @@ export default function withSidebarAnnotations(
|
|
|
173
173
|
return;
|
|
174
174
|
}
|
|
175
175
|
|
|
176
|
-
feedAPI.
|
|
176
|
+
feedAPI.modifyFeedItemRepliesCountBy(annotationId, 1);
|
|
177
177
|
feedAPI.updateReplyItem({ ...annotationReply, isPending: false }, annotationId, requestId);
|
|
178
178
|
}
|
|
179
179
|
|
|
@@ -223,14 +223,14 @@ export default function withSidebarAnnotations(
|
|
|
223
223
|
return;
|
|
224
224
|
}
|
|
225
225
|
|
|
226
|
-
// Check if the parent annotation has the reply currently visible
|
|
226
|
+
// Check if the parent annotation has the reply currently visible and if so, remove it
|
|
227
227
|
const replyItem = annotationItem.replies.find(({ id }) => id === replyId);
|
|
228
228
|
if (replyItem) {
|
|
229
229
|
feedAPI.deleteReplyItem(replyId, annotationId);
|
|
230
|
-
} else if (annotationItem.total_reply_count > 0) {
|
|
231
|
-
// Decrease the amount of replies by 1
|
|
232
|
-
feedAPI.updateFeedItem({ total_reply_count: annotationItem.total_reply_count - 1 }, annotationId);
|
|
233
230
|
}
|
|
231
|
+
|
|
232
|
+
// Decrease the amount of replies by 1
|
|
233
|
+
feedAPI.modifyFeedItemRepliesCountBy(annotationId, -1);
|
|
234
234
|
}
|
|
235
235
|
|
|
236
236
|
this.refreshActivitySidebar();
|