Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/api/Annotations.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ export default class Annotations extends MarkerBasedApi {
successCallback: (annotation: Annotation) => void,
errorCallback: (e: ElementsXhrError, code: string) => void,
shouldFetchReplies?: boolean,
shouldEnableRichText?: boolean,
): void {
this.errorCode = ERROR_CODE_FETCH_ANNOTATION;

Expand All @@ -217,7 +218,11 @@ export default class Annotations extends MarkerBasedApi {
return;
}

const requestData = shouldFetchReplies ? { params: { fields: 'replies' } } : undefined;
const params = {
...(shouldFetchReplies ? { fields: 'replies' } : {}),
...(shouldEnableRichText ? { enable_rich_text: true } : {}),
};
const requestData = Object.keys(params).length ? { params } : undefined;

this.get({
id: fileId,
Expand All @@ -237,6 +242,7 @@ export default class Annotations extends MarkerBasedApi {
limit?: number,
shouldFetchAll?: boolean,
shouldFetchReplies?: boolean,
shouldEnableRichText?: boolean,
): void {
this.errorCode = ERROR_CODE_FETCH_ANNOTATIONS;

Expand All @@ -251,6 +257,7 @@ export default class Annotations extends MarkerBasedApi {
file_id: fileId,
file_version_id: fileVersionId,
...(shouldFetchReplies ? { fields: 'replies' } : null),
...(shouldEnableRichText ? { enable_rich_text: true } : null),
};

this.markerGet({
Expand All @@ -269,6 +276,7 @@ export default class Annotations extends MarkerBasedApi {
permissions: BoxItemPermission,
successCallback: (comments: ThreadedComments) => void,
errorCallback: (e: ElementsXhrError, code: string) => void,
shouldEnableRichText?: boolean,
): void {
this.errorCode = ERROR_CODE_FETCH_REPLIES;

Expand All @@ -284,6 +292,7 @@ export default class Annotations extends MarkerBasedApi {
errorCallback,
successCallback,
url: this.getUrlWithRepliesForId(annotationId),
...(shouldEnableRichText ? { requestData: { params: { enable_rich_text: true } } } : {}),
});
}

Expand Down
36 changes: 32 additions & 4 deletions src/api/Feed.js
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,11 @@ class Feed extends Base {
*/
fileActivitiesAPI: FileActivitiesAPI;

/**
* @property {boolean}
*/
shouldEnableRichText: boolean;

/**
* @property {BoxItem}
*/
Expand All @@ -362,6 +367,7 @@ class Feed extends Base {
this.taskCollaboratorsAPI = [];
this.taskLinksAPI = [];
this.errors = [];
this.shouldEnableRichText = false;
}

/**
Expand Down Expand Up @@ -581,6 +587,7 @@ class Feed extends Base {
shouldShowVersions = true,
shouldUseEnhancedActivities = false,
shouldUseUAA = false,
shouldEnableRichText = false,
}: {
shouldShowAnnotations?: boolean,
shouldShowAppActivity?: boolean,
Expand All @@ -589,6 +596,7 @@ class Feed extends Base {
shouldShowVersions?: boolean,
shouldUseEnhancedActivities?: boolean,
shouldUseUAA?: boolean,
shouldEnableRichText?: boolean,
} = {},
): void {
const { id, permissions = {} } = file;
Expand All @@ -609,15 +617,18 @@ class Feed extends Base {
this.file = file;
this.errors = [];
this.errorCallback = onError;
this.shouldEnableRichText = shouldEnableRichText;

// Using the UAA File Activities endpoint replaces the need for these calls
const annotationsPromise =
!shouldUseUAA && shouldShowAnnotations
? this.fetchAnnotations(permissions, shouldShowReplies)
? this.fetchAnnotations(permissions, shouldShowReplies, shouldEnableRichText)
: Promise.resolve();
const commentsPromise = () => {
if (shouldUseUAA) return Promise.resolve();
return shouldShowReplies ? this.fetchThreadedComments(permissions) : this.fetchComments(permissions);
return shouldShowReplies
? this.fetchThreadedComments(permissions, shouldEnableRichText)
: this.fetchComments(permissions);
};
const tasksPromise = !shouldUseUAA && shouldShowTasks ? this.fetchTasksNew() : Promise.resolve();
const appActivityPromise =
Expand Down Expand Up @@ -652,6 +663,7 @@ class Feed extends Base {
filteredActivityTypes,
shouldShowReplies,
shouldUseEnhancedActivities,
shouldEnableRichText,
)
: Promise.resolve();

Expand Down Expand Up @@ -698,7 +710,11 @@ class Feed extends Base {
}
}

fetchAnnotations(permissions: BoxItemPermission, shouldFetchReplies?: boolean): Promise<?Annotations> {
fetchAnnotations(
permissions: BoxItemPermission,
shouldFetchReplies?: boolean,
shouldEnableRichText?: boolean = this.shouldEnableRichText,
): Promise<?Annotations> {
this.annotationsAPI = new AnnotationsAPI(this.options);
return new Promise(resolve => {
this.annotationsAPI.getAnnotations(
Expand All @@ -710,6 +726,7 @@ class Feed extends Base {
undefined,
undefined,
shouldFetchReplies,
shouldEnableRichText,
);
});
}
Expand Down Expand Up @@ -746,6 +763,7 @@ class Feed extends Base {
commentId: string,
successCallback: (comment: Comment) => void,
errorCallback: ErrorCallback,
shouldEnableRichText?: boolean = this.shouldEnableRichText,
): Promise<?Comment> {
const { id, permissions } = file;
if (!id || !permissions) {
Expand All @@ -759,6 +777,7 @@ class Feed extends Base {
errorCallback,
fileId: id,
permissions,
shouldEnableRichText,
successCallback: this.fetchThreadedCommentSuccessCallback.bind(this, resolve, successCallback),
});
});
Expand All @@ -783,13 +802,17 @@ class Feed extends Base {
* @param {Object} permissions - the file permissions
* @return {Promise} - the file comments
*/
fetchThreadedComments(permissions: BoxItemPermission): Promise<?ThreadedCommentsType> {
fetchThreadedComments(
permissions: BoxItemPermission,
shouldEnableRichText?: boolean = this.shouldEnableRichText,
): Promise<?ThreadedCommentsType> {
this.threadedCommentsAPI = new ThreadedCommentsAPI(this.options);
return new Promise(resolve => {
this.threadedCommentsAPI.getComments({
errorCallback: this.fetchFeedItemErrorCallback.bind(this, resolve),
fileId: this.file.id,
permissions,
shouldEnableRichText,
successCallback: resolve,
});
});
Expand All @@ -808,6 +831,7 @@ class Feed extends Base {
activityTypes: FileActivityTypes[],
shouldShowReplies?: boolean = false,
shouldUseEnhancedActivities?: boolean = false,
shouldEnableRichText?: boolean = this.shouldEnableRichText,
): Promise<Object> {
this.fileActivitiesAPI = new FileActivitiesAPI(this.options);
return new Promise(resolve => {
Expand All @@ -819,6 +843,7 @@ class Feed extends Base {
activityTypes,
shouldShowReplies,
shouldUseEnhancedActivities,
shouldEnableRichText,
});
});
}
Expand All @@ -839,6 +864,7 @@ class Feed extends Base {
commentFeedItemType: CommentFeedItemType,
successCallback: (comments: Array<Comment>) => void,
errorCallback: ErrorCallback,
shouldEnableRichText?: boolean = this.shouldEnableRichText,
): void {
const { id, permissions } = file;
if (!id || !permissions) {
Expand Down Expand Up @@ -870,6 +896,7 @@ class Feed extends Base {
permissions,
successCallbackFn,
errorCallbackFn,
shouldEnableRichText,
);
} else if (commentFeedItemType === FEED_ITEM_TYPE_COMMENT) {
this.threadedCommentsAPI = new ThreadedCommentsAPI(this.options);
Expand All @@ -878,6 +905,7 @@ class Feed extends Base {
fileId: file.id,
commentId: commentFeedItemId,
permissions,
shouldEnableRichText,
successCallback: successCallbackFn,
errorCallback: errorCallbackFn,
});
Expand Down
17 changes: 14 additions & 3 deletions src/api/FileActivities.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,17 @@ const getFileActivityQueryParams = (
activityTypes?: FileActivityTypes[] = [],
shouldShowReplies?: boolean = false,
shouldUseEnhancedActivities?: boolean = false,
shouldEnableRichText?: boolean = false,
) => {
const baseEndpoint = `/file_activities?file_id=${fileID}`;
const hasActivityTypes = !!activityTypes && !!activityTypes.length;
const enableReplies = shouldShowReplies ? 'true' : 'false';
const replyLimit = shouldUseEnhancedActivities ? V2_REPLY_LIMIT : V1_REPLY_LIMIT;
const enabledRepliesQueryParam = `&enable_replies=${enableReplies}&reply_limit=${replyLimit}`;
const activityTypeQueryParam = hasActivityTypes ? `&activity_types=${activityTypes.join()}` : '';
const richTextQueryParam = shouldEnableRichText ? '&enable_rich_text=true' : '';

return `${baseEndpoint}${activityTypeQueryParam}${enabledRepliesQueryParam}`;
return `${baseEndpoint}${activityTypeQueryParam}${enabledRepliesQueryParam}${richTextQueryParam}`;
};

class FileActivities extends Base {
Expand All @@ -49,8 +51,9 @@ class FileActivities extends Base {
activityTypes?: FileActivityTypes[],
shouldShowReplies?: boolean,
shouldUseEnhancedActivities?: boolean,
shouldEnableRichText?: boolean,
): string {
return `${this.getBaseApiUrl()}${getFileActivityQueryParams(id, activityTypes, shouldShowReplies, shouldUseEnhancedActivities)}`;
return `${this.getBaseApiUrl()}${getFileActivityQueryParams(id, activityTypes, shouldShowReplies, shouldUseEnhancedActivities, shouldEnableRichText)}`;
}

/**
Expand All @@ -73,6 +76,7 @@ class FileActivities extends Base {
repliesCount,
shouldShowReplies,
shouldUseEnhancedActivities,
shouldEnableRichText,
successCallback,
}: {
activityTypes: FileActivityTypes[],
Expand All @@ -82,6 +86,7 @@ class FileActivities extends Base {
repliesCount?: number,
shouldShowReplies?: boolean,
shouldUseEnhancedActivities?: boolean,
shouldEnableRichText?: boolean,
successCallback: (activity: FileActivity) => void,
}): void {
this.errorCode = ERROR_CODE_FETCH_ACTIVITY;
Expand All @@ -108,7 +113,13 @@ class FileActivities extends Base {
requestData: {
...(repliesCount ? { replies_count: repliesCount } : null),
},
url: this.getFilteredUrl(fileID, activityTypes, shouldShowReplies, shouldUseEnhancedActivities),
url: this.getFilteredUrl(
fileID,
activityTypes,
shouldShowReplies,
shouldUseEnhancedActivities,
shouldEnableRichText,
),
});
}
}
Expand Down
9 changes: 9 additions & 0 deletions src/api/ThreadedComments.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,12 +244,14 @@ class ThreadedComments extends MarkerBasedApi {
errorCallback,
fileId,
permissions,
shouldEnableRichText,
successCallback,
}: {
commentId: string,
errorCallback: (e: ElementsXhrError, code: string) => void,
fileId: string,
permissions: BoxItemPermission,
shouldEnableRichText?: boolean,
successCallback: (comment: Comment) => void,
}): void {
this.errorCode = ERROR_CODE_FETCH_COMMENT;
Expand All @@ -265,6 +267,7 @@ class ThreadedComments extends MarkerBasedApi {
errorCallback,
successCallback,
url: this.getUrlForId(commentId),
...(shouldEnableRichText ? { requestData: { params: { enable_rich_text: true } } } : {}),
});
}

Expand All @@ -291,13 +294,15 @@ class ThreadedComments extends MarkerBasedApi {
limit,
shouldFetchAll,
repliesCount,
shouldEnableRichText,
}: {
errorCallback: (e: ElementsXhrError, code: string) => void,
fileId: string,
limit?: number,
marker?: string,
permissions: BoxItemPermission,
repliesCount?: number,
shouldEnableRichText?: boolean,
shouldFetchAll?: boolean,
successCallback: (threadedComments: ThreadedCommentsType) => void,
}): void {
Expand All @@ -317,6 +322,7 @@ class ThreadedComments extends MarkerBasedApi {
limit,
requestData: {
...(repliesCount ? { replies_count: repliesCount } : null),
...(shouldEnableRichText ? { enable_rich_text: true } : null),
},
shouldFetchAll,
});
Expand All @@ -333,13 +339,15 @@ class ThreadedComments extends MarkerBasedApi {
fileId,
commentId,
permissions,
shouldEnableRichText,
successCallback,
errorCallback,
}: {
commentId: string,
errorCallback: (e: ElementsXhrError, code: string) => void,
fileId: string,
permissions: BoxItemPermission,
shouldEnableRichText?: boolean,
successCallback: (comments: ThreadedCommentsType) => void,
}): void {
this.errorCode = ERROR_CODE_FETCH_REPLIES;
Expand All @@ -356,6 +364,7 @@ class ThreadedComments extends MarkerBasedApi {
errorCallback,
successCallback,
url: this.getUrlWithRepliesForId(commentId),
...(shouldEnableRichText ? { requestData: { params: { enable_rich_text: true } } } : {}),
});
}

Expand Down
33 changes: 33 additions & 0 deletions src/api/__tests__/Annotations.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,39 @@ describe('api/Annotations', () => {
});
});

test('should pass enable_rich_text when shouldEnableRichText is true', () => {
const permissions = {
can_create_annotations: true,
can_view_annotations: true,
};

annotations.getAnnotations(
'12345',
'67890',
permissions,
successCallback,
errorCallback,
100,
false,
true,
true,
);

expect(annotations.markerGet).toBeCalledWith({
id: '12345',
errorCallback,
successCallback: expect.any(Function),
limit: 100,
shouldFetchAll: false,
requestData: {
file_id: '12345',
file_version_id: '67890',
fields: 'replies',
enable_rich_text: true,
},
});
});

test.each([
{ can_create_annotations: true, can_view_annotations: false },
{ can_create_annotations: false, can_view_annotations: false },
Expand Down
Loading
Loading