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

Marking GRB on task at highest #43927

Merged
merged 11 commits into from
Jul 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
12 changes: 11 additions & 1 deletion src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,7 @@ type OptimisticTaskReport = Pick<
| 'notificationPreference'
| 'parentReportActionID'
| 'lastVisibleActionCreated'
| 'hasParentAccess'
>;

type TransactionDetails = {
Expand Down Expand Up @@ -2279,7 +2280,15 @@ function getLastVisibleMessage(reportID: string | undefined, actionsToMerge: Rep
* @param [parentReportAction] - The parent report action of the report (Used to check if the task has been canceled)
*/
function isWaitingForAssigneeToCompleteTask(report: OnyxEntry<Report>, parentReportAction: OnyxEntry<ReportAction>): boolean {
return isTaskReport(report) && isReportManager(report) && isOpenTaskReport(report, parentReportAction);
if (report?.hasOutstandingChildTask) {
return true;
}

if (isOpenTaskReport(report, parentReportAction) && !report?.hasParentAccess && isReportManager(report)) {
return true;
}

return false;
}

function isUnreadWithMention(reportOrOption: OnyxEntry<Report> | OptionData): boolean {
Expand Down Expand Up @@ -5105,6 +5114,7 @@ function buildOptimisticTaskReport(
statusNum: CONST.REPORT.STATUS_NUM.OPEN,
notificationPreference,
lastVisibleActionCreated: DateUtils.getDBTime(),
hasParentAccess: true,
};
}

Expand Down
4 changes: 4 additions & 0 deletions src/libs/SidebarUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,8 @@ function getOptionData({
searchText: undefined,
isPinned: false,
hasOutstandingChildRequest: false,
hasOutstandingChildTask: false,
hasParentAccess: undefined,
isIOUReportOwner: null,
isChatRoom: false,
isArchivedRoom: false,
Expand Down Expand Up @@ -284,6 +286,8 @@ function getOptionData({
result.isDeletedParentAction = report.isDeletedParentAction;
result.isSelfDM = ReportUtils.isSelfDM(report);
result.tooltipText = ReportUtils.getReportParticipantsTitle(visibleParticipantAccountIDs);
result.hasOutstandingChildTask = report.hasOutstandingChildTask;
result.hasParentAccess = report.hasParentAccess;

const hasMultipleParticipants = participantPersonalDetailList.length > 1 || result.isChatRoom || result.isPolicyExpenseChat || ReportUtils.isExpenseReport(report);
const subtitle = ReportUtils.getChatRoomSubtitle(report);
Expand Down
6 changes: 6 additions & 0 deletions src/libs/actions/Report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3239,6 +3239,8 @@ function completeOnboarding(
description: taskDescription ?? '',
}));

const hasOutstandingChildTask = tasksData.some((task) => !task.completedTaskReportAction);

const tasksForOptimisticData = tasksData.reduce<OnyxUpdate[]>((acc, {currentTask, taskCreatedAction, taskReportAction, taskDescription, completedTaskReportAction}) => {
acc.push(
{
Expand All @@ -3261,6 +3263,7 @@ function completeOnboarding(
managerID: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD,
},
isOptimisticReport: true,
managerID: currentUserAccountID,
},
},
{
Expand All @@ -3287,6 +3290,7 @@ function completeOnboarding(
value: {
stateNum: CONST.REPORT.STATE_NUM.APPROVED,
statusNum: CONST.REPORT.STATUS_NUM.APPROVED,
managerID: currentUserAccountID,
},
});
}
Expand Down Expand Up @@ -3371,6 +3375,7 @@ function completeOnboarding(
key: `${ONYXKEYS.COLLECTION.REPORT}${targetChatReportID}`,
value: {
lastMentionedTime: DateUtils.getDBTime(),
hasOutstandingChildTask,
},
},
{
Expand Down Expand Up @@ -3402,6 +3407,7 @@ function completeOnboarding(
lastMessageTranslationKey: '',
lastMessageText: '',
lastVisibleActionCreated: '',
hasOutstandingChildTask: false,
};
const {lastMessageText = '', lastMessageTranslationKey = ''} = ReportActionsUtils.getLastVisibleMessage(targetChatReportID);
if (lastMessageText || lastMessageTranslationKey) {
Expand Down
117 changes: 116 additions & 1 deletion src/libs/actions/Task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,14 @@ function createTaskAndNavigate(

const currentTime = DateUtils.getDBTimeWithSkew();
const lastCommentText = ReportUtils.formatReportLastMessageText(ReportActionsUtils.getReportActionText(optimisticAddCommentReport.reportAction));
const parentReport = getReport(parentReportID);
const optimisticParentReport = {
lastVisibleActionCreated: optimisticAddCommentReport.reportAction.created,
lastMessageText: lastCommentText,
lastActorAccountID: currentUserAccountID,
lastReadTime: currentTime,
lastMessageTranslationKey: '',
hasOutstandingChildTask: assigneeAccountID === currentUserAccountID ? true : parentReport?.hasOutstandingChildTask,
};

// We're only setting onyx data for the task report here because it's possible for the parent report to not exist yet (if you're assigning a task to someone you haven't chatted with before)
Expand Down Expand Up @@ -272,6 +274,13 @@ function createTaskAndNavigate(
},
},
});
failureData.push({
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${parentReportID}`,
value: {
hasOutstandingChildTask: parentReport?.hasOutstandingChildTask,
},
});

clearOutTaskInfo();

Expand All @@ -295,14 +304,37 @@ function createTaskAndNavigate(
Report.notifyNewAction(parentReportID, currentUserAccountID);
}

/**
* @returns the object to update `report.hasOutstandingChildTask`
*/
function getOutstandingChildTask(taskReport: OnyxEntry<OnyxTypes.Report>) {
const parentReportActions = allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${taskReport?.parentReportID}`] ?? {};
return Object.values(parentReportActions).some((reportAction) => {
if (String(reportAction.childReportID) === String(taskReport?.reportID)) {
return false;
}

if (
reportAction.childType === CONST.REPORT.TYPE.TASK &&
reportAction?.childStateNum === CONST.REPORT.STATE_NUM.OPEN &&
reportAction?.childStatusNum === CONST.REPORT.STATUS_NUM.OPEN &&
ReportActionsUtils.getReportActionMessage(reportAction)?.isDeletedParentAction
) {
return true;
}

return false;
});
}

/**
* Complete a task
*/
function completeTask(taskReport: OnyxEntry<OnyxTypes.Report>) {
const taskReportID = taskReport?.reportID ?? '-1';
const message = `marked as complete`;
const completedTaskReportAction = ReportUtils.buildOptimisticTaskReportAction(taskReportID, CONST.REPORT.ACTIONS.TYPE.TASK_COMPLETED, message);

const parentReport = getParentReport(taskReport);
const optimisticData: OnyxUpdate[] = [
{
onyxMethod: Onyx.METHOD.MERGE,
Expand Down Expand Up @@ -352,6 +384,24 @@ function completeTask(taskReport: OnyxEntry<OnyxTypes.Report>) {
},
];

if (parentReport?.hasOutstandingChildTask) {
const hasOutstandingChildTask = getOutstandingChildTask(taskReport);
optimisticData.push({
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${taskReport?.parentReportID}`,
value: {
hasOutstandingChildTask,
},
});
failureData.push({
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${taskReport?.parentReportID}`,
value: {
hasOutstandingChildTask: parentReport?.hasOutstandingChildTask,
},
});
}

const parameters: CompleteTaskParams = {
taskReportID,
completedTaskReportActionID: completedTaskReportAction.reportActionID,
Expand All @@ -369,6 +419,8 @@ function reopenTask(taskReport: OnyxEntry<OnyxTypes.Report>) {
const taskReportID = taskReport?.reportID ?? '-1';
const message = `marked as incomplete`;
const reopenedTaskReportAction = ReportUtils.buildOptimisticTaskReportAction(taskReportID, CONST.REPORT.ACTIONS.TYPE.TASK_REOPENED, message);
const parentReport = getParentReport(taskReport);
const hasOutstandingChildTask = taskReport?.managerID === currentUserAccountID ? true : parentReport?.hasOutstandingChildTask;

const optimisticData: OnyxUpdate[] = [
{
Expand All @@ -383,6 +435,13 @@ function reopenTask(taskReport: OnyxEntry<OnyxTypes.Report>) {
lastReadTime: reopenedTaskReportAction.created,
},
},
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${taskReport?.parentReportID}`,
value: {
hasOutstandingChildTask,
},
},
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${taskReportID}`,
Expand Down Expand Up @@ -410,6 +469,13 @@ function reopenTask(taskReport: OnyxEntry<OnyxTypes.Report>) {
statusNum: CONST.REPORT.STATUS_NUM.APPROVED,
},
},
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${taskReport?.parentReportID}`,
value: {
hasOutstandingChildTask: taskReport?.hasOutstandingChildTask,
},
},
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${taskReportID}`,
Expand Down Expand Up @@ -565,6 +631,39 @@ function editTaskAssignee(report: OnyxTypes.Report, ownerAccountID: number, assi
},
];

if (currentUserAccountID === assigneeAccountID) {
const parentReport = getParentReport(report);
if (!isEmptyObject(parentReport)) {
optimisticData.push({
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${parentReport.reportID}`,
value: {hasOutstandingChildTask: true},
});
failureData.push({
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${parentReport.reportID}`,
value: {hasOutstandingChildTask: parentReport?.hasOutstandingChildTask},
});
}
}

if (report.managerID === currentUserAccountID) {
const hasOutstandingChildTask = getOutstandingChildTask(report);
const parentReport = getParentReport(report);
if (!isEmptyObject(parentReport)) {
optimisticData.push({
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${parentReport.reportID}`,
value: {hasOutstandingChildTask},
});
failureData.push({
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${parentReport.reportID}`,
value: {hasOutstandingChildTask: parentReport?.hasOutstandingChildTask},
});
}
}

// If we make a change to the assignee, we want to add a comment to the assignee's chat
// Check if the assignee actually changed
if (assigneeAccountID && assigneeAccountID !== report.managerID && assigneeAccountID !== ownerAccountID && assigneeChatReport) {
Expand Down Expand Up @@ -812,6 +911,13 @@ function getParentReport(report: OnyxEntry<OnyxTypes.Report>): OnyxEntry<OnyxTyp
return allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${report.parentReportID}`];
}

/**
* Returns the report
*/
function getReport(reportID: string): OnyxEntry<OnyxTypes.Report> {
return allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`];
}

/**
* Cancels a task by setting the report state to SUBMITTED and status to CLOSED
*/
Expand Down Expand Up @@ -846,6 +952,7 @@ function deleteTask(report: OnyxEntry<OnyxTypes.Report>) {
const optimisticReportActions = {
[parentReportAction?.reportActionID ?? '-1']: optimisticReportAction,
};
const hasOutstandingChildTask = getOutstandingChildTask(report);

const optimisticData: OnyxUpdate[] = [
{
Expand All @@ -864,6 +971,7 @@ function deleteTask(report: OnyxEntry<OnyxTypes.Report>) {
value: {
lastMessageText: ReportActionsUtils.getLastVisibleMessage(parentReport?.reportID ?? '-1', optimisticReportActions as OnyxTypes.ReportActions).lastMessageText ?? '',
lastVisibleActionCreated: ReportActionsUtils.getLastVisibleAction(parentReport?.reportID ?? '-1', optimisticReportActions as OnyxTypes.ReportActions)?.created,
hasOutstandingChildTask,
},
},
{
Expand Down Expand Up @@ -926,6 +1034,13 @@ function deleteTask(report: OnyxEntry<OnyxTypes.Report>) {
statusNum: report.statusNum ?? '',
} as OnyxTypes.Report,
},
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${parentReport?.reportID}`,
value: {
hasOutstandingChildTask: parentReport?.hasOutstandingChildTask,
},
},
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.reportID}`,
Expand Down
3 changes: 3 additions & 0 deletions src/types/onyx/Report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ type Report = OnyxCommon.OnyxValueWithOfflineFeedback<
/** Whether the report has a child that is an outstanding expense that is awaiting action from the current user */
hasOutstandingChildRequest?: boolean;

/** Whether the report has a child task that is awaiting action from the current user */
hasOutstandingChildTask?: boolean;

/** List of icons for report participants */
icons?: OnyxCommon.Icon[];

Expand Down
Loading