Skip to content
Open
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
19 changes: 16 additions & 3 deletions src/components/OptionListContextProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {sortedActionsSelector} from '@selectors/SortedReportActions';
import React, {createContext, useCallback, useContext, useEffect, useMemo, useRef, useState} from 'react';
import type {OnyxCollection, OnyxEntry} from 'react-native-onyx';
import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails';
Expand Down Expand Up @@ -66,6 +67,7 @@ function OptionsListContextProvider({children}: OptionsListProviderProps) {
const personalDetails = usePersonalDetails();
const prevPersonalDetails = usePrevious(personalDetails);
const privateIsArchivedMap = usePrivateIsArchivedMap();
const [sortedActions] = useOnyx(ONYXKEYS.DERIVED.SORTED_REPORT_ACTIONS, {selector: sortedActionsSelector});
const currentUserPersonalDetails = useCurrentUserPersonalDetails();
const currentUserAccountID = currentUserPersonalDetails.accountID;
const hasInitialData = useMemo(() => Object.keys(personalDetails ?? {}).length > 0, [personalDetails]);
Expand Down Expand Up @@ -243,9 +245,20 @@ function OptionsListContextProvider({children}: OptionsListProviderProps) {

const privateIsArchived = privateIsArchivedMap[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report.reportID}`];
const policy = allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${report.policyID}`];
const newReportOption = createOptionFromReport(report, personalDetails, currentUserAccountID, privateIsArchived, policy, reportAttributes?.reports, {
showPersonalDetails: true,
});
const newReportOption = createOptionFromReport(
report,
personalDetails,
currentUserAccountID,
privateIsArchived,
policy,
reportAttributes?.reports,
{
showPersonalDetails: true,
},
undefined,
undefined,
sortedActions,
);
const replaceIndex = options.reports.findIndex((option) => option.reportID === report.reportID);
newReportOptions.push({
newReportOption,
Expand Down
4 changes: 4 additions & 0 deletions src/components/Search/SearchAutocompleteList.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {sortedActionsSelector} from '@selectors/SortedReportActions';
import type {ForwardedRef, RefObject} from 'react';
import React, {useContext, useEffect, useMemo, useRef, useState} from 'react';
import type {OnyxCollection, OnyxEntry} from 'react-native-onyx';
Expand Down Expand Up @@ -159,6 +160,7 @@ function SearchAutocompleteList({
const [loginList] = useOnyx(ONYXKEYS.LOGIN_LIST);
const [policies = getEmptyObject<NonNullable<OnyxCollection<Policy>>>()] = useOnyx(ONYXKEYS.COLLECTION.POLICY);
const [visibleReportActionsData] = useOnyx(ONYXKEYS.DERIVED.VISIBLE_REPORT_ACTIONS);
const [sortedActions] = useOnyx(ONYXKEYS.DERIVED.SORTED_REPORT_ACTIONS, {selector: sortedActionsSelector});
const currentUserPersonalDetails = useCurrentUserPersonalDetails();
const currentUserEmail = currentUserPersonalDetails.email ?? '';
const currentUserAccountID = currentUserPersonalDetails.accountID;
Expand Down Expand Up @@ -213,6 +215,7 @@ function SearchAutocompleteList({
currentUserEmail,
policyCollection: policies,
personalDetails,
sortedActions,
});
})();

Expand Down Expand Up @@ -285,6 +288,7 @@ function SearchAutocompleteList({
loginList,
policies,
visibleReportActionsData,
sortedActions,
currentUserAccountID,
currentUserEmail,
personalDetails,
Expand Down
18 changes: 16 additions & 2 deletions src/components/Search/SearchFiltersChatsSelector.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import passthroughPolicyTagListSelector from '@selectors/PolicyTagList';
import {sortedActionsSelector} from '@selectors/SortedReportActions';
import React, {useEffect, useState} from 'react';
import {usePersonalDetails} from '@components/OnyxListItemProvider';
import {useOptionsList} from '@components/OptionListContextProvider';
Expand Down Expand Up @@ -67,18 +68,30 @@ function SearchFiltersChatsSelector({initialReportIDs, onFiltersUpdate, isScreen
const privateIsArchivedMap = usePrivateIsArchivedMap();
const [nvpDismissedProductTraining] = useOnyx(ONYXKEYS.NVP_DISMISSED_PRODUCT_TRAINING);
const [policyTags] = useOnyx(ONYXKEYS.COLLECTION.POLICY_TAGS, {selector: passthroughPolicyTagListSelector});
const [sortedActions] = useOnyx(ONYXKEYS.DERIVED.SORTED_REPORT_ACTIONS, {selector: sortedActionsSelector});

const selectedOptions: OptionData[] = selectedReportIDs.map((id) => {
const privateIsArchived = privateIsArchivedMap[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${id}`];
const reportData = reports?.[`${ONYXKEYS.COLLECTION.REPORT}${id}`];
const reportPolicy = allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${reportData?.policyID}`];
const report = getSelectedOptionData(
createOptionFromReport({...reportData, reportID: id}, personalDetails, currentUserAccountID, privateIsArchived, reportPolicy, reportAttributesDerived),
createOptionFromReport(
{...reportData, reportID: id},
personalDetails,
currentUserAccountID,
privateIsArchived,
reportPolicy,
reportAttributesDerived,
undefined,
undefined,
undefined,
sortedActions,
),
);
const isReportArchived = !!privateIsArchived;
const policy = allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${reportData?.policyID}`];
const reportPolicyTags = policyTags?.[`${ONYXKEYS.COLLECTION.POLICY_TAGS}${getNonEmptyStringOnyxID(report?.policyID)}`];
const alternateText = getAlternateText(report, {}, isReportArchived, currentUserAccountID, policy, {}, undefined, undefined, reportAttributesDerived, reportPolicyTags);
const alternateText = getAlternateText(report, {}, isReportArchived, policy, {}, undefined, undefined, reportAttributesDerived, reportPolicyTags, sortedActions);
return {...report, alternateText};
});

Expand All @@ -97,6 +110,7 @@ function SearchFiltersChatsSelector({initialReportIDs, onFiltersUpdate, isScreen
currentUserEmail,
personalDetails,
policyCollection: allPolicies,
sortedActions,
});

const chatOptions = filterAndOrderOptions(defaultOptions, cleanSearchTerm, countryCode, loginList, currentUserEmail, currentUserAccountID, personalDetails, {
Expand Down
16 changes: 15 additions & 1 deletion src/components/Search/SearchRouter/SearchRouter.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {hasSeenTourSelector} from '@selectors/Onboarding';
import {sortedActionsSelector} from '@selectors/SortedReportActions';
import {deepEqual} from 'fast-equals';
import React, {useCallback, useEffect, useRef, useState} from 'react';
import type {TextInputProps} from 'react-native';
Expand Down Expand Up @@ -71,6 +72,7 @@ function SearchRouter({onRouterClose, shouldHideInputCaret, isSearchRouterDispla
const [policies] = useOnyx(ONYXKEYS.COLLECTION.POLICY);
const [personalAndWorkspaceCards] = useOnyx(ONYXKEYS.DERIVED.PERSONAL_AND_WORKSPACE_CARD_LIST);
const [allFeeds] = useOnyx(ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_DOMAIN_MEMBER);
const [sortedActions] = useOnyx(ONYXKEYS.DERIVED.SORTED_REPORT_ACTIONS, {selector: sortedActionsSelector});
const privateIsArchivedMap = usePrivateIsArchivedMap();
const {shouldUseNarrowLayout} = useResponsiveLayout();
const listRef = useRef<SelectionListWithSectionsHandle>(null);
Expand Down Expand Up @@ -112,7 +114,18 @@ function SearchRouter({onRouterClose, shouldHideInputCaret, isSearchRouterDispla

const privateIsArchived = privateIsArchivedMap[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${contextualReportID}`];
const reportPolicy = policies?.[`${ONYXKEYS.COLLECTION.POLICY}${report.policyID}`];
const option = createOptionFromReport(report, personalDetails, currentUserAccountID, privateIsArchived, reportPolicy, undefined, {showPersonalDetails: true});
const option = createOptionFromReport(
report,
personalDetails,
currentUserAccountID,
privateIsArchived,
reportPolicy,
undefined,
{showPersonalDetails: true},
undefined,
undefined,
sortedActions,
);
reportForContextualSearch = option;
}

Expand Down Expand Up @@ -177,6 +190,7 @@ function SearchRouter({onRouterClose, shouldHideInputCaret, isSearchRouterDispla
currentUserAccountID,
privateIsArchivedMap,
policies,
sortedActions,
],
);

Expand Down
6 changes: 5 additions & 1 deletion src/hooks/useAutocompleteSuggestions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {getUserFriendlyKey, getUserFriendlyValue} from '@libs/SearchQueryUtils';
import {getDatePresets, getHasOptions} from '@libs/SearchUIUtils';
import CONST, {CONTINUATION_DETECTION_SEARCH_FILTER_KEYS} from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import type {Beta, CardFeeds, CardList, DismissedProductTraining, PersonalDetailsList, Policy} from '@src/types/onyx';
import type {Beta, CardFeeds, CardList, DismissedProductTraining, PersonalDetailsList, Policy, ReportAction} from '@src/types/onyx';
import type {VisibleReportActionsDerivedValue} from '@src/types/onyx/DerivedValues';
import type {SearchDataTypes} from '@src/types/onyx/SearchResults';
import {useCurrencyListState} from './useCurrencyList';
Expand All @@ -47,6 +47,7 @@ type UseAutocompleteSuggestionsParams = {
loginList: OnyxEntry<Record<string, unknown>>;
policies: NonNullable<OnyxCollection<Policy>>;
visibleReportActionsData?: VisibleReportActionsDerivedValue;
sortedActions?: Record<string, ReportAction[]>;
currentUserAccountID: number;
currentUserEmail: string;
personalDetails: OnyxEntry<PersonalDetailsList>;
Expand Down Expand Up @@ -93,6 +94,7 @@ function useAutocompleteSuggestions({
loginList,
policies,
visibleReportActionsData,
sortedActions,
currentUserAccountID,
currentUserEmail,
personalDetails,
Expand Down Expand Up @@ -232,6 +234,7 @@ function useAutocompleteSuggestions({
currentUserAccountID,
currentUserEmail,
personalDetails,
sortedActions,
}).personalDetails.filter((participant) => participant.text && !alreadyAutocompletedKeys.has(participant.text.toLowerCase()));

return participants.map((participant) => ({
Expand Down Expand Up @@ -268,6 +271,7 @@ function useAutocompleteSuggestions({
currentUserAccountID,
currentUserEmail,
personalDetails,
sortedActions,
}).recentReports.filter((chat) => {
if (!chat.text) {
return false;
Expand Down
1 change: 1 addition & 0 deletions src/hooks/useSearchSelector.base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ function useSearchSelectorBase({
currentUserAccountID,
currentUserEmail,
personalDetails,
sortedActions,
});
case CONST.SEARCH_SELECTOR.SEARCH_CONTEXT_MEMBER_INVITE:
return getValidOptions(optionsWithContacts, allPolicies, draftComments, nvpDismissedProductTraining, loginList, currentUserAccountID, currentUserEmail, {
Expand Down
35 changes: 28 additions & 7 deletions src/libs/OptionsListUtils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@
*/

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

Check warning on line 210 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 @@ -223,7 +223,7 @@
const deprecatedCachedOneTransactionThreadReportIDs: Record<string, string | undefined> = {};
/** @deprecated Use sortedReportActionsData from ONYXKEYS.DERIVED.SORTED_REPORT_ACTIONS instead. Will be removed once all flows are migrated. */
let deprecatedAllReportActions: OnyxCollection<ReportActions>;
Onyx.connect({

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

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

Check warning on line 276 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 @@ -429,14 +429,14 @@
option: OptionData,
{showChatPreviewLine = false, forcePolicyNamePreview = false}: PreviewConfig,
isReportArchived: boolean | undefined,
currentUserAccountID: number,
// We'll make it required in the next PR. Ref: https://github.com/Expensify/App/issues/66415
policy?: OnyxEntry<Policy>,
lastActorDetails: Partial<PersonalDetails> | null = {},
visibleReportActionsData: VisibleReportActionsDerivedValue = {},
translate?: LocalizedTranslate,
reportAttributesDerived?: ReportAttributesDerivedValue['reports'],
policyTags?: OnyxEntry<PolicyTagLists>,
sortedActions?: Record<string, ReportAction[]>,
) {
const report = getReportOrDraftReport(option.reportID);
const isAdminRoom = reportUtilsIsAdminRoom(report);
Expand All @@ -456,6 +456,7 @@
visibleReportActionsDataParam: visibleReportActionsData,
reportAttributesDerived,
policyTags,
sortedActions,
});
const reportPrefix = getReportSubtitlePrefix(report);
const formattedLastMessageTextWithPrefix = reportPrefix + formattedLastMessageText;
Expand Down Expand Up @@ -608,6 +609,8 @@
policyTags,
currentUserLogin,
conciergeReportID,
// eslint-disable-next-line @typescript-eslint/no-deprecated
sortedActions = deprecatedAllSortedReportActions,
}: {
translate: LocalizedTranslate;
report: OnyxEntry<Report>;
Expand All @@ -625,6 +628,7 @@
currentUserLogin?: string;
// TODO: conciergeReportID will be required eventually. Refactor issue: https://github.com/Expensify/App/issues/66411
conciergeReportID?: string;
sortedActions?: Record<string, ReportAction[]>;
}): string {
const reportID = report?.reportID;
const canUserPerformWrite = canUserPerformWriteAction(report, isReportArchived);
Expand Down Expand Up @@ -695,8 +699,7 @@
const iouReportID = iouReport?.reportID;
const reportCache = iouReportID ? visibleReportActionsDataParam?.[iouReportID] : undefined;
const visibleReportActionsForIOUReport = reportCache && Object.keys(reportCache).length > 0 ? visibleReportActionsDataParam : undefined;
// eslint-disable-next-line @typescript-eslint/no-deprecated
const iouReportActions = iouReportID ? deprecatedAllSortedReportActions[iouReportID] : undefined;
const iouReportActions = iouReportID ? sortedActions?.[iouReportID] : undefined;
const canPerformWrite = canUserPerformWriteAction(report, isReportArchived);
const lastIOUMoneyReportAction =
iouReportID && iouReportActions
Expand Down Expand Up @@ -962,6 +965,7 @@
translate?: LocalizedTranslate;
// TODO: conciergeReportID will be required eventually. Refactor issue: https://github.com/Expensify/App/issues/66411
conciergeReportID?: string;
sortedActions?: Record<string, ReportAction[]>;
};

/**
Expand All @@ -971,7 +975,6 @@
accountIDs,
personalDetails,
report,
currentUserAccountID,
privateIsArchived,
policy,
config,
Expand All @@ -980,6 +983,7 @@
visibleReportActionsData = {},
translate,
conciergeReportID,
sortedActions,
}: CreateOptionParams): SearchOptionData {
const {showChatPreviewLine = false, forcePolicyNamePreview = false, showPersonalDetails = false, selected, isSelected, isDisabled} = config ?? {};

Expand Down Expand Up @@ -1063,6 +1067,7 @@
reportAttributesDerived,
policyTags,
conciergeReportID,
sortedActions,
});
result.alternateText =
showPersonalDetails && personalDetail?.login
Expand All @@ -1071,13 +1076,13 @@
result,
{showChatPreviewLine, forcePolicyNamePreview},
!!result.private_isArchived,
currentUserAccountID,
policy,
lastActorDetails,
visibleReportActionsData,
translateFn,
reportAttributesDerived,
policyTags,
sortedActions,
);

const computedReportName = getReportName(report, reportAttributesDerived);
Expand Down Expand Up @@ -1652,12 +1657,25 @@
config?: PreviewConfig,
policyTags?: OnyxEntry<PolicyTagLists>,
visibleReportActionsData: VisibleReportActionsDerivedValue = {},
sortedActions?: Record<string, ReportAction[]>,
) {
const accountIDs = getParticipantsAccountIDsForDisplay(report);

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

Expand Down Expand Up @@ -2313,13 +2331,13 @@
option,
{showChatPreviewLine, forcePolicyNamePreview},
!!option.private_isArchived,
currentUserAccountID,
policy,
null,
visibleReportActionsData,
undefined,
reportAttributesDerived,
reportPolicyTags,
sortedActions,
);
const isSelected = isReportSelected(option, selectedOptions);

Expand Down Expand Up @@ -2740,6 +2758,7 @@
personalDetails?: OnyxEntry<PersonalDetailsList>;
reportAttributesDerived?: ReportAttributesDerivedValue['reports'];
allPolicyTags?: OnyxCollection<PolicyTagLists>;
sortedActions?: Record<string, ReportAction[]>;
};

/**
Expand Down Expand Up @@ -2768,6 +2787,7 @@
reportAttributesDerived,
personalDetails,
allPolicyTags,
sortedActions,
}: SearchOptionsConfig): Options {
const optionList = getValidOptions(options, policyCollection, draftComments, nvpDismissedProductTraining, loginList, currentUserAccountID, currentUserEmail, {
betas,
Expand All @@ -2794,6 +2814,7 @@
visibleReportActionsData,
reportAttributesDerived,
allPolicyTags,
sortedActions,
});

return optionList;
Expand Down
3 changes: 3 additions & 0 deletions src/pages/Share/ShareTab.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {sortedActionsSelector} from '@selectors/SortedReportActions';
import type {Ref} from 'react';
import React, {useEffect, useImperativeHandle, useRef} from 'react';
import {View} from 'react-native';
Expand Down Expand Up @@ -54,6 +55,7 @@ function ShareTab({ref}: ShareTabProps) {
const [draftComments] = useOnyx(ONYXKEYS.COLLECTION.REPORT_DRAFT_COMMENT);
const [nvpDismissedProductTraining] = useOnyx(ONYXKEYS.NVP_DISMISSED_PRODUCT_TRAINING);
const [visibleReportActionsData] = useOnyx(ONYXKEYS.DERIVED.VISIBLE_REPORT_ACTIONS);
const [sortedActions] = useOnyx(ONYXKEYS.DERIVED.SORTED_REPORT_ACTIONS, {selector: sortedActionsSelector});
const currentUserPersonalDetails = useCurrentUserPersonalDetails();
const currentUserAccountID = currentUserPersonalDetails.accountID;
const currentUserEmail = currentUserPersonalDetails.email ?? '';
Expand Down Expand Up @@ -92,6 +94,7 @@ function ShareTab({ref}: ShareTabProps) {
currentUserEmail,
policyCollection: allPolicies,
personalDetails,
sortedActions,
})
: defaultListOptions;

Expand Down
Loading
Loading