Skip to content

Commit

Permalink
feat(tasks): add support for new task api in activity feed
Browse files Browse the repository at this point in the history
- this is feature-flagged under
  activityFeed.tasks.newApi
- tasks are created and read from new service when enabled
- the new API format is not compatible with the old one
  • Loading branch information
alexkrolick committed Mar 4, 2019
1 parent 09deef4 commit 68f4f78
Show file tree
Hide file tree
Showing 21 changed files with 1,433 additions and 686 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ module.exports = {
'react/no-access-state-in-setstate': 'off', // fixme
'react/no-array-index-key': 'off', // fixme
'react/no-this-in-sfc': 'off',
'valid-jsdoc': 1,
},
globals: {
shallow: true,
Expand Down
5 changes: 0 additions & 5 deletions src/api/TaskCollaborators.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,6 @@ const headers = {
};

class TaskCollaborators extends Base {
// Root route only works on Box internal dev env
getBaseApiUrl(): string {
return '/api/2.0';
}

getUrlForTaskCollaborators(taskId: string): string {
return `${this.getBaseApiUrl()}/undoc/tasks/${taskId}/task_collaborators?limit=${API_PAGE_LIMIT}`;
}
Expand Down
5 changes: 0 additions & 5 deletions src/api/TaskLinks.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,6 @@ const headers = {
};

class TaskLinks extends Base {
// Root route only works on Box internal dev env
getBaseApiUrl(): string {
return '/api/2.0';
}

getUrlForTaskLinkCreate(): string {
return `${this.getBaseApiUrl()}/undoc/task_links`;
}
Expand Down
5 changes: 0 additions & 5 deletions src/api/TasksNew.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,6 @@ const headers = {
};

class TasksNew extends Base {
// Root route only works on Box internal dev env
getBaseApiUrl(): string {
return '/api/2.0';
}

getUrlForFileTasks(id: string): string {
return `${this.getBaseApiUrl()}/undoc/inbox?task_link_target_type=FILE&task_link_target_id=${id}&limit=${API_PAGE_LIMIT}`;
}
Expand Down
22 changes: 21 additions & 1 deletion src/elements/common/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -890,14 +890,34 @@ const messages: { [string]: MessageDescriptor } = defineMessages({
},
tasksFeedCompleteAction: {
id: 'be.tasks.feed.completeAction',
defaultMessage: 'Complete',
defaultMessage: 'Mark as Complete',
description: 'Completion option for a general task',
},
tasksFeedRejectAction: {
id: 'be.tasks.feed.rejectAction',
defaultMessage: 'Reject',
description: 'Reject option for an approval task',
},
tasksFeedCompletedLabel: {
id: 'be.tasks.feed.completedLabel',
defaultMessage: 'Task Complete',
description: 'Label for a completed task',
},
tasksFeedApprovedLabel: {
id: 'be.tasks.feed.approvedLabel',
defaultMessage: 'Task Approved',
description: 'Label for an approved task',
},
tasksFeedRejectedLabel: {
id: 'be.tasks.feed.rejectedLabel',
defaultMessage: 'Task Rejected',
description: 'Label for a rejected task',
},
tasksFeedIncompleteLabel: {
id: 'be.tasks.feed.incompleteLabel',
defaultMessage: 'Awaiting Assignees',
description: 'Label for an incomplete task',
},
versionDeleted: {
id: 'be.versionDeleted',
defaultMessage: '{ name } deleted version { version_number }',
Expand Down
2 changes: 2 additions & 0 deletions src/elements/content-preview/__tests__/ContentPreview-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,8 @@ describe('elements/content-preview/ContentPreview', () => {
instance.loadPreview = jest.fn();
});

// Test fails in [email protected] due to regression
// https://github.com/airbnb/enzyme/issues/2020
test('should destroy preview and load the file if file id changed', () => {
wrapper.setProps({
fileId: 'bar',
Expand Down
16 changes: 12 additions & 4 deletions src/elements/content-sidebar/ActivitySidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ class ActivitySidebar extends React.PureComponent<Props, State> {
updateTaskAssignment: (taskId: string, taskAssignmentId: string, status: TaskAssignmentStatus): void => {
const { file, api } = this.props;

api.getFeedAPI(false).updateTaskAssignment(
api.getFeedAPI(false).updateTaskCollaborator(
file,
taskId,
taskAssignmentId,
Expand Down Expand Up @@ -530,11 +530,15 @@ class ActivitySidebar extends React.PureComponent<Props, State> {
approverSelectorContacts,
getAvatarUrl,
};
return <AddTaskButton {...props} />;
return (
<FeatureFlag feature="activityFeed.tasks.newApi">
<AddTaskButton {...props} />
</FeatureFlag>
);
};

render() {
const { file, isDisabled = false, onVersionHistoryClick, getUserProfileUrl } = this.props;
const { file, isDisabled = false, onVersionHistoryClick, getUserProfileUrl, features } = this.props;
const {
currentUser,
approverSelectorContacts,
Expand All @@ -544,6 +548,10 @@ class ActivitySidebar extends React.PureComponent<Props, State> {
currentUserError,
} = this.state;

const updateTaskAssignment = isFeatureEnabled(features, 'activityFeed.tasks.newApi')
? this.tasksApiNew.updateTaskAssignment
: this.updateTaskAssignment;

return (
<SidebarContent
className="bcs-activity"
Expand All @@ -562,7 +570,7 @@ class ActivitySidebar extends React.PureComponent<Props, State> {
onTaskCreate={this.createTask}
onTaskDelete={this.deleteTask}
onTaskUpdate={this.updateTask}
onTaskAssignmentUpdate={this.updateTaskAssignment}
onTaskAssignmentUpdate={updateTaskAssignment}
getApproverWithQuery={this.getApproverWithQuery}
getMentionWithQuery={this.getMentionWithQuery}
onVersionHistoryClick={onVersionHistoryClick}
Expand Down
6 changes: 4 additions & 2 deletions src/elements/content-sidebar/AddTaskButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,15 @@ class AddTaskButton extends React.Component<Props, State> {
<FormattedMessage {...messages.tasksAddTask} />
</Button>
<Modal
className="be task-modal"
className="be-modal task-modal"
data-testid="create-task-modal"
isOpen={isTaskFormOpen}
onRequestClose={this.handleClose}
title={<FormattedMessage {...messages.tasksAddTaskFormTitle} />}
>
<TaskForm {...passThrough} onCancel={this.handleClose} onSubmit={this.handleSubmit} />
<div className="be">
<TaskForm {...passThrough} onCancel={this.handleClose} onSubmit={this.handleSubmit} />
</div>
</Modal>
</React.Fragment>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ const ActiveState = ({
<FeatureFlag
feature="activityFeed.tasks.newCards"
disabled={() =>
item.task_assignment_collection &&
item.task_assignment_collection.total_count && (
<li key={type + id} className="bcs-activity-feed-task">
<Task
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react';
import { shallow } from 'enzyme';
import { shallow, mount } from 'enzyme';

import ActiveState from '../ActiveState';
import Task from '../../task/Task';
Expand Down Expand Up @@ -64,7 +64,7 @@ describe('elements/content-sidebar/ActiveState/activity-feed/ActiveState', () =>
});

test('should correctly render with comments, tasks, versions', () => {
const wrapper = shallow(<ActiveState items={items} />).dive();
const wrapper = mount(<ActiveState items={items} />);
expect(wrapper).toMatchSnapshot();
expect(wrapper.find(Task)).toHaveLength(1);
});
Expand Down
Loading

0 comments on commit 68f4f78

Please sign in to comment.