Skip to content
Merged
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
2 changes: 2 additions & 0 deletions src/CONST/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1957,10 +1957,12 @@ const CONST = {
DOWNLOAD_CSV: 'downloadCSV',
REPORT_LEVEL_EXPORT: 'report_level_export',
EXPENSE_LEVEL_EXPORT: 'detailed_export',
MULTIPLE_TAX_EXPORT: 'multiple_tax_export',
},
EXPORT_OPTION_LABELS: {
REPORT_LEVEL_EXPORT: 'All Data - Report Level Export',
EXPENSE_LEVEL_EXPORT: 'All Data - Expense Level Export',
MULTIPLE_TAX_EXPORT: 'Canadian Multiple Tax Export',
DEFAULT_CSV: 'Default CSV',
},
ROOM_MEMBERS_BULK_ACTION_TYPES: {
Expand Down
13 changes: 5 additions & 8 deletions src/components/Search/FilterComponents/ExportedToSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import useStyleUtils from '@hooks/useStyleUtils';
import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';

import {getSearchValueForConnection} from '@libs/AccountingUtils';
import {getSearchValueForConnection, getStandardExportTemplateDisplayName, isStandardExportTemplate} from '@libs/AccountingUtils';
import {getIntegrationIcon} from '@libs/ReportUtils';
import {getAllPolicyValues, getConnectedIntegrationNamesForPolicies} from '@libs/SearchQueryUtils';

Expand All @@ -28,11 +28,6 @@ type ExportedToSelectorProps = SearchFilterCommonProps<string[] | undefined> & {
policyID: Filter | undefined;
};

const STANDARD_EXPORT_TEMPLATE_ID_TO_DISPLAY_LABEL: Record<string, string> = {
[CONST.REPORT.EXPORT_OPTIONS.REPORT_LEVEL_EXPORT]: CONST.REPORT.EXPORT_OPTION_LABELS.REPORT_LEVEL_EXPORT,
[CONST.REPORT.EXPORT_OPTIONS.EXPENSE_LEVEL_EXPORT]: CONST.REPORT.EXPORT_OPTION_LABELS.EXPENSE_LEVEL_EXPORT,
};

function ExportedToSelector({value = [], policyID, selectionListTextInputStyle, selectionListStyle, autoFocus, footer, onChange}: ExportedToSelectorProps) {
const styles = useThemeStyles();
const {localeCompare} = useLocalize();
Expand Down Expand Up @@ -106,13 +101,15 @@ function ExportedToSelector({value = [], policyID, selectionListTextInputStyle,
}

const displayName = template.name ?? template.templateName ?? '';
const filterValue = STANDARD_EXPORT_TEMPLATE_ID_TO_DISPLAY_LABEL[template.templateName] ?? displayName;

// Standard templates are filtered on by the label the backend records for them, while custom templates are filtered on by their display name
Comment thread
dukenv0307 marked this conversation as resolved.
Resolved
const isStandardTemplate = isStandardExportTemplate(template.templateName);
const filterValue = isStandardTemplate ? getStandardExportTemplateDisplayName(template.templateName) : displayName;
if (usedPickerValueKeys.has(filterValue)) {
continue;
}

usedPickerValueKeys.add(filterValue);
const isStandardTemplate = !!STANDARD_EXPORT_TEMPLATE_ID_TO_DISPLAY_LABEL[template.templateName];
standardAndIntegrationCustomTemplatePickerItems.push({
text: displayName,
value: filterValue,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {useMemoizedLazyExpensifyIcons} from '@hooks/useLazyAsset';
import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';

import {isStandardExportTemplateLabel} from '@libs/AccountingUtils';
import {getOriginalMessage, isExportedToIntegrationAction} from '@libs/ReportActionsUtils';

import CONST from '@src/CONST';
Expand All @@ -17,8 +18,6 @@ type ExportedIconCellProps = {
reportActions?: ReportAction[];
};

const STANDARD_EXPORT_TEMPLATE_LABELS = new Set<string>([CONST.REPORT.EXPORT_OPTION_LABELS.EXPENSE_LEVEL_EXPORT, CONST.REPORT.EXPORT_OPTION_LABELS.REPORT_LEVEL_EXPORT]);

function ExportedIconCell({reportActions}: ExportedIconCellProps) {
const theme = useTheme();
const styles = useThemeStyles();
Expand Down Expand Up @@ -60,7 +59,7 @@ function ExportedIconCell({reportActions}: ExportedIconCellProps) {
const message = getOriginalMessage(action);
const label = message?.label;
const type = message?.type;
const isStandardExportTemplate = !!label && STANDARD_EXPORT_TEMPLATE_LABELS.has(label);
const isStandardExportTemplate = !!label && isStandardExportTemplateLabel(label);

if (type === CONST.EXPORT_TEMPLATE && isStandardExportTemplate) {
isExportedToStandardTemplate = true;
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/useExportedToFilterOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function exportedToPoliciesSelector(policies: OnyxCollection<Policy>): OnyxColle
if (!policy) {
continue;
}
result[key] = {id: policy.id, name: policy.name, connections: policy.connections, exportLayouts: policy.exportLayouts} as Policy;
result[key] = {id: policy.id, name: policy.name, connections: policy.connections, exportLayouts: policy.exportLayouts, outputCurrency: policy.outputCurrency} as Policy;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR introduced a regression: #103030

The Canadian Multiple Tax Export template is gated on the outputCurrency of the policies returned by useExportedToFilterOptions. Those policies come from the last submitted search (currentSearchQueryJSON), not from the query being typed.

So with a USD workspace and a CAD workspace, typing workspace:"USD WS" exported-to: before submitting still suggests the CAD-only template. The scope falls back to all workspaces, and one of them is CAD.

Fixed in #106174

}
return result;
}
Expand Down
25 changes: 24 additions & 1 deletion src/hooks/useSearchBulkActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ import {
isSelfDM,
shouldShowMarkAsDone,
} from '@libs/ReportUtils';
import {buildSearchQueryJSON, buildSearchQueryString, isDefaultExpensesQuery, serializeQueryJSONForBackend} from '@libs/SearchQueryUtils';
import {buildSearchQueryJSON, buildSearchQueryString, getFilterFromQuery, isDefaultExpensesQuery, serializeQueryJSONForBackend} from '@libs/SearchQueryUtils';
import {getColumnsToShow, getSearchColumnTranslationKey, getSelectedGroupFilterEntry, getValidGroupBy, isGroupEntry, navigateToSearchRHP, shouldShowDeleteOption} from '@libs/SearchUIUtils';
import showConfirmModalAfterMoreMenuDismiss from '@libs/showConfirmModalAfterMoreMenuDismiss';
import playSound, {SOUNDS} from '@libs/Sound';
Expand Down Expand Up @@ -572,6 +572,27 @@ function useSearchBulkActions({queryJSON}: UseSearchBulkActionsParams) {
],
[selectedTransactions],
);

// A bulk selection can span several workspaces, so the Canadian Multiple Tax Export template is only offered when every selected item belongs to a workspace that outputs in CAD.
// Reports and transactions are both checked because a selection can mix whole reports with individual transactions from other reports, and the export request covers all of them.
const doAllSelectedItemsBelongToCADPolicies = useMemo(() => {
if (areAllMatchingItemsSelected) {
const policyIDFilter = getFilterFromQuery(queryJSON, CONST.SEARCH.SYNTAX_FILTER_KEYS.POLICY_ID);
if (!policyIDFilter.value?.length || policyIDFilter.isNegated) {
return false;
}

return policyIDFilter.value.every((policyID) => policies?.[`${ONYXKEYS.COLLECTION.POLICY}${policyID}`]?.outputCurrency === CONST.CURRENCY.CAD);
}

const selectedItems = [...selectedReports, ...Object.values(selectedTransactions)];
if (selectedItems.length === 0) {
return false;
}

return selectedItems.every((item) => !!item.policyID && policies?.[`${ONYXKEYS.COLLECTION.POLICY}${item.policyID}`]?.outputCurrency === CONST.CURRENCY.CAD);
Comment thread
dukenv0307 marked this conversation as resolved.
Resolved
}, [areAllMatchingItemsSelected, queryJSON, selectedReports, selectedTransactions, policies]);

const selectedBulkCurrency = selectedReports.at(0)?.currency ?? Object.values(selectedTransactions).at(0)?.currency;
const totalFormattedAmount = getTotalFormattedAmount(convertToDisplayString, selectedReports, selectedTransactions, selectedBulkCurrency);

Expand Down Expand Up @@ -1688,6 +1709,7 @@ function useSearchBulkActions({queryJSON}: UseSearchBulkActionsParams) {
policy,
includeReportLevelExport,
!isGroupedSearch,
doAllSelectedItemsBelongToCADPolicies,
);
const shouldHideTemplateExports = isExpenseType && areAllMatchingItemsSelected && Object.keys(excludedTransactions).length > 0;
const availableCustomTemplates = shouldHideTemplateExports
Expand Down Expand Up @@ -2507,6 +2529,7 @@ function useSearchBulkActions({queryJSON}: UseSearchBulkActionsParams) {
personalPolicy?.outputCurrency,
restrictedActionPolicyID,
doSelectedItemsBelongToSubmitPolicy,
doAllSelectedItemsBelongToCADPolicies,
openSearchReportSubmitToPopover,
deleteTransactionsFromHook,
duplicateTransactionViolations,
Expand Down
1 change: 1 addition & 0 deletions src/languages/de.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10393,6 +10393,7 @@ Hier ist ein *Testbeleg*, um dir zu zeigen, wie es funktioniert:`,
basicExport: 'Standardexport',
reportLevelExport: 'Alle Daten – Berichtsebene',
expenseLevelExport: 'Alle Daten – Ausgabenebene',
multipleTaxExport: 'Kanadischer Export mit mehreren Steuern',
exportInProgress: 'Export wird ausgeführt',
conciergeWillSend: 'Concierge wird dir die Datei in Kürze senden.',
currentView: 'Aktuelle Ansicht',
Expand Down
1 change: 1 addition & 0 deletions src/languages/el.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10610,6 +10610,7 @@ ${reportName}`,
currentView: 'Τρέχουσα προβολή',
reportLevelExport: 'Όλα τα δεδομένα - σε επίπεδο αναφοράς',
expenseLevelExport: 'Όλα τα δεδομένα - επίπεδο δαπάνης',
multipleTaxExport: 'Καναδική εξαγωγή πολλαπλών φόρων',
exportInProgress: 'Εξαγωγή σε εξέλιξη',
conciergeWillSend: 'Ο Concierge θα σας στείλει το αρχείο σύντομα.',
downloadStatementPDF: 'Λήψη κατάστασης',
Expand Down
1 change: 1 addition & 0 deletions src/languages/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10548,6 +10548,7 @@ const translations = {
currentView: 'Current view',
reportLevelExport: 'All Data - report level',
expenseLevelExport: 'All Data - expense level',
multipleTaxExport: 'Canadian Multiple Tax Export',
exportInProgress: 'Export in progress',
conciergeWillSend: 'Concierge will send you the file shortly.',
},
Expand Down
1 change: 1 addition & 0 deletions src/languages/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10590,6 +10590,7 @@ El plan Controlar empieza en 9 $ por miembro activo al mes.`,
basicExport: 'Exportar básico',
reportLevelExport: 'Todos los datos - a nivel de informe',
expenseLevelExport: 'Todos los datos - a nivel de gasto',
multipleTaxExport: 'Exportación canadiense de impuestos múltiples',
exportInProgress: 'Exportación en curso',
conciergeWillSend: 'Concierge te enviará el archivo en breve.',
currentView: 'Vista actual',
Expand Down
1 change: 1 addition & 0 deletions src/languages/fr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10427,6 +10427,7 @@ Voici un *reçu test* pour vous montrer comment ça fonctionne :`,
basicExport: 'Export basique',
reportLevelExport: 'Toutes les données - niveau note de frais',
expenseLevelExport: 'Toutes les données - niveau dépense',
multipleTaxExport: 'Export canadien à taxes multiples',
exportInProgress: 'Export en cours',
conciergeWillSend: 'Concierge vous enverra le fichier sous peu.',
currentView: 'Vue actuelle',
Expand Down
1 change: 1 addition & 0 deletions src/languages/it.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10364,6 +10364,7 @@ Ecco una *ricevuta di prova* per mostrarti come funziona:`,
basicExport: 'Esportazione di base',
reportLevelExport: 'Tutti i dati - livello report',
expenseLevelExport: 'Tutti i dati - livello spesa',
multipleTaxExport: 'Esportazione canadese con imposte multiple',
exportInProgress: 'Esportazione in corso',
conciergeWillSend: 'Concierge ti invierà il file a breve.',
currentView: 'Vista corrente',
Expand Down
1 change: 1 addition & 0 deletions src/languages/ja.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10227,6 +10227,7 @@ ${reportName}`,
basicExport: '基本エクスポート',
reportLevelExport: 'すべてのデータ - レポートレベル',
expenseLevelExport: 'すべてのデータ - 経費レベル',
multipleTaxExport: 'カナダの複数税エクスポート',
exportInProgress: 'エクスポート処理中',
conciergeWillSend: 'Conciergeがまもなくファイルを送信します。',
currentView: '現在のビュー',
Expand Down
1 change: 1 addition & 0 deletions src/languages/nl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10335,6 +10335,7 @@ Hier is een *proefbon* om je te laten zien hoe het werkt:`,
basicExport: 'Standaardexport',
reportLevelExport: 'Alle gegevens - rapportniveau',
expenseLevelExport: 'Alle gegevens - uitgaveniveau',
multipleTaxExport: 'Canadese export met meerdere belastingen',
exportInProgress: 'Export bezig',
conciergeWillSend: 'Concierge stuurt je het bestand zo meteen.',
currentView: 'Huidige weergave',
Expand Down
1 change: 1 addition & 0 deletions src/languages/pl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10304,6 +10304,7 @@ Oto *paragon testowy*, żeby pokazać Ci, jak to działa:`,
basicExport: 'Podstawowy eksport',
reportLevelExport: 'Wszystkie dane – poziom raportu',
expenseLevelExport: 'Wszystkie dane – poziom wydatku',
multipleTaxExport: 'Kanadyjski eksport z wieloma podatkami',
exportInProgress: 'Trwa eksport',
conciergeWillSend: 'Concierge wkrótce wyśle Ci plik.',
currentView: 'Bieżący widok',
Expand Down
1 change: 1 addition & 0 deletions src/languages/pt-BR.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10328,6 +10328,7 @@ Aqui está um *comprovante de teste* para mostrar como funciona:`,
basicExport: 'Exportação básica',
reportLevelExport: 'Todos os dados - nível de relatório',
expenseLevelExport: 'Todos os dados - nível de despesa',
multipleTaxExport: 'Exportação canadense de múltiplos impostos',
exportInProgress: 'Exportação em andamento',
conciergeWillSend: 'O Concierge enviará o arquivo para você em breve.',
currentView: 'Visualização atual',
Expand Down
1 change: 1 addition & 0 deletions src/languages/zh-hans.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9979,6 +9979,7 @@ ${reportName}`,
basicExport: '基本导出',
reportLevelExport: '所有数据 - 报告级别',
expenseLevelExport: '所有数据 - 报销级别',
multipleTaxExport: '加拿大多种税导出',
exportInProgress: '导出进行中',
conciergeWillSend: 'Concierge 将很快把文件发送给你。',
currentView: '当前视图',
Expand Down
22 changes: 21 additions & 1 deletion src/libs/AccountingUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,11 @@ const NAME_ROUTE_MAPPING = {
const STANDARD_EXPORT_TEMPLATE_NAME_MAPPING = {
[CONST.REPORT.EXPORT_OPTIONS.EXPENSE_LEVEL_EXPORT]: CONST.REPORT.EXPORT_OPTION_LABELS.EXPENSE_LEVEL_EXPORT,
[CONST.REPORT.EXPORT_OPTIONS.REPORT_LEVEL_EXPORT]: CONST.REPORT.EXPORT_OPTION_LABELS.REPORT_LEVEL_EXPORT,
[CONST.REPORT.EXPORT_OPTIONS.MULTIPLE_TAX_EXPORT]: CONST.REPORT.EXPORT_OPTION_LABELS.MULTIPLE_TAX_EXPORT,
};

const STANDARD_EXPORT_TEMPLATE_LABELS = new Set<string>(Object.values(STANDARD_EXPORT_TEMPLATE_NAME_MAPPING));

function getConnectionNameFromRouteParam(routeParam: ValueOf<typeof CONST.POLICY.CONNECTIONS.ROUTE>) {
return ROUTE_NAME_MAPPING[routeParam];
}
Expand All @@ -52,4 +55,21 @@ function getStandardExportTemplateDisplayName(templateName: string): string {
return STANDARD_EXPORT_TEMPLATE_NAME_MAPPING[templateName as keyof typeof STANDARD_EXPORT_TEMPLATE_NAME_MAPPING] ?? templateName;
}

export {getConnectionNameFromRouteParam, getRouteParamForConnection, getSearchValueForConnection, getStandardExportTemplateDisplayName};
/** Whether the given template ID belongs to one of the standard (i.e. not user-defined) export templates */
function isStandardExportTemplate(templateName: string): boolean {
return templateName in STANDARD_EXPORT_TEMPLATE_NAME_MAPPING;
}

/** Whether the given export label, as sent by the backend on an export report action, belongs to one of the standard (i.e. not user-defined) export templates */
function isStandardExportTemplateLabel(label: string): boolean {
return STANDARD_EXPORT_TEMPLATE_LABELS.has(label);
}

export {
getConnectionNameFromRouteParam,
getRouteParamForConnection,
getSearchValueForConnection,
getStandardExportTemplateDisplayName,
isStandardExportTemplate,
isStandardExportTemplateLabel,
};
10 changes: 3 additions & 7 deletions src/libs/SearchQueryUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ import Onyx from 'react-native-onyx';

import type {SearchFullscreenNavigatorParamList} from './Navigation/types';

import {getStandardExportTemplateDisplayName} from './AccountingUtils';
import {getBankAccountSearchLabel, isBankAccountPartiallySetup} from './BankAccountUtils';
import {getCardFeedsForDisplay} from './CardFeedUtils';
import {getCardDescription} from './CardUtils';
Expand Down Expand Up @@ -1756,13 +1757,8 @@ function getFilterDisplayValue({
return getPolicyNameWithFallback(filterValue, policies, reports);
}
if (filterName === CONST.SEARCH.SYNTAX_FILTER_KEYS.EXPORTED_TO) {
if (filterValue === CONST.REPORT.EXPORT_OPTIONS.REPORT_LEVEL_EXPORT) {
return CONST.REPORT.EXPORT_OPTION_LABELS.REPORT_LEVEL_EXPORT;
}
if (filterValue === CONST.REPORT.EXPORT_OPTIONS.EXPENSE_LEVEL_EXPORT) {
return CONST.REPORT.EXPORT_OPTION_LABELS.EXPENSE_LEVEL_EXPORT;
}
return filterValue;
// A query can carry a standard template's ID, so display the label the backend records for it. Custom template names are returned as-is.
return getStandardExportTemplateDisplayName(filterValue);
}
return filterValue;
}
Expand Down
8 changes: 8 additions & 0 deletions src/libs/actions/Search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1775,6 +1775,8 @@ type ExportTemplateGroups = {
* @param policy - The user's policy
* @param includeReportLevelExport - Whether to include the report level export template
* @param includeBasicExport - Whether to include the basic export (CSV download) template in the default group
* @param includeMultipleTaxExport - Whether to include the Canadian Multiple Tax Export template. Defaults to whether the given policy outputs in CAD, so callers that
* export across several workspaces (e.g. a bulk selection in Search) can instead pass whether every selected workspace outputs in CAD.
* @returns The export templates pre-grouped into the custom group and the default group, each sorted alphabetically
*/
function getExportTemplates(
Expand All @@ -1785,6 +1787,7 @@ function getExportTemplates(
policy?: Policy,
includeReportLevelExport = true,
includeBasicExport = false,
includeMultipleTaxExport = policy?.outputCurrency === CONST.CURRENCY.CAD,
): ExportTemplateGroups {
// Helper function to normalize template data into consistent ExportTemplate format
const normalizeTemplate = (
Expand All @@ -1811,6 +1814,11 @@ function getExportTemplates(
exportTemplates.push(normalizeTemplate(CONST.REPORT.EXPORT_OPTIONS.REPORT_LEVEL_EXPORT, {name: translate('export.reportLevelExport')}, CONST.EXPORT_TEMPLATE_TYPES.INTEGRATIONS));
}

// The Canadian Multiple Tax Export template is only relevant to workspaces that output in CAD, so it's hidden for every other currency
if (includeMultipleTaxExport) {
exportTemplates.push(normalizeTemplate(CONST.REPORT.EXPORT_OPTIONS.MULTIPLE_TAX_EXPORT, {name: translate('export.multipleTaxExport')}, CONST.EXPORT_TEMPLATE_TYPES.INTEGRATIONS));
}

// Conditionally include the basic export (CSV download) template so it's sorted alphabetically alongside the other default templates
if (includeBasicExport) {
exportTemplates.push(normalizeTemplate(CONST.REPORT.EXPORT_OPTIONS.DOWNLOAD_CSV, {name: translate('export.basicExport')}, CONST.EXPORT_TEMPLATE_TYPES.INTEGRATIONS));
Expand Down
Loading
Loading