Skip to content

Commit 8d383b0

Browse files
authored
Merge pull request #87449 from dukenv0307/fix/66411-part-19
refactor getValidOptions to use conciergeReportID from useOnyx
2 parents 83157c4 + a356d17 commit 8d383b0

9 files changed

Lines changed: 143 additions & 24 deletions

File tree

src/components/Search/FilterDropdowns/InSelectPopup.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ function InSelectPopup({closeOverlay, updateFilterForm}: InSelectPopupProps) {
7171
const privateIsArchivedMap = usePrivateIsArchivedMap();
7272
const [nvpDismissedProductTraining] = useOnyx(ONYXKEYS.NVP_DISMISSED_PRODUCT_TRAINING);
7373
const [policyTags] = useOnyx(ONYXKEYS.COLLECTION.POLICY_TAGS, {selector: passthroughPolicyTagListSelector});
74+
const [conciergeReportID] = useOnyx(ONYXKEYS.CONCIERGE_REPORT_ID);
7475

7576
const selectedOptions: OptionData[] = selectedReportIDs.map((id) => {
7677
const privateIsArchived = privateIsArchivedMap[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${id}`];
@@ -80,7 +81,7 @@ function InSelectPopup({closeOverlay, updateFilterForm}: InSelectPopupProps) {
8081
const isReportArchived = !!privateIsArchived;
8182
const policy = allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${reportData?.policyID}`];
8283
const reportPolicyTags = policyTags?.[`${ONYXKEYS.COLLECTION.POLICY_TAGS}${getNonEmptyStringOnyxID(report?.policyID)}`];
83-
const alternateText = getAlternateText(report, {}, {isReportArchived, policy, reportAttributesDerived, policyTags: reportPolicyTags});
84+
const alternateText = getAlternateText(report, {}, {isReportArchived, policy, reportAttributesDerived, policyTags: reportPolicyTags, conciergeReportID});
8485
return {...report, alternateText};
8586
});
8687

src/components/Search/SearchFiltersChatsSelector.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ function SearchFiltersChatsSelector({initialReportIDs, onFiltersUpdate, isScreen
5454
const [countryCode = CONST.DEFAULT_COUNTRY_CODE] = useOnyx(ONYXKEYS.COUNTRY_CODE);
5555
const [loginList] = useOnyx(ONYXKEYS.LOGIN_LIST);
5656
const [allPolicies] = useOnyx(ONYXKEYS.COLLECTION.POLICY);
57+
const [conciergeReportID] = useOnyx(ONYXKEYS.CONCIERGE_REPORT_ID);
5758
const currentUserPersonalDetails = useCurrentUserPersonalDetails();
5859
const currentUserAccountID = currentUserPersonalDetails.accountID;
5960
const currentUserEmail = currentUserPersonalDetails.email ?? '';
@@ -75,7 +76,7 @@ function SearchFiltersChatsSelector({initialReportIDs, onFiltersUpdate, isScreen
7576
const report = getSelectedOptionData(createOptionFromReport({...reportData, reportID: id}, personalDetails, privateIsArchived, reportPolicy, reportAttributesDerived));
7677
const policy = allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${reportData?.policyID}`];
7778
const reportPolicyTags = policyTags?.[`${ONYXKEYS.COLLECTION.POLICY_TAGS}${getNonEmptyStringOnyxID(report?.policyID)}`];
78-
const alternateText = getAlternateText(report, {}, {isReportArchived: privateIsArchived, policy, reportAttributesDerived, policyTags: reportPolicyTags});
79+
const alternateText = getAlternateText(report, {}, {isReportArchived: privateIsArchived, policy, reportAttributesDerived, policyTags: reportPolicyTags, conciergeReportID});
7980
return {...report, alternateText};
8081
});
8182

src/hooks/useSearchSelector.base.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ function useSearchSelectorBase({
201201
const currentUserEmail = currentUserPersonalDetails.email ?? '';
202202
const personalDetails = usePersonalDetails();
203203
const [allPolicyTags] = useOnyx(ONYXKEYS.COLLECTION.POLICY_TAGS, {selector: passthroughPolicyTagListSelector});
204+
const [conciergeReportID] = useOnyx(ONYXKEYS.CONCIERGE_REPORT_ID);
204205

205206
const onListEndReached = useDebounce(
206207
useCallback(() => {
@@ -240,7 +241,7 @@ function useSearchSelectorBase({
240241
personalDetails,
241242
});
242243
case CONST.SEARCH_SELECTOR.SEARCH_CONTEXT_MEMBER_INVITE:
243-
return getValidOptions(optionsWithContacts, allPolicies, draftComments, nvpDismissedProductTraining, loginList, currentUserAccountID, currentUserEmail, {
244+
return getValidOptions(optionsWithContacts, allPolicies, draftComments, nvpDismissedProductTraining, loginList, currentUserAccountID, currentUserEmail, conciergeReportID, {
244245
betas: betas ?? [],
245246
includeP2P: true,
246247
includeSelectedOptions: false,
@@ -261,7 +262,7 @@ function useSearchSelectorBase({
261262
sortedActions,
262263
});
263264
case CONST.SEARCH_SELECTOR.SEARCH_CONTEXT_GENERAL:
264-
return getValidOptions(optionsWithContacts, allPolicies, draftComments, nvpDismissedProductTraining, loginList, currentUserAccountID, currentUserEmail, {
265+
return getValidOptions(optionsWithContacts, allPolicies, draftComments, nvpDismissedProductTraining, loginList, currentUserAccountID, currentUserEmail, conciergeReportID, {
265266
betas: betas ?? [],
266267
searchString: computedSearchTerm,
267268
searchInputValue: trimmedSearchInput,
@@ -284,7 +285,7 @@ function useSearchSelectorBase({
284285
...getValidOptionsConfig,
285286
});
286287
case CONST.SEARCH_SELECTOR.SEARCH_CONTEXT_SHARE_DESTINATION:
287-
return getValidOptions(optionsWithContacts, allPolicies, draftComments, nvpDismissedProductTraining, loginList, currentUserAccountID, currentUserEmail, {
288+
return getValidOptions(optionsWithContacts, allPolicies, draftComments, nvpDismissedProductTraining, loginList, currentUserAccountID, currentUserEmail, conciergeReportID, {
288289
betas,
289290
selectedOptions,
290291
includeMultipleParticipantReports: true,
@@ -308,7 +309,7 @@ function useSearchSelectorBase({
308309
sortedActions,
309310
});
310311
case CONST.SEARCH_SELECTOR.SEARCH_CONTEXT_ATTENDEES:
311-
return getValidOptions(optionsWithContacts, allPolicies, draftComments, nvpDismissedProductTraining, loginList, currentUserAccountID, currentUserEmail, {
312+
return getValidOptions(optionsWithContacts, allPolicies, draftComments, nvpDismissedProductTraining, loginList, currentUserAccountID, currentUserEmail, conciergeReportID, {
312313
betas: betas ?? [],
313314
includeP2P: true,
314315
includeSelectedOptions: false,
@@ -348,6 +349,7 @@ function useSearchSelectorBase({
348349
loginList,
349350
currentUserAccountID,
350351
currentUserEmail,
352+
conciergeReportID,
351353
personalDetails,
352354
excludeLogins,
353355
excludeFromSuggestionsOnly,

src/libs/OptionsListUtils/index.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,7 @@ type GetAlternateTextConfig = {
439439
translate?: LocalizedTranslate;
440440
reportAttributesDerived?: ReportAttributesDerivedValue['reports'];
441441
policyTags?: OnyxEntry<PolicyTagLists>;
442+
conciergeReportID: string | undefined;
442443
};
443444

444445
/**
@@ -447,7 +448,7 @@ type GetAlternateTextConfig = {
447448
function getAlternateText(
448449
option: OptionData,
449450
{showChatPreviewLine = false, forcePolicyNamePreview = false}: PreviewConfig,
450-
{isReportArchived, policy, lastActorDetails = {}, visibleReportActionsData = {}, translate, reportAttributesDerived, policyTags}: GetAlternateTextConfig,
451+
{isReportArchived, policy, lastActorDetails = {}, visibleReportActionsData = {}, translate, reportAttributesDerived, policyTags, conciergeReportID}: GetAlternateTextConfig,
451452
) {
452453
const report = getReportOrDraftReport(option.reportID);
453454
const isAdminRoom = reportUtilsIsAdminRoom(report);
@@ -467,6 +468,7 @@ function getAlternateText(
467468
visibleReportActionsDataParam: visibleReportActionsData,
468469
reportAttributesDerived,
469470
policyTags,
471+
conciergeReportID,
470472
});
471473
const reportPrefix = getReportSubtitlePrefix(report);
472474
const formattedLastMessageTextWithPrefix = reportPrefix + formattedLastMessageText;
@@ -1109,6 +1111,7 @@ function createOption({
11091111
translate: translateFn,
11101112
reportAttributesDerived,
11111113
policyTags,
1114+
conciergeReportID,
11121115
},
11131116
);
11141117

@@ -2271,6 +2274,7 @@ function prepareReportOptionsForDisplay(
22712274
policiesCollection: OnyxCollection<Policy>,
22722275
currentUserAccountID: number,
22732276
config: GetValidReportsConfig,
2277+
conciergeReportID: string | undefined,
22742278
visibleReportActionsData: VisibleReportActionsDerivedValue = {},
22752279
reportAttributesDerived?: ReportAttributesDerivedValue['reports'],
22762280
// eslint-disable-next-line @typescript-eslint/no-deprecated
@@ -2318,6 +2322,7 @@ function prepareReportOptionsForDisplay(
23182322
visibleReportActionsData,
23192323
reportAttributesDerived,
23202324
policyTags: reportPolicyTags,
2325+
conciergeReportID,
23212326
},
23222327
);
23232328
const isSelected = isReportSelected(option, selectedOptions);
@@ -2440,6 +2445,7 @@ function getValidOptions(
24402445
loginList: OnyxEntry<Login>,
24412446
currentUserAccountID: number,
24422447
currentUserEmail: string,
2448+
conciergeReportID: string | undefined,
24432449
{
24442450
excludeLogins = {},
24452451
excludeFromSuggestionsOnly = {},
@@ -2566,6 +2572,7 @@ function getValidOptions(
25662572
shouldShowGBR,
25672573
personalDetails,
25682574
},
2575+
conciergeReportID,
25692576
visibleReportActionsData,
25702577
reportAttributesDerived,
25712578
sortedActions,
@@ -2589,6 +2596,7 @@ function getValidOptions(
25892596
shouldShowGBR,
25902597
personalDetails,
25912598
},
2599+
conciergeReportID,
25922600
visibleReportActionsData,
25932601
reportAttributesDerived,
25942602
sortedActions,
@@ -2608,6 +2616,7 @@ function getValidOptions(
26082616
shouldShowGBR,
26092617
personalDetails,
26102618
},
2619+
conciergeReportID,
26112620
visibleReportActionsData,
26122621
reportAttributesDerived,
26132622
sortedActions,
@@ -2771,7 +2780,8 @@ function getSearchOptions({
27712780
personalDetails,
27722781
allPolicyTags,
27732782
}: SearchOptionsConfig): Options {
2774-
const optionList = getValidOptions(options, policyCollection, draftComments, nvpDismissedProductTraining, loginList, currentUserAccountID, currentUserEmail, {
2783+
// TODO: We'll pass the conciergeReportID eventually. Refactor issue: https://github.com/Expensify/App/issues/66411
2784+
const optionList = getValidOptions(options, policyCollection, draftComments, nvpDismissedProductTraining, loginList, currentUserAccountID, currentUserEmail, undefined, {
27752785
betas,
27762786
includeRecentReports,
27772787
includeMultipleParticipantReports: true,

src/pages/NewChatPage.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ function useOptions(reportAttributesDerived: ReportAttributesDerivedValue['repor
7878
const isScreenFocusedRef = useIsFocusedRef();
7979
const [sortedActions] = useOnyx(ONYXKEYS.DERIVED.RAM_ONLY_SORTED_REPORT_ACTIONS, {selector: sortedActionsSelector});
8080
const [allPolicyTags] = useOnyx(ONYXKEYS.COLLECTION.POLICY_TAGS, {selector: passthroughPolicyTagListSelector});
81+
const [conciergeReportID] = useOnyx(ONYXKEYS.CONCIERGE_REPORT_ID);
8182

8283
const {
8384
options: listOptions,
@@ -111,6 +112,7 @@ function useOptions(reportAttributesDerived: ReportAttributesDerivedValue['repor
111112
loginList,
112113
currentUserAccountID,
113114
currentUserEmail,
115+
conciergeReportID,
114116
{
115117
betas: betas ?? [],
116118
includeSelfDM: true,

src/pages/iou/request/MoneyRequestAccountantSelector.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ function MoneyRequestAccountantSelector({onFinish, onAccountantSelected, iouType
7272
const currentUserEmail = currentUserPersonalDetails.email ?? '';
7373
const currentUserAccountID = currentUserPersonalDetails.accountID;
7474
const [allPolicies] = useOnyx(ONYXKEYS.COLLECTION.POLICY);
75+
const [conciergeReportID] = useOnyx(ONYXKEYS.CONCIERGE_REPORT_ID);
7576
const privateIsArchivedMap = usePrivateIsArchivedMap();
7677

7778
useEffect(() => {
@@ -94,6 +95,7 @@ function MoneyRequestAccountantSelector({onFinish, onAccountantSelected, iouType
9495
loginList,
9596
currentUserAccountID,
9697
currentUserEmail,
98+
conciergeReportID,
9799
{
98100
betas,
99101
excludeLogins: CONST.EXPENSIFY_EMAILS_OBJECT,
@@ -123,6 +125,7 @@ function MoneyRequestAccountantSelector({onFinish, onAccountantSelected, iouType
123125
countryCode,
124126
currentUserAccountID,
125127
currentUserEmail,
128+
conciergeReportID,
126129
personalDetails,
127130
]);
128131

tests/perf-test/OptionsListUtils.perf-test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ describe('OptionsListUtils', () => {
156156
loginList,
157157
MOCK_CURRENT_USER_ACCOUNT_ID,
158158
MOCK_CURRENT_USER_EMAIL,
159+
undefined,
159160
ValidOptionsConfig,
160161
);
161162
await measureFunction(() => {
@@ -172,6 +173,7 @@ describe('OptionsListUtils', () => {
172173
loginList,
173174
MOCK_CURRENT_USER_ACCOUNT_ID,
174175
MOCK_CURRENT_USER_EMAIL,
176+
undefined,
175177
ValidOptionsConfig,
176178
);
177179
await measureFunction(() => {
@@ -191,6 +193,7 @@ describe('OptionsListUtils', () => {
191193
loginList,
192194
MOCK_CURRENT_USER_ACCOUNT_ID,
193195
MOCK_CURRENT_USER_EMAIL,
196+
undefined,
194197
{
195198
betas: mockedBetas,
196199
includeMultipleParticipantReports: true,

0 commit comments

Comments
 (0)