Skip to content
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
2 changes: 1 addition & 1 deletion src/components/LHNOptionsList/LHNOptionsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ function LHNOptionsList({style, contentContainerStyles, data, onSelectRow, optio
itemOneTransactionThreadReport?.reportID,
);

const iouReportIDOfLastAction = getIOUReportIDOfLastAction(item, visibleReportActionsData, lastAction);
const iouReportIDOfLastAction = getIOUReportIDOfLastAction(item, itemReportNameValuePairs?.private_isArchived, visibleReportActionsData, lastAction);
const itemIouReportReportActions = iouReportIDOfLastAction ? reportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${iouReportIDOfLastAction}`] : undefined;

const lastReportActionTransactionID = isMoneyRequestAction(lastAction) ? (getOriginalMessage(lastAction)?.IOUTransactionID ?? CONST.DEFAULT_NUMBER_ID) : CONST.DEFAULT_NUMBER_ID;
Expand Down
49 changes: 19 additions & 30 deletions src/libs/OptionsListUtils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,6 @@
ReportActions,
ReportAttributesDerivedValue,
ReportMetadata,
ReportNameValuePairs,
VisibleReportActionsDerivedValue,
} from '@src/types/onyx';
import type {Attendee, Participant} from '@src/types/onyx/IOU';
Expand Down Expand Up @@ -207,7 +206,7 @@
*/

let allReports: OnyxCollection<Report>;
Onyx.connect({

Check warning on line 209 in src/libs/OptionsListUtils/index.ts

View workflow job for this annotation

GitHub Actions / ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function

Check warning on line 209 in src/libs/OptionsListUtils/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.REPORT,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -215,20 +214,11 @@
},
});

let allReportNameValuePairsOnyxConnect: OnyxCollection<ReportNameValuePairs>;
Onyx.connect({
key: ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS,
waitForCollectionCallback: true,
callback: (value) => {
allReportNameValuePairsOnyxConnect = value;
},
});

const lastReportActions: ReportActions = {};
const allSortedReportActions: Record<string, ReportAction[]> = {};
const cachedOneTransactionThreadReportIDs: Record<string, string | undefined> = {};
let allReportActions: OnyxCollection<ReportActions>;
Onyx.connect({

Check warning on line 221 in src/libs/OptionsListUtils/index.ts

View workflow job for this annotation

GitHub Actions / ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function

Check warning on line 221 in src/libs/OptionsListUtils/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.REPORT_ACTIONS,
waitForCollectionCallback: true,
callback: (actions) => {
Expand Down Expand Up @@ -273,7 +263,7 @@
});

let activePolicyID: OnyxEntry<string>;
Onyx.connect({

Check warning on line 266 in src/libs/OptionsListUtils/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.NVP_ACTIVE_POLICY_ID,
callback: (value) => (activePolicyID = value),
});
Expand Down Expand Up @@ -533,13 +523,16 @@
/**
* Get IOU report ID of report last action if the action is report action preview
*/
function getIOUReportIDOfLastAction(report: OnyxEntry<Report>, visibleReportActionsData?: VisibleReportActionsDerivedValue, lastAction?: OnyxEntry<ReportAction>): string | undefined {
function getIOUReportIDOfLastAction(
report: OnyxEntry<Report>,
privateIsArchived: string | undefined,
visibleReportActionsData?: VisibleReportActionsDerivedValue,
lastAction?: OnyxEntry<ReportAction>,
): string | undefined {
if (!report?.reportID) {
return;
}
// Use lastAction if available (from useOnyx), otherwise fallback to getLastVisibleAction which uses isReportActionVisibleAsLastAction with proper filters
const reportNameValuePairs = allReportNameValuePairsOnyxConnect?.[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report.reportID}`];
const isReportArchived = !!reportNameValuePairs?.private_isArchived;
const isReportArchived = !!privateIsArchived;
const canUserPerformWrite = canUserPerformWriteAction(report, isReportArchived);
const action = lastAction ?? getLastVisibleAction(report.reportID, canUserPerformWrite, {}, undefined, visibleReportActionsData);
if (!isReportPreviewAction(action)) {
Expand All @@ -557,13 +550,12 @@
lastActorDetails: Partial<PersonalDetails> | null,
currentUserAccountIDParam: number,
personalDetails: OnyxEntry<PersonalDetailsList>,
privateIsArchived: string | undefined,
visibleReportActionsData?: VisibleReportActionsDerivedValue,
lastAction?: OnyxEntry<ReportAction>,
): string {
const reportID = report?.reportID;
// Use lastAction if available (from useOnyx), otherwise fallback to getLastVisibleAction which uses isReportActionVisibleAsLastAction with proper filters
const reportNameValuePairs = reportID ? allReportNameValuePairsOnyxConnect?.[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${reportID}`] : undefined;
const isReportArchived = !!reportNameValuePairs?.private_isArchived;
const isReportArchived = !!privateIsArchived;
const canUserPerformWrite = canUserPerformWriteAction(report, isReportArchived);
const lastReportAction = lastAction ?? getLastVisibleAction(reportID, canUserPerformWrite, {}, undefined, visibleReportActionsData);

Expand Down Expand Up @@ -955,9 +947,9 @@
personalDetails: OnyxInputOrEntry<PersonalDetailsList>,
report: OnyxInputOrEntry<Report>,
currentUserAccountID: number,
privateIsArchived: string | undefined,
config?: PreviewConfig,
reportAttributesDerived?: ReportAttributesDerivedValue['reports'],
privateIsArchived?: string,
visibleReportActionsData: VisibleReportActionsDerivedValue = {},
translate?: LocalizedTranslate,
): SearchOptionData {
Expand Down Expand Up @@ -1018,10 +1010,7 @@
result.participantsList = personalDetailList;

if (report) {
const reportNameValuePairsForReport = allReportNameValuePairsOnyxConnect?.[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report.reportID}`];

// Set properties that are used in SearchOption context
result.private_isArchived = privateIsArchived ?? reportNameValuePairsForReport?.private_isArchived;
result.private_isArchived = privateIsArchived;
result.keyForList = String(report.reportID);

// Type/category flags already set in initialization above, but update brickRoadIndicator
Expand Down Expand Up @@ -1124,12 +1113,12 @@
personalDetails ?? {},
!isEmptyObject(report) ? report : undefined,
currentUserAccountID,
privateIsArchived,
{
showChatPreviewLine: false,
forcePolicyNamePreview: false,
},
reportAttributesDerived,
privateIsArchived,
visibleReportActionsData,
);

