Skip to content

Commit ffe3bfe

Browse files
neil-marcelliniOSBotify
authored andcommitted
Merge pull request #20014 from Expensify/jack-moveReportActions
Move task reportActions onto the task report (cherry picked from commit a61b74a)
1 parent 84ccf2a commit ffe3bfe

File tree

8 files changed

+43
-69
lines changed

8 files changed

+43
-69
lines changed

src/components/ReportActionItem/TaskAction.js

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,23 @@
11
import React from 'react';
2-
import {View, Pressable} from 'react-native';
2+
import {View} from 'react-native';
33
import PropTypes from 'prop-types';
44
import {withOnyx} from 'react-native-onyx';
5-
import Navigation from '../../libs/Navigation/Navigation';
65
import withLocalize, {withLocalizePropTypes} from '../withLocalize';
7-
import ROUTES from '../../ROUTES';
86
import compose from '../../libs/compose';
97
import ONYXKEYS from '../../ONYXKEYS';
108
import Text from '../Text';
119
import styles from '../../styles/styles';
12-
import Icon from '../Icon';
13-
import * as Expensicons from '../Icon/Expensicons';
14-
import * as StyleUtils from '../../styles/StyleUtils';
15-
import getButtonState from '../../libs/getButtonState';
1610
import CONST from '../../CONST';
1711

