Skip to content

Commit

Permalink
fix(sidebar): Task assignment to use new status field (#720)
Browse files Browse the repository at this point in the history
  • Loading branch information
Conrad Chan authored Dec 19, 2018
1 parent a71390b commit 4f4c18e
Show file tree
Hide file tree
Showing 13 changed files with 56 additions and 63 deletions.
8 changes: 6 additions & 2 deletions flow-typed/box-ui-elements.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ import {
ORIGIN_ACTIVITY_SIDEBAR,
ORIGIN_SKILLS_SIDEBAR,
ORIGIN_METADATA_SIDEBAR,
TASK_APPROVED,
TASK_COMPLETED,
TASK_INCOMPLETE,
TASK_REJECTED,
} from '../src/constants';

type Method =
Expand Down Expand Up @@ -104,6 +108,7 @@ type ItemType = typeof TYPE_FILE | typeof TYPE_FOLDER | typeof TYPE_WEBLINK;
type UploadStatus = typeof STATUS_PENDING | typeof STATUS_IN_PROGRESS | typeof STATUS_COMPLETE | typeof STATUS_ERROR;
type Delimiter = typeof DELIMITER_SLASH | typeof DELIMITER_CARET;
type Size = typeof SIZE_SMALL | typeof SIZE_LARGE | typeof SIZE_MEDIUM;
type TaskAssignmentStatus = typeof TASK_APPROVED | typeof TASK_COMPLETED | typeof TASK_INCOMPLETE | typeof TASK_REJECTED;

type SharedLink = {
url: string,
Expand Down Expand Up @@ -523,8 +528,7 @@ type TaskAssignment = {
type: 'task_assignment',
id: string,
assigned_to: User,
resolution_state: string,
message: string,
status: TaskAssignmentStatus,
};

type TaskAssignments = {
Expand Down
17 changes: 6 additions & 11 deletions src/api/Feed.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,7 @@ class Feed extends Base {
* @param {BoxItem} file - The file to which the task is assigned
* @param {string} taskId - ID of task to be updated
* @param {string} taskAssignmentId - Task assignment ID
* @param {string} resolutionState - New task assignment status
* @param {string} message - optional the message to the assignee
* @param {TaskAssignmentStatus} taskStatus - New task assignment status
* @param {Function} successCallback - the function which will be called on success
* @param {Function} errorCallback - the function which will be called on error
* @return {void}
Expand All @@ -242,8 +241,7 @@ class Feed extends Base {
file: BoxItem,
taskId: string,
taskAssignmentId: string,
resolutionState: string,
message?: string,
taskStatus: TaskAssignmentStatus,
successCallback: Function,
errorCallback: ErrorCallback,
): void => {
Expand All @@ -259,8 +257,7 @@ class Feed extends Base {
assignmentAPI.updateTaskAssignment({
file,
taskAssignmentId,
resolutionState,
message,
taskStatus,
successCallback: (taskAssignment: TaskAssignment) => {
this.updateTaskAssignmentSuccessCallback(taskId, taskAssignment, successCallback);
},
Expand Down Expand Up @@ -294,7 +291,6 @@ class Feed extends Base {
return {
...item,
...updatedAssignment,
resolution_state: updatedAssignment.message.toLowerCase(),
};
}

Expand Down Expand Up @@ -513,7 +509,7 @@ class Feed extends Base {
id: assignee.id,
name: assignee.name,
},
resolution_state: TASK_INCOMPLETE,
status: TASK_INCOMPLETE,
}));

const task = {
Expand Down Expand Up @@ -706,13 +702,12 @@ class Feed extends Base {
}

task.task_assignment_collection.entries = assignments.map(taskAssignment => {
const { id, assigned_to, message, resolution_state } = taskAssignment;
const { id, assigned_to, status } = taskAssignment;
return {
type: TASK_ASSIGNMENT,
id,
assigned_to,
message,
resolution_state: message ? message.toLowerCase() : resolution_state,
status,
};
});

Expand Down
11 changes: 4 additions & 7 deletions src/api/TaskAssignments.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,26 +83,23 @@ class TaskAssignments extends Base {
*
* @param {BoxItem} file - File object for which we are updating a task assignment
* @param {string} taskAssignmentId - Task assignment to be edited
* @param {string} resolutionState - The updated task assignment status
* @param {TaskAssignmentStatus} taskStatus - The updated task assignment status
* @param {Function} successCallback - Success callback
* @param {Function} errorCallback - Error callback
* @param {string} [message] - The task assignments text
* @return {void}
*/
updateTaskAssignment({
file,
taskAssignmentId,
resolutionState,
message,
taskStatus,
successCallback,
errorCallback,
}: {
file: BoxItem,
taskAssignmentId: string,
resolutionState: string,
taskStatus: TaskAssignmentStatus,
successCallback: Function,
errorCallback: ElementsErrorCallback,
message?: string,
}): void {
this.errorCode = ERROR_CODE_UPDATE_TASK_ASSIGNMENT;
const { id = '', permissions } = file;
Expand All @@ -116,7 +113,7 @@ class TaskAssignments extends Base {
}

const requestData = {
data: { resolution_state: resolutionState, message },
data: { status: taskStatus },
};

this.put({
Expand Down
23 changes: 10 additions & 13 deletions src/api/__tests__/Feed-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ jest.mock('../Tasks', () => {
name: 'Daniel DeMicco',
login: '[email protected]',
},
resolution_state: 'incomplete',
message: 'Completed',
status: 'completed',
},
],
});
Expand Down Expand Up @@ -151,8 +150,7 @@ describe('api/Feed', () => {
name: 'Daniel DeMicco',
login: '[email protected]',
},
resolution_state: 'incomplete',
message: 'Completed',
status: 'completed',
},
],
};
Expand Down Expand Up @@ -409,11 +407,11 @@ describe('api/Feed', () => {
taskId,
{
...tasks.entries[0].task_assignment_collection.entries[0],
message: updatedState,
status: updatedState,
},
successCb,
);
expect(feed.updateFeedItem.mock.calls[0][0].task_assignment_collection.entries[0].resolution_state).toBe(
expect(feed.updateFeedItem.mock.calls[0][0].task_assignment_collection.entries[0].status).toBe(
updatedState,
);
expect(successCb).toBeCalled();
Expand Down Expand Up @@ -564,7 +562,7 @@ describe('api/Feed', () => {
entries: [
{
assigned_to: assignees[0],
resolution_state: 'incomplete',
status: 'incomplete',
},
],
total_count: 1,
Expand All @@ -588,7 +586,7 @@ describe('api/Feed', () => {
entries: [
{
assigned_to: assignees[0],
resolution_state: 'incomplete',
status: 'incomplete',
},
],
total_count: 1,
Expand Down Expand Up @@ -748,13 +746,12 @@ describe('api/Feed', () => {
{
id: '1',
assigned_to: { id: '1234' },
message: 'completed',
resolution_state: 'completed',
status: 'completed',
},
];
const expectedResult = {
task_assignment_collection: {
entries: [{ ...assignments[0], type: 'task_assignment' }],
entries: [{ ...assignments[0], status: 'completed', type: 'task_assignment' }],
total_count: 1,
},
};
Expand All @@ -776,12 +773,12 @@ describe('api/Feed', () => {
{
id: '1',
assigned_to: { id: '1234' },
resolution_state: 'completed',
status: 'completed',
},
];
const expectedResult = {
task_assignment_collection: {
entries: [{ ...assignments[0], type: 'task_assignment' }],
entries: [{ ...assignments[0], status: 'completed', type: 'task_assignment' }],
total_count: 1,
},
};
Expand Down
8 changes: 4 additions & 4 deletions src/api/__tests__/TaskAssignments-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe('api/TaskAssignments', () => {
id: '987654321',
};

const resolutionState = 'rejected';
const taskStatus = 'rejected';
const successCallback = jest.fn();
const errorCallback = jest.fn();

Expand Down Expand Up @@ -93,7 +93,7 @@ describe('api/TaskAssignments', () => {
taskAssignments.updateTaskAssignment({
file,
taskAssignmentId,
resolutionState,
taskStatus,
successCallback,
errorCallback,
});
Expand All @@ -106,13 +106,13 @@ describe('api/TaskAssignments', () => {

test('should put a well formed task update to the tasks endpoint', () => {
const requestData = {
data: { resolution_state: resolutionState },
data: { status: taskStatus },
};

taskAssignments.updateTaskAssignment({
file,
taskAssignmentId,
resolutionState,
taskStatus,
successCallback,
errorCallback,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const items = [
entries: [
{
assigned_to: { name: 'Akon', id: 11 },
resolution_state: 'incomplete',
status: 'incomplete',
},
],
total_count: 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ exports[`components/ContentSidebar/ActiveState/activity-feed/ActiveState should
"id": 11,
"name": "Akon",
},
"resolution_state": "incomplete",
"status": "incomplete",
},
],
"total_count": 1,
Expand Down
10 changes: 3 additions & 7 deletions src/components/ContentSidebar/ActivityFeed/task/Task.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,7 @@ import RejectedAssignment from './RejectedAssignment';

import './Task.scss';
import { fillUserPlaceholder } from '../../../../util/fields';

const TASK_APPROVED = 'approved';
const TASK_REJECTED = 'rejected';
const TASK_COMPLETED = 'completed';
const TASK_INCOMPLETE = 'incomplete';
import { TASK_APPROVED, TASK_REJECTED, TASK_COMPLETED, TASK_INCOMPLETE } from '../../../../constants';

type Props = {
task_assignment_collection: TaskAssignments | SelectorItems,
Expand Down Expand Up @@ -117,8 +113,8 @@ class Task extends React.Component<Props> {
{task_assignment_collection && task_assignment_collection.entries
? task_assignment_collection.entries
.map(fillUserPlaceholder)
.map(({ id: assignmentId, assigned_to, resolution_state }) => {
switch (resolution_state) {
.map(({ id: assignmentId, assigned_to, status }) => {
switch (status) {
case TASK_COMPLETED:
case TASK_APPROVED:
return <CompletedAssignment {...assigned_to} key={assigned_to.id} />;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ describe('components/ContentSidebar/ActivityFeed/task/Task', () => {
{
id: 0,
assigned_to: { name: 'Jake Thomas', id: 1 },
resolution_state: 'incomplete',
status: 'incomplete',
},
{
id: 1,
assigned_to: { name: 'Peter Pan', id: 2 },
resolution_state: 'completed',
status: 'completed',
},
],
},
Expand Down Expand Up @@ -78,12 +78,12 @@ describe('components/ContentSidebar/ActivityFeed/task/Task', () => {
{
id: 0,
assigned_to: { name: 'Jake Thomas', id: 1 },
resolution_state: 'incomplete',
status: 'incomplete',
},
{
id: 1,
assigned_to: { name: 'Peter Pan', id: 2 },
resolution_state: 'completed',
status: 'completed',
},
``,
],
Expand Down Expand Up @@ -188,12 +188,12 @@ describe('components/ContentSidebar/ActivityFeed/task/Task', () => {
{
id: 0,
assigned_to: { name: 'Jake Thomas', id: 1 },
resolution_state: 'incomplete',
status: 'incomplete',
},
{
id: 1,
assigned_to: { name: 'Peter Pan', id: 2 },
resolution_state: 'completed',
status: 'completed',
},
],
},
Expand Down Expand Up @@ -227,12 +227,12 @@ describe('components/ContentSidebar/ActivityFeed/task/Task', () => {
{
id: 0,
assigned_to: { name: 'Jake Thomas', id: 1 },
resolution_state: 'incomplete',
status: 'incomplete',
},
{
id: 1,
assigned_to: { name: 'Peter Pan', id: 2 },
resolution_state: 'completed',
status: 'completed',
},
],
},
Expand Down
6 changes: 2 additions & 4 deletions src/components/ContentSidebar/ActivitySidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,19 +149,17 @@ class ActivitySidebar extends React.PureComponent<Props, State> {
*
* @param {string} taskId - ID of task to be updated
* @param {string} taskAssignmentId - Task assignment ID
* @param {string} status - New task assignment status
* @param {string} message - the message to the assignee
* @param {TaskAssignmentStatus} status - New task assignment status
* @return void
*/
updateTaskAssignment = (taskId: string, taskAssignmentId: string, status: string, message?: string): void => {
updateTaskAssignment = (taskId: string, taskAssignmentId: string, status: TaskAssignmentStatus): void => {
const { file, api } = this.props;

api.getFeedAPI(false).updateTaskAssignment(
file,
taskId,
taskAssignmentId,
status,
message,
this.feedSuccessCallback,
this.feedErrorCallback,
);
Expand Down
8 changes: 7 additions & 1 deletion src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ export const FIELD_MESSAGE = 'message';
export const FIELD_TAGGED_MESSAGE = 'tagged_message';
export const FIELD_TRASHED_AT = 'trashed_at';
export const FIELD_ASSIGNED_TO = 'assigned_to';
export const FIELD_RESOLUTION_STATE = 'resolution_state';
export const FIELD_RELEVANCE: '' = '';
export const FIELD_STATUS = 'status';

/* ----------------------- Permissions --------------------------- */
export const PERMISSION_CAN_PREVIEW = 'can_preview';
Expand Down Expand Up @@ -306,3 +306,9 @@ export const PLACEHOLDER_USER = { type: 'user', id: '2', name: '' };

/* ------------------ Integrations ------------------------- */
export const APP_INTEGRATION = 'app_integration';

/* ------------------ Task Assignment Statuses ----------------- */
export const TASK_APPROVED: 'approved' = 'approved';
export const TASK_COMPLETED: 'completed' = 'completed';
export const TASK_INCOMPLETE: 'incomplete' = 'incomplete';
export const TASK_REJECTED: 'rejected' = 'rejected';
Loading

0 comments on commit 4f4c18e

Please sign in to comment.