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

Track expense lhn #41668

Merged
merged 20 commits into from
May 28, 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
5 changes: 3 additions & 2 deletions src/libs/OptionsListUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ Onyx.connect({
const transactionThreadReportID = ReportActionUtils.getOneTransactionThreadReportID(reportID, actions[reportActions[0]], true);
if (transactionThreadReportID) {
const transactionThreadReportActionsArray = Object.values(actions[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${transactionThreadReportID}`] ?? {});
sortedReportActions = ReportActionUtils.getCombinedReportActions(reportActionsArray, transactionThreadReportActionsArray);
sortedReportActions = ReportActionUtils.getCombinedReportActions(reportActionsArray, transactionThreadReportActionsArray, reportID);
}

lastReportActions[reportID] = sortedReportActions[0];
Expand All @@ -299,7 +299,8 @@ Onyx.connect({
ReportActionUtils.shouldReportActionBeVisible(reportAction, actionKey) &&
!ReportActionUtils.isWhisperAction(reportAction) &&
reportAction.actionName !== CONST.REPORT.ACTIONS.TYPE.CREATED &&
reportAction.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE,
reportAction.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE &&
!ReportActionUtils.isResolvedActionTrackExpense(reportAction),
);
visibleReportActionItems[reportID] = reportActionsForDisplay[0];
});
Expand Down
32 changes: 26 additions & 6 deletions src/libs/ReportActionsUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -310,17 +310,22 @@ function shouldIgnoreGap(currentReportAction: ReportAction | undefined, nextRepo
* Returns a sorted and filtered list of report actions from a report and it's associated child
* transaction thread report in order to correctly display reportActions from both reports in the one-transaction report view.
*/
function getCombinedReportActions(reportActions: ReportAction[], transactionThreadReportActions: ReportAction[]): ReportAction[] {
function getCombinedReportActions(reportActions: ReportAction[], transactionThreadReportActions: ReportAction[], reportID?: string): ReportAction[] {
if (isEmptyObject(transactionThreadReportActions)) {
return reportActions;
}

// Filter out the created action from the transaction thread report actions, since we already have the parent report's created action in `reportActions`
const filteredTransactionThreadReportActions = transactionThreadReportActions?.filter((action) => action.actionName !== CONST.REPORT.ACTIONS.TYPE.CREATED);

const report = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`];
const isSelfDM = report?.chatType === CONST.REPORT.CHAT_TYPE.SELF_DM;
// Filter out request and send money request actions because we don't want to show any preview actions for one transaction reports
const filteredReportActions = [...reportActions, ...filteredTransactionThreadReportActions].filter((action) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
const filteredReportActions = [...reportActions, ...filteredTransactionThreadReportActions].filter((action) => {
const report = allReports?.[reportID ?? ''];
const isSelfDM = report?.chatType === CONST.REPORT.CHAT_TYPE.SELF_DM;
const filteredReportActions = [...reportActions, ...filteredTransactionThreadReportActions].filter((action) => {

const actionType = (action as OriginalMessageIOU).originalMessage?.type ?? '';
if (isSelfDM) {
return actionType !== CONST.IOU.REPORT_ACTION_TYPE.CREATE && !isSentMoneyReportAction(action);
}
return actionType !== CONST.IOU.REPORT_ACTION_TYPE.CREATE && actionType !== CONST.IOU.REPORT_ACTION_TYPE.TRACK && !isSentMoneyReportAction(action);
});

Expand Down Expand Up @@ -560,6 +565,23 @@ function shouldHideNewMarker(reportAction: OnyxEntry<ReportAction>): boolean {
return !isNetworkOffline && reportAction.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE;
}

/**
* Checks whether an action is actionable track expense.
*
*/
function isActionableTrackExpense(reportAction: OnyxEntry<ReportAction>): reportAction is ReportActionBase & OriginalMessageActionableTrackedExpenseWhisper {
return reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.ACTIONABLE_TRACK_EXPENSE_WHISPER;
}

/**
* Checks whether an action is actionable track expense and resolved.
*
*/
function isResolvedActionTrackExpense(reportAction: OnyxEntry<ReportAction>): boolean {
const resolution = (reportAction?.originalMessage as OriginalMessageActionableMentionWhisper['originalMessage'])?.resolution;
return isActionableTrackExpense(reportAction) && !!resolution;
}

/**
* Checks if a reportAction is fit for display as report last action, meaning that
* it satisfies shouldReportActionBeVisible, it's not whisper action and not deleted.
Expand All @@ -578,7 +600,8 @@ function shouldReportActionBeVisibleAsLastAction(reportAction: OnyxEntry<ReportA
return (
shouldReportActionBeVisible(reportAction, reportAction.reportActionID) &&
!(isWhisperAction(reportAction) && !isReportPreviewAction(reportAction) && !isMoneyRequestAction(reportAction)) &&
!(isDeletedAction(reportAction) && !isDeletedParentAction(reportAction))
!(isDeletedAction(reportAction) && !isDeletedParentAction(reportAction)) &&
!isResolvedActionTrackExpense(reportAction)
);
}

Expand Down Expand Up @@ -1161,10 +1184,6 @@ function isActionableJoinRequest(reportAction: OnyxEntry<ReportAction>): reportA
return reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.ACTIONABLE_JOIN_REQUEST;
}

function isActionableTrackExpense(reportAction: OnyxEntry<ReportAction>): reportAction is ReportActionBase & OriginalMessageActionableTrackedExpenseWhisper {
return reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.ACTIONABLE_TRACK_EXPENSE_WHISPER;
}

/**
* Checks if any report actions correspond to a join request action that is still pending.
* @param reportID
Expand Down Expand Up @@ -1265,6 +1284,7 @@ export {
isActionableJoinRequestPending,
isActionableTrackExpense,
isLinkedTransactionHeld,
isResolvedActionTrackExpense,
};

export type {LastVisibleMessage};
49 changes: 20 additions & 29 deletions src/libs/actions/IOU.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1479,6 +1479,8 @@ function getDeleteTrackExpenseInformation(
reportAction: OnyxTypes.ReportAction,
shouldDeleteTransactionFromOnyx = true,
isMovingTransactionFromTrackExpense = false,
actionableWhisperReportActionID = '',
resolution = '',
) {
// STEP 1: Get all collections we're updating
const chatReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${chatReportID}`] ?? null;
Expand Down Expand Up @@ -1516,10 +1518,10 @@ function getDeleteTrackExpenseInformation(
},
errors: undefined,
},
...(actionableWhisperReportActionID && {[actionableWhisperReportActionID]: {originalMessage: {resolution}}}),
} as OnyxTypes.ReportActions;

const lastVisibleAction = ReportActionsUtils.getLastVisibleAction(chatReport?.reportID ?? '', updatedReportAction);
const reportLastMessageText = ReportActionsUtils.getLastVisibleMessage(chatReport?.reportID ?? '', updatedReportAction).lastMessageText;
const {lastMessageText = '', lastMessageHtml = ''} = ReportActionsUtils.getLastVisibleMessage(chatReport?.reportID ?? '', updatedReportAction);

// STEP 4: Build Onyx data
const optimisticData: OnyxUpdate[] = [];
Expand Down Expand Up @@ -1565,8 +1567,9 @@ function getDeleteTrackExpenseInformation(
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${chatReport?.reportID}`,
value: {
lastMessageText: reportLastMessageText,
lastMessageText,
lastVisibleActionCreated: lastVisibleAction?.created,
lastMessageHtml: !lastMessageHtml ? lastMessageText : lastMessageHtml,
},
},
);
Expand Down Expand Up @@ -1610,6 +1613,19 @@ function getDeleteTrackExpenseInformation(
});
}

if (actionableWhisperReportActionID) {
failureData.push({
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${chatReport?.reportID}`,
value: {
[actionableWhisperReportActionID]: {
originalMessage: {
resolution: null,
},
},
},
});
}
failureData.push(
{
onyxMethod: Onyx.METHOD.MERGE,
Expand Down Expand Up @@ -3008,7 +3024,7 @@ const getConvertTrackedExpenseInformation = (
optimisticData: deleteOptimisticData,
successData: deleteSuccessData,
failureData: deleteFailureData,
} = getDeleteTrackExpenseInformation(linkedTrackedExpenseReportID, transactionID, linkedTrackedExpenseReportAction, false, true);
} = getDeleteTrackExpenseInformation(linkedTrackedExpenseReportID, transactionID, linkedTrackedExpenseReportAction, false, true, actionableWhisperReportActionID, resolution);

optimisticData?.push(...deleteOptimisticData);
successData?.push(...deleteSuccessData);
Expand Down Expand Up @@ -3042,31 +3058,6 @@ const getConvertTrackedExpenseInformation = (
},
});

// Resolve actionable whisper message
optimisticData?.push({

This comment was marked as outdated.

This comment was marked as outdated.

This comment was marked as resolved.

onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${linkedTrackedExpenseReportID}`,
value: {
[actionableWhisperReportActionID]: {
originalMessage: {
resolution,
},
},
},
});

failureData?.push({
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${linkedTrackedExpenseReportID}`,
value: {
[actionableWhisperReportActionID]: {
originalMessage: {
resolution: null,
},
},
},
});

return {optimisticData, successData, failureData, modifiedExpenseReportActionID: modifiedExpenseReportAction.reportActionID};
};

Expand Down
Loading