Skip to content

Commit

Permalink
Merge pull request #20014 from Expensify/jack-moveReportActions
Browse files Browse the repository at this point in the history
Move task reportActions onto the task report
  • Loading branch information
neil-marcellini authored Jun 6, 2023
2 parents 14bc16d + 8933e76 commit a61b74a
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 73 deletions.
32 changes: 7 additions & 25 deletions src/components/ReportActionItem/TaskAction.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,23 @@
import React from 'react';
import {View, Pressable} from 'react-native';
import {View} from 'react-native';
import PropTypes from 'prop-types';
import {withOnyx} from 'react-native-onyx';
import Navigation from '../../libs/Navigation/Navigation';
import withLocalize, {withLocalizePropTypes} from '../withLocalize';
import ROUTES from '../../ROUTES';
import compose from '../../libs/compose';
import ONYXKEYS from '../../ONYXKEYS';
import Text from '../Text';
import styles from '../../styles/styles';
import Icon from '../Icon';
import * as Expensicons from '../Icon/Expensicons';
import * as StyleUtils from '../../styles/StyleUtils';
import getButtonState from '../../libs/getButtonState';
import CONST from '../../CONST';

const propTypes = {
/** The ID of the associated taskReport */
taskReportID: PropTypes.string.isRequired,

/** Whether the task preview is hovered so we can modify its style */
isHovered: PropTypes.bool,

/** Name of the reportAction action */
actionName: PropTypes.string.isRequired,

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

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

const defaultProps = {
taskReport: {},
isHovered: false,
};
const TaskAction = (props) => {
const taskReportID = props.taskReportID;
const taskReportName = props.taskReport.reportName || '';

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

return (
<Pressable
onPress={() => Navigation.navigate(ROUTES.getReportRoute(taskReportID))}
style={[styles.flexRow, styles.justifyContentBetween]}
>
<>
<View style={[styles.flex1, styles.flexRow, styles.alignItemsCenter]}>
<Text style={styles.chatItemMessageLink}>{messageLinkText}</Text>
<Text style={[styles.chatItemMessage]}>{` ${taskReportName}`}</Text>
</View>
<Icon
src={Expensicons.ArrowRight}
fill={StyleUtils.getIconFillColor(getButtonState(props.isHovered))}
/>
</Pressable>
</>
);
};

Expand Down
11 changes: 5 additions & 6 deletions src/components/ReportActionItem/TaskPreview.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,12 @@ const TaskPreview = (props) => {
// The reportAction might not contain details regarding the taskReport
// Only the direct parent reportAction will contain details about the taskReport
// Other linked reportActions will only contain the taskReportID and we will grab the details from there
const isTaskCompleted =
(props.taskReport.stateNum === CONST.REPORT.STATE_NUM.SUBMITTED && props.taskReport.statusNum === CONST.REPORT.STATUS.APPROVED) ||
(props.action.childStateNum === CONST.REPORT.STATE_NUM.SUBMITTED && props.action.childStatusNum === CONST.REPORT.STATUS.APPROVED);
const isTaskCompleted = props.taskReport
? props.taskReport.stateNum === CONST.REPORT.STATE_NUM.SUBMITTED && props.taskReport.statusNum === CONST.REPORT.STATUS.APPROVED
: props.action.childStateNum === CONST.REPORT.STATE_NUM.SUBMITTED && props.action.childStatusNum === CONST.REPORT.STATUS.APPROVED;
const taskTitle = props.taskReport.reportName || props.action.childReportName;
const taskAssignee = props.taskReport.managerEmail || props.action.childManagerEmail;
const htmlForTaskPreview = taskAssignee ? `<comment><mention-user>@${taskAssignee}</mention-user> ${taskTitle}</comment>` : `<comment>${taskTitle}</comment>`;
const parentReportID = props.taskReport.parentReportID || props.action.parentReportID;

return (
<Pressable
Expand All @@ -74,9 +73,9 @@ const TaskPreview = (props) => {
disabled={TaskUtils.isTaskCanceled(props.taskReport)}
onPress={() => {
if (isTaskCompleted) {
TaskUtils.reopenTask(props.taskReportID, parentReportID, taskTitle);
TaskUtils.reopenTask(props.taskReportID, taskTitle);
} else {
TaskUtils.completeTask(props.taskReportID, parentReportID, taskTitle);
TaskUtils.completeTask(props.taskReportID, taskTitle);
}
}}
/>
Expand Down
3 changes: 1 addition & 2 deletions src/components/TaskHeader.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ function TaskHeader(props) {
const assigneeAvatar = UserUtils.getAvatar(lodashGet(props.personalDetails, [props.report.managerEmail, 'avatar']), props.report.managerEmail);
const isOpen = props.report.stateNum === CONST.REPORT.STATE_NUM.OPEN && props.report.statusNum === CONST.REPORT.STATUS.OPEN;
const isCompleted = props.report.stateNum === CONST.REPORT.STATE_NUM.SUBMITTED && props.report.statusNum === CONST.REPORT.STATUS.APPROVED;
const parentReportID = props.report.parentReportID;

useEffect(() => {
TaskUtils.setTaskReport(props.report);
Expand Down Expand Up @@ -97,7 +96,7 @@ function TaskHeader(props) {
isDisabled={TaskUtils.isTaskCanceled(props.report)}
medium
text={props.translate('newTaskPage.markAsDone')}
onPress={() => TaskUtils.completeTask(props.report.reportID, parentReportID, title)}
onPress={() => TaskUtils.completeTask(props.report.reportID, title)}
/>
)}
</View>
Expand Down
6 changes: 3 additions & 3 deletions src/languages/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -1273,9 +1273,9 @@ export default {
task: {
completed: 'Completed',
messages: {
completed: 'Completed task',
canceled: 'Canceled task',
reopened: 'Reopened task',
completed: 'completed task',
canceled: 'canceled task',
reopened: 'reopened task',
},
},
statementPage: {
Expand Down
6 changes: 3 additions & 3 deletions src/languages/es.js
Original file line number Diff line number Diff line change
Expand Up @@ -1279,9 +1279,9 @@ export default {
task: {
completed: 'Completada',
messages: {
completed: 'Tarea completada',
canceled: 'Tarea cancelada',
reopened: 'Tarea reabrir',
completed: 'tarea completada',
canceled: 'tarea cancelada',
reopened: 'tarea reabrir',
},
},
statementPage: {
Expand Down
45 changes: 15 additions & 30 deletions src/libs/actions/Task.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,8 @@ function createTaskAndNavigate(currentUserEmail, parentReportID, title, descript
Navigation.navigate(ROUTES.getReportRoute(optimisticTaskReport.reportID));
}

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

const optimisticData = [
Expand All @@ -183,18 +183,10 @@ function completeTask(taskReportID, parentReportID, taskTitle) {
statusNum: CONST.REPORT.STATUS.APPROVED,
},
},

{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${parentReportID}`,
value: {
lastVisibleActionCreated: completedTaskReportAction.created,
lastMessageText: message,
lastActorEmail: completedTaskReportAction.actorEmail,
},
},
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${parentReportID}`,
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${taskReportID}`,
value: {[completedTaskReportAction.reportActionID]: completedTaskReportAction},
},
];
Expand All @@ -211,7 +203,7 @@ function completeTask(taskReportID, parentReportID, taskTitle) {
},
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${parentReportID}`,
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${taskReportID}`,
value: {[completedTaskReportAction.reportActionID]: {pendingAction: null}},
},
];
Expand All @@ -229,11 +221,10 @@ function completeTask(taskReportID, parentReportID, taskTitle) {
/**
* Reopens a closed task
* @param {string} taskReportID ReportID of the task
* @param {string} parentReportID ReportID of the linked parent report of the task so we can add the action
* @param {string} taskTitle Title of the task
*/
function reopenTask(taskReportID, parentReportID, taskTitle) {
const message = `Reopened task: ${taskTitle}`;
function reopenTask(taskReportID, taskTitle) {
const message = `reopened task: ${taskTitle}`;
const reopenedTaskReportAction = ReportUtils.buildOptimisticTaskReportAction(taskReportID, CONST.REPORT.ACTIONS.TYPE.TASKREOPENED, message);

const optimisticData = [
Expand All @@ -243,20 +234,15 @@ function reopenTask(taskReportID, parentReportID, taskTitle) {
value: {
stateNum: CONST.REPORT.STATE_NUM.OPEN,
statusNum: CONST.REPORT.STATUS.OPEN,
},
},
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${parentReportID}`,
value: {
lastVisibleActionCreated: reopenedTaskReportAction.created,
lastMessageText: message,
lastActorEmail: reopenedTaskReportAction.actorEmail,
lastReadTime: reopenedTaskReportAction.created,
},
},
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${parentReportID}`,
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${taskReportID}`,
value: {[reopenedTaskReportAction.reportActionID]: reopenedTaskReportAction},
},
];
Expand All @@ -273,7 +259,7 @@ function reopenTask(taskReportID, parentReportID, taskTitle) {
},
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${parentReportID}`,
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${taskReportID}`,
value: {[reopenedTaskReportAction.reportActionID]: {pendingAction: null}},
},
];
Expand Down Expand Up @@ -526,13 +512,12 @@ function getShareDestination(reportID, reports, personalDetails) {
/**
* Cancels a task by setting the report state to SUBMITTED and status to CLOSED
* @param {string} taskReportID
* @param {string} parentReportID
* @param {string} taskTitle
* @param {number} originalStateNum
* @param {number} originalStatusNum
*/
function cancelTask(taskReportID, parentReportID, taskTitle, originalStateNum, originalStatusNum) {
const message = `Canceled task: ${taskTitle}`;
function cancelTask(taskReportID, taskTitle, originalStateNum, originalStatusNum) {
const message = `canceled task: ${taskTitle}`;
const optimisticCancelReportAction = ReportUtils.buildOptimisticTaskReportAction(taskReportID, CONST.REPORT.ACTIONS.TYPE.TASKCANCELED, message);
const optimisticReportActionID = optimisticCancelReportAction.reportActionID;

Expand All @@ -547,7 +532,7 @@ function cancelTask(taskReportID, parentReportID, taskTitle, originalStateNum, o
},
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${parentReportID}`,
key: `${ONYXKEYS.COLLECTION.REPORT}${taskReportID}`,
value: {
lastVisibleActionCreated: optimisticCancelReportAction.created,
lastMessageText: message,
Expand All @@ -556,7 +541,7 @@ function cancelTask(taskReportID, parentReportID, taskTitle, originalStateNum, o
},
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${parentReportID}`,
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${taskReportID}`,
value: {
[optimisticReportActionID]: optimisticCancelReportAction,
},
Expand All @@ -574,7 +559,7 @@ function cancelTask(taskReportID, parentReportID, taskTitle, originalStateNum, o
},
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${parentReportID}`,
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${taskReportID}`,
value: {
[optimisticReportActionID]: null,
},
Expand Down
6 changes: 3 additions & 3 deletions src/pages/home/HeaderView.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ const HeaderView = (props) => {
threeDotMenuItems.push({
icon: Expensicons.Checkmark,
text: props.translate('newTaskPage.markAsDone'),
onSelected: () => Task.completeTask(props.report.reportID, props.report.parentReportID, title),
onSelected: () => Task.completeTask(props.report.reportID, title),
});
}

Expand All @@ -101,7 +101,7 @@ const HeaderView = (props) => {
threeDotMenuItems.push({
icon: Expensicons.Checkmark,
text: props.translate('newTaskPage.markAsIncomplete'),
onSelected: () => Task.reopenTask(props.report.reportID, props.report.parentReportID, title),
onSelected: () => Task.reopenTask(props.report.reportID, title),
});
}

Expand All @@ -110,7 +110,7 @@ const HeaderView = (props) => {
threeDotMenuItems.push({
icon: Expensicons.Trashcan,
text: props.translate('common.cancel'),
onSelected: () => Task.cancelTask(props.report.reportID, props.report.parentReportID, props.report.reportName, props.report.stateNum, props.report.statusNum),
onSelected: () => Task.cancelTask(props.report.reportID, props.report.reportName, props.report.stateNum, props.report.statusNum),
});
}
}
Expand Down
1 change: 0 additions & 1 deletion src/pages/home/report/ReportActionItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,6 @@ function ReportActionItem(props) {
<TaskAction
taskReportID={props.action.originalMessage.taskReportID.toString()}
actionName={props.action.actionName}
isHovered={hovered}
/>
);
} else if (ReportActionsUtils.isCreatedTaskReportAction(props.action)) {
Expand Down

0 comments on commit a61b74a

Please sign in to comment.