Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
666fafd
feat: use Table component for Add existing expense flow
Krishna2323 Sep 10, 2026
f67e9ff
fix knip check.
Krishna2323 Sep 10, 2026
040a048
refactor: extract AddExistingExpenseTable to match Tables/ convention
Krishna2323 Sep 10, 2026
76d1831
add fixed footer.
Krishna2323 Sep 11, 2026
3fa4727
fix: preserve error message and selection in Add existing expense table
Krishna2323 Sep 11, 2026
3d42fe2
fix: correct skeleton margin/divider and last-row radius during pagin…
Krishna2323 Sep 11, 2026
db5bee7
fix: match skeleton row height to real row's rendered height
Krishna2323 Sep 11, 2026
f02a752
Merge branch 'Expensify:main' into krishna2323/table-add-existing-exp…
Krishna2323 Sep 11, 2026
c654dd8
fix receipt border radius issue.
Krishna2323 Sep 11, 2026
663a6ac
fix failing tests.
Krishna2323 Sep 11, 2026
29ac9fb
fix: mobile selection mode and receipt clipping in Add existing expense
Krishna2323 Sep 14, 2026
efd4e33
fix: restore mobile selection mode flag for SelectionToolbar's test mock
Krishna2323 Sep 14, 2026
e516f51
Merge branch 'Expensify:main' into krishna2323/table-add-existing-exp…
Krishna2323 Sep 17, 2026
e296c87
fix: address review findings on the Add existing expense table
Krishna2323 Sep 17, 2026
465232e
fix: justify the new lint suppressions and simplify the new comments
Krishna2323 Sep 17, 2026
f350601
Merge branch 'main' into krishna2323/table-add-existing-expense-100589
Krishna2323 Sep 18, 2026
1879aac
fix: compare expense dates as strings and use the display merchant name
Krishna2323 Sep 20, 2026
e6f1d84
fix: use the sort order CONST and drop the redundant selection Set
Krishna2323 Sep 21, 2026
37173ff
fix: only let the report header turn off the shared selection mode wh…
Krishna2323 Sep 22, 2026
6a35679
fix: drop the dead lint suppression and mock useIsFocused in the head…
Krishna2323 Sep 22, 2026
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
8 changes: 4 additions & 4 deletions src/components/AddExistingExpenseFooter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import {usePersonalDetails, useSession} from './OnyxListItemProvider';