1812
const propTypes = {
19-
/** The ID of the associated taskReport */
20-
taskReportID: PropTypes.string.isRequired,
21-
22-
/** Whether the task preview is hovered so we can modify its style */
23-
isHovered: PropTypes.bool,
24-
2513
/** Name of the reportAction action */
2614
actionName: PropTypes.string.isRequired,
2715

28-
/* Onyx Props */
16+
/** The ID of the associated taskReport */
17+
// eslint-disable-next-line react/no-unused-prop-types -- This is used in the withOnyx HOC
18+
taskReportID: PropTypes.string.isRequired,
2919

20+
/* Onyx Props */
3021
taskReport: PropTypes.shape({
3122
/** Title of the task */
3223
reportName: PropTypes.string,
@@ -43,10 +34,8 @@ const propTypes = {
4334

4435
const defaultProps = {
4536
taskReport: {},
46-
isHovered: false,
4737
};
4838
const TaskAction = (props) => {
49-
const taskReportID = props.taskReportID;
5039
const taskReportName = props.taskReport.reportName || '';
5140

5241
let messageLinkText = '';
@@ -65,19 +54,12 @@ const TaskAction = (props) => {
6554
}
6655

6756
return (
68-
<Pressable
69-
onPress={() => Navigation.navigate(ROUTES.getReportRoute(taskReportID))}
70-
style={[styles.flexRow, styles.justifyContentBetween]}
71-
>
57+
<>
7258
<View style={[styles.flex1, styles.flexRow, styles.alignItemsCenter]}>
7359
<Text style={styles.chatItemMessageLink}>{messageLinkText}</Text>
7460
<Text style={[styles.chatItemMessage]}>{` ${taskReportName}`}</Text>
7561
</View>
76-
<Icon
77-
src={Expensicons.ArrowRight}
78-
fill={StyleUtils.getIconFillColor(getButtonState(props.isHovered))}
79-
/>
80-
</Pressable>
62+
</>
8163
);
8264
};
8365

src/components/ReportActionItem/TaskPreview.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,20 @@ const TaskPreview = (props) => {
5353
// The reportAction might not contain details regarding the taskReport
5454
// Only the direct parent reportAction will contain details about the taskReport
5555
// Other linked reportActions will only contain the taskReportID and we will grab the details from there
56+
<<<<<<< HEAD
5657
const isTaskCompleted =
5758
(props.taskReport.stateNum === CONST.REPORT.STATE_NUM.SUBMITTED && props.taskReport.statusNum === CONST.REPORT.STATUS.APPROVED) ||
5859
(props.action.childStateNum === CONST.REPORT.STATE_NUM.SUBMITTED && props.action.childStatusNum === CONST.REPORT.STATUS.APPROVED);
5960
const taskTitle = props.action.taskTitle || props.taskReport.reportName;
6061
const parentReportID = props.action.parentReportID || props.taskReport.parentReportID;
62+
=======
63+
const isTaskCompleted = props.taskReport
64+
? props.taskReport.stateNum === CONST.REPORT.STATE_NUM.SUBMITTED && props.taskReport.statusNum === CONST.REPORT.STATUS.APPROVED
65+
: props.action.childStateNum === CONST.REPORT.STATE_NUM.SUBMITTED && props.action.childStatusNum === CONST.REPORT.STATUS.APPROVED;
66+
const taskTitle = props.taskReport.reportName || props.action.childReportName;
67+
const taskAssignee = props.taskReport.managerEmail || props.action.childManagerEmail;
68+
const htmlForTaskPreview = taskAssignee ? `<comment><mention-user>@${taskAssignee}</mention-user> ${taskTitle}</comment>` : `<comment>${taskTitle}</comment>`;
69+
>>>>>>> a61b74a169 (Merge pull request #20014 from Expensify/jack-moveReportActions)
6170

6271
return (
6372
<Pressable
@@ -72,9 +81,9 @@ const TaskPreview = (props) => {
7281
disabled={TaskUtils.isTaskCanceled(props.taskReport)}
7382
onPress={() => {
7483
if (isTaskCompleted) {
75-
TaskUtils.reopenTask(props.taskReportID, parentReportID, taskTitle);
84+
TaskUtils.reopenTask(props.taskReportID, taskTitle);
7685
} else {
77-
TaskUtils.completeTask(props.taskReportID, parentReportID, taskTitle);
86+
TaskUtils.completeTask(props.taskReportID, taskTitle);
7887
}
7988
}}
8089
/>

src/components/TaskHeader.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ function TaskHeader(props) {
4040
const assigneeAvatar = UserUtils.getAvatar(lodashGet(props.personalDetails, [props.report.managerEmail, 'avatar']), props.report.managerEmail);
4141
const isOpen = props.report.stateNum === CONST.REPORT.STATE_NUM.OPEN && props.report.statusNum === CONST.REPORT.STATUS.OPEN;
4242
const isCompleted = props.report.stateNum === CONST.REPORT.STATE_NUM.SUBMITTED && props.report.statusNum === CONST.REPORT.STATUS.APPROVED;
43-
const parentReportID = props.report.parentReportID;
4443

4544
useEffect(() => {
4645
TaskUtils.setTaskReport(props.report);
@@ -97,7 +96,7 @@ function TaskHeader(props) {
9796
isDisabled={TaskUtils.isTaskCanceled(props.report)}
9897
medium
9998
text={props.translate('newTaskPage.markAsDone')}
100-
onPress={() => TaskUtils.completeTask(props.report.reportID, parentReportID, title)}
99+
onPress={() => TaskUtils.completeTask(props.report.reportID, title)}
101100
/>
102101
)}
103102
</View>

src/languages/en.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1273,9 +1273,9 @@ export default {
12731273
task: {
12741274
completed: 'Completed',
12751275
messages: {
1276-
completed: 'Completed task',
1277-
canceled: 'Canceled task',
1278-
reopened: 'Reopened task',
1276+
completed: 'completed task',
1277+
canceled: 'canceled task',
1278+
reopened: 'reopened task',
12791279
},
12801280
},
12811281
statementPage: {

src/languages/es.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1279,9 +1279,9 @@ export default {
12791279
task: {
12801280
completed: 'Completada',
12811281
messages: {
1282-
completed: 'Tarea completada',
1283-
canceled: 'Tarea cancelada',
1284-
reopened: 'Tarea reabrir',
1282+
completed: 'tarea completada',
1283+
canceled: 'tarea cancelada',
1284+
reopened: 'tarea reabrir',
12851285
},
12861286
},
12871287
statementPage: {

src/libs/actions/Task.js

Lines changed: 15 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,8 @@ function createTaskAndNavigate(currentUserEmail, parentReportID, title, descript
170170
Navigation.navigate(ROUTES.getReportRoute(optimisticTaskReport.reportID));
171171
}
172172

173-
function completeTask(taskReportID, parentReportID, taskTitle) {
174-
const message = `Completed task: ${taskTitle}`;
173+
function completeTask(taskReportID, taskTitle) {
174+
const message = `completed task: ${taskTitle}`;
175175
const completedTaskReportAction = ReportUtils.buildOptimisticTaskReportAction(taskReportID, CONST.REPORT.ACTIONS.TYPE.TASKCOMPLETED, message);
176176

177177
const optimisticData = [
@@ -183,18 +183,10 @@ function completeTask(taskReportID, parentReportID, taskTitle) {
183183
statusNum: CONST.REPORT.STATUS.APPROVED,
184184
},
185185
},
186+
186187
{
187188
onyxMethod: Onyx.METHOD.MERGE,
188-
key: `${ONYXKEYS.COLLECTION.REPORT}${parentReportID}`,
189-
value: {
190-
lastVisibleActionCreated: completedTaskReportAction.created,
191-
lastMessageText: message,
192-
lastActorEmail: completedTaskReportAction.actorEmail,
193-
},
194-
},
195-
{
196-
onyxMethod: Onyx.METHOD.MERGE,
197-
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${parentReportID}`,
189+
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${taskReportID}`,
198190
value: {[completedTaskReportAction.reportActionID]: completedTaskReportAction},
199191
},
200192
];
@@ -211,7 +203,7 @@ function completeTask(taskReportID, parentReportID, taskTitle) {
211203
},
212204
{
213205
onyxMethod: Onyx.METHOD.MERGE,
214-
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${parentReportID}`,
206+
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${taskReportID}`,
215207
value: {[completedTaskReportAction.reportActionID]: {pendingAction: null}},
216208
},
217209
];
@@ -229,11 +221,10 @@ function completeTask(taskReportID, parentReportID, taskTitle) {
229221
/**
230222
* Reopens a closed task
231223
* @param {string} taskReportID ReportID of the task
232-
* @param {string} parentReportID ReportID of the linked parent report of the task so we can add the action
233224
* @param {string} taskTitle Title of the task
234225
*/
235-
function reopenTask(taskReportID, parentReportID, taskTitle) {
236-
const message = `Reopened task: ${taskTitle}`;
226+
function reopenTask(taskReportID, taskTitle) {
227+
const message = `reopened task: ${taskTitle}`;
237228
const reopenedTaskReportAction = ReportUtils.buildOptimisticTaskReportAction(taskReportID, CONST.REPORT.ACTIONS.TYPE.TASKREOPENED, message);
238229

239230
const optimisticData = [
@@ -243,20 +234,15 @@ function reopenTask(taskReportID, parentReportID, taskTitle) {
243234
value: {
244235
stateNum: CONST.REPORT.STATE_NUM.OPEN,
245236
statusNum: CONST.REPORT.STATUS.OPEN,
246-
},
247-
},
248-
{
249-
onyxMethod: Onyx.METHOD.MERGE,
250-
key: `${ONYXKEYS.COLLECTION.REPORT}${parentReportID}`,
251-
value: {
252237
lastVisibleActionCreated: reopenedTaskReportAction.created,
253238
lastMessageText: message,
254239
lastActorEmail: reopenedTaskReportAction.actorEmail,
240+
lastReadTime: reopenedTaskReportAction.created,
255241
},
256242
},
257243
{
258244
onyxMethod: Onyx.METHOD.MERGE,
259-
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${parentReportID}`,
245+
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${taskReportID}`,
260246
value: {[reopenedTaskReportAction.reportActionID]: reopenedTaskReportAction},
261247
},
262248
];
@@ -273,7 +259,7 @@ function reopenTask(taskReportID, parentReportID, taskTitle) {
273259
},
274260
{
275261
onyxMethod: Onyx.METHOD.MERGE,
276-
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${parentReportID}`,
262+
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${taskReportID}`,
277263
value: {[reopenedTaskReportAction.reportActionID]: {pendingAction: null}},
278264
},
279265
];
@@ -526,13 +512,12 @@ function getShareDestination(reportID, reports, personalDetails) {
526512
/**
527513
* Cancels a task by setting the report state to SUBMITTED and status to CLOSED
528514
* @param {string} taskReportID
529-
* @param {string} parentReportID
530515
* @param {string} taskTitle
531516
* @param {number} originalStateNum
532517
* @param {number} originalStatusNum
533518
*/
534-
function cancelTask(taskReportID, parentReportID, taskTitle, originalStateNum, originalStatusNum) {
535-
const message = `Canceled task: ${taskTitle}`;
519+
function cancelTask(taskReportID, taskTitle, originalStateNum, originalStatusNum) {
520+
const message = `canceled task: ${taskTitle}`;
536521
const optimisticCancelReportAction = ReportUtils.buildOptimisticTaskReportAction(taskReportID, CONST.REPORT.ACTIONS.TYPE.TASKCANCELED, message);
537522
const optimisticReportActionID = optimisticCancelReportAction.reportActionID;
538523

@@ -547,7 +532,7 @@ function cancelTask(taskReportID, parentReportID, taskTitle, originalStateNum, o
547532
},
548533
{
549534
onyxMethod: Onyx.METHOD.MERGE,
550-
key: `${ONYXKEYS.COLLECTION.REPORT}${parentReportID}`,
535+
key: `${ONYXKEYS.COLLECTION.REPORT}${taskReportID}`,
551536
value: {
552537
lastVisibleActionCreated: optimisticCancelReportAction.created,
553538
lastMessageText: message,
@@ -556,7 +541,7 @@ function cancelTask(taskReportID, parentReportID, taskTitle, originalStateNum, o
556541
},
557542
{
558543
onyxMethod: Onyx.METHOD.MERGE,
559-
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${parentReportID}`,
544+
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${taskReportID}`,
560545
value: {
561546
[optimisticReportActionID]: optimisticCancelReportAction,
562547
},
@@ -574,7 +559,7 @@ function cancelTask(taskReportID, parentReportID, taskTitle, originalStateNum, o
574559
},
575560
{
576561
onyxMethod: Onyx.METHOD.MERGE,
577-
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${parentReportID}`,
562+
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${taskReportID}`,
578563
value: {
579564
[optimisticReportActionID]: null,
580565
},

src/pages/home/HeaderView.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ const HeaderView = (props) => {
9292
threeDotMenuItems.push({
9393
icon: Expensicons.Checkmark,
9494
text: props.translate('newTaskPage.markAsDone'),
95-
onSelected: () => Task.completeTask(props.report.reportID, props.report.parentReportID, title),
95+
onSelected: () => Task.completeTask(props.report.reportID, title),
9696
});
9797
}
9898

@@ -101,7 +101,7 @@ const HeaderView = (props) => {
101101
threeDotMenuItems.push({
102102
icon: Expensicons.Checkmark,
103103
text: props.translate('newTaskPage.markAsIncomplete'),
104-
onSelected: () => Task.reopenTask(props.report.reportID, props.report.parentReportID, title),
104+
onSelected: () => Task.reopenTask(props.report.reportID, title),
105105
});
106106
}
107107

@@ -110,7 +110,7 @@ const HeaderView = (props) => {
110110
threeDotMenuItems.push({
111111
icon: Expensicons.Trashcan,
112112
text: props.translate('common.cancel'),
113-
onSelected: () => Task.cancelTask(props.report.reportID, props.report.parentReportID, props.report.reportName, props.report.stateNum, props.report.statusNum),
113+
onSelected: () => Task.cancelTask(props.report.reportID, props.report.reportName, props.report.stateNum, props.report.statusNum),
114114
});
115115
}
116116
}

src/pages/home/report/ReportActionItem.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,6 @@ function ReportActionItem(props) {
232232
<TaskAction
233233
taskReportID={props.action.originalMessage.taskReportID.toString()}
234234
actionName={props.action.actionName}
235-
isHovered={hovered}
236235
/>
237236
);
238237
} else if (ReportActionsUtils.isCreatedTaskReportAction(props.action)) {

0 commit comments

Comments
 (0)