Skip to content
Merged
1 change: 1 addition & 0 deletions src/components/Search/SearchFiltersChatsSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ function SearchFiltersChatsSelector({initialReportIDs, onFiltersUpdate, isScreen
selectedOptions,
chatOptions.recentReports,
chatOptions.personalDetails,
privateIsArchivedMap,
currentUserAccountID,
personalDetails,
false,
Expand Down
16 changes: 15 additions & 1 deletion src/components/Search/SearchFiltersParticipantsSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import SelectionListWithSections from '@components/SelectionList/SelectionListWi
import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails';
import useLocalize from '@hooks/useLocalize';
import useOnyx from '@hooks/useOnyx';
import usePrivateIsArchivedMap from '@hooks/usePrivateIsArchivedMap';
import useReportAttributes from '@hooks/useReportAttributes';
import useScreenWrapperTransitionStatus from '@hooks/useScreenWrapperTransitionStatus';
import {canUseTouchScreen} from '@libs/DeviceCapabilities';
Expand Down Expand Up @@ -96,6 +97,7 @@ function SearchFiltersParticipantsSelector({initialAccountIDs, onFiltersUpdate,
const [nvpDismissedProductTraining] = useOnyx(ONYXKEYS.NVP_DISMISSED_PRODUCT_TRAINING);
const [allPolicies] = useOnyx(ONYXKEYS.COLLECTION.POLICY);
const [recentAttendees] = useOnyx(ONYXKEYS.NVP_RECENT_ATTENDEES);
const privateIsArchivedMap = usePrivateIsArchivedMap();

// Transform raw recentAttendees into Option[] format for use with getValidOptions (only for attendee filter)
const recentAttendeeLists = useMemo(
Expand Down Expand Up @@ -203,6 +205,7 @@ function SearchFiltersParticipantsSelector({initialAccountIDs, onFiltersUpdate,
selectedOptions,
chatOptions.recentReports,
chatOptions.personalDetails,
privateIsArchivedMap,
currentUserAccountID,
personalDetails,
true,
Expand Down Expand Up @@ -260,7 +263,18 @@ function SearchFiltersParticipantsSelector({initialAccountIDs, onFiltersUpdate,
sections: newSections,
headerMessage: message,
};
}, [areOptionsInitialized, cleanSearchTerm, selectedOptions, chatOptions, personalDetails, reportAttributesDerived, translate, formatPhoneNumber, currentUserAccountID]);
}, [
areOptionsInitialized,
cleanSearchTerm,
selectedOptions,
chatOptions,
personalDetails,
reportAttributesDerived,
translate,
formatPhoneNumber,
currentUserAccountID,
privateIsArchivedMap,
]);

const resetChanges = useCallback(() => {
setSelectedOptions([]);
Expand Down
10 changes: 7 additions & 3 deletions src/libs/OptionsListUtils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,13 +206,13 @@
*/

let allPersonalDetails: OnyxEntry<PersonalDetailsList>;
Onyx.connect({

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

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
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
callback: (value) => (allPersonalDetails = isEmptyObject(value) ? {} : value),
});

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

Check warning on line 215 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

Check warning on line 215 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
key: ONYXKEYS.COLLECTION.REPORT,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -221,7 +221,7 @@
});

let allReportNameValuePairsOnyxConnect: OnyxCollection<ReportNameValuePairs>;
Onyx.connect({

Check warning on line 224 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

Check warning on line 224 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
key: ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -232,7 +232,7 @@
const lastReportActions: ReportActions = {};
const allSortedReportActions: Record<string, ReportAction[]> = {};
let allReportActions: OnyxCollection<ReportActions>;
Onyx.connect({

Check warning on line 235 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 @@ -274,7 +274,7 @@
});

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

Check warning on line 277 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 @@ -1226,6 +1226,7 @@
*/
function getPolicyExpenseReportOption(
participant: Participant | SearchOptionData,
privateIsArchived: string | undefined,
currentUserAccountID: number,
personalDetails: OnyxEntry<PersonalDetailsList>,
expenseReport: OnyxEntry<Report>,
Expand All @@ -1248,7 +1249,7 @@
forcePolicyNamePreview: false,
},
reportAttributesDerived,
undefined,
privateIsArchived,
visibleReportActionsData,
);

Expand Down Expand Up @@ -2911,6 +2912,7 @@
selectedOptions: SearchOptionData[],
filteredRecentReports: SearchOptionData[],
filteredPersonalDetails: SearchOptionData[],
privateIsArchivedMap: Record<string, string | undefined>,
currentUserAccountID: number,
personalDetails: OnyxEntry<PersonalDetailsList> = {},
shouldGetOptionDetails = false,
Expand All @@ -2932,7 +2934,8 @@
// TODO: This allReports usage is temporary and will be removed once the full Onyx.connect() refactor is complete (https://github.com/Expensify/App/issues/66378)
const expenseReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${participant.reportID}`];
const chatReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${expenseReport?.chatReportID}`];
return getPolicyExpenseReportOption(participant, currentUserAccountID, personalDetails, expenseReport, chatReport, reportAttributesDerived);
const privateIsArchived = privateIsArchivedMap[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${expenseReport?.reportID}`];
return getPolicyExpenseReportOption(participant, privateIsArchived, currentUserAccountID, personalDetails, expenseReport, chatReport, reportAttributesDerived);
}
return getParticipantsOption(participant, personalDetails);
})
Expand Down Expand Up @@ -2964,7 +2967,8 @@
// TODO: This allReports usage is temporary and will be removed once the full Onyx.connect() refactor is complete (https://github.com/Expensify/App/issues/66378)
const expenseReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${participant.reportID}`];
const chatReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${expenseReport?.chatReportID}`];
return getPolicyExpenseReportOption(participant, currentUserAccountID, personalDetails, expenseReport, chatReport, reportAttributesDerived);
const privateIsArchived = privateIsArchivedMap[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${expenseReport?.reportID}`];
return getPolicyExpenseReportOption(participant, privateIsArchived, currentUserAccountID, personalDetails, expenseReport, chatReport, reportAttributesDerived);
}
return getParticipantsOption(participant, personalDetails);
})
Expand Down
4 changes: 4 additions & 0 deletions src/pages/NewChatPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import useFilteredOptions from '@hooks/useFilteredOptions';
import useLocalize from '@hooks/useLocalize';
import useNetwork from '@hooks/useNetwork';
import useOnyx from '@hooks/useOnyx';
import usePrivateIsArchivedMap from '@hooks/usePrivateIsArchivedMap';
import useSafeAreaInsets from '@hooks/useSafeAreaInsets';
import useSingleExecution from '@hooks/useSingleExecution';
import useThemeStyles from '@hooks/useThemeStyles';
Expand Down Expand Up @@ -242,6 +243,8 @@ function NewChatPage({ref}: NewChatPageProps) {
const [isSearchingForReports] = useOnyx(ONYXKEYS.IS_SEARCHING_FOR_REPORTS, {initWithStoredValues: false});
const [introSelected] = useOnyx(ONYXKEYS.NVP_INTRO_SELECTED);
const [reportAttributesDerivedFull] = useOnyx(ONYXKEYS.DERIVED.REPORT_ATTRIBUTES);
const privateIsArchivedMap = usePrivateIsArchivedMap();

const reportAttributesDerived = reportAttributesDerivedFull?.reports;
const selectionListRef = useRef<SelectionListHandle | null>(null);

Expand Down Expand Up @@ -275,6 +278,7 @@ function NewChatPage({ref}: NewChatPageProps) {
selectedOptions as OptionData[],
recentReports,
personalDetails,
privateIsArchivedMap,
currentUserAccountID,
allPersonalDetails,
undefined,
Expand Down
13 changes: 12 additions & 1 deletion src/pages/iou/SplitBillDetailsPage.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {privateIsArchivedSelector} from '@selectors/ReportNameValuePairs';
import React, {useCallback, useState} from 'react';
import {View} from 'react-native';
import FullPageNotFoundView from '@components/BlockingViews/FullPageNotFoundView';
Expand Down Expand Up @@ -67,13 +68,23 @@ function SplitBillDetailsPage({route, report, reportAction}: SplitBillDetailsPag
const reportAttributesDerived = useReportAttributes();
const [betas] = useOnyx(ONYXKEYS.BETAS);
const [chatReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${getNonEmptyStringOnyxID(report?.chatReportID)}`);
const [privateIsArchived] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${reportID}`, {selector: privateIsArchivedSelector});
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it is better to reuse useReportIsArchived()

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 thought about it, but useReportIsArchived returns a boolean while getPolicyExpenseReportOption and the downstream chain accept a string

Copy link
Contributor

Choose a reason for hiding this comment

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

Hm, that's fair, but from what I can see, all the code referencing it uses !! before the value, so it's being cast to a boolean in the end anyway.

I can open a separate GH for this.

Copy link
Contributor

Choose a reason for hiding this comment

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

Created here: #84608


// In case this is workspace split expense, we manually add the workspace as the second participant of the split expense
// because we don't save any accountID in the report action's originalMessage other than the payee's accountID
let participants: Array<Participant | OptionData>;
if (isPolicyExpenseChat(report)) {
participants = [
getParticipantsOption({accountID: participantAccountIDs.at(0), selected: true, reportID: ''}, personalDetails),
getPolicyExpenseReportOption({...report, selected: true, reportID}, currentUserPersonalDetails.accountID, personalDetails, report, chatReport, reportAttributesDerived),
getPolicyExpenseReportOption(
{...report, selected: true, reportID},
privateIsArchived,
currentUserPersonalDetails.accountID,
personalDetails,
report,
chatReport,
reportAttributesDerived,
),
];
} else {
participants = participantAccountIDs.map((accountID) => getParticipantsOption({accountID, selected: true, reportID: ''}, personalDetails));
Expand Down
15 changes: 14 additions & 1 deletion src/pages/iou/request/MoneyRequestAccountantSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import useDebouncedState from '@hooks/useDebouncedState';
import useLocalize from '@hooks/useLocalize';
import useNetwork from '@hooks/useNetwork';
import useOnyx from '@hooks/useOnyx';
import usePrivateIsArchivedMap from '@hooks/usePrivateIsArchivedMap';
import useReportAttributes from '@hooks/useReportAttributes';
import useScreenWrapperTransitionStatus from '@hooks/useScreenWrapperTransitionStatus';
import useUserToInviteReports from '@hooks/useUserToInviteReports';
Expand Down Expand Up @@ -71,6 +72,7 @@ function MoneyRequestAccountantSelector({onFinish, onAccountantSelected, iouType
const currentUserEmail = currentUserPersonalDetails.email ?? '';
const currentUserAccountID = currentUserPersonalDetails.accountID;
const [allPolicies] = useOnyx(ONYXKEYS.COLLECTION.POLICY);
const privateIsArchivedMap = usePrivateIsArchivedMap();

useEffect(() => {
searchUserInServer(debouncedSearchTerm.trim());
Expand Down Expand Up @@ -160,6 +162,7 @@ function MoneyRequestAccountantSelector({onFinish, onAccountantSelected, iouType
[],
chatOptions.recentReports,
chatOptions.personalDetails,
privateIsArchivedMap,
currentUserAccountID,
personalDetails,
true,
Expand Down Expand Up @@ -191,8 +194,17 @@ function MoneyRequestAccountantSelector({onFinish, onAccountantSelected, iouType
newSections.push({
data: [chatOptions.userToInvite].map((participant) => {
const isPolicyExpenseChat = participant?.isPolicyExpenseChat ?? false;
const privateIsArchived = privateIsArchivedMap[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${userToInviteExpenseReport?.reportID}`];
return isPolicyExpenseChat
? getPolicyExpenseReportOption(participant, currentUserAccountID, personalDetails, userToInviteExpenseReport, userToInviteChatReport, reportAttributesDerived)
? getPolicyExpenseReportOption(
participant,
privateIsArchived,
currentUserAccountID,
personalDetails,
userToInviteExpenseReport,
userToInviteChatReport,
reportAttributesDerived,
)
: getParticipantsOption(participant, personalDetails);
}),
sectionIndex: 3,
Expand Down Expand Up @@ -222,6 +234,7 @@ function MoneyRequestAccountantSelector({onFinish, onAccountantSelected, iouType
translate,
loginList,
countryCode,
privateIsArchivedMap,
currentUserAccountID,
currentUserEmail,
]);
Expand Down
14 changes: 13 additions & 1 deletion src/pages/iou/request/MoneyRequestAttendeeSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import useLocalize from '@hooks/useLocalize';
import useNetwork from '@hooks/useNetwork';
import useOnyx from '@hooks/useOnyx';
import usePolicy from '@hooks/usePolicy';
import usePrivateIsArchivedMap from '@hooks/usePrivateIsArchivedMap';
import useReportAttributes from '@hooks/useReportAttributes';
import useScreenWrapperTransitionStatus from '@hooks/useScreenWrapperTransitionStatus';
import useSearchSelector from '@hooks/useSearchSelector';
Expand Down Expand Up @@ -71,6 +72,7 @@ function MoneyRequestAttendeeSelector({attendees = [], onFinish, onAttendeesAdde
const reportAttributesDerived = useReportAttributes();
const offlineMessage: string = isOffline ? `${translate('common.youAppearToBeOffline')} ${translate('search.resultsAreLimited')}` : '';
const [loginList] = useOnyx(ONYXKEYS.LOGIN_LIST);
const privateIsArchivedMap = usePrivateIsArchivedMap();
const currentUserPersonalDetails = useCurrentUserPersonalDetails();
const currentUserEmail = currentUserPersonalDetails.email ?? '';
const currentUserAccountID = currentUserPersonalDetails.accountID;
Expand Down Expand Up @@ -207,6 +209,7 @@ function MoneyRequestAttendeeSelector({attendees = [], onFinish, onAttendeesAdde
initialSelectedOptions,
orderedAvailableOptions.recentReports,
orderedAvailableOptions.personalDetails,
privateIsArchivedMap,
currentUserAccountID,
personalDetails,
true,
Expand Down Expand Up @@ -252,8 +255,17 @@ function MoneyRequestAttendeeSelector({attendees = [], onFinish, onAttendeesAdde
title: undefined,
data: [orderedAvailableOptions.userToInvite].map((participant) => {
const isPolicyExpenseChat = participant?.isPolicyExpenseChat ?? false;
const privateIsArchived = privateIsArchivedMap[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${userToInviteExpenseReport?.reportID}`];
return isPolicyExpenseChat
? getPolicyExpenseReportOption(participant, currentUserAccountID, personalDetails, userToInviteExpenseReport, userToInviteChatReport, reportAttributesDerived)
? getPolicyExpenseReportOption(
participant,
privateIsArchived,
currentUserAccountID,
personalDetails,
userToInviteExpenseReport,
userToInviteChatReport,
reportAttributesDerived,
)
: getParticipantsOption(participant, personalDetails);
}) as OptionData[],
sectionIndex: 3,
Expand Down
15 changes: 14 additions & 1 deletion src/pages/iou/request/MoneyRequestParticipantsSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import useLocalize from '@hooks/useLocalize';
import useNetwork from '@hooks/useNetwork';
import useOnyx from '@hooks/useOnyx';
import usePreferredPolicy from '@hooks/usePreferredPolicy';
import usePrivateIsArchivedMap from '@hooks/usePrivateIsArchivedMap';
import useReportAttributes from '@hooks/useReportAttributes';
import useScreenWrapperTransitionStatus from '@hooks/useScreenWrapperTransitionStatus';
import useSearchSelector from '@hooks/useSearchSelector';
Expand Down Expand Up @@ -126,6 +127,7 @@ function MoneyRequestParticipantsSelector({
const reportAttributesDerived = useReportAttributes();
const [countryCode = CONST.DEFAULT_COUNTRY_CODE] = useOnyx(ONYXKEYS.COUNTRY_CODE);
const [loginList] = useOnyx(ONYXKEYS.LOGIN_LIST);
const privateIsArchivedMap = usePrivateIsArchivedMap();

const [textInputAutoFocus, setTextInputAutoFocus] = useState<boolean>(!isNative);
const selectionListRef = useRef<SelectionListWithSectionsHandle | null>(null);
Expand Down Expand Up @@ -292,6 +294,7 @@ function MoneyRequestParticipantsSelector({
participants.map((participant) => ({...participant, reportID: participant.reportID})) as OptionData[],
[],
[],
privateIsArchivedMap,
currentUserAccountID,
personalDetails,
true,
Expand Down Expand Up @@ -354,8 +357,17 @@ function MoneyRequestParticipantsSelector({
title: undefined,
data: [availableOptions.userToInvite].map((participant) => {
const isPolicyExpenseChat = participant?.isPolicyExpenseChat ?? false;
const privateIsArchived = privateIsArchivedMap[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${userToInviteExpenseReport?.reportID}`];
return isPolicyExpenseChat
? getPolicyExpenseReportOption(participant, currentUserAccountID, personalDetails, userToInviteExpenseReport, userToInviteChatReport, reportAttributesDerived)
? getPolicyExpenseReportOption(
participant,
privateIsArchived,
currentUserAccountID,
personalDetails,
userToInviteExpenseReport,
userToInviteChatReport,
reportAttributesDerived,
)
: getParticipantsOption(participant, personalDetails);
}),
sectionIndex: 5,
Expand Down Expand Up @@ -388,6 +400,7 @@ function MoneyRequestParticipantsSelector({
isPerDiemRequest,
showImportContacts,
inputHelperText,
privateIsArchivedMap,
currentUserAccountID,
currentUserEmail,
]);
Expand Down
10 changes: 10 additions & 0 deletions src/selectors/ReportNameValuePairs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import type {OnyxEntry} from 'react-native-onyx';
import type {ReportNameValuePairs} from '@src/types/onyx';

/**
* Selector that extracts only the private_isArchived value from a single ReportNameValuePairs entry
*/
const privateIsArchivedSelector = (reportNameValuePairs: OnyxEntry<ReportNameValuePairs>): string | undefined => reportNameValuePairs?.private_isArchived;

// eslint-disable-next-line import/prefer-default-export
export {privateIsArchivedSelector};
3 changes: 2 additions & 1 deletion tests/perf-test/OptionsListUtils.perf-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ describe('OptionsListUtils', () => {
Object.values(selectedOptions),
Object.values(filteredRecentReports),
Object.values(filteredPersonalDetails),
{},
MOCK_CURRENT_USER_ACCOUNT_ID,
mockedPersonalDetails,
true,
Expand All @@ -283,6 +284,6 @@ describe('OptionsListUtils', () => {
const mockedPersonalDetails = getMockedPersonalDetails(PERSONAL_DETAILS_COUNT);

await waitForBatchedUpdates();
await measureFunction(() => formatSectionsFromSearchTerm('', Object.values(selectedOptions), [], [], MOCK_CURRENT_USER_ACCOUNT_ID, mockedPersonalDetails, true));
await measureFunction(() => formatSectionsFromSearchTerm('', Object.values(selectedOptions), [], [], {}, MOCK_CURRENT_USER_ACCOUNT_ID, mockedPersonalDetails, true));
});
});
Loading
Loading