Skip to content

Commit

Permalink
Merge pull request #35449 from infinitered/violations/cdanwards/lhn-o…
Browse files Browse the repository at this point in the history
…ptimistic-ids
  • Loading branch information
cead22 authored Feb 23, 2024
2 parents acbfffe + a8a96f8 commit 690174f
Show file tree
Hide file tree
Showing 11 changed files with 286 additions and 62 deletions.
11 changes: 7 additions & 4 deletions src/components/LHNOptionsList/OptionRowLHN.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,13 @@ function OptionRowLHN({reportID, isFocused = false, onSelectRow = () => {}, opti
return null;
}

const isHidden = optionItem?.notificationPreference === CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN;
if (isHidden && !isFocused && !optionItem?.isPinned) {
const hasBrickError = optionItem.brickRoadIndicator === CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR;
const shouldShowGreenDotIndicator = !hasBrickError && ReportUtils.requiresAttentionFromCurrentUser(optionItem, optionItem.parentReportAction);

const isHidden = optionItem.notificationPreference === CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN;

const shouldOverrideHidden = hasBrickError || isFocused || optionItem.isPinned;
if (isHidden && !shouldOverrideHidden) {
return null;
}

Expand All @@ -74,8 +79,6 @@ function OptionRowLHN({reportID, isFocused = false, onSelectRow = () => {}, opti
const hoveredBackgroundColor = !!styles.sidebarLinkHover && 'backgroundColor' in styles.sidebarLinkHover ? styles.sidebarLinkHover.backgroundColor : theme.sidebar;
const focusedBackgroundColor = styles.sidebarLinkActive.backgroundColor;

const hasBrickError = optionItem.brickRoadIndicator === CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR;
const shouldShowGreenDotIndicator = !hasBrickError && ReportUtils.requiresAttentionFromCurrentUser(optionItem, optionItem.parentReportAction);
/**
* Show the ReportActionContextMenu modal popover.
*
Expand Down
2 changes: 2 additions & 0 deletions src/libs/API/parameters/CreateDistanceRequestParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ type CreateDistanceRequestParams = {
category?: string;
tag?: string;
billable?: boolean;
transactionThreadReportID: string;
createdReportActionIDForThread: string;
};

export default CreateDistanceRequestParams;
2 changes: 2 additions & 0 deletions src/libs/API/parameters/RequestMoneyParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ type RequestMoneyParams = {
taxAmount: number;
billable?: boolean;
gpsPoints?: string;
transactionThreadReportID: string;
createdReportActionIDForThread: string;
};

export default RequestMoneyParams;
2 changes: 2 additions & 0 deletions src/libs/API/parameters/SendMoneyParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ type SendMoneyParams = {
newIOUReportDetails: string;
createdReportActionID: string;
reportPreviewReportActionID: string;
transactionThreadReportID: string;
createdReportActionIDForThread: string;
};

export default SendMoneyParams;
15 changes: 9 additions & 6 deletions src/libs/ReportActionsUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import Onyx from 'react-native-onyx';
import type {ValueOf} from 'type-fest';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import type {ActionName, ChangeLog, OriginalMessageActionableMentionWhisper, OriginalMessageIOU, OriginalMessageReimbursementDequeued} from '@src/types/onyx/OriginalMessage';
import type {ActionName, ChangeLog, IOUMessage, OriginalMessageActionableMentionWhisper, OriginalMessageIOU, OriginalMessageReimbursementDequeued} from '@src/types/onyx/OriginalMessage';
import type Report from '@src/types/onyx/Report';
import type {Message, ReportActionBase, ReportActions} from '@src/types/onyx/ReportAction';
import type ReportAction from '@src/types/onyx/ReportAction';
Expand All @@ -19,6 +19,7 @@ import * as Localize from './Localize';
import Log from './Log';
import type {MessageElementBase, MessageTextElement} from './MessageElement';
import * as PersonalDetailsUtils from './PersonalDetailsUtils';
import type {OptimisticIOUReportAction} from './ReportUtils';

type LastVisibleMessage = {
lastMessageTranslationKey?: string;
Expand Down Expand Up @@ -93,7 +94,7 @@ function isCreatedAction(reportAction: OnyxEntry<ReportAction>): boolean {
return reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.CREATED;
}

function isDeletedAction(reportAction: OnyxEntry<ReportAction>): boolean {
function isDeletedAction(reportAction: OnyxEntry<ReportAction | OptimisticIOUReportAction>): boolean {
// A deleted comment has either an empty array or an object with html field with empty string as value
const message = reportAction?.message ?? [];
return message.length === 0 || message[0]?.html === '';
Expand All @@ -103,8 +104,8 @@ function isDeletedParentAction(reportAction: OnyxEntry<ReportAction>): boolean {
return (reportAction?.message?.[0]?.isDeletedParentAction ?? false) && (reportAction?.childVisibleActionCount ?? 0) > 0;
}

function isReversedTransaction(reportAction: OnyxEntry<ReportAction>) {
return (reportAction?.message?.[0]?.isReversedTransaction ?? false) && (reportAction?.childVisibleActionCount ?? 0) > 0;
function isReversedTransaction(reportAction: OnyxEntry<ReportAction | OptimisticIOUReportAction>) {
return (reportAction?.message?.[0]?.isReversedTransaction ?? false) && ((reportAction as ReportAction)?.childVisibleActionCount ?? 0) > 0;
}

function isPendingRemove(reportAction: OnyxEntry<ReportAction> | EmptyObject): boolean {
Expand Down Expand Up @@ -184,9 +185,11 @@ function getParentReportAction(report: OnyxEntry<Report> | EmptyObject): ReportA
/**
* Determines if the given report action is sent money report action by checking for 'pay' type and presence of IOUDetails object.
*/
function isSentMoneyReportAction(reportAction: OnyxEntry<ReportAction>): boolean {
function isSentMoneyReportAction(reportAction: OnyxEntry<ReportAction | OptimisticIOUReportAction>): boolean {
return (
reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.IOU && reportAction?.originalMessage?.type === CONST.IOU.REPORT_ACTION_TYPE.PAY && !!reportAction?.originalMessage?.IOUDetails
reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.IOU &&
(reportAction?.originalMessage as IOUMessage)?.type === CONST.IOU.REPORT_ACTION_TYPE.PAY &&
!!(reportAction?.originalMessage as IOUMessage)?.IOUDetails
);
}

Expand Down
16 changes: 9 additions & 7 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2259,7 +2259,7 @@ function hasMissingSmartscanFields(iouReportID: string): boolean {
/**
* Given a parent IOU report action get report name for the LHN.
*/
function getTransactionReportName(reportAction: OnyxEntry<ReportAction>): string {
function getTransactionReportName(reportAction: OnyxEntry<ReportAction | OptimisticIOUReportAction>): string {
if (ReportActionsUtils.isReversedTransaction(reportAction)) {
return Localize.translateLocal('parentReportAction.reversedTransaction');
}
Expand Down Expand Up @@ -3763,7 +3763,7 @@ function buildOptimisticTaskReport(
*
* @param moneyRequestReportID - the reportID which the report action belong to
*/
function buildTransactionThread(reportAction: OnyxEntry<ReportAction>, moneyRequestReportID: string): OptimisticChatReport {
function buildTransactionThread(reportAction: OnyxEntry<ReportAction | OptimisticIOUReportAction>, moneyRequestReportID: string): OptimisticChatReport {
const participantAccountIDs = [...new Set([currentUserAccountID, Number(reportAction?.actorAccountID)])].filter(Boolean) as number[];
return buildOptimisticChatReport(
participantAccountIDs,
Expand Down Expand Up @@ -3967,6 +3967,13 @@ function shouldReportBeInOptionList({
return true;
}

const reportIsSettled = report.statusNum === CONST.REPORT.STATUS_NUM.REIMBURSED;

// Always show IOU reports with violations unless they are reimbursed
if (isExpenseRequest(report) && doesReportHaveViolations && !reportIsSettled) {
return true;
}

// Hide only chat threads that haven't been commented on (other threads are actionable)
if (isChatThread(report) && canHideReport && isEmptyChat) {
return false;
Expand All @@ -3978,11 +3985,6 @@ function shouldReportBeInOptionList({
return true;
}

// Always show IOU reports with violations
if (isExpenseRequest(report) && doesReportHaveViolations) {
return true;
}

// All unread chats (even archived ones) in GSD mode will be shown. This is because GSD mode is specifically for focusing the user on the most relevant chats, primarily, the unread ones
if (isInGSDMode) {
return isUnread(report) && report.notificationPreference !== CONST.REPORT.NOTIFICATION_PREFERENCE.MUTE;
Expand Down
6 changes: 4 additions & 2 deletions src/libs/TransactionUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ import type {ValueOf} from 'type-fest';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import type {RecentWaypoint, Report, ReportAction, Transaction, TransactionViolation} from '@src/types/onyx';
import type {IOUMessage} from '@src/types/onyx/OriginalMessage';
import type {PolicyTaxRate, PolicyTaxRates} from '@src/types/onyx/PolicyTaxRates';
import type {Comment, Receipt, TransactionChanges, TransactionPendingFieldsKey, Waypoint, WaypointCollection} from '@src/types/onyx/Transaction';
import type {EmptyObject} from '@src/types/utils/EmptyObject';
import {isEmptyObject} from '@src/types/utils/EmptyObject';
import {isCorporateCard, isExpensifyCard} from './CardUtils';
import DateUtils from './DateUtils';
import * as NumberUtils from './NumberUtils';
import type {OptimisticIOUReportAction} from './ReportUtils';

let allTransactions: OnyxCollection<Transaction> = {};

Expand Down Expand Up @@ -495,11 +497,11 @@ function hasRoute(transaction: Transaction): boolean {
*
* @deprecated Use Onyx.connect() or withOnyx() instead
*/
function getLinkedTransaction(reportAction: OnyxEntry<ReportAction>): Transaction | EmptyObject {
function getLinkedTransaction(reportAction: OnyxEntry<ReportAction | OptimisticIOUReportAction>): Transaction | EmptyObject {
let transactionID = '';

if (reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.IOU) {
transactionID = reportAction.originalMessage?.IOUTransactionID ?? '';
transactionID = (reportAction?.originalMessage as IOUMessage)?.IOUTransactionID ?? '';
}

return allTransactions?.[`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`] ?? {};
Expand Down
Loading

0 comments on commit 690174f

Please sign in to comment.