Skip to content

Commit 919d186

Browse files
authored
Merge pull request Expensify#87740 from nkdengineer/fix/87088
fix: Unable to sort by Attendees and Per attendee
2 parents e1e043b + 9bc7d2c commit 919d186

11 files changed

Lines changed: 92 additions & 36 deletions

File tree

src/CONST/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7708,8 +7708,6 @@ const CONST = {
77087708
this.TABLE_COLUMNS.MERCHANT,
77097709
this.TABLE_COLUMNS.FROM,
77107710
this.TABLE_COLUMNS.CATEGORY,
7711-
this.TABLE_COLUMNS.ATTENDEES,
7712-
this.TABLE_COLUMNS.TOTAL_PER_ATTENDEE,
77137711
this.TABLE_COLUMNS.TAG,
77147712
this.TABLE_COLUMNS.TOTAL_AMOUNT,
77157713
],

src/components/MoneyRequestReportView/MoneyRequestReportTransactionList.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,9 +262,8 @@ function MoneyRequestReportTransactionList({
262262
shouldShowBillableColumn,
263263
shouldShowReimbursableColumn: hasNonReimbursableTransactions(transactions),
264264
reportCurrency: report?.currency,
265-
policy,
266265
});
267-
}, [currentUserDetails?.accountID, transactions, isExpenseReportViewFromIOUReport, reportDetailsColumns, shouldShowBillableColumn, report?.currency, policy]);
266+
}, [currentUserDetails?.accountID, transactions, isExpenseReportViewFromIOUReport, reportDetailsColumns, shouldShowBillableColumn, report?.currency]);
268267

269268
const {windowWidth, windowHeight} = useWindowDimensions();
270269
const minTableWidth = getTableMinWidth(columnsToShow);

