Skip to content

Commit b6e818c

Browse files
authored
Merge pull request #86409 from truph01/fix/66381-part-2
Remove Onyx.connect() key ONYXKEYS.COLLECTION.REPORT_ACTIONS in src/libs/OptionsListUtils.ts - part 2
2 parents 73a1e00 + 43ab3e6 commit b6e818c

14 files changed

Lines changed: 338 additions & 17 deletions

src/components/Search/FilterDropdowns/InSelectPopup.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import useOnyx from '@hooks/useOnyx';
1010
import usePrivateIsArchivedMap from '@hooks/usePrivateIsArchivedMap';
1111
import useReportAttributes from '@hooks/useReportAttributes';
1212
import useResponsiveLayout from '@hooks/useResponsiveLayout';
13+
import useSortedActions from '@hooks/useSortedActions';
1314
import useThemeStyles from '@hooks/useThemeStyles';
1415
import useWindowDimensions from '@hooks/useWindowDimensions';
1516
import {searchInServer} from '@libs/actions/Report';
@@ -59,6 +60,8 @@ function InSelectPopup({closeOverlay, updateFilterForm}: InSelectPopupProps) {
5960
const [loginList] = useOnyx(ONYXKEYS.LOGIN_LIST);
6061
const [allPolicies] = useOnyx(ONYXKEYS.COLLECTION.POLICY);
6162
const [inReportIDs] = useOnyx(ONYXKEYS.FORMS.SEARCH_ADVANCED_FILTERS_FORM, {selector: inSelector});
63+
const sortedActions = useSortedActions();
64+
6265
const currentUserPersonalDetails = useCurrentUserPersonalDetails();
6366
const currentUserAccountID = currentUserPersonalDetails.accountID;
6467
const currentUserEmail = currentUserPersonalDetails.email ?? '';
@@ -100,6 +103,7 @@ function InSelectPopup({closeOverlay, updateFilterForm}: InSelectPopupProps) {
100103
currentUserEmail,
101104
personalDetails,
102105
policyCollection: allPolicies,
106+
sortedActions,
103107
conciergeReportID,
104108
});
105109

