diff --git a/src/hooks/useFilterFormValues.tsx b/src/hooks/useFilterFormValues.tsx index 90f711cad151..8100049ed0c1 100644 --- a/src/hooks/useFilterFormValues.tsx +++ b/src/hooks/useFilterFormValues.tsx @@ -8,7 +8,7 @@ import {buildFilterFormValuesFromQuery} from '@libs/SearchQueryUtils'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import type {SearchAdvancedFiltersForm} from '@src/types/form'; -import type {Policy, PolicyCategories, PolicyTagLists, Report} from '@src/types/onyx'; +import type {Policy, PolicyCategories, PolicyTagLists} from '@src/types/onyx'; import {getEmptyObject} from '@src/types/utils/EmptyObject'; import {useCurrencyListState} from './useCurrencyList'; import useCurrentUserPersonalDetails from './useCurrentUserPersonalDetails'; @@ -29,20 +29,6 @@ function policiesSelector(policies: OnyxCollection): OnyxCollection): OnyxCollection { - if (!reports) { - return reports; - } - const result: OnyxCollection = {}; - for (const [key, report] of Object.entries(reports)) { - if (!report) { - continue; - } - result[key] = {reportID: report.reportID} as Report; - } - return result; -} - function policyCategoriesSelector(categories: OnyxCollection): OnyxCollection { if (!categories) { return categories; @@ -90,7 +76,9 @@ const useFilterFormValues = (queryJSON?: SearchQueryJSON) => { const [userCardList] = useOnyx(ONYXKEYS.CARD_LIST); const [policies] = useOnyx(ONYXKEYS.COLLECTION.POLICY, {selector: policiesSelector}); - const [allReports] = useOnyx(ONYXKEYS.COLLECTION.REPORT, {selector: reportsSelector}); + // Subscribe to the report collection directly. buildFilterFormValuesFromQuery only does keyed existence + // lookups (`in:` filter), so projecting via a selector would just waste an O(n) pass over every report. + const [allReports] = useOnyx(ONYXKEYS.COLLECTION.REPORT); const [policyTagsLists] = useOnyx(ONYXKEYS.COLLECTION.POLICY_TAGS, {selector: policyTagsSelector}); const [policyCategories] = useOnyx(ONYXKEYS.COLLECTION.POLICY_CATEGORIES, {selector: policyCategoriesSelector}); const [workspaceCardFeeds] = useOnyx(ONYXKEYS.COLLECTION.WORKSPACE_CARDS_LIST); @@ -119,4 +107,4 @@ const useFilterFormValues = (queryJSON?: SearchQueryJSON) => { }; export default useFilterFormValues; -export {policiesSelector, reportsSelector, policyCategoriesSelector, policyTagsSelector}; +export {policiesSelector, policyCategoriesSelector, policyTagsSelector}; diff --git a/tests/perf-test/useFilterFormValues.perf-test.tsx b/tests/perf-test/useFilterFormValues.perf-test.tsx index e70372da5d39..4a0e4c43596d 100644 --- a/tests/perf-test/useFilterFormValues.perf-test.tsx +++ b/tests/perf-test/useFilterFormValues.perf-test.tsx @@ -6,7 +6,7 @@ import {measureFunction, measureRenders} from 'reassure'; import {typeOptionsPoliciesSelector} from '@components/Search/FilterComponents/TypeSelector'; import {advancedSearchPoliciesSelector} from '@hooks/useAdvancedSearchFilters'; import {exportedToPoliciesSelector} from '@hooks/useExportedToFilterOptions'; -import {policiesSelector, policyCategoriesSelector, policyTagsSelector, reportsSelector} from '@hooks/useFilterFormValues'; +import {policiesSelector, policyCategoriesSelector, policyTagsSelector} from '@hooks/useFilterFormValues'; import {getAllTaxRates} from '@libs/PolicyUtils'; import {buildFilterFormValuesFromQuery, buildSearchQueryJSON} from '@libs/SearchQueryUtils'; import type {SearchQueryJSON} from '@src/components/Search/types'; @@ -60,25 +60,6 @@ describe('useFilterFormValues', () => { await measureFunction(() => policiesSelector(policies)); }); - test('reportsSelector with 500 reports', async () => { - const reports = createCollection( - (_, index) => `${ONYXKEYS.COLLECTION.REPORT}${index}`, - (index) => - ({ - reportID: `${index}`, - reportName: `Report ${index}`, - chatType: 'policyExpenseChat', - stateNum: 1, - statusNum: 1, - ownerAccountID: index, - participantAccountIDs: [index, index + 1], - }) as unknown as Report, - REPORT_COUNT, - ); - - await measureFunction(() => reportsSelector(reports)); - }); - test('policyCategoriesSelector with 500 policy category collections', async () => { const categories = createCollection( (_, index) => `${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${index}`, @@ -233,7 +214,7 @@ describe('useFilterFormValues', () => { function TestComponent() { const [policies] = useOnyx(ONYXKEYS.COLLECTION.POLICY, {selector: policiesSelector}); - const [allReports] = useOnyx(ONYXKEYS.COLLECTION.REPORT, {selector: reportsSelector}); + const [allReports] = useOnyx(ONYXKEYS.COLLECTION.REPORT); const [policyTagsLists] = useOnyx(ONYXKEYS.COLLECTION.POLICY_TAGS, {selector: policyTagsSelector}); const [policyCategories] = useOnyx(ONYXKEYS.COLLECTION.POLICY_CATEGORIES, {selector: policyCategoriesSelector}); const taxRates = useMemo(() => getAllTaxRates(policies), [policies]); diff --git a/tests/unit/hooks/useFilterFormValues.test.ts b/tests/unit/hooks/useFilterFormValues.test.ts index d4eaed610494..38ba4dd0ad41 100644 --- a/tests/unit/hooks/useFilterFormValues.test.ts +++ b/tests/unit/hooks/useFilterFormValues.test.ts @@ -2,14 +2,12 @@ import type {OnyxCollection} from 'react-native-onyx'; import {typeOptionsPoliciesSelector} from '@components/Search/FilterComponents/TypeSelector'; import {advancedSearchPoliciesSelector} from '@hooks/useAdvancedSearchFilters'; import {exportedToPoliciesSelector} from '@hooks/useExportedToFilterOptions'; -import {policiesSelector, policyCategoriesSelector, policyTagsSelector, reportsSelector} from '@hooks/useFilterFormValues'; +import {policiesSelector, policyCategoriesSelector, policyTagsSelector} from '@hooks/useFilterFormValues'; import ONYXKEYS from '@src/ONYXKEYS'; -import type {Policy, PolicyCategories, PolicyTagLists, Report} from '@src/types/onyx'; +import type {Policy, PolicyCategories, PolicyTagLists} from '@src/types/onyx'; const POLICY_KEY = `${ONYXKEYS.COLLECTION.POLICY}1`; const POLICY_KEY_2 = `${ONYXKEYS.COLLECTION.POLICY}2`; -const REPORT_KEY = `${ONYXKEYS.COLLECTION.REPORT}1`; -const REPORT_KEY_2 = `${ONYXKEYS.COLLECTION.REPORT}2`; const CATEGORIES_KEY = `${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}1`; const CATEGORIES_KEY_2 = `${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}2`; const TAGS_KEY = `${ONYXKEYS.COLLECTION.POLICY_TAGS}1`; @@ -51,38 +49,6 @@ describe('useFilterFormValues selectors', () => { }); }); - describe('reportsSelector', () => { - it('returns undefined input as-is', () => { - expect(reportsSelector(undefined)).toBeUndefined(); - }); - - it('extracts only reportID from each report', () => { - const reports: OnyxCollection = { - [REPORT_KEY]: {reportID: '100', reportName: 'Expense Report', chatType: 'policyExpenseChat'} as unknown as Report, - [REPORT_KEY_2]: {reportID: '200', reportName: 'Invoice', chatType: 'invoice'} as unknown as Report, - }; - - const result = reportsSelector(reports); - - expect(result).toEqual({ - [REPORT_KEY]: {reportID: '100'}, - [REPORT_KEY_2]: {reportID: '200'}, - }); - expect(result?.[REPORT_KEY]).not.toHaveProperty('reportName'); - }); - - it('skips undefined report entries', () => { - const reports: OnyxCollection = { - [REPORT_KEY]: {reportID: '100'} as Report, - [REPORT_KEY_2]: undefined, - }; - - const result = reportsSelector(reports); - - expect(result).toEqual({[REPORT_KEY]: {reportID: '100'}}); - }); - }); - describe('policyCategoriesSelector', () => { it('returns undefined input as-is', () => { expect(policyCategoriesSelector(undefined)).toBeUndefined();