box-ui-elements 18.0.0 → 18.1.0-beta.2

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.
@@ -28,15 +28,17 @@ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || func
28
28
  * @author Box
29
29
  */
30
30
  import Base from './Base';
31
- import { PERMISSION_CAN_COMMENT, PERMISSION_CAN_VIEW_ANNOTATIONS, ERROR_CODE_FETCH_ACTIVITY } from '../constants';
31
+ import { ERROR_CODE_FETCH_ACTIVITY, FILE_ACTIVITY_TYPE_ANNOTATION, FILE_ACTIVITY_TYPE_COMMENT, PERMISSION_CAN_COMMENT, PERMISSION_CAN_VIEW_ANNOTATIONS } from '../constants';
32
32
  // We only show the latest reply in the UI
33
33
  var REPLY_LIMIT = 1;
34
34
 
35
35
  var getFileActivityQueryParams = function getFileActivityQueryParams(fileID) {
36
36
  var activityTypes = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
37
+ var shouldShowReplies = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
37
38
  var baseEndpoint = "/file_activities?file_id=".concat(fileID);
38
39
  var hasActivityTypes = !!activityTypes && !!activityTypes.length;
39
- var enabledRepliesQueryParam = "&enable_replies=true&reply_limit=".concat(REPLY_LIMIT);
40
+ var enableReplies = shouldShowReplies ? 'true' : 'false';
41
+ var enabledRepliesQueryParam = "&enable_replies=".concat(enableReplies, "&reply_limit=").concat(REPLY_LIMIT);
40
42
  var activityTypeQueryParam = hasActivityTypes ? "&activity_types=".concat(activityTypes.join()) : '';
41
43
  return "".concat(baseEndpoint).concat(activityTypeQueryParam).concat(enabledRepliesQueryParam);
42
44
  };
@@ -60,10 +62,11 @@ function (_Base) {
60
62
  *
61
63
  * @param {string} [id] - a box file id
62
64
  * @param {Array<FileActivityTypes>} activityTypes - optional. Array of File Activity types to filter by, returns all Activity Types if omitted.
65
+ * @param {boolean} shouldShowReplies - optional. Specify if replies should be included in the response
63
66
  * @return {string} base url for files
64
67
  */
65
- value: function getFilteredUrl(id, activityTypes) {
66
- return "".concat(this.getBaseApiUrl()).concat(getFileActivityQueryParams(id, activityTypes));
68
+ value: function getFilteredUrl(id, activityTypes, shouldShowReplies) {
69
+ return "".concat(this.getBaseApiUrl()).concat(getFileActivityQueryParams(id, activityTypes, shouldShowReplies));
67
70
  }
68
71
  /**
69
72
  * API for fetching file activities
@@ -73,6 +76,7 @@ function (_Base) {
73
76
  * @param {string} fileId - the file id
74
77
  * @param {BoxItemPermission} permissions - the permissions for the file
75
78
  * @param {number} repliesCount - number of replies to return, by default all replies are returned
79
+ * @param {boolean} shouldShowReplies - specify if replies should be included in the response
76
80
  * @param {Function} successCallback - the success callback
77
81
  * @returns {void}
78
82
  */
@@ -85,6 +89,7 @@ function (_Base) {
85
89
  fileID = _ref.fileID,
86
90
  permissions = _ref.permissions,
87
91
  repliesCount = _ref.repliesCount,
92
+ shouldShowReplies = _ref.shouldShowReplies,
88
93
  successCallback = _ref.successCallback;
89
94
  this.errorCode = ERROR_CODE_FETCH_ACTIVITY;
90
95
 
@@ -93,8 +98,13 @@ function (_Base) {
93
98
  throw new Error('Missing file id!');
94
99
  }
95
100
 
96
- this.checkApiCallValidity(PERMISSION_CAN_COMMENT, permissions, fileID);
97
- this.checkApiCallValidity(PERMISSION_CAN_VIEW_ANNOTATIONS, permissions, fileID);
101
+ if (activityTypes.includes(FILE_ACTIVITY_TYPE_COMMENT)) {
102
+ this.checkApiCallValidity(PERMISSION_CAN_COMMENT, permissions, fileID);
103
+ }
104
+
105
+ if (activityTypes.includes(FILE_ACTIVITY_TYPE_ANNOTATION)) {
106
+ this.checkApiCallValidity(PERMISSION_CAN_VIEW_ANNOTATIONS, permissions, fileID);
107
+ }
98
108
  } catch (e) {
99
109
  errorCallback(e, this.errorCode);
100
110
  return;
@@ -107,7 +117,7 @@ function (_Base) {
107
117
  requestData: _objectSpread({}, repliesCount ? {
108
118
  replies_count: repliesCount
109
119
  } : null),
110
- url: this.getFilteredUrl(fileID, activityTypes)
120
+ url: this.getFilteredUrl(fileID, activityTypes, shouldShowReplies)
111
121
  });
112
122
  }
113
123
  }]);