src/components/Search/SearchAutocompleteList.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import useLocalize from '@hooks/useLocalize';
1919
import useOnyx from '@hooks/useOnyx';
2020
import useReportAttributes from '@hooks/useReportAttributes';
2121
import useResponsiveLayout from '@hooks/useResponsiveLayout';
22+
import useSortedActions from '@hooks/useSortedActions';
2223
import useThemeStyles from '@hooks/useThemeStyles';
2324
import FS from '@libs/Fullstory';
2425
import type {Options, SearchOption} from '@libs/OptionsListUtils';
@@ -153,6 +154,7 @@ function SearchAutocompleteList({
153154
const [loginList] = useOnyx(ONYXKEYS.LOGIN_LIST);
154155
const [policies = getEmptyObject<NonNullable<OnyxCollection<Policy>>>()] = useOnyx(ONYXKEYS.COLLECTION.POLICY);
155156
const [visibleReportActionsData] = useOnyx(ONYXKEYS.DERIVED.VISIBLE_REPORT_ACTIONS);
157+
const sortedActions = useSortedActions();
156158
const personalDetails = usePersonalDetails();
157159
const [reports] = useOnyx(ONYXKEYS.COLLECTION.REPORT);
158160
const [personalAndWorkspaceCards] = useOnyx(ONYXKEYS.DERIVED.PERSONAL_AND_WORKSPACE_CARD_LIST);
@@ -212,6 +214,7 @@ function SearchAutocompleteList({
212214
currentUserEmail,
213215
policyCollection: policies,
214216
personalDetails,
217+
sortedActions,
215218
conciergeReportID,
216219
});
217220
}, [
@@ -227,6 +230,7 @@ function SearchAutocompleteList({
227230
currentUserEmail,
228231
policies,
229232
personalDetails,
233+
sortedActions,
230234
conciergeReportID,
231235
]);
232236

src/components/Search/SearchFiltersChatsSelector.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import useOnyx from '@hooks/useOnyx';
1111
import usePrivateIsArchivedMap from '@hooks/usePrivateIsArchivedMap';
1212
import useReportAttributes from '@hooks/useReportAttributes';
1313
import useScreenWrapperTransitionStatus from '@hooks/useScreenWrapperTransitionStatus';
14+
import useSortedActions from '@hooks/useSortedActions';
1415
import {canUseTouchScreen} from '@libs/DeviceCapabilities';
1516
import getNonEmptyStringOnyxID from '@libs/getNonEmptyStringOnyxID';
1617
import {createOptionFromReport, filterAndOrderOptions, formatSectionsFromSearchTerm, getAlternateText, getSearchOptions} from '@libs/OptionsListUtils';
@@ -68,6 +69,7 @@ function SearchFiltersChatsSelector({initialReportIDs, onFiltersUpdate, isScreen
6869
const privateIsArchivedMap = usePrivateIsArchivedMap();
6970
const [nvpDismissedProductTraining] = useOnyx(ONYXKEYS.NVP_DISMISSED_PRODUCT_TRAINING);
7071
const [policyTags] = useOnyx(ONYXKEYS.COLLECTION.POLICY_TAGS, {selector: passthroughPolicyTagListSelector});
72+
const sortedActions = useSortedActions();
7173

7274
const selectedOptions: OptionData[] = selectedReportIDs.map((id) => {
7375
const privateIsArchived = privateIsArchivedMap[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${id}`];
@@ -95,6 +97,7 @@ function SearchFiltersChatsSelector({initialReportIDs, onFiltersUpdate, isScreen
9597
currentUserEmail,
9698
personalDetails,
9799
policyCollection: allPolicies,
100+
sortedActions,
98101
conciergeReportID,
99102
});
100103

src/hooks/useAutocompleteSuggestions.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import {useCurrencyListState} from './useCurrencyList';
2929
import useExportedToFilterOptions from './useExportedToFilterOptions';
3030
import type {FeedKeysWithAssignedCards} from './useFeedKeysWithAssignedCards';
3131
import useOnyx from './useOnyx';
32+
import useSortedActions from './useSortedActions';
3233

3334
type AutocompleteItemData = {
3435
filterKey: UserFriendlyKey;
@@ -110,6 +111,7 @@ function useAutocompleteSuggestions({
110111
const [conciergeReportID] = useOnyx(ONYXKEYS.CONCIERGE_REPORT_ID);
111112
const [allPoliciesTags] = useOnyx(ONYXKEYS.COLLECTION.POLICY_TAGS, {selector: passthroughPolicyTagListSelector});
112113
const [allRecentTags] = useOnyx(ONYXKEYS.COLLECTION.POLICY_RECENTLY_USED_TAGS);
114+
const sortedActions = useSortedActions();
113115
const {currencyList} = useCurrencyListState();
114116
const {exportedToFilterOptions} = useExportedToFilterOptions();
115117

@@ -238,6 +240,7 @@ function useAutocompleteSuggestions({
238240
currentUserAccountID,
239241
currentUserEmail,
240242
personalDetails,
243+
sortedActions,
241244
conciergeReportID,
242245
}).personalDetails.filter((participant) => participant.text && !alreadyAutocompletedKeys.has(participant.text.toLowerCase()));
243246

@@ -275,6 +278,7 @@ function useAutocompleteSuggestions({
275278
currentUserAccountID,
276279
currentUserEmail,
277280
personalDetails,
281+
sortedActions,
278282
conciergeReportID,
279283
}).recentReports.filter((chat) => {
280284
if (!chat.text) {

src/hooks/useSearchSelector.base.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import passthroughPolicyTagListSelector from '@selectors/PolicyTagList';
2-
import {sortedActionsSelector} from '@selectors/SortedReportActions';
32
import {useCallback, useMemo, useState} from 'react';
43
import type {PermissionStatus} from 'react-native-permissions';
54
import {usePersonalDetails} from '@components/OnyxListItemProvider';
@@ -15,6 +14,7 @@ import useCurrentUserPersonalDetails from './useCurrentUserPersonalDetails';
1514
import useDebounce from './useDebounce';
1615
import useDebouncedState from './useDebouncedState';
1716
import useOnyx from './useOnyx';
17+
import useSortedActions from './useSortedActions';
1818

1919
type SearchSelectorContext = (typeof CONST.SEARCH_SELECTOR)[keyof Pick<
2020
typeof CONST.SEARCH_SELECTOR,
@@ -196,7 +196,7 @@ function useSearchSelectorBase({
196196
const [draftComments] = useOnyx(ONYXKEYS.COLLECTION.REPORT_DRAFT_COMMENT);
197197
const [nvpDismissedProductTraining] = useOnyx(ONYXKEYS.NVP_DISMISSED_PRODUCT_TRAINING);
198198
const [visibleReportActionsData] = useOnyx(ONYXKEYS.DERIVED.VISIBLE_REPORT_ACTIONS);
199-
const [sortedActions] = useOnyx(ONYXKEYS.DERIVED.RAM_ONLY_SORTED_REPORT_ACTIONS, {selector: sortedActionsSelector});
199+
const sortedActions = useSortedActions();
200200
const currentUserPersonalDetails = useCurrentUserPersonalDetails();
201201
const currentUserAccountID = currentUserPersonalDetails.accountID;
202202
const currentUserEmail = currentUserPersonalDetails.email ?? '';
@@ -240,6 +240,7 @@ function useSearchSelectorBase({
240240
currentUserAccountID,
241241
currentUserEmail,
242242
personalDetails,
243+
sortedActions,
243244
conciergeReportID,
244245
});
245246
case CONST.SEARCH_SELECTOR.SEARCH_CONTEXT_MEMBER_INVITE:

src/hooks/useSortedActions.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import ONYXKEYS from '@src/ONYXKEYS';
2+
import useOnyx from './useOnyx';
3+
4+
/**
5+
* Returns `sortedActions` from the RAM_ONLY_SORTED_REPORT_ACTIONS derived value.
6+
*/
7+
function useSortedActions() {
8+
const [sortedReportActions] = useOnyx(ONYXKEYS.DERIVED.RAM_ONLY_SORTED_REPORT_ACTIONS);
9+
return sortedReportActions?.sortedActions;
10+
}
11+
12+
export default useSortedActions;

src/libs/OptionsListUtils/index.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2276,10 +2276,9 @@ function prepareReportOptionsForDisplay(
22762276
currentUserAccountID: number,
22772277
config: GetValidReportsConfig,
22782278
conciergeReportID: string | undefined,
2279+
sortedActions: Record<string, ReportAction[]> | undefined,
22792280
visibleReportActionsData: VisibleReportActionsDerivedValue = {},
22802281
reportAttributesDerived?: ReportAttributesDerivedValue['reports'],
2281-
// eslint-disable-next-line @typescript-eslint/no-deprecated
2282-
sortedActions: Record<string, ReportAction[]> = deprecatedAllSortedReportActions,
22832282
policyTags?: OnyxCollection<PolicyTagLists>,
22842283
): Array<SearchOption<Report>> {
22852284
const {
@@ -2333,7 +2332,7 @@ function prepareReportOptionsForDisplay(
23332332
const chatReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${report.chatReportID}`];
23342333
const oneTransactionThreadReportID =
23352334
report.type === CONST.REPORT.TYPE.IOU || report.type === CONST.REPORT.TYPE.EXPENSE || report.type === CONST.REPORT.TYPE.INVOICE
2336-
? getOneTransactionThreadReportID(report, chatReport, sortedActions[report.reportID])
2335+
? getOneTransactionThreadReportID(report, chatReport, sortedActions?.[report.reportID])
23372336
: undefined;
23382337
const oneTransactionThreadReport = oneTransactionThreadReportID ? allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${oneTransactionThreadReportID}`] : undefined;
23392338

@@ -2343,11 +2342,11 @@ function prepareReportOptionsForDisplay(
23432342
let lastIOUCreationDate;
23442343
// Add a field to sort the recent reports by the time of last IOU request for create actions
23452344
if (preferRecentExpenseReports) {
2346-
const reportPreviewAction = sortedActions[option.reportID]?.find((reportAction) => isActionOfType(reportAction, CONST.REPORT.ACTIONS.TYPE.REPORT_PREVIEW));
2345+
const reportPreviewAction = sortedActions?.[option.reportID]?.find((reportAction) => isActionOfType(reportAction, CONST.REPORT.ACTIONS.TYPE.REPORT_PREVIEW));
23472346

23482347
if (reportPreviewAction) {
23492348
const iouReportID = getIOUReportIDFromReportActionPreview(reportPreviewAction);
2350-
const iouReportActions = iouReportID ? (sortedActions[iouReportID] ?? []) : [];
2349+
const iouReportActions = iouReportID ? (sortedActions?.[iouReportID] ?? []) : [];
23512350
const lastIOUAction = iouReportActions.find((iouAction) => iouAction.actionName === CONST.REPORT.ACTIONS.TYPE.IOU);
23522351
if (lastIOUAction) {
23532352
lastIOUCreationDate = lastIOUAction.lastModified;
@@ -2574,9 +2573,9 @@ function getValidOptions(
25742573
personalDetails,
25752574
},
25762575
conciergeReportID,
2576+
sortedActions,
25772577
visibleReportActionsData,
25782578
reportAttributesDerived,
2579-
sortedActions,
25802579
allPolicyTags,
25812580
).at(0);
25822581
}
@@ -2598,9 +2597,9 @@ function getValidOptions(
25982597
personalDetails,
25992598
},
26002599
conciergeReportID,
2600+
sortedActions,
26012601
visibleReportActionsData,
26022602
reportAttributesDerived,
2603-
sortedActions,
26042603
allPolicyTags,
26052604
);
26062605

@@ -2618,9 +2617,9 @@ function getValidOptions(
26182617
personalDetails,
26192618
},
26202619
conciergeReportID,
2620+
sortedActions,
26212621
visibleReportActionsData,
26222622
reportAttributesDerived,
2623-
sortedActions,
26242623
allPolicyTags,
26252624
);
26262625
} else if (recentAttendees && recentAttendees?.length > 0) {
@@ -2754,6 +2753,7 @@ type SearchOptionsConfig = {
27542753
personalDetails?: OnyxEntry<PersonalDetailsList>;
27552754
reportAttributesDerived?: ReportAttributesDerivedValue['reports'];
27562755
allPolicyTags?: OnyxCollection<PolicyTagLists>;
2756+
sortedActions: Record<string, ReportAction[]> | undefined;
27572757
conciergeReportID: string | undefined;
27582758
};
27592759

@@ -2783,6 +2783,7 @@ function getSearchOptions({
27832783
reportAttributesDerived,
27842784
personalDetails,
27852785
allPolicyTags,
2786+
sortedActions,
27862787
conciergeReportID,
27872788
}: SearchOptionsConfig): Options {
27882789
const optionList = getValidOptions(options, policyCollection, draftComments, nvpDismissedProductTraining, loginList, currentUserAccountID, currentUserEmail, conciergeReportID, {
@@ -2810,6 +2811,7 @@ function getSearchOptions({
28102811
visibleReportActionsData,
28112812
reportAttributesDerived,
28122813
allPolicyTags,
2814+
sortedActions,
28132815
});
28142816

28152817
return optionList;

src/libs/OptionsListUtils/types.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,6 @@ type GetOptionsConfig = {
222222
countryCode?: number;
223223
visibleReportActionsData?: VisibleReportActionsDerivedValue;
224224
reportAttributesDerived?: ReportAttributesDerivedValue['reports'];
225-
// TODO: Remove the optional operator once all call sites pass sortedActions (https://github.com/Expensify/App/issues/66381)
226225
sortedActions?: Record<string, ReportAction[]>;
227226
} & GetValidReportsConfig;
228227

src/pages/NewChatPage.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import useNetwork from '@hooks/useNetwork';
2626
import useOnyx from '@hooks/useOnyx';
2727
import useSafeAreaInsets from '@hooks/useSafeAreaInsets';
2828
import useSingleExecution from '@hooks/useSingleExecution';
29+
import useSortedActions from '@hooks/useSortedActions';
2930
import useThemeStyles from '@hooks/useThemeStyles';
3031
import {navigateToAndOpenReport, searchInServer, setGroupDraft} from '@libs/actions/Report';
3132
import {canUseTouchScreen} from '@libs/DeviceCapabilities';
@@ -39,7 +40,6 @@ import variables from '@styles/variables';
3940
import CONST from '@src/CONST';
4041
import ONYXKEYS from '@src/ONYXKEYS';
4142
import ROUTES from '@src/ROUTES';
42-
import {sortedActionsSelector} from '@src/selectors/SortedReportActions';
4343
import type {ReportAttributesDerivedValue} from '@src/types/onyx/DerivedValues';
4444
import type {SelectedParticipant} from '@src/types/onyx/NewGroupChatDraft';
4545
import getEmptyArray from '@src/types/utils/getEmptyArray';
@@ -68,7 +68,7 @@ function useOptions(reportAttributesDerived: ReportAttributesDerivedValue['repor
6868
const [draftComments] = useOnyx(ONYXKEYS.COLLECTION.REPORT_DRAFT_COMMENT);
6969
const allPersonalDetails = usePersonalDetails();
7070
const isScreenFocusedRef = useIsFocusedRef();
71-
const [sortedActions] = useOnyx(ONYXKEYS.DERIVED.RAM_ONLY_SORTED_REPORT_ACTIONS, {selector: sortedActionsSelector});
71+
const sortedActions = useSortedActions();
7272
const [allPolicyTags] = useOnyx(ONYXKEYS.COLLECTION.POLICY_TAGS, {selector: passthroughPolicyTagListSelector});
7373
const [conciergeReportID] = useOnyx(ONYXKEYS.CONCIERGE_REPORT_ID);
7474

src/pages/Share/ShareTab.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import useLocalize from '@hooks/useLocalize';
1313
import useNetwork from '@hooks/useNetwork';
1414
import useOnyx from '@hooks/useOnyx';
1515
import useScreenWrapperTransitionStatus from '@hooks/useScreenWrapperTransitionStatus';
16+
import useSortedActions from '@hooks/useSortedActions';
1617
import useThemeStyles from '@hooks/useThemeStyles';
1718
import {getOptimisticChatReport, saveReportDraft, searchInServer} from '@libs/actions/Report';
1819
import {clearUnknownUserDetails, saveUnknownUserDetails} from '@libs/actions/Share';
@@ -54,6 +55,7 @@ function ShareTab({ref}: ShareTabProps) {
5455
const [draftComments] = useOnyx(ONYXKEYS.COLLECTION.REPORT_DRAFT_COMMENT);
5556
const [nvpDismissedProductTraining] = useOnyx(ONYXKEYS.NVP_DISMISSED_PRODUCT_TRAINING);
5657
const [visibleReportActionsData] = useOnyx(ONYXKEYS.DERIVED.VISIBLE_REPORT_ACTIONS);
58+
const sortedActions = useSortedActions();
5759
const [conciergeReportID] = useOnyx(ONYXKEYS.CONCIERGE_REPORT_ID);
5860
const currentUserPersonalDetails = useCurrentUserPersonalDetails();
5961
const currentUserAccountID = currentUserPersonalDetails.accountID;
@@ -93,6 +95,7 @@ function ShareTab({ref}: ShareTabProps) {
9395
currentUserEmail,
9496
policyCollection: allPolicies,
9597
personalDetails,
98+
sortedActions,
9699
conciergeReportID,
97100
})
98101
: defaultListOptions;

0 commit comments

Comments
 (0)