Skip to content

Commit 99c8585

Browse files
committed
fix: create new useSortedActions hook
1 parent 8bdf529 commit 99c8585

9 files changed

Lines changed: 27 additions & 16 deletions

File tree

src/components/Search/FilterDropdowns/InSelectPopup.tsx

Lines changed: 2 additions & 2 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';
@@ -22,7 +23,6 @@ import variables from '@styles/variables';
2223
import CONST from '@src/CONST';
2324
import ONYXKEYS from '@src/ONYXKEYS';
2425
import passthroughPolicyTagListSelector from '@src/selectors/PolicyTagList';
25-
import {sortedActionsSelector} from '@src/selectors/SortedReportActions';
2626
import type {SearchAdvancedFiltersForm} from '@src/types/form';
2727
import BasePopup from './BasePopup';
2828

@@ -60,7 +60,7 @@ function InSelectPopup({closeOverlay, updateFilterForm}: InSelectPopupProps) {
6060
const [loginList] = useOnyx(ONYXKEYS.LOGIN_LIST);
6161
const [allPolicies] = useOnyx(ONYXKEYS.COLLECTION.POLICY);
6262
const [inReportIDs] = useOnyx(ONYXKEYS.FORMS.SEARCH_ADVANCED_FILTERS_FORM, {selector: inSelector});
63-
const [sortedActions] = useOnyx(ONYXKEYS.DERIVED.RAM_ONLY_SORTED_REPORT_ACTIONS, {selector: sortedActionsSelector});
63+
const sortedActions = useSortedActions();
6464

6565
const currentUserPersonalDetails = useCurrentUserPersonalDetails();
6666
const currentUserAccountID = currentUserPersonalDetails.accountID;

src/components/Search/SearchAutocompleteList.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import {sortedActionsSelector} from '@selectors/SortedReportActions';
21
import type {ForwardedRef, RefObject} from 'react';
32
import React, {useEffect, useMemo, useRef, useState} from 'react';
43
import type {OnyxCollection} from 'react-native-onyx';
@@ -20,6 +19,7 @@ import useLocalize from '@hooks/useLocalize';
2019
import useOnyx from '@hooks/useOnyx';
2120
import useReportAttributes from '@hooks/useReportAttributes';
2221
import useResponsiveLayout from '@hooks/useResponsiveLayout';
22+
import useSortedActions from '@hooks/useSortedActions';
2323
import useThemeStyles from '@hooks/useThemeStyles';
2424
import FS from '@libs/Fullstory';
2525
import type {Options, SearchOption} from '@libs/OptionsListUtils';
@@ -150,7 +150,7 @@ function SearchAutocompleteList({
150150
const [loginList] = useOnyx(ONYXKEYS.LOGIN_LIST);
151151
const [policies = getEmptyObject<NonNullable<OnyxCollection<Policy>>>()] = useOnyx(ONYXKEYS.COLLECTION.POLICY);
152152
const [visibleReportActionsData] = useOnyx(ONYXKEYS.DERIVED.VISIBLE_REPORT_ACTIONS);
153-
const [sortedActions] = useOnyx(ONYXKEYS.DERIVED.RAM_ONLY_SORTED_REPORT_ACTIONS, {selector: sortedActionsSelector});
153+
const sortedActions = useSortedActions();
154154
const personalDetails = usePersonalDetails();
155155
const [reports] = useOnyx(ONYXKEYS.COLLECTION.REPORT);
156156
const [personalAndWorkspaceCards] = useOnyx(ONYXKEYS.DERIVED.PERSONAL_AND_WORKSPACE_CARD_LIST);

src/components/Search/SearchFiltersChatsSelector.tsx

Lines changed: 2 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 React, {useEffect, useState} from 'react';
43
import {usePersonalDetails} from '@components/OnyxListItemProvider';
54
import {useOptionsList} from '@components/OptionListContextProvider';
@@ -12,6 +11,7 @@ import useOnyx from '@hooks/useOnyx';
1211
import usePrivateIsArchivedMap from '@hooks/usePrivateIsArchivedMap';
1312
import useReportAttributes from '@hooks/useReportAttributes';
1413
import useScreenWrapperTransitionStatus from '@hooks/useScreenWrapperTransitionStatus';
14+
import useSortedActions from '@hooks/useSortedActions';
1515
import {canUseTouchScreen} from '@libs/DeviceCapabilities';
1616
import getNonEmptyStringOnyxID from '@libs/getNonEmptyStringOnyxID';
1717
import {createOptionFromReport, filterAndOrderOptions, formatSectionsFromSearchTerm, getAlternateText, getSearchOptions} from '@libs/OptionsListUtils';
@@ -69,7 +69,7 @@ function SearchFiltersChatsSelector({initialReportIDs, onFiltersUpdate, isScreen
6969
const privateIsArchivedMap = usePrivateIsArchivedMap();
7070
const [nvpDismissedProductTraining] = useOnyx(ONYXKEYS.NVP_DISMISSED_PRODUCT_TRAINING);
7171
const [policyTags] = useOnyx(ONYXKEYS.COLLECTION.POLICY_TAGS, {selector: passthroughPolicyTagListSelector});
72-
const [sortedActions] = useOnyx(ONYXKEYS.DERIVED.RAM_ONLY_SORTED_REPORT_ACTIONS, {selector: sortedActionsSelector});
72+
const sortedActions = useSortedActions();
7373

7474
const selectedOptions: OptionData[] = selectedReportIDs.map((id) => {
7575
const privateIsArchived = privateIsArchivedMap[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${id}`];

src/hooks/useAutocompleteSuggestions.ts

Lines changed: 2 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 type {OnyxCollection, OnyxEntry} from 'react-native-onyx';
43
import type {LocaleContextProps} from '@components/LocaleContextProvider';
54
import type {SearchFilterKey, UserFriendlyKey} from '@components/Search/types';
@@ -28,6 +27,7 @@ import {useCurrencyListState} from './useCurrencyList';
2827
import useExportedToFilterOptions from './useExportedToFilterOptions';
2928
import type {FeedKeysWithAssignedCards} from './useFeedKeysWithAssignedCards';
3029
import useOnyx from './useOnyx';
30+
import useSortedActions from './useSortedActions';
3131

3232
type AutocompleteItemData = {
3333
filterKey: UserFriendlyKey;
@@ -106,7 +106,7 @@ function useAutocompleteSuggestions({
106106
const [conciergeReportID] = useOnyx(ONYXKEYS.CONCIERGE_REPORT_ID);
107107
const [allPoliciesTags] = useOnyx(ONYXKEYS.COLLECTION.POLICY_TAGS, {selector: passthroughPolicyTagListSelector});
108108
const [allRecentTags] = useOnyx(ONYXKEYS.COLLECTION.POLICY_RECENTLY_USED_TAGS);
109-
const [sortedActions] = useOnyx(ONYXKEYS.DERIVED.RAM_ONLY_SORTED_REPORT_ACTIONS, {selector: sortedActionsSelector});
109+
const sortedActions = useSortedActions();
110110
const {currencyList} = useCurrencyListState();
111111
const {exportedToFilterOptions} = useExportedToFilterOptions();
112112

src/hooks/useSearchSelector.base.ts

Lines changed: 2 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 ?? '';

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/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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import {sortedActionsSelector} from '@selectors/SortedReportActions';
21
import type {Ref} from 'react';
32
import React, {useEffect, useImperativeHandle, useRef} from 'react';
43
import {View} from 'react-native';
@@ -14,6 +13,7 @@ import useLocalize from '@hooks/useLocalize';
1413
import useNetwork from '@hooks/useNetwork';
1514
import useOnyx from '@hooks/useOnyx';
1615
import useScreenWrapperTransitionStatus from '@hooks/useScreenWrapperTransitionStatus';
16+
import useSortedActions from '@hooks/useSortedActions';
1717
import useThemeStyles from '@hooks/useThemeStyles';
1818
import {getOptimisticChatReport, saveReportDraft, searchInServer} from '@libs/actions/Report';
1919
import {clearUnknownUserDetails, saveUnknownUserDetails} from '@libs/actions/Share';
@@ -55,7 +55,7 @@ function ShareTab({ref}: ShareTabProps) {
5555
const [draftComments] = useOnyx(ONYXKEYS.COLLECTION.REPORT_DRAFT_COMMENT);
5656
const [nvpDismissedProductTraining] = useOnyx(ONYXKEYS.NVP_DISMISSED_PRODUCT_TRAINING);
5757
const [visibleReportActionsData] = useOnyx(ONYXKEYS.DERIVED.VISIBLE_REPORT_ACTIONS);
58-
const [sortedActions] = useOnyx(ONYXKEYS.DERIVED.RAM_ONLY_SORTED_REPORT_ACTIONS, {selector: sortedActionsSelector});
58+
const sortedActions = useSortedActions();
5959
const [conciergeReportID] = useOnyx(ONYXKEYS.CONCIERGE_REPORT_ID);
6060
const currentUserPersonalDetails = useCurrentUserPersonalDetails();
6161
const currentUserAccountID = currentUserPersonalDetails.accountID;
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import type {OnyxEntry} from 'react-native-onyx';
22
import type {SortedReportActionsDerivedValue} from '@src/types/onyx/DerivedValues';
33

4-
const sortedActionsSelector = (value: OnyxEntry<SortedReportActionsDerivedValue>) => value?.sortedActions;
54
const lastActionsSelector = (value: OnyxEntry<SortedReportActionsDerivedValue>) => value?.lastActions;
65

7-
export {sortedActionsSelector, lastActionsSelector};
6+
export {lastActionsSelector};

0 commit comments

Comments
 (0)