Skip to content

Commit 4945938

Browse files
authored
Merge pull request #77110 from marufsharifi/fix/delete-expense-from-search-offline
fix(search): handle delete expenses from search in offline mode
2 parents 533cd70 + de4ecdd commit 4945938

File tree

12 files changed

+146
-114
lines changed

12 files changed

+146
-114
lines changed

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@
188188
"react-native-localize": "^3.5.4",
189189
"react-native-nitro-modules": "0.29.4",
190190
"react-native-nitro-sqlite": "9.2.0",
191-
"react-native-onyx": "3.0.32",
191+
"react-native-onyx": "3.0.33",
192192
"react-native-pager-view": "7.0.2",
193193
"react-native-pdf": "7.0.2",
194194
"react-native-performance": "^6.0.0",

src/components/SelectionListWithSections/Search/TransactionListItem.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ function TransactionListItem<TItem extends ListItem>({
205205
handleActionButtonPress={handleActionButtonPress}
206206
shouldShowUserInfo={!!transactionItem?.from}
207207
isInMobileSelectionMode={shouldUseNarrowLayout && !!canSelectMultiple}
208+
isDisabledItem={!!isDisabled}
208209
/>
209210
)}
210211
<TransactionItemRow
@@ -217,6 +218,7 @@ function TransactionListItem<TItem extends ListItem>({
217218
columns={columns}
218219
isActionLoading={isLoading ?? isActionLoading}
219220
isSelected={!!transactionItem.isSelected}
221+
isDisabled={!!isDisabled}
220222
dateColumnSize={dateColumnSize}
221223
submittedColumnSize={submittedColumnSize}
222224
approvedColumnSize={approvedColumnSize}

src/components/SelectionListWithSections/Search/UserInfoAndActionButtonRow.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,14 @@ function UserInfoAndActionButtonRow({
1919
shouldShowUserInfo,
2020
containerStyles,
2121
isInMobileSelectionMode,
22+
isDisabledItem = false,
2223
}: {
2324
item: TransactionReportGroupListItemType | TransactionListItemType;
2425
handleActionButtonPress: () => void;
2526
shouldShowUserInfo: boolean;
2627
containerStyles?: StyleProp<ViewStyle>;
2728
isInMobileSelectionMode: boolean;
29+
isDisabledItem?: boolean;
2830
}) {
2931
const styles = useThemeStyles();
3032
const {isLargeScreenWidth} = useResponsiveLayout();
@@ -73,7 +75,7 @@ function UserInfoAndActionButtonRow({
7375
hash={item.hash}
7476
amount={(item as TransactionListItemType)?.amount ?? (item as TransactionReportGroupListItemType)?.total}
7577
extraSmall={!isLargeScreenWidth}
76-
shouldDisablePointerEvents={isInMobileSelectionMode}
78+
shouldDisablePointerEvents={isInMobileSelectionMode || isDisabledItem}
7779
/>
7880
</View>
7981
</View>

src/components/TransactionItemRow/index.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,7 @@ function TransactionItemRow({
409409
policyID={report?.policyID}
410410
hash={transactionItem?.hash}
411411
amount={report?.total}
412+
shouldDisablePointerEvents={isDisabled}
412413
/>
413414
)}
414415
</View>
@@ -602,6 +603,7 @@ function TransactionItemRow({
602603
isReportItemChild,
603604
onButtonPress,
604605
isActionLoading,
606+
isDisabled,
605607
merchant,
606608
description,
607609
cardName,
@@ -780,6 +782,7 @@ function TransactionItemRow({
780782
)}
781783
{!!isLargeScreenWidth && !!onArrowRightPress && (
782784
<PressableWithFeedback
785+
disabled={!!isDisabled}
783786
onPress={() => onArrowRightPress?.()}
784787
style={[styles.p3Half, styles.pl0half, styles.pr0half, styles.justifyContentCenter, styles.alignItemsEnd]}
785788
accessibilityRole={CONST.ROLE.BUTTON}

src/hooks/useDeleteTransactions.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,6 @@ function useDeleteTransactions({report, reportActions, policy}: UseDeleteTransac
179179
isSingleTransactionView,
180180
transactionIDsPendingDeletion: deletedTransactionIDs,
181181
selectedTransactionIDs: transactionIDs,
182-
hash: currentSearchHash,
183182
allTransactionViolationsParam: transactionViolations,
184183
currentUserAccountID: currentUserPersonalDetails.accountID,
185184
});

src/libs/SearchUIUtils.ts

Lines changed: 33 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -4604,50 +4604,46 @@ function updateQueryStringOnSearchTypeChange(type: SearchDataTypes, searchAdvanc
46044604
function shouldShowDeleteOption(
46054605
selectedTransactions: Record<string, SelectedTransactionInfo>,
46064606
currentSearchResults: SearchResults['data'] | undefined,
4607-
isOffline: boolean,
46084607
selectedReports: SelectedReports[] = [],
46094608
searchDataType?: SearchDataTypes,
46104609
) {
46114610
const selectedTransactionsKeys = Object.keys(selectedTransactions);
46124611

4613-
return (
4614-
!isOffline &&
4615-
(selectedReports.length && searchDataType !== CONST.SEARCH.DATA_TYPES.EXPENSE
4616-
? selectedReports.every((selectedReport) => {
4617-
const fullReport = currentSearchResults?.[`${ONYXKEYS.COLLECTION.REPORT}${selectedReport.reportID}`];
4618-
if (!fullReport) {
4619-
return false;
4620-
}
4621-
const reportActionsData = currentSearchResults?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${selectedReport.reportID}`];
4622-
const reportActionsArray = Object.values(reportActionsData ?? {});
4623-
const reportTransactions: OnyxTypes.Transaction[] = [];
4624-
const searchData = currentSearchResults ?? {};
4625-
for (const key of Object.keys(searchData)) {
4626-
if (!key.startsWith(ONYXKEYS.COLLECTION.TRANSACTION)) {
4627-
continue;
4628-
}
4629-
const item = searchData[key as keyof typeof searchData] as OnyxTypes.Transaction | undefined;
4630-
if (item && 'transactionID' in item && 'reportID' in item && item.reportID === selectedReport.reportID) {
4631-
reportTransactions.push(item);
4632-
}
4612+
return selectedReports.length && searchDataType !== CONST.SEARCH.DATA_TYPES.EXPENSE
4613+
? selectedReports.every((selectedReport) => {
4614+
const fullReport = currentSearchResults?.[`${ONYXKEYS.COLLECTION.REPORT}${selectedReport.reportID}`];
4615+
if (!fullReport) {
4616+
return false;
4617+
}
4618+
const reportActionsData = currentSearchResults?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${selectedReport.reportID}`];
4619+
const reportActionsArray = Object.values(reportActionsData ?? {});
4620+
const reportTransactions: OnyxTypes.Transaction[] = [];
4621+
const searchData = currentSearchResults ?? {};
4622+
for (const key of Object.keys(searchData)) {
4623+
if (!key.startsWith(ONYXKEYS.COLLECTION.TRANSACTION)) {
4624+
continue;
46334625
}
4634-
return canDeleteMoneyRequestReport(fullReport, reportTransactions, reportActionsArray);
4635-
})
4636-
: selectedTransactionsKeys.every((id) => {
4637-
const transaction = currentSearchResults?.[`${ONYXKEYS.COLLECTION.TRANSACTION}${id}`] ?? selectedTransactions[id]?.transaction;
4638-
if (!transaction) {
4639-
return false;
4626+
const item = searchData[key as keyof typeof searchData] as OnyxTypes.Transaction | undefined;
4627+
if (item && 'transactionID' in item && 'reportID' in item && item.reportID === selectedReport.reportID) {
4628+
reportTransactions.push(item);
46404629
}
4641-
const parentReportID = transaction.reportID;
4642-
const parentReport = currentSearchResults?.[`${ONYXKEYS.COLLECTION.REPORT}${parentReportID}`] ?? selectedTransactions[id].report;
4643-
const reportActions = currentSearchResults?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${parentReportID}`];
4644-
const parentReportAction =
4645-
Object.values(reportActions ?? {}).find((action) => (isMoneyRequestAction(action) ? getOriginalMessage(action)?.IOUTransactionID : undefined) === id) ??
4646-
selectedTransactions[id].reportAction;
4647-
4648-
return canDeleteMoneyRequestReport(parentReport, [transaction], parentReportAction ? [parentReportAction] : []);
4649-
}))
4650-
);
4630+
}
4631+
return canDeleteMoneyRequestReport(fullReport, reportTransactions, reportActionsArray);
4632+
})
4633+
: selectedTransactionsKeys.every((id) => {
4634+
const transaction = currentSearchResults?.[`${ONYXKEYS.COLLECTION.TRANSACTION}${id}`] ?? selectedTransactions[id]?.transaction;
4635+
if (!transaction) {
4636+
return false;
4637+
}
4638+
const parentReportID = transaction.reportID;
4639+
const parentReport = currentSearchResults?.[`${ONYXKEYS.COLLECTION.REPORT}${parentReportID}`] ?? selectedTransactions[id].report;
4640+
const reportActions = currentSearchResults?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${parentReportID}`];
4641+
const parentReportAction =
4642+
Object.values(reportActions ?? {}).find((action) => (isMoneyRequestAction(action) ? getOriginalMessage(action)?.IOUTransactionID : undefined) === id) ??
4643+
selectedTransactions[id].reportAction;
4644+
4645+
return canDeleteMoneyRequestReport(parentReport, [transaction], parentReportAction ? [parentReportAction] : []);
4646+
});
46514647
}
46524648

46534649
export {

src/libs/actions/IOU/index.ts

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -872,7 +872,6 @@ type DeleteMoneyRequestFunctionParams = {
872872
isSingleTransactionView?: boolean;
873873
transactionIDsPendingDeletion?: string[];
874874
selectedTransactionIDs?: string[];
875-
hash?: number;
876875
allTransactionViolationsParam: OnyxCollection<OnyxTypes.TransactionViolations>;
877876
currentUserAccountID: number;
878877
};
@@ -8796,7 +8795,6 @@ function deleteMoneyRequest({
87968795
transactionIDsPendingDeletion,
87978796
selectedTransactionIDs,
87988797
allTransactionViolationsParam,
8799-
hash,
88008798
currentUserAccountID,
88018799
}: DeleteMoneyRequestFunctionParams) {
88028800
if (!transactionID) {
@@ -8822,13 +8820,7 @@ function deleteMoneyRequest({
88228820
// STEP 2: Build Onyx data
88238821
// The logic mostly resembles the cleanUpMoneyRequest function
88248822
const optimisticData: Array<
8825-
OnyxUpdate<
8826-
| typeof ONYXKEYS.COLLECTION.TRANSACTION
8827-
| typeof ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS
8828-
| typeof ONYXKEYS.COLLECTION.REPORT
8829-
| typeof ONYXKEYS.COLLECTION.REPORT_ACTIONS
8830-
| typeof ONYXKEYS.COLLECTION.SNAPSHOT
8831-
>
8823+
OnyxUpdate<typeof ONYXKEYS.COLLECTION.TRANSACTION | typeof ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS | typeof ONYXKEYS.COLLECTION.REPORT | typeof ONYXKEYS.COLLECTION.REPORT_ACTIONS>
88328824
> = [
88338825
{
88348826
onyxMethod: Onyx.METHOD.SET,
@@ -9057,23 +9049,6 @@ function deleteMoneyRequest({
90579049
});
90589050
}
90599051

9060-
if (hash && shouldDeleteIOUReport) {
9061-
optimisticData.push({
9062-
onyxMethod: Onyx.METHOD.MERGE,
9063-
key: `${ONYXKEYS.COLLECTION.SNAPSHOT}${hash}`,
9064-
value: {
9065-
data: {
9066-
[`${ONYXKEYS.COLLECTION.REPORT}${iouReport?.reportID}`]: {
9067-
pendingFields: {
9068-
// @ts-expect-error - will be solved in https://github.com/Expensify/App/issues/73830
9069-
preview: CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE,
9070-
},
9071-
},
9072-
},
9073-
},
9074-
});
9075-
}
9076-
90779052
const parameters: DeleteMoneyRequestParams = {
90789053
transactionID,
90799054
reportActionID: reportAction.reportActionID,

0 commit comments

Comments
 (0)