@@ -5,7 +5,13 @@
5
5
  */
6
6
 
7
7
  import Base from './Base';
8
- import { PERMISSION_CAN_COMMENT, PERMISSION_CAN_VIEW_ANNOTATIONS, ERROR_CODE_FETCH_ACTIVITY } from '../constants';
8
+ import {
9
+ ERROR_CODE_FETCH_ACTIVITY,
10
+ FILE_ACTIVITY_TYPE_ANNOTATION,
11
+ FILE_ACTIVITY_TYPE_COMMENT,
12
+ PERMISSION_CAN_COMMENT,
13
+ PERMISSION_CAN_VIEW_ANNOTATIONS,
14
+ } from '../constants';
9
15
  import type { BoxItemPermission } from '../common/types/core';
10
16
  import type { ElementsXhrError } from '../common/types/api';
11
17
  import type { FileActivity, FileActivityTypes } from '../common/types/feed';
@@ -13,10 +19,15 @@ import type { FileActivity, FileActivityTypes } from '../common/types/feed';
13
19
  // We only show the latest reply in the UI
14
20
  const REPLY_LIMIT = 1;
15
21
 
16
- const getFileActivityQueryParams = (fileID: string, activityTypes?: FileActivityTypes[] = []) => {
22
+ const getFileActivityQueryParams = (
23
+ fileID: string,
24
+ activityTypes?: FileActivityTypes[] = [],
25
+ shouldShowReplies?: boolean = false,
26
+ ) => {
17
27
  const baseEndpoint = `/file_activities?file_id=${fileID}`;
18
28
  const hasActivityTypes = !!activityTypes && !!activityTypes.length;
19
- const enabledRepliesQueryParam = `&enable_replies=true&reply_limit=${REPLY_LIMIT}`;
29
+ const enableReplies = shouldShowReplies ? 'true' : 'false';
30
+ const enabledRepliesQueryParam = `&enable_replies=${enableReplies}&reply_limit=${REPLY_LIMIT}`;
20
31
  const activityTypeQueryParam = hasActivityTypes ? `&activity_types=${activityTypes.join()}` : '';
21
32
 
22
33
  return `${baseEndpoint}${activityTypeQueryParam}${enabledRepliesQueryParam}`;
@@ -28,10 +39,11 @@ class FileActivities extends Base {
28
39
  *
29
40
  * @param {string} [id] - a box file id
30
41
  * @param {Array<FileActivityTypes>} activityTypes - optional. Array of File Activity types to filter by, returns all Activity Types if omitted.
42
+ * @param {boolean} shouldShowReplies - optional. Specify if replies should be included in the response
31
43
  * @return {string} base url for files
32
44
  */
33
- getFilteredUrl(id: string, activityTypes?: FileActivityTypes[]): string {
34
- return `${this.getBaseApiUrl()}${getFileActivityQueryParams(id, activityTypes)}`;
45
+ getFilteredUrl(id: string, activityTypes?: FileActivityTypes[], shouldShowReplies?: boolean): string {
46
+ return `${this.getBaseApiUrl()}${getFileActivityQueryParams(id, activityTypes, shouldShowReplies)}`;
35
47
  }
36
48
 
37
49
  /**
@@ -42,6 +54,7 @@ class FileActivities extends Base {
42
54
  * @param {string} fileId - the file id
43
55
  * @param {BoxItemPermission} permissions - the permissions for the file
44
56
  * @param {number} repliesCount - number of replies to return, by default all replies are returned
57
+ * @param {boolean} shouldShowReplies - specify if replies should be included in the response
45
58
  * @param {Function} successCallback - the success callback
46
59
  * @returns {void}
47
60
  */
@@ -51,6 +64,7 @@ class FileActivities extends Base {
51
64
  fileID,
52
65
  permissions,
53
66
  repliesCount,
67
+ shouldShowReplies,
54
68
  successCallback,
55
69
  }: {
56
70
  activityTypes: FileActivityTypes[],
@@ -58,6 +72,7 @@ class FileActivities extends Base {
58
72
  fileID: string,
59
73
  permissions: BoxItemPermission,
60
74
  repliesCount?: number,
75
+ shouldShowReplies?: boolean,
61
76
  successCallback: (activity: FileActivity) => void,
62
77
  }): void {
63
78
  this.errorCode = ERROR_CODE_FETCH_ACTIVITY;
@@ -66,8 +81,12 @@ class FileActivities extends Base {
66
81
  throw new Error('Missing file id!');
67
82
  }
68
83
 
69
- this.checkApiCallValidity(PERMISSION_CAN_COMMENT, permissions, fileID);
70
- this.checkApiCallValidity(PERMISSION_CAN_VIEW_ANNOTATIONS, permissions, fileID);
84
+ if (activityTypes.includes(FILE_ACTIVITY_TYPE_COMMENT)) {
85
+ this.checkApiCallValidity(PERMISSION_CAN_COMMENT, permissions, fileID);
86
+ }
87
+ if (activityTypes.includes(FILE_ACTIVITY_TYPE_ANNOTATION)) {
88
+ this.checkApiCallValidity(PERMISSION_CAN_VIEW_ANNOTATIONS, permissions, fileID);
89
+ }
71
90
  } catch (e) {
72
91
  errorCallback(e, this.errorCode);
73
92
  return;
@@ -80,7 +99,7 @@ class FileActivities extends Base {
80
99
  requestData: {
81
100
  ...(repliesCount ? { replies_count: repliesCount } : null),
82
101
  },
83
- url: this.getFilteredUrl(fileID, activityTypes),
102
+ url: this.getFilteredUrl(fileID, activityTypes, shouldShowReplies),
84
103
  });
85
104
  }
86
105
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/api/FileActivities.js"],"names":["Base","PERMISSION_CAN_COMMENT","PERMISSION_CAN_VIEW_ANNOTATIONS","ERROR_CODE_FETCH_ACTIVITY","REPLY_LIMIT","getFileActivityQueryParams","fileID","activityTypes","baseEndpoint","hasActivityTypes","length","enabledRepliesQueryParam","activityTypeQueryParam","join","FileActivities","id","getBaseApiUrl","errorCallback","permissions","repliesCount","successCallback","errorCode","Error","checkApiCallValidity","e","get","requestData","replies_count","url","getFilteredUrl"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;AAMA,OAAOA,IAAP,MAAiB,QAAjB;AACA,SAASC,sBAAT,EAAiCC,+BAAjC,EAAkEC,yBAAlE,QAAmG,cAAnG;AAKA;AACA,IAAMC,WAAW,GAAG,CAApB;;AAEA,IAAMC,0BAA0B,GAAG,SAA7BA,0BAA6B,CAACC,MAAD,EAA8D;AAAA,MAA7CC,aAA6C,uEAAP,EAAO;AAC7F,MAAMC,YAAY,sCAA+BF,MAA/B,CAAlB;AACA,MAAMG,gBAAgB,GAAG,CAAC,CAACF,aAAF,IAAmB,CAAC,CAACA,aAAa,CAACG,MAA5D;AACA,MAAMC,wBAAwB,8CAAuCP,WAAvC,CAA9B;AACA,MAAMQ,sBAAsB,GAAGH,gBAAgB,6BAAsBF,aAAa,CAACM,IAAd,EAAtB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from './Base';\nimport { PERMISSION_CAN_COMMENT, PERMISSION_CAN_VIEW_ANNOTATIONS, ERROR_CODE_FETCH_ACTIVITY } from '../constants';\nimport type { BoxItemPermission } from '../common/types/core';\nimport type { ElementsXhrError } from '../common/types/api';\nimport type { FileActivity, FileActivityTypes } from '../common/types/feed';\n\n// We only show the latest reply in the UI\nconst REPLY_LIMIT = 1;\n\nconst getFileActivityQueryParams = (fileID: string, activityTypes?: FileActivityTypes[] = []) => {\n const baseEndpoint = `/file_activities?file_id=${fileID}`;\n const hasActivityTypes = !!activityTypes && !!activityTypes.length;\n const enabledRepliesQueryParam = `&enable_replies=true&reply_limit=${REPLY_LIMIT}`;\n const activityTypeQueryParam = hasActivityTypes ? `&activity_types=${activityTypes.join()}` : '';\n\n return `${baseEndpoint}${activityTypeQueryParam}${enabledRepliesQueryParam}`;\n};\n\nclass FileActivities extends Base {\n /**\n * API URL for filtered file activities\n *\n * @param {string} [id] - a box file id\n * @param {Array<FileActivityTypes>} activityTypes - optional. Array of File Activity types to filter by, returns all Activity Types if omitted.\n * @return {string} base url for files\n */\n getFilteredUrl(id: string, activityTypes?: FileActivityTypes[]): string {\n return `${this.getBaseApiUrl()}${getFileActivityQueryParams(id, activityTypes)}`;\n }\n\n /**\n * API for fetching file activities\n *\n * @param {Array<FileActivityTypes>} activityTypes - optional. Array of File Activity types to filter by, returns all Activity Types if omitted.\n * @param {Function} errorCallback - the error callback\n * @param {string} fileId - the file id\n * @param {BoxItemPermission} permissions - the permissions for the file\n * @param {number} repliesCount - number of replies to return, by default all replies are returned\n * @param {Function} successCallback - the success callback\n * @returns {void}\n */\n getActivities({\n activityTypes,\n errorCallback,\n fileID,\n permissions,\n repliesCount,\n successCallback,\n }: {\n activityTypes: FileActivityTypes[],\n errorCallback: (e: ElementsXhrError, code: string) => void,\n fileID: string,\n permissions: BoxItemPermission,\n repliesCount?: number,\n successCallback: (activity: FileActivity) => void,\n }): void {\n this.errorCode = ERROR_CODE_FETCH_ACTIVITY;\n try {\n if (!fileID) {\n throw new Error('Missing file id!');\n }\n\n this.checkApiCallValidity(PERMISSION_CAN_COMMENT, permissions, fileID);\n this.checkApiCallValidity(PERMISSION_CAN_VIEW_ANNOTATIONS, permissions, fileID);\n } catch (e) {\n errorCallback(e, this.errorCode);\n return;\n }\n\n this.get({\n id: fileID,\n successCallback,\n errorCallback,\n requestData: {\n ...(repliesCount ? { replies_count: repliesCount } : null),\n },\n url: this.getFilteredUrl(fileID, activityTypes),\n });\n }\n}\n\nexport default FileActivities;\n"],"file":"FileActivities.js"}
1
+ {"version":3,"sources":["../../src/api/FileActivities.js"],"names":["Base","ERROR_CODE_FETCH_ACTIVITY","FILE_ACTIVITY_TYPE_ANNOTATION","FILE_ACTIVITY_TYPE_COMMENT","PERMISSION_CAN_COMMENT","PERMISSION_CAN_VIEW_ANNOTATIONS","REPLY_LIMIT","getFileActivityQueryParams","fileID","activityTypes","shouldShowReplies","baseEndpoint","hasActivityTypes","length","enableReplies","enabledRepliesQueryParam","activityTypeQueryParam","join","FileActivities","id","getBaseApiUrl","errorCallback","permissions","repliesCount","successCallback","errorCode","Error","includes","checkApiCallValidity","e","get","requestData","replies_count","url","getFilteredUrl"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;AAMA,OAAOA,IAAP,MAAiB,QAAjB;AACA,SACIC,yBADJ,EAEIC,6BAFJ,EAGIC,0BAHJ,EAIIC,sBAJJ,EAKIC,+BALJ,QAMO,cANP;AAWA;AACA,IAAMC,WAAW,GAAG,CAApB;;AAEA,IAAMC,0BAA0B,GAAG,SAA7BA,0BAA6B,CAC/BC,MAD+B,EAI9B;AAAA,MAFDC,aAEC,uEAFqC,EAErC;AAAA,MADDC,iBACC,uEAD6B,KAC7B;AACD,MAAMC,YAAY,sCAA+BH,MAA/B,CAAlB;AACA,MAAMI,gBAAgB,GAAG,CAAC,CAACH,aAAF,IAAmB,CAAC,CAACA,aAAa,CAACI,MAA5D;AACA,MAAMC,aAAa,GAAGJ,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AACLX,QAAAA,EAAE,EAAEX,MADC;AAELgB,QAAAA,eAAe,EAAfA,eAFK;AAGLH,QAAAA,aAAa,EAAbA,aAHK;AAILU,QAAAA,WAAW,oBACHR,YAAY,GAAG;AAAES,UAAAA,aAAa,EAAET;AAAjB,SAAH,GAAqC,IAD9C,CAJN;AAOLU,QAAAA,GAAG,EAAE,KAAKC,cAAL,CAAoB1B,MAApB,EAA4BC,aAA5B,EAA2CC,iBAA3C;AAPA,OAAT;AASH;;;;EApEwBV,I;;AAuE7B,eAAekB,cAAf","sourcesContent":["/**\n * @flow\n * @file Helper for the box File Activity API\n * @author Box\n */\n\nimport Base from './Base';\nimport {\n ERROR_CODE_FETCH_ACTIVITY,\n FILE_ACTIVITY_TYPE_ANNOTATION,\n FILE_ACTIVITY_TYPE_COMMENT,\n PERMISSION_CAN_COMMENT,\n PERMISSION_CAN_VIEW_ANNOTATIONS,\n} from '../constants';\nimport type { BoxItemPermission } from '../common/types/core';\nimport type { ElementsXhrError } from '../common/types/api';\nimport type { FileActivity, FileActivityTypes } from '../common/types/feed';\n\n// We only show the latest reply in the UI\nconst REPLY_LIMIT = 1;\n\nconst getFileActivityQueryParams = (\n fileID: string,\n activityTypes?: FileActivityTypes[] = [],\n shouldShowReplies?: boolean = false,\n) => {\n const baseEndpoint = `/file_activities?file_id=${fileID}`;\n const hasActivityTypes = !!activityTypes && !!activityTypes.length;\n const enableReplies = shouldShowReplies ? 'true' : 'false';\n const enabledRepliesQueryParam = `&enable_replies=${enableReplies}&reply_limit=${REPLY_LIMIT}`;\n const activityTypeQueryParam = hasActivityTypes ? `&activity_types=${activityTypes.join()}` : '';\n\n return `${baseEndpoint}${activityTypeQueryParam}${enabledRepliesQueryParam}`;\n};\n\nclass FileActivities extends Base {\n /**\n * API URL for filtered file activities\n *\n * @param {string} [id] - a box file id\n * @param {Array<FileActivityTypes>} activityTypes - optional. Array of File Activity types to filter by, returns all Activity Types if omitted.\n * @param {boolean} shouldShowReplies - optional. Specify if replies should be included in the response\n * @return {string} base url for files\n */\n getFilteredUrl(id: string, activityTypes?: FileActivityTypes[], shouldShowReplies?: boolean): string {\n return `${this.getBaseApiUrl()}${getFileActivityQueryParams(id, activityTypes, shouldShowReplies)}`;\n }\n\n /**\n * API for fetching file activities\n *\n * @param {Array<FileActivityTypes>} activityTypes - optional. Array of File Activity types to filter by, returns all Activity Types if omitted.\n * @param {Function} errorCallback - the error callback\n * @param {string} fileId - the file id\n * @param {BoxItemPermission} permissions - the permissions for the file\n * @param {number} repliesCount - number of replies to return, by default all replies are returned\n * @param {boolean} shouldShowReplies - specify if replies should be included in the response\n * @param {Function} successCallback - the success callback\n * @returns {void}\n */\n getActivities({\n activityTypes,\n errorCallback,\n fileID,\n permissions,\n repliesCount,\n shouldShowReplies,\n successCallback,\n }: {\n activityTypes: FileActivityTypes[],\n errorCallback: (e: ElementsXhrError, code: string) => void,\n fileID: string,\n permissions: BoxItemPermission,\n repliesCount?: number,\n shouldShowReplies?: boolean,\n successCallback: (activity: FileActivity) => void,\n }): void {\n this.errorCode = ERROR_CODE_FETCH_ACTIVITY;\n try {\n if (!fileID) {\n throw new Error('Missing file id!');\n }\n\n if (activityTypes.includes(FILE_ACTIVITY_TYPE_COMMENT)) {\n this.checkApiCallValidity(PERMISSION_CAN_COMMENT, permissions, fileID);\n }\n if (activityTypes.includes(FILE_ACTIVITY_TYPE_ANNOTATION)) {\n this.checkApiCallValidity(PERMISSION_CAN_VIEW_ANNOTATIONS, permissions, fileID);\n }\n } catch (e) {\n errorCallback(e, this.errorCode);\n return;\n }\n\n this.get({\n id: fileID,\n successCallback,\n errorCallback,\n requestData: {\n ...(repliesCount ? { replies_count: repliesCount } : null),\n },\n url: this.getFilteredUrl(fileID, activityTypes, shouldShowReplies),\n });\n }\n}\n\nexport default FileActivities;\n"],"file":"FileActivities.js"}
package/i18n/ja-JP.js CHANGED
@@ -184,7 +184,7 @@ export default {
184
184
  "be.createDialogErrorTooLong": "フォルダ名が長すぎます。",
185
185
  "be.createDialogLabel": "新規フォルダ",
186
186
  "be.createDialogText": "名前を入力してください。",
187
- "be.currentUserErrorHeaderMessage": "現行ユーザーの取得中にエラーが発生しました。",
187
+ "be.currentUserErrorHeaderMessage": "現在のユーザーの取得中にエラーが発生しました。",
188
188
  "be.dateASC": "日付: 最も古い → 最も新しい",
189
189
  "be.dateDESC": "日付: 最も新しい → 最も古い",
190
190
  "be.defaultErrorMaskHeaderMessage": "申し訳ありません。問題が発生しました。",
@@ -369,7 +369,7 @@ be.createDialogLabel = 新規フォルダ
369
369
  # Text for create folder dialog
370
370
  be.createDialogText = 名前を入力してください。
371
371
  # Current user error message
372
- be.currentUserErrorHeaderMessage = 現行ユーザーの取得中にエラーが発生しました。
372
+ be.currentUserErrorHeaderMessage = 現在のユーザーの取得中にエラーが発生しました。
373
373
  # Date ascending option shown in the share access drop down select.
374
374
  be.dateASC = 日付: 最も古い → 最も新しい
375
375
  # Date descending option shown in the share access drop down select.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "box-ui-elements",
3
- "version": "18.0.0",
3
+ "version": "18.1.0-beta.2",
4
4
  "description": "Box UI Elements",
5
5
  "author": "Box (https://www.box.com/)",
6
6
  "license": "SEE LICENSE IN LICENSE",
package/src/api/Feed.js CHANGED
@@ -35,6 +35,7 @@ import {
35
35
  FILE_ACTIVITY_TYPE_TASK,
36
36
  HTTP_STATUS_CODE_CONFLICT,
37
37
  IS_ERROR_DISPLAYED,
38
+ PERMISSION_CAN_VIEW_ANNOTATIONS,
38
39
  TASK_NEW_APPROVED,
39
40
  TASK_NEW_COMPLETED,
40
41
  TASK_NEW_REJECTED,
@@ -518,13 +519,22 @@ class Feed extends Base {
518
519
 
519
520
  const versionsPromise = shouldShowVersions ? this.fetchVersions() : Promise.resolve();
520
521
  const currentVersionPromise = shouldShowVersions ? this.fetchCurrentVersion() : Promise.resolve();
522
+
523
+ const annotationActivityType =
524
+ shouldShowAnnotations && permissions[PERMISSION_CAN_VIEW_ANNOTATIONS]
525
+ ? [FILE_ACTIVITY_TYPE_ANNOTATION]
526
+ : [];
527
+ const appActivityActivityType = shouldShowAppActivity ? [FILE_ACTIVITY_TYPE_APP_ACTIVITY] : [];
528
+ const taskActivityType = shouldShowTasks ? [FILE_ACTIVITY_TYPE_TASK] : [];
529
+ const filteredActivityTypes = [
530
+ ...annotationActivityType,
531
+ ...appActivityActivityType,
532
+ FILE_ACTIVITY_TYPE_COMMENT,
533
+ ...taskActivityType,
534
+ ];
535
+
521
536
  const fileActivitiesPromise = shouldUseUAA
522
- ? this.fetchFileActivities(permissions, [
523
- FILE_ACTIVITY_TYPE_ANNOTATION,
524
- FILE_ACTIVITY_TYPE_APP_ACTIVITY,
525
- FILE_ACTIVITY_TYPE_COMMENT,
526
- FILE_ACTIVITY_TYPE_TASK,
527
- ])
537
+ ? this.fetchFileActivities(permissions, filteredActivityTypes, shouldShowReplies)
528
538
  : Promise.resolve();
529
539
 
530
540
  const handleFeedItems = (feedItems: FeedItems) => {
@@ -675,9 +685,14 @@ class Feed extends Base {
675
685
  *
676
686
  * @param {BoxItemPermission} permissions - the file permissions
677
687
  * @param {FileActivityTypes[]} activityTypes - the activity types to filter by
688
+ * @param {boolean} shouldShowReplies - specify if replies should be included in the response
678
689
  * @return {Promise} - the file comments
679
690
  */
680
- fetchFileActivities(permissions: BoxItemPermission, activityTypes: FileActivityTypes[]): Promise<Object> {
691
+ fetchFileActivities(
692
+ permissions: BoxItemPermission,
693
+ activityTypes: FileActivityTypes[],
694
+ shouldShowReplies?: boolean = false,
695
+ ): Promise<Object> {
681
696
  this.fileActivitiesAPI = new FileActivitiesAPI(this.options);
682
697
  return new Promise(resolve => {
683
698
  this.fileActivitiesAPI.getActivities({
@@ -686,6 +701,7 @@ class Feed extends Base {
686
701
  permissions,
687
702
  successCallback: resolve,
688
703
  activityTypes,
704
+ shouldShowReplies,
689
705
  });
690
706
  });
691
707
  }
@@ -5,7 +5,13 @@
5
5
  */
6
6
 
7
7
  import Base from './Base';
8
- import { PERMISSION_CAN_COMMENT, PERMISSION_CAN_VIEW_ANNOTATIONS, ERROR_CODE_FETCH_ACTIVITY } from '../constants';
8
+ import {
9
+ ERROR_CODE_FETCH_ACTIVITY,
10
+ FILE_ACTIVITY_TYPE_ANNOTATION,
11
+ FILE_ACTIVITY_TYPE_COMMENT,
12
+ PERMISSION_CAN_COMMENT,
13
+ PERMISSION_CAN_VIEW_ANNOTATIONS,
14
+ } from '../constants';
9
15
  import type { BoxItemPermission } from '../common/types/core';
10
16
  import type { ElementsXhrError } from '../common/types/api';
11
17
  import type { FileActivity, FileActivityTypes } from '../common/types/feed';
@@ -13,10 +19,15 @@ import type { FileActivity, FileActivityTypes } from '../common/types/feed';
13
19
  // We only show the latest reply in the UI
14
20
  const REPLY_LIMIT = 1;
15
21
 
16
- const getFileActivityQueryParams = (fileID: string, activityTypes?: FileActivityTypes[] = []) => {
22
+ const getFileActivityQueryParams = (
23
+ fileID: string,
24
+ activityTypes?: FileActivityTypes[] = [],
25
+ shouldShowReplies?: boolean = false,
26
+ ) => {
17
27
  const baseEndpoint = `/file_activities?file_id=${fileID}`;
18
28
  const hasActivityTypes = !!activityTypes && !!activityTypes.length;
19
- const enabledRepliesQueryParam = `&enable_replies=true&reply_limit=${REPLY_LIMIT}`;
29
+ const enableReplies = shouldShowReplies ? 'true' : 'false';
30
+ const enabledRepliesQueryParam = `&enable_replies=${enableReplies}&reply_limit=${REPLY_LIMIT}`;
20
31
  const activityTypeQueryParam = hasActivityTypes ? `&activity_types=${activityTypes.join()}` : '';
21
32
 
22
33
  return `${baseEndpoint}${activityTypeQueryParam}${enabledRepliesQueryParam}`;
@@ -28,10 +39,11 @@ class FileActivities extends Base {
28
39
  *
29
40
  * @param {string} [id] - a box file id
30
41
  * @param {Array<FileActivityTypes>} activityTypes - optional. Array of File Activity types to filter by, returns all Activity Types if omitted.
42
+ * @param {boolean} shouldShowReplies - optional. Specify if replies should be included in the response
31
43
  * @return {string} base url for files
32
44
  */
33
- getFilteredUrl(id: string, activityTypes?: FileActivityTypes[]): string {
34
- return `${this.getBaseApiUrl()}${getFileActivityQueryParams(id, activityTypes)}`;
45
+ getFilteredUrl(id: string, activityTypes?: FileActivityTypes[], shouldShowReplies?: boolean): string {
46
+ return `${this.getBaseApiUrl()}${getFileActivityQueryParams(id, activityTypes, shouldShowReplies)}`;
35
47
  }
36
48
 
37
49
  /**
@@ -42,6 +54,7 @@ class FileActivities extends Base {
42
54
  * @param {string} fileId - the file id
43
55
  * @param {BoxItemPermission} permissions - the permissions for the file
44
56
  * @param {number} repliesCount - number of replies to return, by default all replies are returned
57
+ * @param {boolean} shouldShowReplies - specify if replies should be included in the response
45
58
  * @param {Function} successCallback - the success callback
46
59
  * @returns {void}
47
60
  */
@@ -51,6 +64,7 @@ class FileActivities extends Base {
51
64
  fileID,
52
65
  permissions,
53
66
  repliesCount,
67
+ shouldShowReplies,
54
68
  successCallback,
55
69
  }: {
56
70
  activityTypes: FileActivityTypes[],
@@ -58,6 +72,7 @@ class FileActivities extends Base {
58
72
  fileID: string,
59
73
  permissions: BoxItemPermission,
60
74
  repliesCount?: number,
75
+ shouldShowReplies?: boolean,
61
76
  successCallback: (activity: FileActivity) => void,
62
77
  }): void {
63
78
  this.errorCode = ERROR_CODE_FETCH_ACTIVITY;
@@ -66,8 +81,12 @@ class FileActivities extends Base {
66
81
  throw new Error('Missing file id!');
67
82
  }
68
83
 
69
- this.checkApiCallValidity(PERMISSION_CAN_COMMENT, permissions, fileID);
70
- this.checkApiCallValidity(PERMISSION_CAN_VIEW_ANNOTATIONS, permissions, fileID);
84
+ if (activityTypes.includes(FILE_ACTIVITY_TYPE_COMMENT)) {
85
+ this.checkApiCallValidity(PERMISSION_CAN_COMMENT, permissions, fileID);
86
+ }
87
+ if (activityTypes.includes(FILE_ACTIVITY_TYPE_ANNOTATION)) {
88
+ this.checkApiCallValidity(PERMISSION_CAN_VIEW_ANNOTATIONS, permissions, fileID);
89
+ }
71
90
  } catch (e) {
72
91
  errorCallback(e, this.errorCode);
73
92
  return;
@@ -80,7 +99,7 @@ class FileActivities extends Base {
80
99
  requestData: {
81
100
  ...(repliesCount ? { replies_count: repliesCount } : null),
82
101
  },
83
- url: this.getFilteredUrl(fileID, activityTypes),
102
+ url: this.getFilteredUrl(fileID, activityTypes, shouldShowReplies),
84
103
  });
85
104
  }
86
105
  }
@@ -606,14 +606,24 @@ describe('api/Feed', () => {
606
606
  });
607
607
 
608
608
  test('should use the file activities api if shouldUseUAA is true', done => {
609
- feed.feedItems(file, false, successCb, errorCb, errorCb, { shouldUseUAA: true });
609
+ feed.feedItems(file, false, successCb, errorCb, errorCb, {
610
+ shouldUseUAA: true,
611
+ shouldShowAnnotations: true,
612
+ shouldShowAppActivity: true,
613
+ shouldShowTasks: true,
614
+ shouldShowReplies: true,
615
+ });
610
616
  setImmediate(() => {
611
- expect(feed.fetchFileActivities).toBeCalledWith(file.permissions, [
612
- FILE_ACTIVITY_TYPE_ANNOTATION,
613
- FILE_ACTIVITY_TYPE_APP_ACTIVITY,
614
- FILE_ACTIVITY_TYPE_COMMENT,
615
- FILE_ACTIVITY_TYPE_TASK,
616
- ]);
617
+ expect(feed.fetchFileActivities).toBeCalledWith(
618
+ file.permissions,
619
+ [
620
+ FILE_ACTIVITY_TYPE_ANNOTATION,
621
+ FILE_ACTIVITY_TYPE_APP_ACTIVITY,
622
+ FILE_ACTIVITY_TYPE_COMMENT,
623
+ FILE_ACTIVITY_TYPE_TASK,
624
+ ],
625
+ true,
626
+ );
617
627
  expect(feed.fetchComments).not.toBeCalled();
618
628
  expect(feed.fetchThreadedComments).not.toBeCalled();
619
629
  done();
@@ -842,7 +852,7 @@ describe('api/Feed', () => {
842
852
  });
843
853
 
844
854
  test('should return a promise and call the file activities api', () => {
845
- const permissions = { can_edit: true, can_delete: true, can_resolve: true };
855
+ const permissions = { can_edit: true, can_delete: true, can_resolve: true, can_view_annotations: true };
846
856
  const fileActivityItems = feed.fetchFileActivities(permissions, [
847
857
  FILE_ACTIVITY_TYPE_ANNOTATION,
848
858
  FILE_ACTIVITY_TYPE_APP_ACTIVITY,
@@ -860,6 +870,7 @@ describe('api/Feed', () => {
860
870
  errorCallback: expect.any(Function),
861
871
  fileID: feed.file.id,
862
872
  permissions,
873
+ shouldShowReplies: false,
863
874
  successCallback: expect.any(Function),
864
875
  });
865
876
  expect(fileActivityItems).resolves.toEqual({ entries: mockFileActivities });
@@ -26,11 +26,24 @@ describe('api/FileActivities', () => {
26
26
  `(
27
27
  'should return the filtered query parameters as $expected when $activityTypes is passed in',
28
28
  ({ activityTypes, expected }) => {
29
- expect(fileActivities.getFilteredUrl('1', activityTypes)).toBe(
29
+ expect(fileActivities.getFilteredUrl('1', activityTypes, true)).toBe(
30
30
  `https://api.box.com/2.0/file_activities?file_id=1${expected}&enable_replies=true&reply_limit=1`,
31
31
  );
32
32
  },
33
33
  );
34
+
35
+ test.each`
36
+ enableReplies | expected
37
+ ${true} | ${'&enable_replies=true'}
38
+ ${false} | ${'&enable_replies=false'}
39
+ `(
40
+ 'should return the enable_replies as $expected when $enableReplies is passed in',
41
+ ({ enableReplies, expected }) => {
42
+ expect(fileActivities.getFilteredUrl('1', ['comment', 'annotation', 'task'], enableReplies)).toBe(
43
+ `https://api.box.com/2.0/file_activities?file_id=1&activity_types=comment,annotation,task${expected}&reply_limit=1`,
44
+ );
45
+ },
46
+ );
34
47
  });
35
48
 
36
49
  describe('getActivities()', () => {
@@ -40,7 +53,6 @@ describe('api/FileActivities', () => {
40
53
  test('should call the underlying get method', () => {
41
54
  const permissions = {
42
55
  can_comment: true,
43
- can_view_annotations: true,
44
56
  };
45
57
 
46
58
  fileActivities.getActivities({
@@ -49,6 +61,7 @@ describe('api/FileActivities', () => {
49
61
  permissions,
50
62
  successCallback,
51
63
  errorCallback,
64
+ shouldShowReplies: true,
52
65
  });
53
66
 
54
67
  expect(fileActivities.get).toBeCalledWith({
@@ -68,7 +81,7 @@ describe('api/FileActivities', () => {
68
81
  ])('should reject with an error code for calls with invalid permissions %s', permissions => {
69
82
  fileActivities.getActivities({
70
83
  fileID: '123',
71
- activityTypes: ['comment', 'task'],
84
+ activityTypes: ['annotation', 'comment', 'task'],
72
85
  permissions,
73
86
  successCallback,
74
87
  errorCallback,