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
7 changes: 7 additions & 0 deletions src/CONST/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1132,6 +1132,7 @@ const CONST = {
EXPORT: 'export',
PAY: 'pay',
MERGE: 'merge',
REPORT_LAYOUT: 'reportLayout',
},
PRIMARY_ACTIONS: {
SUBMIT: 'submit',
Expand Down Expand Up @@ -1560,6 +1561,12 @@ const CONST = {
DATE_TIME: 'dateTime',
},
},
REPORT_LAYOUT: {
GROUP_BY: {
CATEGORY: 'mcc',
TAG: 'tag',
},
} as const,
UNREPORTED_EXPENSES_PAGE_SIZE: 50,
COMPOSER: {
NATIVE_ID: 'composer',
Expand Down
4 changes: 4 additions & 0 deletions src/ONYXKEYS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,9 @@ const ONYXKEYS = {
/** Stores the last created distance expense type (map or manual) */
NVP_LAST_DISTANCE_EXPENSE_TYPE: 'nvp_lastDistanceExpenseType',

/** Stores the user's report layout group-by preference */
NVP_REPORT_LAYOUT_GROUP_BY: 'nvp_expensify_groupByOption',

/** Whether the user has denied the contact import permission prompt */
HAS_DENIED_CONTACT_IMPORT_PROMPT: 'hasDeniedContactImportPrompt',

Expand Down Expand Up @@ -1303,6 +1306,7 @@ type OnyxValuesMapping = {
[ONYXKEYS.HYBRID_APP]: OnyxTypes.HybridApp;
[ONYXKEYS.NVP_CSV_EXPORT_LAYOUTS]: Record<string, OnyxTypes.ExportTemplate>;
[ONYXKEYS.NVP_LAST_DISTANCE_EXPENSE_TYPE]: DistanceExpenseType;
[ONYXKEYS.NVP_REPORT_LAYOUT_GROUP_BY]: string;
[ONYXKEYS.HAS_DENIED_CONTACT_IMPORT_PROMPT]: boolean | undefined;
[ONYXKEYS.SELF_DM_REPORT_ID]: string | undefined;
};
Expand Down
4 changes: 4 additions & 0 deletions src/ROUTES.ts
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,10 @@ const ROUTES = {
route: 'r/:reportID/change-approver/add',
getRoute: (reportID: string) => `r/${reportID}/change-approver/add` as const,
},
REPORT_SETTINGS_REPORT_LAYOUT: {
route: 'r/:reportID/settings/report-layout',
getRoute: (reportID: string) => `r/${reportID}/settings/report-layout` as const,
},
SPLIT_BILL_DETAILS: {
route: 'r/:reportID/split/:reportActionID',
getRoute: (reportID: string | undefined, reportActionID: string, backTo?: string) => {
Expand Down
1 change: 1 addition & 0 deletions src/SCREENS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,7 @@ const SCREENS = {
NOTIFICATION_PREFERENCES: 'Report_Settings_Notification_Preferences',
WRITE_CAPABILITY: 'Report_Settings_Write_Capability',
VISIBILITY: 'Report_Settings_Visibility',
REPORT_LAYOUT: 'Report_Settings_Report_Layout',
},

NEW_TASK: {
Expand Down
12 changes: 12 additions & 0 deletions src/components/MoneyReportHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ function MoneyReportHeader({
'Info',
'Export',
'Document',
'Feed',
] as const);
const [lastDistanceExpenseType] = useOnyx(ONYXKEYS.NVP_LAST_DISTANCE_EXPENSE_TYPE, {canBeMissing: true});
const {translate} = useLocalize();
Expand Down Expand Up @@ -1143,6 +1144,17 @@ function MoneyReportHeader({
Navigation.navigate(ROUTES.REPORT_CHANGE_APPROVER.getRoute(moneyRequestReport.reportID, Navigation.getActiveRoute()));
},
},
[CONST.REPORT.SECONDARY_ACTIONS.REPORT_LAYOUT]: {
text: translate('reportLayout.reportLayout'),
icon: expensifyIcons.Feed,
value: CONST.REPORT.SECONDARY_ACTIONS.REPORT_LAYOUT,
onSelected: () => {
if (!moneyRequestReport) {
return;
}
Navigation.navigate(ROUTES.REPORT_SETTINGS_REPORT_LAYOUT.getRoute(moneyRequestReport.reportID));
},
},
[CONST.REPORT.SECONDARY_ACTIONS.DELETE]: {
text: translate('common.delete'),
icon: expensifyIcons.Trashcan,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
import React, {useCallback, useMemo} from 'react';
import {View} from 'react-native';
import type {StyleProp, ViewStyle} from 'react-native';
import Checkbox from '@components/Checkbox';
import Text from '@components/Text';
import useLocalize from '@hooks/useLocalize';
import useResponsiveLayout from '@hooks/useResponsiveLayout';
import useThemeStyles from '@hooks/useThemeStyles';
import {getCommaSeparatedTagNameWithSanitizedColons} from '@libs/PolicyUtils';
import variables from '@styles/variables';
import type {GroupedTransactions} from '@src/types/onyx';

// Height constants
const DESKTOP_HEIGHT = 28;
const MOBILE_HEIGHT_WITH_CHECKBOX = 20;
const MOBILE_HEIGHT_WITHOUT_CHECKBOX = 16;

type MoneyRequestReportGroupHeaderProps = {
/** The grouped transaction data */
group: GroupedTransactions;

/** The group key for toggle callback */
groupKey: string;

/** Whether grouping by tag (if false, grouping by category) */
isGroupedByTag?: boolean;

/** Whether selection mode is active (checkboxes should be visible) */
isSelectionModeEnabled?: boolean;

/** Whether all transactions in this group are selected */
isSelected?: boolean;

/** Whether some (but not all) transactions in this group are selected */
isIndeterminate?: boolean;

/** Callback when group checkbox is toggled - receives groupKey */
onToggleSelection?: (groupKey: string) => void;

/** Additional styles to apply */
style?: StyleProp<ViewStyle>;
};

function MoneyRequestReportGroupHeader({
group,
groupKey,
isGroupedByTag = false,
isSelectionModeEnabled = false,
isSelected = false,
isIndeterminate = false,
onToggleSelection,
style,
}: MoneyRequestReportGroupHeaderProps) {
const styles = useThemeStyles();
const {translate} = useLocalize();
const {shouldUseNarrowLayout} = useResponsiveLayout();

const cleanedGroupName = isGroupedByTag && group.groupName ? getCommaSeparatedTagNameWithSanitizedColons(group.groupName) : group.groupName;
const displayName = cleanedGroupName || translate(isGroupedByTag ? 'reportLayout.noTag' : 'reportLayout.uncategorized');

const shouldShowCheckbox = isSelectionModeEnabled || !shouldUseNarrowLayout;

const conditionalHeight = useMemo(
() => (shouldUseNarrowLayout ? {height: shouldShowCheckbox ? MOBILE_HEIGHT_WITH_CHECKBOX : MOBILE_HEIGHT_WITHOUT_CHECKBOX} : {height: DESKTOP_HEIGHT, minHeight: DESKTOP_HEIGHT}),
[shouldUseNarrowLayout, shouldShowCheckbox],
);

const textStyle = useMemo(
() =>
shouldUseNarrowLayout
? {fontSize: variables.fontSizeLabel, lineHeight: shouldShowCheckbox ? MOBILE_HEIGHT_WITH_CHECKBOX : MOBILE_HEIGHT_WITHOUT_CHECKBOX}
: {fontSize: variables.fontSizeNormal, lineHeight: DESKTOP_HEIGHT},
[shouldUseNarrowLayout, shouldShowCheckbox],
);

const handleToggleSelection = useCallback(() => {
onToggleSelection?.(groupKey);
}, [onToggleSelection, groupKey]);

return (
<View style={[styles.reportLayoutGroupHeader, conditionalHeight, style]}>
<View style={[styles.flexRow, styles.alignItemsCenter, styles.flex1]}>
{shouldShowCheckbox && (
<Checkbox
isChecked={isSelected}
isIndeterminate={isIndeterminate}
onPress={handleToggleSelection}
accessibilityLabel={translate('reportLayout.selectGroup', {groupName: displayName})}
style={styles.mr2}
/>
)}
<Text
style={[styles.textBold, textStyle, styles.flexShrink1, shouldShowCheckbox && styles.ml2]}
shouldUseDefaultLineHeight={false}
numberOfLines={1}
>
{displayName}
</Text>
</View>
</View>
);
}

MoneyRequestReportGroupHeader.displayName = 'MoneyRequestReportGroupHeader';

export default MoneyRequestReportGroupHeader;
Loading