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
4 changes: 4 additions & 0 deletions src/components/Search/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ function mapTransactionItemToSelectedEntry(
item.keyForList,
{
isSelected: true,
canDelete: item.canDelete,
canReject: canRejectRequest,
canHold: canHoldRequest,
isHeld: isOnHold(item),
Expand Down Expand Up @@ -199,6 +200,7 @@ function prepareTransactionsList(
...selectedTransactions,
[item.keyForList]: {
isSelected: true,
canDelete: item.canDelete,
canReject: canRejectRequest,
canHold: canHoldRequest,
isHeld: isOnHold(item),
Expand Down Expand Up @@ -544,6 +546,7 @@ function Search({
),
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
isSelected: areAllMatchingItemsSelected || selectedTransactions[transactionItem.transactionID]?.isSelected || isExpenseReportType,
canDelete: transactionItem.canDelete,
canReject: canRejectRequest,
reportID: transactionItem.reportID,
policyID: transactionItem.report?.policyID,
Expand Down Expand Up @@ -595,6 +598,7 @@ function Search({
),
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
isSelected: areAllMatchingItemsSelected || selectedTransactions[transactionItem.transactionID].isSelected,
canDelete: transactionItem.canDelete,
canReject: canRejectRequest,
reportID: transactionItem.reportID,
policyID: transactionItem.report?.policyID,
Expand Down
3 changes: 3 additions & 0 deletions src/components/Search/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ type SelectedTransactionInfo = {
/** Whether the transaction is selected */
isSelected: boolean;

/** If the transaction can be deleted */
canDelete: boolean;

/** If the transaction can be rejected */
canReject: boolean;

Expand Down
1 change: 1 addition & 0 deletions src/libs/SearchUIUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2839,6 +2839,7 @@ function getTransactionFromTransactionListItem(item: TransactionListItemType): O
isTaxAmountColumnWide,
violations,
hash,
canDelete,
accountID,
policyID,
...transaction
Expand Down
32 changes: 6 additions & 26 deletions src/pages/Search/SearchPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,7 @@ import Navigation from '@libs/Navigation/Navigation';
import type {PlatformStackScreenProps} from '@libs/Navigation/PlatformStackNavigation/types';
import type {SearchFullscreenNavigatorParamList} from '@libs/Navigation/types';
import {getActiveAdminWorkspaces, hasDynamicExternalWorkflow, hasOnlyPersonalPolicies as hasOnlyPersonalPoliciesUtil, isPaidGroupPolicy} from '@libs/PolicyUtils';
import {getOriginalMessage, isMoneyRequestAction} from '@libs/ReportActionsUtils';
import {
canDeleteMoneyRequestReport,
generateReportID,
getPolicyExpenseChat,
getReportOrDraftReport,
Expand Down Expand Up @@ -677,24 +675,7 @@ function SearchPage({route}: SearchPageProps) {
});
}

const shouldShowDeleteOption =
!isOffline &&
selectedTransactionsKeys.every((id) => {
const transaction = currentSearchResults?.data?.[`${ONYXKEYS.COLLECTION.TRANSACTION}${id}`];
if (!transaction) {
return false;
}
const parentReportID = transaction.reportID;
const parentReport = currentSearchResults?.data?.[`${ONYXKEYS.COLLECTION.REPORT}${parentReportID}`];
if (!parentReport) {
return false;
}
const reportActions = currentSearchResults?.data?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${parentReportID}`];
const parentReportAction = Object.values(reportActions ?? {}).find(
(action) => (isMoneyRequestAction(action) ? getOriginalMessage(action)?.IOUTransactionID : undefined) === transaction.transactionID,
);
return canDeleteMoneyRequestReport(parentReport, [transaction], parentReportAction ? [parentReportAction] : []);
});
const shouldShowDeleteOption = !isOffline && selectedTransactionsKeys.every((id) => selectedTransactions[id].canDelete);

if (shouldShowDeleteOption) {
options.push({
Expand Down Expand Up @@ -741,16 +722,15 @@ function SearchPage({route}: SearchPageProps) {
status,
hash,
selectedTransactions,
expensifyIcons,
translate,
areAllMatchingItemsSelected,
isOffline,
selectedReports,
queryJSON,
selectedTransactionReportIDs,
lastPaymentMethods,
selectedReportIDs,
allTransactions,
selectedTransactionReportIDs,
queryJSON,
selectedPolicyIDs,
policies,
integrationsExportTemplates,
Expand All @@ -760,14 +740,14 @@ function SearchPage({route}: SearchPageProps) {
dismissedRejectUseExplanation,
bulkPayButtonOptions,
onBulkPaySelected,
areAllTransactionsFromSubmitter,
dismissedHoldUseExplanation,
allReports,
currentSearchResults?.data,
theme.icon,
styles.colorMuted,
styles.fontWeightNormal,
styles.textWrap,
expensifyIcons,
dismissedHoldUseExplanation,
areAllTransactionsFromSubmitter,
]);

const handleDeleteExpenses = () => {
Expand Down
3 changes: 3 additions & 0 deletions src/types/onyx/SearchResults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ type SearchTransaction = {
/** The transaction amount */
amount: number;

/** If the transaction can be deleted */
canDelete: boolean;

/** The edited transaction amount */
modifiedAmount: number;

Expand Down
1 change: 1 addition & 0 deletions tests/unit/MoneyRequestReportUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ const transactionItemBaseMock: TransactionListItemType = {
policy: policyBaseMock,
reportAction: reportActionBaseMock,
holdReportAction: undefined,
canDelete: true,
cardID: undefined,
cardName: undefined,
category: '',
Expand Down
18 changes: 16 additions & 2 deletions tests/unit/Search/SearchUIUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,7 @@ const searchResults: OnyxTypes.SearchResults = {
[`report_${reportID5}`]: report5,
[`transactions_${transactionID}`]: {
amount: -5000,
canDelete: true,
cardID: undefined,
cardName: undefined,
category: '',
Expand Down Expand Up @@ -419,6 +420,7 @@ const searchResults: OnyxTypes.SearchResults = {
},
[`transactions_${transactionID2}`]: {
amount: -5000,
canDelete: true,
cardID: undefined,
cardName: undefined,
category: '',
Expand Down Expand Up @@ -449,6 +451,7 @@ const searchResults: OnyxTypes.SearchResults = {
...allViolations,
[`transactions_${transactionID3}`]: {
amount: 1200,
canDelete: true,
cardID: undefined,
cardName: undefined,
category: '',
Expand Down Expand Up @@ -478,6 +481,7 @@ const searchResults: OnyxTypes.SearchResults = {
},
[`transactions_${transactionID4}`]: {
amount: 3200,
canDelete: true,
cardID: undefined,
cardName: undefined,
category: '',
Expand Down Expand Up @@ -763,6 +767,7 @@ const transactionsListItems = [
policy,
reportAction: reportAction1,
holdReportAction: undefined,
canDelete: true,
cardID: undefined,
cardName: undefined,
category: '',
Expand Down Expand Up @@ -818,6 +823,7 @@ const transactionsListItems = [
policy,
reportAction: reportAction2,
holdReportAction: undefined,
canDelete: true,
cardID: undefined,
cardName: undefined,
category: '',
Expand Down Expand Up @@ -883,6 +889,7 @@ const transactionsListItems = [
policy,
reportAction: reportAction3,
holdReportAction: undefined,
canDelete: true,
cardID: undefined,
cardName: undefined,
category: '',
Expand Down Expand Up @@ -943,6 +950,7 @@ const transactionsListItems = [
policy,
reportAction: reportAction4,
holdReportAction: undefined,
canDelete: true,
cardID: undefined,
cardName: undefined,
category: '',
Expand Down Expand Up @@ -1042,6 +1050,7 @@ const transactionReportGroupListItems = [
reportAction: reportAction1,
holdReportAction: undefined,
amount: -5000,
canDelete: true,
cardID: undefined,
cardName: undefined,
category: '',
Expand Down Expand Up @@ -1142,6 +1151,7 @@ const transactionReportGroupListItems = [
reportAction: reportAction2,
holdReportAction: undefined,
amount: -5000,
canDelete: true,
cardID: undefined,
cardName: undefined,
category: '',
Expand Down Expand Up @@ -1258,6 +1268,7 @@ const transactionReportGroupListItems = [
policy,
reportAction: reportAction3,
holdReportAction: undefined,
canDelete: true,
cardID: undefined,
cardName: undefined,
category: '',
Expand Down Expand Up @@ -1316,6 +1327,7 @@ const transactionReportGroupListItems = [
policy,
reportAction: reportAction4,
holdReportAction: undefined,
canDelete: true,
cardID: undefined,
cardName: undefined,
category: '',
Expand Down Expand Up @@ -1849,7 +1861,7 @@ describe('SearchUIUtils', () => {
expect(distanceTransaction).toBeDefined();
expect(distanceTransaction?.iouRequestType).toBe(CONST.IOU.REQUEST_TYPE.DISTANCE);

const expectedPropertyCount = 49;
const expectedPropertyCount = 50;
expect(Object.keys(distanceTransaction ?? {}).length).toBe(expectedPropertyCount);
});

Expand Down Expand Up @@ -1882,7 +1894,7 @@ describe('SearchUIUtils', () => {
expect(distanceTransaction).toBeDefined();
expect(distanceTransaction?.iouRequestType).toBe(CONST.IOU.REQUEST_TYPE.DISTANCE);

const expectedPropertyCount = 47;
const expectedPropertyCount = 48;
expect(Object.keys(distanceTransaction ?? {}).length).toBe(expectedPropertyCount);
});

Expand Down Expand Up @@ -2474,6 +2486,7 @@ describe('SearchUIUtils', () => {
// eslint-disable-next-line @typescript-eslint/naming-convention
transactions_1805965960759424086: {
amount: 0,
canDelete: false,
category: 'Employee Meals Remote (Fringe Benefit)',
comment: {
comment: '',
Expand Down Expand Up @@ -2596,6 +2609,7 @@ describe('SearchUIUtils', () => {
// eslint-disable-next-line @typescript-eslint/naming-convention
transactions_1805965960759424086: {
amount: 0,
canDelete: false,
cardID: undefined,
cardName: undefined,
category: 'Employee Meals Remote (Fringe Benefit)',
Expand Down
2 changes: 2 additions & 0 deletions tests/unit/Search/handleActionButtonPressTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ const mockReportItemWithHold = {
action: 'view',
allActions: ['view'],
amount: -1200,
canDelete: true,
category: '',
comment: {
comment: '',
Expand Down Expand Up @@ -188,6 +189,7 @@ const mockReportItemWithHold = {
action: 'view',
allActions: ['view'],
amount: -12300,
canDelete: true,
category: '',
comment: {
comment: '',
Expand Down
1 change: 1 addition & 0 deletions tests/unit/TransactionGroupListItemTest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ jest.mock('@libs/SearchUIUtils', () => ({
const mockTransaction: TransactionListItemType = {
accountID: 1,
amount: 0,
canDelete: true,
category: '',
groupAmount: 1284,
groupCurrency: 'USD',
Expand Down
Loading