Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CancelTask frontend #18747

Merged
merged 22 commits into from
May 16, 2023
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
5ba5bee
add initial cancel task action with optimistic state and status changes
arosiclair May 10, 2023
fde26f3
create optimistic cancel task report action
arosiclair May 10, 2023
067e77e
remove unused const
arosiclair May 10, 2023
b9c9f50
Merge branch 'main' of github.com:Expensify/App into arosiclair-cance…
arosiclair May 11, 2023
dd199e5
make canceled task actions visible
arosiclair May 11, 2023
3ac8891
add CancelTaskAction
arosiclair May 11, 2023
39e0a12
Merge branch 'main' of github.com:Expensify/App into arosiclair-cance…
arosiclair May 15, 2023
adad9a4
match other task actions
arosiclair May 15, 2023
e5c08b5
Merge branch 'jack-completeTask' of github.com:Expensify/App into aro…
arosiclair May 15, 2023
1017659
use TaskAction for cancel actions
arosiclair May 15, 2023
eb825c7
update the report optimistically for the LHN
arosiclair May 15, 2023
a9f6882
Merge branch 'main' of github.com:Expensify/App into arosiclair-cance…
arosiclair May 15, 2023
e68d5ea
use shared optimistic task action helper
arosiclair May 15, 2023
0d86edd
combine TaskAction logic
arosiclair May 15, 2023
1dea583
added spanish translation
arosiclair May 15, 2023
1d1ec1e
Merge branch 'main' of github.com:Expensify/App into arosiclair-cance…
arosiclair May 16, 2023
e0bef3a
added jsdoc for cancelTask
arosiclair May 16, 2023
c8e284a
disable TaskPreview checkbox when canceled
arosiclair May 16, 2023
af6d95c
disable done button when task is canceled
arosiclair May 16, 2023
3ed87e9
hide three dot menu when canceled
arosiclair May 16, 2023
e234c0d
Merge branch 'main' of github.com:Expensify/App into arosiclair-cance…
arosiclair May 16, 2023
c0377c4
revert Podfile.lock change
arosiclair May 16, 2023
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
1 change: 1 addition & 0 deletions src/CONST.js
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,7 @@ const CONST = {
CLOSED: 'CLOSED',
CREATED: 'CREATED',
TASKEDITED: 'TASKEDITED',
TASKCANCELED: 'TASKCANCELED',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

beep boop 🤖 🐧

This PR caused #21314 (comment)

Because we have a typo-ish here.
The backend uses TASKCANCELLED (notice the double LL)

IOU: 'IOU',
RENAMED: 'RENAMED',
CHRONOSOOOLIST: 'CHRONOSOOOLIST',
Expand Down
13 changes: 12 additions & 1 deletion src/components/ReportActionItem/TaskAction.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,18 @@ const TaskAction = (props) => {
const taskReportID = props.taskReportID;
const taskReportName = props.taskReport.reportName || '';

const messageLinkText = props.actionName === CONST.REPORT.ACTIONS.TYPE.TASKCOMPLETED ? props.translate('task.messages.completed') : props.translate('newTaskPage.task');
let messageLinkText = '';
switch (props.actionName) {
case CONST.REPORT.ACTIONS.TYPE.TASKCOMPLETED:
messageLinkText = props.translate('task.messages.completed');
break;
case CONST.REPORT.ACTIONS.TYPE.TASKCANCELED:
messageLinkText = props.translate('task.canceled');
break;
default:
messageLinkText = props.translate('newTaskPage.task');
}

return (
<Pressable
onPress={() => Navigation.navigate(ROUTES.getReportRoute(taskReportID))}
Expand Down
1 change: 1 addition & 0 deletions src/languages/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -1193,6 +1193,7 @@ export default {
pleaseEnterTaskDestination: 'Please select a share destination',
},
task: {
canceled: 'Canceled task',
completed: 'Completed',
messages: {
completed: 'Completed task',
Expand Down
6 changes: 5 additions & 1 deletion src/libs/ReportActionsUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,11 @@ function shouldReportActionBeVisible(reportAction, key) {
}

// Filter out any unsupported reportAction types
if (!_.has(CONST.REPORT.ACTIONS.TYPE, reportAction.actionName) && !_.contains(_.values(CONST.REPORT.ACTIONS.TYPE.POLICYCHANGELOG), reportAction.actionName)) {
if (
!_.has(CONST.REPORT.ACTIONS.TYPE, reportAction.actionName) &&
!_.contains(_.values(CONST.REPORT.ACTIONS.TYPE.POLICYCHANGELOG), reportAction.actionName) &&
!_.contains(_.values(CONST.REPORT.ACTIONS.TYPE.TASK), reportAction.actionName)
) {
return false;
}

Expand Down
35 changes: 35 additions & 0 deletions src/libs/ReportUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -2085,6 +2085,40 @@ function getWhisperDisplayNames(participants) {
return _.map(participants, (login) => getDisplayNameForParticipant(login, !isWhisperOnlyVisibleToCurrentUSer)).join(', ');
}

function buildOptimisticCancelTaskReportAction(taskReportID) {
return {
taskReportID,
actionName: CONST.REPORT.ACTIONS.TYPE.TASKCANCELED,
actorAccountID: currentUserAccountID,
actorEmail: currentUserEmail,
arosiclair marked this conversation as resolved.
Show resolved Hide resolved
automatic: false,
avatar: lodashGet(currentUserPersonalDetails, 'avatar', getDefaultAvatar(currentUserEmail)),
isAttachment: false,
person: [
{
style: 'strong',
text: lodashGet(currentUserPersonalDetails, 'displayName', currentUserEmail),
type: 'TEXT',
},
],
reportActionID: NumberUtils.rand64(),
shouldShow: true,
created: DateUtils.getDBTime(),
message: [
{
type: CONST.REPORT.MESSAGE.TYPE.TEXT,
style: 'strong',
text: 'You',
},
{
type: CONST.REPORT.MESSAGE.TYPE.TEXT,
style: 'normal',
text: ' closed this report',
},
],
};
thienlnam marked this conversation as resolved.
Show resolved Hide resolved
}

/**
* Show subscript on IOU or expense report
* @param {Object} report
Expand Down Expand Up @@ -2192,6 +2226,7 @@ export {
canRequestMoney,
getWhisperDisplayNames,
getWorkspaceAvatar,
buildOptimisticCancelTaskReportAction,
isThread,
isThreadParent,
isThreadFirstChat,
Expand Down
58 changes: 57 additions & 1 deletion src/libs/actions/Task.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import * as ReportUtils from '../ReportUtils';
import * as Report from './Report';
import Navigation from '../Navigation/Navigation';
import ROUTES from '../../ROUTES';
import DateUtils from '../DateUtils';
import CONST from '../../CONST';
import DateUtils from '../DateUtils';

/**
* Clears out the task info from the store
Expand Down Expand Up @@ -429,6 +429,61 @@ function getShareDestination(reportID, reports, personalDetails) {
};
}

arosiclair marked this conversation as resolved.
Show resolved Hide resolved
function cancelTask(taskReportID, parentReportID, originalStateNum, originalStatusNum, currentUserEmail, cancelMessage) {
const optimisticCancelReportAction = ReportUtils.buildOptimisticCancelTaskReportAction(taskReportID);
arosiclair marked this conversation as resolved.
Show resolved Hide resolved
const optimisticReportActionID = optimisticCancelReportAction.reportActionID;
const now = DateUtils.getDBTime();
const lastCommentText = ReportUtils.formatReportLastMessageText(cancelMessage);

const optimisticData = [
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${taskReportID}`,
value: {
stateNum: CONST.REPORT.STATE_NUM.SUBMITTED,
statusNum: CONST.REPORT.STATUS.CLOSED,
},
},
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${parentReportID}`,
value: {
lastVisibleActionCreated: now,
lastMessageText: Str.htmlDecode(lastCommentText),
lastActorEmail: currentUserEmail,
lastReadTime: now,
},
},
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${parentReportID}`,
value: {
[optimisticReportActionID]: optimisticCancelReportAction,
},
},
];

const failureData = [
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${taskReportID}`,
value: {
stateNum: originalStateNum,
statusNum: originalStatusNum,
},
},
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${parentReportID}`,
value: {
[optimisticReportActionID]: null,
},
},
];

API.write('CancelTask', {taskReportID, optimisticReportActionID}, {optimisticData, failureData});
}

export {
createTaskAndNavigate,
editTaskAndNavigate,
Expand All @@ -443,4 +498,5 @@ export {
clearOutTaskInfoAndNavigate,
getAssignee,
getShareDestination,
cancelTask,
};
3 changes: 2 additions & 1 deletion src/libs/isReportMessageAttachment.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ import CONST from '../CONST';
* @returns {Boolean}
*/
export default function isReportMessageAttachment({text, html}) {
return text === CONST.ATTACHMENT_MESSAGE_TEXT && html !== CONST.ATTACHMENT_MESSAGE_TEXT;
const regex = new RegExp(` ${CONST.ATTACHMENT_SOURCE_ATTRIBUTE}="(.*)"`, 'i');
return text === CONST.ATTACHMENT_MESSAGE_TEXT && !!html.match(regex);
}
19 changes: 15 additions & 4 deletions src/pages/home/HeaderView.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import colors from '../../styles/colors';
import reportPropTypes from '../reportPropTypes';
import ONYXKEYS from '../../ONYXKEYS';
import ThreeDotsMenu from '../../components/ThreeDotsMenu';
import * as Task from '../../libs/actions/Task';
import reportActionPropTypes from './report/reportActionPropTypes';

const propTypes = {
Expand Down Expand Up @@ -115,9 +116,15 @@ const HeaderView = (props) => {
threeDotMenuItems.push({
icon: Expensicons.Trashcan,
text: props.translate('common.cancel'),

// Implementing in https://github.com/Expensify/App/issues/16857
onSelected: () => {},
onSelected: () =>
Task.cancelTask(
props.report.reportID,
props.report.parentReportID,
props.report.stateNum,
props.report.statusNum,
props.account.primaryLogin,
props.translate('task.canceled'),
),
});
}
}
Expand Down Expand Up @@ -234,7 +241,11 @@ export default compose(
withOnyx({
account: {
key: ONYXKEYS.ACCOUNT,
selector: (account) => account && {guideCalendarLink: account.guideCalendarLink},
selector: (account) =>
account && {
guideCalendarLink: account.guideCalendarLink,
primaryLogin: account.primaryLogin,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason why primaryLogin is added here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not really sure might have just been added in a bad merge. If it isn't being used still I think it's fine to remove

},
},
parentReportActions: {
key: ({report}) => `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.parentReportID}`,
Expand Down
8 changes: 8 additions & 0 deletions src/pages/home/report/ReportActionItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,14 @@ class ReportActionItem extends Component {
isHovered={hovered}
/>
);
} else if (this.props.action.actionName === CONST.REPORT.ACTIONS.TYPE.TASKCANCELED) {
children = (
<TaskAction
taskReportID={this.props.action.taskReportID}
actionName={this.props.action.actionName}
isHovered={hovered}
/>
);
} else if (ReportActionUtils.isCreatedTaskReportAction(this.props.action)) {
children = (
<TaskPreview
Expand Down
22 changes: 22 additions & 0 deletions tests/unit/isReportMessageAttachmentTest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import isReportMessageAttachment from '../../src/libs/isReportMessageAttachment';

describe('isReportMessageAttachment', () => {
it('returns true if a report action is attachment', () => {
const message = {
text: '[Attachment]',
html: '<img src="https://www.expensify.com/chat-attachments/1260926113061804740/w_66791ca35b3c34c2a0eda4d065d97c9907cadd61.jpg.1024.jpg" data-expensify-source="https://www.expensify.com/chat-attachments/1260926113061804740/w_66791ca35b3c34c2a0eda4d065d97c9907cadd61.jpg" data-name="rn_image_picker_lib_temp_636b71a8-18fd-41a1-9725-6587ffb207a7.jpg" data-expensify-width="4000" data-expensify-height="3000" />',
};
expect(isReportMessageAttachment(message)).toBe(true);
});

it('returns false if a report action is not attachment', () => {
let message = {text: '[Attachment]', html: '<em>[Attachment]</em>'};
expect(isReportMessageAttachment(message)).toBe(false);

message = {text: '[Attachment]', html: '<a href="https://www.google.com" target="_blank" rel="noreferrer noopener">[Attachment]</a>'};
expect(isReportMessageAttachment(message)).toBe(false);

message = {text: '[Attachment]', html: '<a href="https://www.google.com/?data-expensify-source=" target="_blank" rel="noreferrer noopener">[Attachment]</a>'};
expect(isReportMessageAttachment(message)).toBe(false);
});
});