Expand Down Expand Up @@ -1183,12 +1172,12 @@
personalDetails ?? {},
!isEmptyObject(report) ? report : undefined,
currentUserAccountID,
privateIsArchived,
{
showChatPreviewLine: false,
forcePolicyNamePreview: false,
},
reportAttributesDerived,
privateIsArchived,
visibleReportActionsData,
);

Expand Down Expand Up @@ -1236,12 +1225,12 @@
personalDetails ?? {},
!isEmptyObject(expenseReport) ? expenseReport : null,
currentUserAccountID,
privateIsArchived,
{
showChatPreviewLine: false,
forcePolicyNamePreview: false,
},
reportAttributesDerived,
privateIsArchived,
visibleReportActionsData,
);

Expand Down Expand Up @@ -1378,7 +1367,7 @@
reportMapEntry,
reportOption: {
item: report,
...createOption(accountIDs, personalDetails, report, currentUserAccountID, undefined, reportAttributesDerived, privateIsArchived, visibleReportActionsData),
...createOption(accountIDs, personalDetails, report, currentUserAccountID, privateIsArchived, undefined, reportAttributesDerived, visibleReportActionsData),
},
};
}
Expand Down Expand Up @@ -1422,11 +1411,11 @@
personalDetails,
report,
currentUserAccountID,
privateIsArchived,
{
showPersonalDetails: true,
},
reportAttributesDerived,
privateIsArchived,
visibleReportActionsData,
),
};
Expand Down Expand Up @@ -1557,9 +1546,9 @@
personalDetails,
reportMapForAccountIDs[accountID],
currentUserAccountID,
privateIsArchived,
{showPersonalDetails: true},
reportAttributesDerived,
privateIsArchived,
visibleReportActionsData,
),
};
Expand All @@ -1585,7 +1574,7 @@

return {
item: report,
...createOption(accountIDs, personalDetails, report, currentUserAccountID, config, reportAttributesDerived, privateIsArchived, visibleReportActionsData),
...createOption(accountIDs, personalDetails, report, currentUserAccountID, privateIsArchived, config, reportAttributesDerived, visibleReportActionsData),
};
}

Expand Down Expand Up @@ -1909,7 +1898,7 @@
login: searchValue,
},
};
const userToInvite = createOption([optimisticAccountID], personalDetailsExtended, null, currentUserAccountID, {showChatPreviewLine}, undefined, undefined, visibleReportActionsData);
const userToInvite = createOption([optimisticAccountID], personalDetailsExtended, null, currentUserAccountID, undefined, {showChatPreviewLine}, undefined, visibleReportActionsData);
userToInvite.isOptimisticAccount = true;
userToInvite.login = searchValue;

Expand Down
20 changes: 18 additions & 2 deletions src/libs/SidebarUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1114,7 +1114,15 @@ function getOptionData({
} else if (lastAction?.actionName !== CONST.REPORT.ACTIONS.TYPE.REPORT_PREVIEW && lastActorDisplayName && lastMessageTextFromReport) {
const displayName =
(lastMessageTextFromReport.length > 0 &&
getLastActorDisplayNameFromLastVisibleActions(report, lastActorDetails, currentUserAccountID, personalDetails, visibleReportActionsData, lastAction)) ||
getLastActorDisplayNameFromLastVisibleActions(
report,
lastActorDetails,
currentUserAccountID,
personalDetails,
reportNameValuePairs?.private_isArchived,
visibleReportActionsData,
lastAction,
)) ||
lastActorDisplayName;
result.alternateText = formatReportLastMessageText(`${displayName}: ${lastMessageText}`);
} else {
Expand Down Expand Up @@ -1158,7 +1166,15 @@ function getOptionData({
if (shouldShowLastActorDisplayName(report, lastActorDetails, lastAction, currentUserAccountID) && !isReportArchived) {
const displayName =
(lastMessageTextFromReport.length > 0 &&
getLastActorDisplayNameFromLastVisibleActions(report, lastActorDetails, currentUserAccountID, personalDetails, visibleReportActionsData, lastAction)) ||
getLastActorDisplayNameFromLastVisibleActions(
report,
lastActorDetails,
currentUserAccountID,
personalDetails,
reportNameValuePairs?.private_isArchived,
visibleReportActionsData,
lastAction,
)) ||
lastActorDisplayName;
result.alternateText = `${displayName}: ${formatReportLastMessageText(lastMessageText)}`;
} else {
Expand Down
Loading
Loading