From 082f161060f489fa33124a977c63a45b15a3df2e Mon Sep 17 00:00:00 2001 From: Samran Ahmed Date: Fri, 20 Mar 2026 04:14:36 +0500 Subject: [PATCH 1/6] Refactor export template handling to include both standard and integration custom templates in filter options --- src/hooks/useExportedToFilterOptions.ts | 16 +++++++++------- .../SearchFiltersExportedToPage.tsx | 14 +++++--------- 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/src/hooks/useExportedToFilterOptions.ts b/src/hooks/useExportedToFilterOptions.ts index 36666e02e8f0..f2b06cd95753 100644 --- a/src/hooks/useExportedToFilterOptions.ts +++ b/src/hooks/useExportedToFilterOptions.ts @@ -63,14 +63,16 @@ export default function useExportedToFilterOptions(): UseExportedToFilterDataRes const combinedUniqueExportTemplates = Array.from(uniqueExportTemplatesByName.values()); - const standardExportTemplates: string[] = []; + const standardAndCustomExportTemplates: string[] = []; for (const template of combinedUniqueExportTemplates) { - const displayName = getStandardExportTemplateDisplayName(template.templateName); - const isStandardTemplate = displayName !== template.templateName; - - if (isStandardTemplate) { - standardExportTemplates.push(displayName); + // Classic export formats map to in-app templates and cannot be identified in exported-to filter. + if (template.type === CONST.EXPORT_TEMPLATE_TYPES.IN_APP) { + continue; } + + const standardExportTemplateDisplayName = getStandardExportTemplateDisplayName(template.templateName); + const filterValue = standardExportTemplateDisplayName !== template.templateName ? standardExportTemplateDisplayName : (template.name ?? template.templateName); + standardAndCustomExportTemplates.push(filterValue); } const connectedIntegrationNames = policyIDs && policyIDs.length === 0 ? new Set() : getConnectedIntegrationNamesForPolicies(policies, policyIDs); @@ -84,7 +86,7 @@ export default function useExportedToFilterOptions(): UseExportedToFilterDataRes return connectionName && connectedIntegrationNames.has(connectionName); }); - const exportedToFilterOptions = [...connectedIntegrationDisplayNames, ...standardExportTemplates]; + const exportedToFilterOptions = [...new Set([...connectedIntegrationDisplayNames, ...standardAndCustomExportTemplates])]; return { exportedToFilterOptions, diff --git a/src/pages/Search/SearchAdvancedFiltersPage/SearchFiltersExportedToPage.tsx b/src/pages/Search/SearchAdvancedFiltersPage/SearchFiltersExportedToPage.tsx index 7a028f1132e3..dc5de3843dd3 100644 --- a/src/pages/Search/SearchAdvancedFiltersPage/SearchFiltersExportedToPage.tsx +++ b/src/pages/Search/SearchAdvancedFiltersPage/SearchFiltersExportedToPage.tsx @@ -96,27 +96,23 @@ function SearchFiltersExportedToPage() { } const deduplicatedExportTemplates = Array.from(exportTemplatesByTemplateId.values()); - const standardExportTemplatePickerItems: SearchMultipleSelectionPickerItem[] = []; + const standardAndIntegrationCustomTemplatePickerItems: SearchMultipleSelectionPickerItem[] = []; for (const template of deduplicatedExportTemplates) { - if (!template.templateName || integrationConnectionNamesSet.has(template.templateName)) { - continue; - } - - if (!STANDARD_EXPORT_TEMPLATE_ID_TO_DISPLAY_LABEL[template.templateName]) { + if (!template.templateName || integrationConnectionNamesSet.has(template.templateName) || template.type === CONST.EXPORT_TEMPLATE_TYPES.IN_APP) { continue; } const displayName = template.name ?? template.templateName ?? ''; - const filterValue = STANDARD_EXPORT_TEMPLATE_ID_TO_DISPLAY_LABEL[template.templateName] ?? template.templateName; - standardExportTemplatePickerItems.push({ + const filterValue = STANDARD_EXPORT_TEMPLATE_ID_TO_DISPLAY_LABEL[template.templateName] ?? displayName; + standardAndIntegrationCustomTemplatePickerItems.push({ name: displayName, value: filterValue, leftElement: tableIconForExportOption, }); } - return [...connectedIntegrationPickerItems, ...standardExportTemplatePickerItems]; + return [...connectedIntegrationPickerItems, ...standardAndIntegrationCustomTemplatePickerItems]; })(); const initiallySelectedPickerItems: SearchMultipleSelectionPickerItem[] | undefined = (() => { From 46230cf951b7dc3273089f9f01995e96182f1b67 Mon Sep 17 00:00:00 2001 From: Samran Ahmed Date: Fri, 20 Mar 2026 04:14:56 +0500 Subject: [PATCH 2/6] Update export template tests to include integration custom templates and exclude in-app templates --- .../unit/hooks/useExportedToFilterOptions.test.ts | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/tests/unit/hooks/useExportedToFilterOptions.test.ts b/tests/unit/hooks/useExportedToFilterOptions.test.ts index 2dab1601c775..e9525d0ca436 100644 --- a/tests/unit/hooks/useExportedToFilterOptions.test.ts +++ b/tests/unit/hooks/useExportedToFilterOptions.test.ts @@ -59,13 +59,22 @@ describe('useExportedToFilterOptions', () => { expect(result.current.connectedIntegrationNames).toContain(CONST.POLICY.CONNECTIONS.NAME.QBO); }); - it('excludes custom template name from options when getExportTemplates returns custom template', () => { + it('includes integration custom template name from options when getExportTemplates returns integration template', () => { const customName = 'Export Layout'; - mockGetExportTemplates.mockReturnValue([{templateName: customName, name: customName} as ExportTemplate]); + mockGetExportTemplates.mockReturnValue([{templateName: customName, name: customName, type: CONST.EXPORT_TEMPLATE_TYPES.INTEGRATIONS} as ExportTemplate]); const {result} = renderHook(() => useExportedToFilterOptions()); - expect(result.current.exportedToFilterOptions).not.toContain(customName); + expect(result.current.exportedToFilterOptions).toContain(customName); + }); + + it('excludes in-app custom templates from options', () => { + const templateName = 'Custom Export Format from OD'; + mockGetExportTemplates.mockReturnValue([{templateName, name: templateName, type: CONST.EXPORT_TEMPLATE_TYPES.IN_APP} as ExportTemplate]); + + const {result} = renderHook(() => useExportedToFilterOptions()); + + expect(result.current.exportedToFilterOptions).not.toContain(templateName); }); it('includes standard export label in options when getExportTemplates returns standard template', () => { From 2de7ed8aafaa92912802636e58d0d2772e02b102 Mon Sep 17 00:00:00 2001 From: Samran Ahmed Date: Fri, 20 Mar 2026 23:01:37 +0500 Subject: [PATCH 3/6] dedupe Exported To picker items by value --- .../SearchFiltersExportedToPage.tsx | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/pages/Search/SearchAdvancedFiltersPage/SearchFiltersExportedToPage.tsx b/src/pages/Search/SearchAdvancedFiltersPage/SearchFiltersExportedToPage.tsx index dc5de3843dd3..c01ca31db189 100644 --- a/src/pages/Search/SearchAdvancedFiltersPage/SearchFiltersExportedToPage.tsx +++ b/src/pages/Search/SearchAdvancedFiltersPage/SearchFiltersExportedToPage.tsx @@ -46,6 +46,8 @@ function SearchFiltersExportedToPage() { const selectedExportedToValues = searchAdvancedFiltersForm?.exportedTo ?? []; const connectedIntegrationNames = getConnectedIntegrationNamesForPolicies(policies, policyIDs.length > 0 ? policyIDs : undefined); + const getPickerItemValueKey = (value: SearchMultipleSelectionPickerItem['value']): string => (typeof value === 'string' ? value : (value.at(0) ?? '')); + const tableIconForExportOption = ( getPickerItemValueKey(item.value))); const policiesToLoadTemplatesFrom = policyIDs.length > 0 ? policyIDs.map((id) => policies?.[`${ONYXKEYS.COLLECTION.POLICY}${id}`]).filter(Boolean) : Object.values(policies ?? {}); const exportTemplatesFromPolicies = policiesToLoadTemplatesFrom.flatMap((policy) => getExportTemplates([], {}, translate, policy, false)); const exportTemplatesFromAccount = getExportTemplates(integrationsExportTemplates ?? [], csvExportLayouts ?? {}, translate, undefined, true); @@ -105,6 +108,12 @@ function SearchFiltersExportedToPage() { const displayName = template.name ?? template.templateName ?? ''; const filterValue = STANDARD_EXPORT_TEMPLATE_ID_TO_DISPLAY_LABEL[template.templateName] ?? displayName; + const filterValueKey = getPickerItemValueKey(filterValue); + if (usedPickerValueKeys.has(filterValueKey)) { + continue; + } + + usedPickerValueKeys.add(filterValueKey); standardAndIntegrationCustomTemplatePickerItems.push({ name: displayName, value: filterValue, @@ -121,12 +130,10 @@ function SearchFiltersExportedToPage() { } const normalizedSelectedValues = new Set(selectedExportedToValues); const selectedOptionsPresentInCurrentList = exportedToPickerOptions.filter((option) => { - const optionValue = typeof option.value === 'string' ? option.value : (option.value.at(0) ?? ''); + const optionValue = getPickerItemValueKey(option.value); return normalizedSelectedValues.has(optionValue); }); - const selectedValueIdsFoundInCurrentOptions = new Set( - selectedOptionsPresentInCurrentList.map((option) => (typeof option.value === 'string' ? option.value : (option.value.at(0) ?? ''))), - ); + const selectedValueIdsFoundInCurrentOptions = new Set(selectedOptionsPresentInCurrentList.map((option) => getPickerItemValueKey(option.value))); const unavailableSelectedValues = selectedExportedToValues.filter((value) => !selectedValueIdsFoundInCurrentOptions.has(value)); const unavailableSelectedOptions: SearchMultipleSelectionPickerItem[] = unavailableSelectedValues.map((value) => { const connectionName = integrationConnectionNames.find((name) => CONST.POLICY.CONNECTIONS.NAME_USER_FRIENDLY[name] === value); From 71cd3f1c0e74e0cc035f6d2cceebf000abad91ee Mon Sep 17 00:00:00 2001 From: Samran Ahmed Date: Fri, 20 Mar 2026 23:43:55 +0500 Subject: [PATCH 4/6] Add integration connection templates exclusion to exported-to filter options --- src/hooks/useExportedToFilterOptions.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/hooks/useExportedToFilterOptions.ts b/src/hooks/useExportedToFilterOptions.ts index f2b06cd95753..4654e2c653ae 100644 --- a/src/hooks/useExportedToFilterOptions.ts +++ b/src/hooks/useExportedToFilterOptions.ts @@ -62,11 +62,12 @@ export default function useExportedToFilterOptions(): UseExportedToFilterDataRes } const combinedUniqueExportTemplates = Array.from(uniqueExportTemplatesByName.values()); + const integrationConnectionNamesSet = new Set(Object.values(CONST.POLICY.CONNECTIONS.NAME)); const standardAndCustomExportTemplates: string[] = []; for (const template of combinedUniqueExportTemplates) { // Classic export formats map to in-app templates and cannot be identified in exported-to filter. - if (template.type === CONST.EXPORT_TEMPLATE_TYPES.IN_APP) { + if (template.type === CONST.EXPORT_TEMPLATE_TYPES.IN_APP || integrationConnectionNamesSet.has(template.templateName)) { continue; } From d7b022a37d7a2a5c544231e2ddf15d64b429965c Mon Sep 17 00:00:00 2001 From: Samran Ahmed Date: Fri, 20 Mar 2026 23:45:40 +0500 Subject: [PATCH 5/6] Add test to exclude integration templates matching connection keys from options --- tests/unit/hooks/useExportedToFilterOptions.test.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/unit/hooks/useExportedToFilterOptions.test.ts b/tests/unit/hooks/useExportedToFilterOptions.test.ts index e9525d0ca436..b2d55f510e51 100644 --- a/tests/unit/hooks/useExportedToFilterOptions.test.ts +++ b/tests/unit/hooks/useExportedToFilterOptions.test.ts @@ -77,6 +77,16 @@ describe('useExportedToFilterOptions', () => { expect(result.current.exportedToFilterOptions).not.toContain(templateName); }); + it('excludes templates whose templateName matches integration connection key', () => { + const templateName = CONST.POLICY.CONNECTIONS.NAME.QBO; + const templateDisplayName = 'QBO Custom Template'; + mockGetExportTemplates.mockReturnValue([{templateName, name: templateDisplayName, type: CONST.EXPORT_TEMPLATE_TYPES.INTEGRATIONS} as ExportTemplate]); + + const {result} = renderHook(() => useExportedToFilterOptions()); + + expect(result.current.exportedToFilterOptions).not.toContain(templateDisplayName); + }); + it('includes standard export label in options when getExportTemplates returns standard template', () => { mockGetExportTemplates.mockReturnValue([{templateName: CONST.REPORT.EXPORT_OPTIONS.EXPENSE_LEVEL_EXPORT, name: expenseLevelLabel} as ExportTemplate]); From 06aef76f83370183ef6e79e76823f489054537bd Mon Sep 17 00:00:00 2001 From: Samran Ahmed Date: Mon, 23 Mar 2026 19:50:05 +0500 Subject: [PATCH 6/6] Refactor getPickerItemValueKey function to move at top --- .../SearchFiltersExportedToPage.tsx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/pages/Search/SearchAdvancedFiltersPage/SearchFiltersExportedToPage.tsx b/src/pages/Search/SearchAdvancedFiltersPage/SearchFiltersExportedToPage.tsx index c01ca31db189..b90fc5e68708 100644 --- a/src/pages/Search/SearchAdvancedFiltersPage/SearchFiltersExportedToPage.tsx +++ b/src/pages/Search/SearchAdvancedFiltersPage/SearchFiltersExportedToPage.tsx @@ -29,6 +29,10 @@ const STANDARD_EXPORT_TEMPLATE_ID_TO_DISPLAY_LABEL: Record = { [CONST.REPORT.EXPORT_OPTIONS.EXPENSE_LEVEL_EXPORT]: CONST.REPORT.EXPORT_OPTION_LABELS.EXPENSE_LEVEL_EXPORT, }; +function getPickerItemValueKey(value: SearchMultipleSelectionPickerItem['value']): string { + return typeof value === 'string' ? value : (value.at(0) ?? ''); +} + function SearchFiltersExportedToPage() { const styles = useThemeStyles(); const {translate} = useLocalize(); @@ -46,8 +50,6 @@ function SearchFiltersExportedToPage() { const selectedExportedToValues = searchAdvancedFiltersForm?.exportedTo ?? []; const connectedIntegrationNames = getConnectedIntegrationNamesForPolicies(policies, policyIDs.length > 0 ? policyIDs : undefined); - const getPickerItemValueKey = (value: SearchMultipleSelectionPickerItem['value']): string => (typeof value === 'string' ? value : (value.at(0) ?? '')); - const tableIconForExportOption = (