type AddExistingExpenseFooterProps = {
/** Selected transaction IDs */
selectedIds: Set<string>;
selectedIds: string[];
/** The report to add expenses to */
report: OnyxEntry<Report>;
reportToConfirm: OnyxEntry<Report>;
Expand Down Expand Up @@ -64,11 +64,11 @@ function AddExistingExpenseFooter({selectedIds, report, reportToConfirm, policy,
const [isTrackIntentUser] = useOnyx(ONYXKEYS.NVP_INTRO_SELECTED, {selector: isTrackIntentUserSelector});
const [rules] = useOnyx(ONYXKEYS.COLLECTION.RULE);

const [transactions] = useTransactionsByID([...selectedIds]);
const [transactions] = useTransactionsByID(selectedIds);
const reports = useChangeTransactionsReportReports(transactions, reportToConfirm?.reportID);

const handleConfirm = () => {
if (selectedIds.size === 0) {
if (selectedIds.length === 0) {
setErrorMessage(translate('iou.selectExistingExpense'));
return;
}
Expand Down Expand Up @@ -99,7 +99,7 @@ function AddExistingExpenseFooter({selectedIds, report, reportToConfirm, policy,
} else {
changeTransactionsReport({
isVendorMatchingBetaEnabled,
transactionIDs: [...selectedIds],
transactionIDs: selectedIds,
isASAPSubmitBetaEnabled,
accountID: session?.accountID ?? CONST.DEFAULT_NUMBER_ID,
email: session?.email ?? '',
Expand Down
9 changes: 6 additions & 3 deletions src/components/MoneyReportHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import ONYXKEYS from '@src/ONYXKEYS';
import type {Route} from '@src/ROUTES';
import SCREENS from '@src/SCREENS';

import {useRoute} from '@react-navigation/native';
import {useIsFocused, useRoute} from '@react-navigation/native';
import React, {useEffect} from 'react';
import {View} from 'react-native';

Expand Down Expand Up @@ -91,6 +91,7 @@ function MoneyReportHeaderContent({reportID: reportIDProp, shouldDisplayBackButt
const shouldShowBackButton = shouldDisplayBackButton || shouldUseNarrowLayout;

const isMobileSelectionModeEnabled = useMobileSelectionMode();
const isFocused = useIsFocused();

useEffect(() => {
return () => {
Expand All @@ -99,9 +100,11 @@ function MoneyReportHeaderContent({reportID: reportIDProp, shouldDisplayBackButt
}, []);

if (isMobileSelectionModeEnabled && shouldUseNarrowLayout) {
// If mobile selection mode is enabled but only one or no transactions remain, turn it off
// If mobile selection mode is enabled but only one or no transactions remain, turn it off. The selection mode
// is shared with every screen, so this report only gets to turn it off while it is the focused one. Another
// screen on top of it, such as the add existing expense modal, owns the mode for as long as it is open.
const visibleTransactions = transactions.filter((t) => t.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE || isOffline);
if (visibleTransactions.length <= 1) {
if (isFocused && visibleTransactions.length <= 1) {
turnOffMobileSelectionMode();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,4 @@ function MultiSelectPopup<T extends string>({showLabel, label, loading, value, i
);
}

export type {MultiSelectItem};
export default MultiSelectPopup;
27 changes: 21 additions & 6 deletions src/components/Skeletons/UnreportedExpensesSkeleton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,31 +41,44 @@ type UnreportedExpensesSkeletonProps = {
function UnreportedExpensesSkeleton({fixedNumberOfItems}: UnreportedExpensesSkeletonProps) {
const {onLayout, containerWidth: pageWidth} = useContainerWidth(40);
const styles = useThemeStyles();
// Passed only when the skeleton is the footer appended below rows that are already on screen, so it gets a top
// divider joining it to the row above instead of rounding its own top corners.
const isPaginationFooter = !!fixedNumberOfItems;

const skeletonItem = useCallback(
(args: {itemIndex: number}) => {
return (
<>
<SkeletonRect
transform={[{translateX: 12}, {translateY: 22}]}
transform={[{translateX: 16}, {translateY: 26}]}
width={20}
height={20}
/>
<SkeletonRect
transform={[{translateX: 44}, {translateY: 12}]}
transform={[{translateX: 48}, {translateY: 16}]}
width={36}
height={40}
/>
<SkeletonRect
transform={[{translateX: 92}, {translateY: 26}]}
transform={[{translateX: 96}, {translateY: 18}]}
width={getMessageSkeletonWidth(args.itemIndex)}
height={12}
/>
<SkeletonRect
transform={[{translateX: pageWidth - 12 - getExpenseAmountSkeletonWidth(args.itemIndex)}, {translateY: 26}]}
transform={[{translateX: 96}, {translateY: 42}]}
width={60}
height={8}
/>
<SkeletonRect
transform={[{translateX: pageWidth - 16 - getExpenseAmountSkeletonWidth(args.itemIndex)}, {translateY: 18}]}
width={getExpenseAmountSkeletonWidth(args.itemIndex)}
height={12}
/>
<SkeletonRect
transform={[{translateX: pageWidth - 16 - 32}, {translateY: 42}]}
width={32}
height={8}
/>
</>
);
},
Expand All @@ -78,8 +91,10 @@ function UnreportedExpensesSkeleton({fixedNumberOfItems}: UnreportedExpensesSkel
onLayout={onLayout}
>
<ItemListSkeletonView
itemViewHeight={64}
itemViewStyle={[styles.highlightBG, styles.mb2, styles.br2, styles.ml5, styles.mr5]}
itemViewHeight={72}
itemViewStyle={[styles.highlightBG, styles.mr0]}
itemContainerStyle={styles.borderBottom}
style={[styles.mh5, styles.overflowHidden, styles.tableBottomRadius, isPaginationFooter ? styles.borderTop : styles.tableTopRadius]}
shouldAnimate
fixedNumItems={fixedNumberOfItems}
renderSkeletonItem={skeletonItem}
Expand Down
22 changes: 20 additions & 2 deletions src/components/Table/Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import useLocalize from '@hooks/useLocalize';
import useMobileSelectionMode from '@hooks/useMobileSelectionMode';
import useResponsiveLayout from '@hooks/useResponsiveLayout';

import {turnOnMobileSelectionMode} from '@libs/actions/MobileSelectionMode';
import {turnOffMobileSelectionMode, turnOnMobileSelectionMode} from '@libs/actions/MobileSelectionMode';
import getPlatform from '@libs/getPlatform';
import {canMeasureText} from '@libs/measureTextWidth';
import {acquireBackgroundInputFocusSuppression} from '@libs/ModalFocusManager';
Expand Down Expand Up @@ -268,18 +268,30 @@ function Table<DataType extends TableData, ColumnKey extends string = string, Fi
isItemInFilter,
isItemInSearch,
initialSortColumn,
initialSortOrder,
narrowLayoutSortColumn,
children,
selectionEnabled,
shouldEnableSelectionInNarrowPaneModal,
shouldUseDynamicColumns = false,
shouldPreserveSelectionOnSearchAndFilter,
shouldFooterRenderAsLastRow,
onRowSelectionChange,
onSearchStringChange,
onSortingChange,
...listProps
}: TableProps<DataType, ColumnKey, FilterKey>) {
const {translate} = useLocalize();
const isMobileSelectionEnabled = useMobileSelectionMode();

const setMobileSelectionModeEnabled = (isEnabled: boolean) => {
if (isEnabled) {
turnOnMobileSelectionMode();
return;
}

turnOffMobileSelectionMode();
};
const icons = useMemoizedLazyExpensifyIcons(['CheckSquare']);
const {shouldUseNarrowLayout, isMediumScreenWidth} = useResponsiveLayout();
const bottomSafeAreaPaddingStyle = useBottomSafeSafeAreaPaddingStyle({addBottomSafeAreaPadding: true, addOfflineIndicatorBottomSafeAreaPadding: false});
Expand All @@ -304,6 +316,7 @@ function Table<DataType extends TableData, ColumnKey extends string = string, Fi
} = useSorting<DataType, ColumnKey>({
compareItems,
initialSortColumn,
initialSortOrder,
narrowLayoutSortColumn,
shouldUseNarrowTableLayout,
onSortingChange,
Expand All @@ -322,6 +335,9 @@ function Table<DataType extends TableData, ColumnKey extends string = string, Fi
selectedKeys,
onRowSelectionChange,
shouldEnableSelectionInNarrowPaneModal,
isSelectionModeEnabled: isMobileSelectionEnabled,
setSelectionModeEnabled: setMobileSelectionModeEnabled,
shouldPreserveSelectionOnSearchAndFilter,
});
const selectionData = selectionMiddleware(sortedData);

Expand Down Expand Up @@ -441,7 +457,7 @@ function Table<DataType extends TableData, ColumnKey extends string = string, Fi
return;
}

turnOnMobileSelectionMode();
setMobileSelectionModeEnabled(true);
selectionMethods.handleSingleRowSelection(mobileSelectionModalRowKey);
selectionMethods.setMobileSelectionModalRowKey(null);
}, [mobileSelectionModalRowKey, selectionMethods, shouldSkipMobileSelectionFocusRestore, shouldSubmitMobileSelection]);
Expand Down Expand Up @@ -474,6 +490,7 @@ function Table<DataType extends TableData, ColumnKey extends string = string, Fi
activeFilters: currentFilters,
activeSorting,
initialSortColumn,
initialSortOrder: initialSortOrder ?? CONST.SEARCH.SORT_ORDER.ASC,
narrowLayoutSortColumn,
activeSearchString,
tableMethods,
Expand All @@ -483,6 +500,7 @@ function Table<DataType extends TableData, ColumnKey extends string = string, Fi
isEmptyResult,
isDefaultViewEmpty,
shouldUseNarrowTableLayout,
shouldFooterRenderAsLastRow,
selectionEnabled,
shouldEnableSelectionInNarrowPaneModal,
isMobileSelectionEnabled,
Expand Down
11 changes: 10 additions & 1 deletion src/components/Table/TableContext.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import type {MeasurableInput} from '@components/SelectionList/SelectionListWithSections/types';

import CONST from '@src/CONST';

import type {FlashListRef} from '@shopify/flash-list';
import type {NativeScrollEvent, NativeSyntheticEvent, View} from 'react-native';

import React, {createContext, useContext} from 'react';

import type {TableListMetadata} from './buildTableListData';
import type {FilterConfig} from './middlewares/filtering';
import type {ActiveSorting} from './middlewares/sorting';
import type {ActiveSorting, SortOrder} from './middlewares/sorting';
import type {TableHeaderProps} from './TableHeader';
import type {SharedListProps, TableColumn, TableData, TableMethods, TableRow} from './types';

Expand Down Expand Up @@ -81,6 +83,9 @@ type TableContextValue<DataType extends TableData, ColumnKey extends string = st
/** The column the table is initially sorted by, used as the reset target for sort controls. */
initialSortColumn: ColumnKey | undefined;

/** The order `initialSortColumn` is initially sorted in, used as the reset target for sort controls. */
initialSortOrder: SortOrder;

/** The column sorting is locked to on narrow layouts, where user sorting is ignored. */
narrowLayoutSortColumn: ColumnKey | undefined;

Expand Down Expand Up @@ -110,6 +115,9 @@ type TableContextValue<DataType extends TableData, ColumnKey extends string = st
/** Whether to use a narrow layout (e.g. on mobile screens). */
shouldUseNarrowTableLayout: boolean;

/** Whether `ListFooterComponent` renders as a continuation of the rows, so it owns the rounded bottom corners. */
shouldFooterRenderAsLastRow?: boolean;

/** Callback when the user changes the search string in the filter bar. */
onSearchStringChange?: (searchString: string) => void;
};
Expand All @@ -129,6 +137,7 @@ const defaultTableContextValue: TableContextValue<TableData, string> = {
order: 'asc',
},
initialSortColumn: undefined,
initialSortOrder: CONST.SEARCH.SORT_ORDER.ASC,
narrowLayoutSortColumn: undefined,
activeSearchString: '',
tableMethods: {} as TableMethods<string, string>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,14 @@ export default function TableDisplaySettingsPopoverComponent({closeOverlay}: Tab
columns,
activeSorting,
initialSortColumn,
initialSortOrder,
tableMethods: {updateSorting},
} = useTableContext();
const [selectedSetting, setSelectedSetting] = useState<'sortBy' | 'sortOrder' | null>(null);

const defaultSorting: ActiveSorting<string> = {
columnKey: initialSortColumn,
order: CONST.SEARCH.SORT_ORDER.ASC,
order: initialSortOrder,
};
const [pendingSorting, setPendingSorting] = useState<ActiveSorting<string>>(defaultSorting);

Expand Down Expand Up @@ -168,7 +169,7 @@ export default function TableDisplaySettingsPopoverComponent({closeOverlay}: Tab
]}
value={selectedOrder}
label={translate('search.display.sortOrder')}
defaultValue={CONST.SEARCH.SORT_ORDER.ASC}
defaultValue={defaultSorting.order}
onBackButtonPress={() => setSelectedSetting('sortBy')}
closeOverlay={closeSettingsOverlay}
onChange={(item) => {
Expand Down
6 changes: 5 additions & 1 deletion src/components/Table/TableRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ export default function TableRow({
shouldEnableSelectionInNarrowPaneModal = false,
tableListMetadata,
dynamicGridTemplateColumns,
listProps,
shouldFooterRenderAsLastRow,
} = useTableContext();
const semanticRowID = useTableRowSemanticID();
const semanticTableHasHeader = !tableListMetadata.hasPageHeader || tableListMetadata.shouldRenderStickyHeader;
Expand All @@ -110,7 +112,9 @@ export default function TableRow({

const isDisabled = !!disabled || isAccessibilityHidden;
const isFirstRow = rowIndex === 0;
const isLastRow = rowIndex === rowCount - 1;
// A footer that continues the rows owns the rounded bottom corners instead of the last row.
const doesFooterOwnBottomRadius = !!shouldFooterRenderAsLastRow && !!listProps?.ListFooterComponent;
const isLastRow = rowIndex === rowCount - 1 && !doesFooterOwnBottomRadius;

if (selectionEnabled && isSelectionCheckboxVisible) {
gridTemplateColumns.unshift(`${variables.tableCheckboxColumnWidth}px`);
Expand Down
34 changes: 26 additions & 8 deletions src/components/Table/middlewares/selection.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import type {TableData, TableRow} from '@components/Table/types';

import useAndroidBackButtonHandler from '@hooks/useAndroidBackButtonHandler';
import useMobileSelectionMode from '@hooks/useMobileSelectionMode';
import usePrevious from '@hooks/usePrevious';
import useResponsiveLayout from '@hooks/useResponsiveLayout';
import useShiftRangeSelection from '@hooks/useShiftRangeSelection';

import {turnOffMobileSelectionMode, turnOnMobileSelectionMode} from '@libs/actions/MobileSelectionMode';
import {applyShiftRangeBatchToKeySet} from '@libs/shiftRangeSelection';

import type {Dispatch, SetStateAction} from 'react';
Expand Down Expand Up @@ -34,6 +32,15 @@ type UseSelectionProps<DataType extends TableData> = {

/** Whether the selection mode should key off the real screen size instead of shouldUseNarrowLayout (for tables inside a narrow pane modal / RHP) */
shouldEnableSelectionInNarrowPaneModal?: boolean;

/** Whether the mobile selection mode is currently on */
isSelectionModeEnabled: boolean;

/** Turns the mobile selection mode on or off */
setSelectionModeEnabled: (isEnabled: boolean) => void;

/** Whether the selection survives a change to the search string or the filters */
shouldPreserveSelectionOnSearchAndFilter?: boolean;
};

type SelectionMethods = {
Expand Down Expand Up @@ -66,14 +73,16 @@ export default function useSelection<DataType extends TableData>({
activeSearchString,
onRowSelectionChange,
shouldEnableSelectionInNarrowPaneModal,
isSelectionModeEnabled,
setSelectionModeEnabled,
shouldPreserveSelectionOnSearchAndFilter,
}: UseSelectionProps<DataType>): UseSelectionResult<DataType> {
// When a table opts into selection inside a narrow pane modal (RHP), the selection-mode auto-sync keys off the real
// screen size (isSmallScreenWidth) so it behaves correctly there (shouldUseNarrowLayout is always true in an RHP).
// Otherwise it keeps the original shouldUseNarrowLayout behavior, so central-pane tables are unaffected.
// eslint-disable-next-line rulesdir/prefer-shouldUseNarrowLayout-instead-of-isSmallScreenWidth
const {shouldUseNarrowLayout, isSmallScreenWidth} = useResponsiveLayout();
const selectionUsesNarrowLayout = shouldEnableSelectionInNarrowPaneModal ? isSmallScreenWidth : shouldUseNarrowLayout;
const isSelectionModeEnabled = useMobileSelectionMode();

// When a user long-presses a row on mobile, store the key of the row that will be selected if
// the user confirms the selection
Expand Down Expand Up @@ -103,9 +112,9 @@ export default function useSelection<DataType extends TableData>({
}

clearSelection();
turnOffMobileSelectionMode();
setSelectionModeEnabled(false);
return true;
}, [isSelectionModeEnabled, clearSelection]);
}, [isSelectionModeEnabled, clearSelection, setSelectionModeEnabled]);

useAndroidBackButtonHandler(androidBackButtonDisableSelectionMode);

Expand All @@ -116,10 +125,13 @@ export default function useSelection<DataType extends TableData>({
const isSelectionModeEnabledWithoutSelectableKeys = isSelectionModeEnabled && !selectableKeys.length && !originalSelectableCount;

if (isMobileMissingSelectionMode) {
turnOnMobileSelectionMode();
setSelectionModeEnabled(true);
} else if (isDesktopWithoutSelectableKeys || isSelectionModeEnabledWithoutSelectableKeys) {
turnOffMobileSelectionMode();
setSelectionModeEnabled(false);
}
// setSelectionModeEnabled is omitted from the dependencies below because a caller is free to pass an inline
// callback, and re-running this effect on every render would fight the selection mode it just set.
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [selectionUsesNarrowLayout, isSelectionModeEnabled, selectedKeys.length, originalSelectableCount, selectableKeys.length]);

// When selection mode is turned off, clear the list of selected keys, so that re-enabling selection mode doesn't retain rows
Expand All @@ -133,7 +145,13 @@ export default function useSelection<DataType extends TableData>({
}, [isSelectionModeEnabled, selectedKeys.length, clearSelection, wasSelectionModeEnabled]);

// When the table filters or the search string change, clear the current selection
useEffect(() => clearSelection(), [currentFilters, activeSearchString, clearSelection]);
useEffect(() => {
if (shouldPreserveSelectionOnSearchAndFilter) {
return;
}

clearSelection();
}, [currentFilters, activeSearchString, clearSelection, shouldPreserveSelectionOnSearchAndFilter]);

// When the table unmounts, clear the selection. Should only run on unmount
// eslint-disable-next-line react-hooks/exhaustive-deps
Expand Down
Loading
Loading