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

Align default IDs in Task.ts file #54960

Merged
Show file tree
Hide file tree
Changes from 3 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
2 changes: 0 additions & 2 deletions .eslintrc.changed.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ module.exports = {
files: [
'src/libs/actions/IOU.ts',
'src/libs/actions/Report.ts',
'src/libs/actions/Task.ts',
'src/libs/OptionsListUtils.ts',
'src/libs/TransactionUtils/index.ts',
'src/pages/home/ReportScreen.tsx',
'src/pages/workspace/WorkspaceInitialPage.tsx',
'src/pages/home/report/PureReportActionItem.tsx',
Expand Down
2 changes: 1 addition & 1 deletion src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8044,7 +8044,7 @@ function getAllAncestorReportActionIDs(report: Report | null | undefined, includ
* @param lastVisibleActionCreated Last visible action created of the child report
* @param type The type of action in the child report
*/
function getOptimisticDataForParentReportAction(reportID: string, lastVisibleActionCreated: string, type: string): Array<OnyxUpdate | null> {
function getOptimisticDataForParentReportAction(reportID: string | undefined, lastVisibleActionCreated: string, type: string): Array<OnyxUpdate | null> {
const report = getReportOrDraftReport(reportID);

if (!report || isEmptyObject(report)) {
Expand Down
59 changes: 22 additions & 37 deletions src/libs/actions/Task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ function createTaskAndNavigate(
) {
const optimisticTaskReport = ReportUtils.buildOptimisticTaskReport(currentUserAccountID, assigneeAccountID, parentReportID, title, description, policyID);

const assigneeChatReportID = assigneeChatReport?.reportID ?? '-1';
const assigneeChatReportID = assigneeChatReport?.reportID;
const taskReportID = optimisticTaskReport.reportID;
let assigneeChatReportOnyxData;

Expand Down Expand Up @@ -220,7 +220,7 @@ function createTaskAndNavigate(
},
];

if (assigneeChatReport) {
if (assigneeChatReport && assigneeChatReportID) {
assigneeChatReportOnyxData = ReportUtils.getTaskAssigneeChatOnyxData(
currentUserAccountID,
assigneeAccountID,
Expand Down Expand Up @@ -619,8 +619,8 @@ function editTaskAssignee(report: OnyxTypes.Report, sessionAccountID: number, as
const reportName = report.reportName?.trim();

let assigneeChatReportOnyxData;
const assigneeChatReportID = assigneeChatReport ? assigneeChatReport.reportID : '-1';
const assigneeChatReportMetadata = ReportUtils.getReportMetadata(assigneeChatReport?.reportID);
const assigneeChatReportID = assigneeChatReport?.reportID;
const assigneeChatReportMetadata = ReportUtils.getReportMetadata(assigneeChatReportID);
const parentReport = getParentReport(report);
const taskOwnerAccountID = getTaskOwnerAccountID(report);
const optimisticReport: OptimisticReport = {
Expand Down Expand Up @@ -712,7 +712,7 @@ function editTaskAssignee(report: OnyxTypes.Report, sessionAccountID: number, as

// 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 !== sessionAccountID && assigneeChatReport) {
if (assigneeAccountID && assigneeAccountID !== report.managerID && assigneeAccountID !== sessionAccountID && assigneeChatReport && assigneeChatReport && assigneeChatReportID) {
optimisticReport.participants = {
...(optimisticReport.participants ?? {}),
[assigneeAccountID]: {
Expand All @@ -724,8 +724,9 @@ function editTaskAssignee(report: OnyxTypes.Report, sessionAccountID: number, as
currentUserAccountID,
assigneeAccountID,
report.reportID,
assigneeChatReportID ?? '-1',
report.parentReportID ?? '-1',
assigneeChatReportID,
// eslint-disable-next-line @typescript-eslint/non-nullable-type-assertion-style
report.parentReportID as string,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@fabioh8010 As I know @pac-guerreiro is working on making report.parentReportID to be required for tasks in his PR, based on this discussion. So I'm not sure if I should change the typing for parentReportID to string | undefined

Copy link
Contributor

@paultsimura paultsimura Jan 10, 2025

Choose a reason for hiding this comment

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

If we merge this PR sooner – we'll need to ensure we handle this in @pac-guerreiro's PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've removed the assertion and updated typing instead:

  • this way, if typing is wrong it will be catched by TS and fixed for sure
  • also, it looks like the PR I mentioned shouldn't effect specifically this place

reportName ?? '',
assigneeChatReport,
);
Expand Down Expand Up @@ -784,7 +785,7 @@ function setDescriptionValue(description: string) {
/**
* Sets the shareDestination value for the task
*/
function setShareDestinationValue(shareDestination: string) {
function setShareDestinationValue(shareDestination: string | undefined) {
// This is only needed for creation of a new task and so it should only be stored locally
Onyx.merge(ONYXKEYS.TASK, {shareDestination});
}
Expand Down Expand Up @@ -844,7 +845,7 @@ function setAssigneeValue(
// If there is no share destination set, automatically set it to the assignee chat report
// This allows for a much quicker process when creating a new task and is likely the desired share destination most times
if (!shareToReportID && !skipShareDestination) {
setShareDestinationValue(selfDMReportID ?? '-1');
setShareDestinationValue(selfDMReportID);
}
} else {
// Check for the chatReport by participants IDs
Expand All @@ -871,7 +872,7 @@ function setAssigneeValue(
// If there is no share destination set, automatically set it to the assignee chat report
// This allows for a much quicker process when creating a new task and is likely the desired share destination most times
if (!shareToReportID && !skipShareDestination) {
setShareDestinationValue(report?.reportID ?? '-1');
setShareDestinationValue(report?.reportID);
}
}

Expand Down Expand Up @@ -1002,7 +1003,7 @@ function getNavigationUrlOnTaskDelete(report: OnyxEntry<OnyxTypes.Report>): stri
return undefined;
}

const shouldDeleteTaskReport = !ReportActionsUtils.doesReportHaveVisibleActions(report.reportID ?? '-1');
const shouldDeleteTaskReport = !ReportActionsUtils.doesReportHaveVisibleActions(report.reportID);
if (!shouldDeleteTaskReport) {
return undefined;
}
Expand Down Expand Up @@ -1030,14 +1031,14 @@ function deleteTask(report: OnyxEntry<OnyxTypes.Report>) {
return;
}
const message = `deleted task: ${report.reportName}`;
const optimisticCancelReportAction = ReportUtils.buildOptimisticTaskReportAction(report.reportID ?? '-1', CONST.REPORT.ACTIONS.TYPE.TASK_CANCELLED, message);
const optimisticCancelReportAction = ReportUtils.buildOptimisticTaskReportAction(report.reportID, CONST.REPORT.ACTIONS.TYPE.TASK_CANCELLED, message);
const optimisticReportActionID = optimisticCancelReportAction.reportActionID;
const parentReportAction = getParentReportAction(report);
const parentReport = getParentReport(report);
const canUserPerformWriteAction = ReportUtils.canUserPerformWriteAction(report);

// If the task report is the last visible action in the parent report, we should navigate back to the parent report
const shouldDeleteTaskReport = !ReportActionsUtils.doesReportHaveVisibleActions(report.reportID ?? '-1', canUserPerformWriteAction);
const shouldDeleteTaskReport = !ReportActionsUtils.doesReportHaveVisibleActions(report.reportID, canUserPerformWriteAction);
const optimisticReportAction: Partial<ReportUtils.OptimisticTaskReportAction> = {
pendingAction: shouldDeleteTaskReport ? CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE : CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE,
previousMessage: parentReportAction?.message,
Expand All @@ -1054,9 +1055,7 @@ function deleteTask(report: OnyxEntry<OnyxTypes.Report>) {
errors: undefined,
linkMetadata: [],
};
const optimisticReportActions = {
[parentReportAction?.reportActionID ?? '-1']: optimisticReportAction,
};
const optimisticReportActions = parentReportAction?.reportActionID ? {[parentReportAction?.reportActionID]: optimisticReportAction} : {};
const hasOutstandingChildTask = getOutstandingChildTask(report);

const optimisticData: OnyxUpdate[] = [
Expand All @@ -1075,13 +1074,9 @@ function deleteTask(report: OnyxEntry<OnyxTypes.Report>) {
key: `${ONYXKEYS.COLLECTION.REPORT}${parentReport?.reportID}`,
value: {
lastMessageText:
ReportActionsUtils.getLastVisibleMessage(parentReport?.reportID ?? '-1', canUserPerformWriteAction, optimisticReportActions as OnyxTypes.ReportActions).lastMessageText ??
'',
lastVisibleActionCreated: ReportActionsUtils.getLastVisibleAction(
parentReport?.reportID ?? '-1',
canUserPerformWriteAction,
optimisticReportActions as OnyxTypes.ReportActions,
)?.created,
ReportActionsUtils.getLastVisibleMessage(parentReport?.reportID, canUserPerformWriteAction, optimisticReportActions as OnyxTypes.ReportActions).lastMessageText ?? '',
lastVisibleActionCreated: ReportActionsUtils.getLastVisibleAction(parentReport?.reportID, canUserPerformWriteAction, optimisticReportActions as OnyxTypes.ReportActions)
?.created,
hasOutstandingChildTask,
},
},
Expand All @@ -1103,7 +1098,7 @@ function deleteTask(report: OnyxEntry<OnyxTypes.Report>) {
const childVisibleActionCount = parentReportAction?.childVisibleActionCount ?? 0;
if (childVisibleActionCount === 0) {
const optimisticParentReportData = ReportUtils.getOptimisticDataForParentReportAction(
parentReport?.reportID ?? '-1',
parentReport?.reportID,
parentReport?.lastVisibleActionCreated ?? '',
CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE,
);
Expand All @@ -1128,11 +1123,7 @@ function deleteTask(report: OnyxEntry<OnyxTypes.Report>) {
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${parentReport?.reportID}`,
value: {
[parentReportAction?.reportActionID ?? '-1']: {
pendingAction: null,
},
},
value: parentReportAction?.reportActionID ? {[parentReportAction.reportActionID]: {pendingAction: null}} : {},
},
];

Expand Down Expand Up @@ -1162,11 +1153,7 @@ function deleteTask(report: OnyxEntry<OnyxTypes.Report>) {
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${parentReport?.reportID}`,
value: {
[parentReportAction?.reportActionID ?? '-1']: {
pendingAction: null,
},
},
value: parentReportAction?.reportActionID ? {[parentReportAction?.reportActionID]: {pendingAction: null}} : {},
},
];

Expand Down Expand Up @@ -1270,9 +1257,7 @@ function clearTaskErrors(reportID: string) {

// Delete the task preview in the parent report
if (report?.pendingFields?.createChat === CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD) {
Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.parentReportID}`, {
[report.parentReportActionID ?? -1]: null,
});
Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.parentReportID}`, report.parentReportActionID ? {[report.parentReportActionID]: null} : {});

Report.navigateToConciergeChatAndDeleteReport(reportID);
return;
Expand Down
Loading