src/components/Search/SearchList/BaseSearchList/index.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ function BaseSearchList({
3232
flattenedItemsLength,
3333
newTransactions,
3434
selectedTransactions,
35+
policyForMovingExpenses,
3536
nonPersonalAndWorkspaceCards,
3637
}: BaseSearchListProps) {
3738
const hasKeyBeenPressed = useRef(false);
@@ -106,8 +107,8 @@ function BaseSearchList({
106107
}, [setHasKeyBeenPressed]);
107108

108109
const extraData = useMemo(
109-
() => [focusedIndex, columns, newTransactions, selectedTransactions, nonPersonalAndWorkspaceCards],
110-
[focusedIndex, columns, newTransactions, selectedTransactions, nonPersonalAndWorkspaceCards],
110+
() => [focusedIndex, columns, newTransactions, selectedTransactions, nonPersonalAndWorkspaceCards, policyForMovingExpenses],
111+
[focusedIndex, columns, newTransactions, selectedTransactions, nonPersonalAndWorkspaceCards, policyForMovingExpenses],
111112
);
112113

113114
return (

src/components/Search/SearchList/BaseSearchList/types.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import type {NativeSyntheticEvent} from 'react-native';
44
import type {SearchListItem} from '@components/Search/SearchList/ListItem/types';
55
import type {SearchColumnType, SelectedTransactions} from '@components/Search/types';
66
import type {ExtendedTargetedEvent} from '@components/SelectionList/ListItem/types';
7-
import type {CardList, Transaction} from '@src/types/onyx';
7+
import type {CardList, Policy, Transaction} from '@src/types/onyx';
88

99
type BaseSearchListProps = Pick<
1010
FlashListProps<SearchListItem>,
@@ -45,6 +45,9 @@ type BaseSearchListProps = Pick<
4545
/** Selected transactions for triggering re-render via extraData */
4646
selectedTransactions?: SelectedTransactions;
4747

48+
/** Policy for moving expenses for triggering re-render via extraData */
49+
policyForMovingExpenses?: Policy;
50+
4851
/** Non-personal and workspace cards for triggering re-render via extraData */
4952
nonPersonalAndWorkspaceCards?: CardList;
5053
};

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ function TransactionGroupListExpanded<TItem extends ListItem>({
5353
shouldDisplayEmptyView,
5454
searchTransactions,
5555
isInSingleTransactionReport,
56+
policyForMovingExpenses,
5657
onLongPress,
5758
nonPersonalAndWorkspaceCards,
5859
onUndelete,
@@ -250,6 +251,7 @@ function TransactionGroupListExpanded<TItem extends ListItem>({
250251
onArrowRightPress={isDeletedTransaction(transaction) ? undefined : () => openReportInRHP(transaction)}
251252
shouldShowArrowRightOnNarrowLayout
252253
reportActions={exportedReportActions}
254+
policyForMovingExpenses={policyForMovingExpenses}
253255
nonPersonalAndWorkspaceCards={nonPersonalAndWorkspaceCards}
254256
/>
255257
);

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ function TransactionListItem<TItem extends ListItem>({
5858
isLastItem,
5959
userBillingGracePeriodEnds,
6060
ownerBillingGracePeriodEnd,
61+
policyForMovingExpenses,
6162
onUndelete,
6263
}: TransactionListItemProps<TItem>) {
6364
const transactionItem = item as unknown as TransactionListItemType;
@@ -260,6 +261,7 @@ function TransactionListItem<TItem extends ListItem>({
260261
isHover={hovered}
261262
nonPersonalAndWorkspaceCards={nonPersonalAndWorkspaceCards}
262263
reportActions={exportedReportActions}
264+
policyForMovingExpenses={policyForMovingExpenses}
263265
/>
264266
</>
265267
)}

src/components/Search/SearchList/ListItem/types.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,7 @@ type TransactionListItemProps<TItem extends ListItem> = ListItemProps<TItem> &
421421
isLoading?: boolean;
422422
columns?: SearchColumnType[];
423423
violations?: Record<string, TransactionViolations | undefined> | undefined;
424+
policyForMovingExpenses?: Policy;
424425
/** Non-personal and workspace cards for company card display */
425426
nonPersonalAndWorkspaceCards?: CardList;
426427
/** Callback to undelete a transaction */
@@ -436,6 +437,7 @@ type TransactionGroupListItemProps<TItem extends ListItem> = ListItemProps<TItem
436437
columns?: SearchColumnType[];
437438
newTransactionID?: string;
438439
violations?: Record<string, TransactionViolations | undefined> | undefined;
440+
policyForMovingExpenses?: Policy;
439441
/** Non-personal and workspace cards for company card display */
440442
nonPersonalAndWorkspaceCards?: CardList;
441443
/** Callback to undelete a transaction */
@@ -444,7 +446,18 @@ type TransactionGroupListItemProps<TItem extends ListItem> = ListItemProps<TItem
444446

445447
type TransactionGroupListExpandedProps<TItem extends ListItem> = Pick<
446448
TransactionGroupListItemProps<TItem>,
447-
'showTooltip' | 'canSelectMultiple' | 'onCheckboxPress' | 'columns' | 'groupBy' | 'accountID' | 'isOffline' | 'violations' | 'onSelectRow' | 'nonPersonalAndWorkspaceCards' | 'onUndelete'
449+
| 'showTooltip'
450+
| 'canSelectMultiple'
451+
| 'onCheckboxPress'
452+
| 'columns'
453+
| 'groupBy'
454+
| 'accountID'
455+
| 'isOffline'
456+
| 'violations'
457+
| 'onSelectRow'
458+
| 'nonPersonalAndWorkspaceCards'
459+
| 'onUndelete'
460+
| 'policyForMovingExpenses'
448461
> & {
449462
transactions: TransactionListItemType[];
450463
transactionsVisibleLimit: number;

src/components/Search/SearchList/index.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ import variables from '@styles/variables';
3737
import type {TransactionPreviewData} from '@userActions/Search';
3838
import CONST from '@src/CONST';
3939
import ONYXKEYS from '@src/ONYXKEYS';
40-
import type {CardList, Transaction, TransactionViolations} from '@src/types/onyx';
40+
import type {CardList, Policy, Transaction, TransactionViolations} from '@src/types/onyx';
4141
import BaseSearchList from './BaseSearchList';
4242
import type ChatListItem from './ListItem/ChatListItem';
4343
import type ExpenseReportListItem from './ListItem/ExpenseReportListItem';
@@ -134,6 +134,8 @@ type SearchListProps = Pick<FlashListProps<SearchListItem>, 'onScroll' | 'conten
134134
/** Whether all transactions have been loaded from snapshots in group-by views */
135135
hasLoadedAllTransactions?: boolean;
136136

137+
policyForMovingExpenses?: Policy;
138+
137139
/** Reference to the outer element */
138140
ref?: ForwardedRef<SearchListHandle>;
139141
};
@@ -218,6 +220,7 @@ function SearchList({
218220
nonPersonalAndWorkspaceCards,
219221
selectedTransactions,
220222
hasLoadedAllTransactions,
223+
policyForMovingExpenses,
221224
ref,
222225
}: SearchListProps) {
223226
const styles = useThemeStyles();
@@ -443,6 +446,7 @@ function SearchList({
443446
queryJSONHash={hash}
444447
columns={columns}
445448
policies={policies}
449+
policyForMovingExpenses={policyForMovingExpenses}
446450
isDisabled={isDisabled}
447451
groupBy={groupBy}
448452
searchType={type}
@@ -497,6 +501,7 @@ function SearchList({
497501
nonPersonalAndWorkspaceCards,
498502
selectedTransactions,
499503
ListFooterComponent,
504+
policyForMovingExpenses,
500505
handleUndelete,
501506
],
502507
);
@@ -564,6 +569,7 @@ function SearchList({
564569
contentContainerStyle={contentContainerStyle}
565570
newTransactions={newTransactions}
566571
selectedTransactions={selectedTransactions}
572+
policyForMovingExpenses={policyForMovingExpenses}
567573
nonPersonalAndWorkspaceCards={nonPersonalAndWorkspaceCards}
568574
/>
569575
<Modal

src/components/Search/index.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import useLocalize from '@hooks/useLocalize';
1717
import useMultipleSnapshots from '@hooks/useMultipleSnapshots';
1818
import useNetwork from '@hooks/useNetwork';
1919
import useOnyx from '@hooks/useOnyx';
20+
import usePolicyForMovingExpenses from '@hooks/usePolicyForMovingExpenses';
2021
import usePrevious from '@hooks/usePrevious';
2122
import useResponsiveLayout from '@hooks/useResponsiveLayout';
2223
import useSearchHighlightAndScroll from '@hooks/useSearchHighlightAndScroll';
@@ -331,6 +332,8 @@ function Search({
331332
selector: selectFilteredReportActions,
332333
});
333334

335+
const {policyForMovingExpenses} = usePolicyForMovingExpenses();
336+
334337
const [cardFeeds, cardFeedsResult] = useOnyx(ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_DOMAIN_MEMBER);
335338
const [bankAccountList] = useOnyx(ONYXKEYS.BANK_ACCOUNT_LIST);
336339
const [onyxPersonalDetailsList] = useOnyx(ONYXKEYS.PERSONAL_DETAILS_LIST);
@@ -531,6 +534,7 @@ function Search({
531534
allReportMetadata,
532535
conciergeReportID,
533536
onyxPersonalDetailsList,
537+
policyForMovingExpenses,
534538
});
535539
return [filteredData1, filteredData1.length, allLength];
536540
}, [
@@ -557,6 +561,7 @@ function Search({
557561
allReportMetadata,
558562
conciergeReportID,
559563
onyxPersonalDetailsList,
564+
policyForMovingExpenses,
560565
]);
561566

562567
// For group-by views, each grouped item has a transactionsQueryJSON with a hash pointing to a separate snapshot
@@ -1682,6 +1687,7 @@ function Search({
16821687
shouldAnimate={type === CONST.SEARCH.DATA_TYPES.EXPENSE}
16831688
newTransactions={newTransactions}
16841689
hasLoadedAllTransactions={hasLoadedAllTransactions}
1690+
policyForMovingExpenses={policyForMovingExpenses}
16851691
nonPersonalAndWorkspaceCards={nonPersonalAndWorkspaceCards}
16861692
/>
16871693
</Animated.View>

src/components/TransactionItemRow/index.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ type TransactionItemRowProps = {
144144
reportActions?: ReportAction[];
145145
checkboxSentryLabel?: string;
146146
isLargeScreenWidth?: boolean;
147+
policyForMovingExpenses?: Policy;
147148
nonPersonalAndWorkspaceCards?: CardList;
148149
};
149150

@@ -198,6 +199,7 @@ function TransactionItemRow({
198199
checkboxSentryLabel,
199200
nonPersonalAndWorkspaceCards = {},
200201
isLargeScreenWidth: isLargeScreenWidthProp,
202+
policyForMovingExpenses,
201203
}: TransactionItemRowProps) {
202204
const styles = useThemeStyles();
203205
const {translate} = useLocalize();
@@ -258,7 +260,9 @@ function TransactionItemRow({
258260
const exchangeRateMessage = getExchangeRate(transactionItem, report?.currency);
259261
const cardName = getCompanyCardDescription(translate, transactionItem?.cardName, transactionItem?.cardID, nonPersonalAndWorkspaceCards);
260262
const transactionAttendees = useMemo(() => getAttendees(transactionItem, currentUserPersonalDetails), [transactionItem, currentUserPersonalDetails]);
261-
const shouldShowAttendees = shouldShowAttendeesUtils(CONST.IOU.TYPE.SUBMIT, policy) && transactionAttendees.length > 0;
263+
264+
const isUnreported = transactionItem.reportID === CONST.REPORT.UNREPORTED_REPORT_ID;
265+
const shouldShowAttendees = shouldShowAttendeesUtils(CONST.IOU.TYPE.SUBMIT, isUnreported ? policyForMovingExpenses : policy) && transactionAttendees.length > 0;
262266

263267
const totalPerAttendee = useMemo(() => {
264268
const attendeesCount = transactionAttendees.length ?? 0;

0 commit comments

Comments
 (0)