Skip to content

Commit ed32325

Browse files
committed
Classify Canadian export consistently in report rows
1 parent 3c14b78 commit ed32325

4 files changed

Lines changed: 51 additions & 14 deletions

File tree

src/components/Search/FilterComponents/ExportedToSelector.tsx

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import useStyleUtils from '@hooks/useStyleUtils';
99
import useTheme from '@hooks/useTheme';
1010
import useThemeStyles from '@hooks/useThemeStyles';
1111

12-
import {getSearchValueForConnection} from '@libs/AccountingUtils';
12+
import {getSearchValueForConnection, getStandardExportTemplateDisplayName, isStandardExportTemplate} from '@libs/AccountingUtils';
1313
import {getIntegrationIcon} from '@libs/ReportUtils';
1414
import {getAllPolicyValues, getConnectedIntegrationNamesForPolicies} from '@libs/SearchQueryUtils';
1515

@@ -28,12 +28,6 @@ type ExportedToSelectorProps = SearchFilterCommonProps<string[] | undefined> & {
2828
policyID: Filter | undefined;
2929
};
3030

31-
const STANDARD_EXPORT_TEMPLATE_ID_TO_DISPLAY_LABEL: Record<string, string> = {
32-
[CONST.REPORT.EXPORT_OPTIONS.REPORT_LEVEL_EXPORT]: CONST.REPORT.EXPORT_OPTION_LABELS.REPORT_LEVEL_EXPORT,
33-
[CONST.REPORT.EXPORT_OPTIONS.EXPENSE_LEVEL_EXPORT]: CONST.REPORT.EXPORT_OPTION_LABELS.EXPENSE_LEVEL_EXPORT,
34-
[CONST.REPORT.EXPORT_OPTIONS.MULTIPLE_TAX_EXPORT]: CONST.REPORT.EXPORT_OPTION_LABELS.MULTIPLE_TAX_EXPORT,
35-
};
36-
3731
function ExportedToSelector({value = [], policyID, selectionListTextInputStyle, selectionListStyle, autoFocus, footer, onChange}: ExportedToSelectorProps) {
3832
const styles = useThemeStyles();
3933
const {localeCompare} = useLocalize();
@@ -106,13 +100,14 @@ function ExportedToSelector({value = [], policyID, selectionListTextInputStyle,
106100
}
107101

108102
const displayName = template.name ?? template.templateName ?? '';
109-
const filterValue = STANDARD_EXPORT_TEMPLATE_ID_TO_DISPLAY_LABEL[template.templateName] ?? displayName;
103+
// Standard templates are filtered on by the label the backend records for them, while custom templates are filtered on by their display name
104+
const isStandardTemplate = isStandardExportTemplate(template.templateName);
105+
const filterValue = isStandardTemplate ? getStandardExportTemplateDisplayName(template.templateName) : displayName;
110106
if (usedPickerValueKeys.has(filterValue)) {
111107
continue;
112108
}
113109

114110
usedPickerValueKeys.add(filterValue);
115-
const isStandardTemplate = !!STANDARD_EXPORT_TEMPLATE_ID_TO_DISPLAY_LABEL[template.templateName];
116111
standardAndIntegrationCustomTemplatePickerItems.push({
117112
text: displayName,
118113
value: filterValue,

src/components/Search/SearchList/ListItem/ExportedIconCell.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {useMemoizedLazyExpensifyIcons} from '@hooks/useLazyAsset';
55
import useTheme from '@hooks/useTheme';
66
import useThemeStyles from '@hooks/useThemeStyles';
77

8+
import {isStandardExportTemplateLabel} from '@libs/AccountingUtils';
89
import {getOriginalMessage, isExportedToIntegrationAction} from '@libs/ReportActionsUtils';
910

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

20-
const STANDARD_EXPORT_TEMPLATE_LABELS = new Set<string>([CONST.REPORT.EXPORT_OPTION_LABELS.EXPENSE_LEVEL_EXPORT, CONST.REPORT.EXPORT_OPTION_LABELS.REPORT_LEVEL_EXPORT]);
21-
2221
function ExportedIconCell({reportActions}: ExportedIconCellProps) {
2322
const theme = useTheme();
2423
const styles = useThemeStyles();
@@ -58,7 +57,7 @@ function ExportedIconCell({reportActions}: ExportedIconCellProps) {
5857
const message = getOriginalMessage(action);
5958
const label = message?.label;
6059
const type = message?.type;
61-
const isStandardExportTemplate = !!label && STANDARD_EXPORT_TEMPLATE_LABELS.has(label);
60+
const isStandardExportTemplate = !!label && isStandardExportTemplateLabel(label);
6261

6362
if (type === CONST.EXPORT_TEMPLATE && isStandardExportTemplate) {
6463
isExportedToStandardTemplate = true;

src/libs/AccountingUtils.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ const STANDARD_EXPORT_TEMPLATE_NAME_MAPPING = {
3535
[CONST.REPORT.EXPORT_OPTIONS.MULTIPLE_TAX_EXPORT]: CONST.REPORT.EXPORT_OPTION_LABELS.MULTIPLE_TAX_EXPORT,
3636
};
3737

38+
const STANDARD_EXPORT_TEMPLATE_LABELS = new Set<string>(Object.values(STANDARD_EXPORT_TEMPLATE_NAME_MAPPING));
39+
3840
function getConnectionNameFromRouteParam(routeParam: ValueOf<typeof CONST.POLICY.CONNECTIONS.ROUTE>) {
3941
return ROUTE_NAME_MAPPING[routeParam];
4042
}
@@ -51,4 +53,21 @@ function getStandardExportTemplateDisplayName(templateName: string): string {
5153
return STANDARD_EXPORT_TEMPLATE_NAME_MAPPING[templateName as keyof typeof STANDARD_EXPORT_TEMPLATE_NAME_MAPPING] ?? templateName;
5254
}
5355

54-
export {getConnectionNameFromRouteParam, getRouteParamForConnection, getSearchValueForConnection, getStandardExportTemplateDisplayName};
56+
/** Whether the given template ID belongs to one of the standard (i.e. not user-defined) export templates */
57+
function isStandardExportTemplate(templateName: string): boolean {
58+
return templateName in STANDARD_EXPORT_TEMPLATE_NAME_MAPPING;
59+
}
60+
61+
/** 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 */
62+
function isStandardExportTemplateLabel(label: string): boolean {
63+
return STANDARD_EXPORT_TEMPLATE_LABELS.has(label);
64+
}
65+
66+
export {
67+
getConnectionNameFromRouteParam,
68+
getRouteParamForConnection,
69+
getSearchValueForConnection,
70+
getStandardExportTemplateDisplayName,
71+
isStandardExportTemplate,
72+
isStandardExportTemplateLabel,
73+
};

tests/unit/SearchAutocompleteUtilsTest.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type {SubstitutionMap} from '@components/Search/SearchRouter/getQueryWithSubstitutions';
22

3-
import {getSearchValueForConnection, getStandardExportTemplateDisplayName} from '@libs/AccountingUtils';
3+
import {getSearchValueForConnection, getStandardExportTemplateDisplayName, isStandardExportTemplate, isStandardExportTemplateLabel} from '@libs/AccountingUtils';
44
import {getTrimmedUserSearchQueryPreservingComma, parseForLiveMarkdown} from '@libs/SearchAutocompleteUtils';
55

66
import CONST from '@src/CONST';
@@ -563,5 +563,29 @@ describe('SearchAutocompleteUtils', () => {
563563
expect(getStandardExportTemplateDisplayName(customName)).toBe(customName);
564564
});
565565
});
566+
567+
describe('isStandardExportTemplate', () => {
568+
it('returns true for every standard export template ID', () => {
569+
expect(isStandardExportTemplate(CONST.REPORT.EXPORT_OPTIONS.EXPENSE_LEVEL_EXPORT)).toBe(true);
570+
expect(isStandardExportTemplate(CONST.REPORT.EXPORT_OPTIONS.REPORT_LEVEL_EXPORT)).toBe(true);
571+
expect(isStandardExportTemplate(CONST.REPORT.EXPORT_OPTIONS.MULTIPLE_TAX_EXPORT)).toBe(true);
572+
});
573+
574+
it('returns false for a custom template ID', () => {
575+
expect(isStandardExportTemplate('Custom Export Layout')).toBe(false);
576+
});
577+
});
578+
579+
describe('isStandardExportTemplateLabel', () => {
580+
it('returns true for every standard export template label', () => {
581+
expect(isStandardExportTemplateLabel(CONST.REPORT.EXPORT_OPTION_LABELS.EXPENSE_LEVEL_EXPORT)).toBe(true);
582+
expect(isStandardExportTemplateLabel(CONST.REPORT.EXPORT_OPTION_LABELS.REPORT_LEVEL_EXPORT)).toBe(true);
583+
expect(isStandardExportTemplateLabel(CONST.REPORT.EXPORT_OPTION_LABELS.MULTIPLE_TAX_EXPORT)).toBe(true);
584+
});
585+
586+
it('returns false for a custom template label', () => {
587+
expect(isStandardExportTemplateLabel('Custom Export Layout')).toBe(false);
588+
});
589+
});
566590
});
567591
});

0 commit comments

Comments
 (0)