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
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import useThemeStyles from '@hooks/useThemeStyles';
import {handleActionButtonPress} from '@libs/actions/Search';
import {syncMissingAttendeesViolation} from '@libs/AttendeeUtils';
import getNonEmptyStringOnyxID from '@libs/getNonEmptyStringOnyxID';
import {isInvoiceReport, isOpenExpenseReport, isProcessingReport} from '@libs/ReportUtils';
import {isInvoiceReport, isOpenExpenseReport, isProcessingReport, isReportPendingDelete} from '@libs/ReportUtils';
import {isViolationDismissed, shouldShowViolation} from '@libs/TransactionUtils';
import variables from '@styles/variables';
import CONST from '@src/CONST';
Expand Down Expand Up @@ -82,6 +82,10 @@ function ExpenseReportListItem<TItem extends ListItem>({
return reportItem.isDisabled ?? reportItem.isDisabledCheckbox;
}, [reportItem.isDisabled, reportItem.isDisabledCheckbox]);

// Prefer live Onyx data over stale search snapshot for pending delete check.
const reportForPendingDeleteCheck = parentReport ?? reportItem;
const isPendingDelete = isReportPendingDelete(reportForPendingDeleteCheck);

// Prefer live Onyx policy data over snapshot to ensure fresh policy settings
// like isAttendeeTrackingEnabled is not missing
// Use snapshotReport/snapshotPolicy as fallbacks to fix offline issues where
Expand Down Expand Up @@ -162,8 +166,9 @@ function ExpenseReportListItem<TItem extends ListItem>({
styles.bgTransparent,
item.isSelected && styles.activeComponentBG,
styles.mh0,
isPendingDelete && styles.cursorDisabled,
],
[styles, item.isSelected],
[styles, item.isSelected, isPendingDelete],
);

const listItemWrapperStyle = useMemo(
Expand Down Expand Up @@ -237,10 +242,12 @@ function ExpenseReportListItem<TItem extends ListItem>({
onLongPressRow={onLongPressRow}
shouldSyncFocus={shouldSyncFocus}
hoverStyle={item.isSelected && styles.activeComponentBG}
pressableWrapperStyle={[styles.mh5, animatedHighlightStyle]}
pressableWrapperStyle={[styles.mh5, animatedHighlightStyle, isPendingDelete && styles.cursorDisabled]}
accessible={false}
shouldShowRightCaret={false}
shouldUseDefaultRightHandSideCheckmark={false}
isDisabled={isPendingDelete}
shouldDisableHoverStyle={isPendingDelete}
Comment thread
TaduJR marked this conversation as resolved.
Resolved
>
{(hovered) => (
<View style={[styles.flex1]}>
Expand All @@ -258,6 +265,7 @@ function ExpenseReportListItem<TItem extends ListItem>({
isDisabledCheckbox={isDisabledCheckbox}
isHovered={hovered}
isFocused={isFocused}
isPendingDelete={isPendingDelete}
/>
{getDescription}
</View>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ type ExpenseReportListItemRowProps = {
isDisabledCheckbox?: boolean;
isHovered?: boolean;
isFocused?: boolean;
isPendingDelete?: boolean;
columns?: SearchColumnType[];
};

Expand All @@ -65,6 +66,7 @@ function ExpenseReportListItemRow({
columns = [],
isHovered = false,
isFocused = false,
isPendingDelete = false,
}: ExpenseReportListItemRowProps) {
const StyleUtils = useStyleUtils();
const styles = useThemeStyles();
Expand Down Expand Up @@ -207,6 +209,7 @@ function ExpenseReportListItemRow({
reportID={item.reportID}
hash={item.hash}
amount={item.total}
shouldDisablePointerEvents={isPendingDelete}
/>
</View>
),
Expand Down Expand Up @@ -312,7 +315,7 @@ function ExpenseReportListItemRow({
hash={item.hash}
amount={item.total}
extraSmall
shouldDisablePointerEvents={isInMobileSelectionMode}
shouldDisablePointerEvents={isInMobileSelectionMode || isPendingDelete}
/>
</View>
</View>
Expand Down
34 changes: 30 additions & 4 deletions src/hooks/useSearchSections.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,30 @@
import type {OnyxEntry} from 'react-native-onyx';
import {selectFilteredReportActions} from '@libs/ReportUtils';
import type {OnyxCollection, OnyxEntry} from 'react-native-onyx';
import {isReportPendingDelete, selectFilteredReportActions} from '@libs/ReportUtils';
import {getSections, getSortedSections} from '@libs/SearchUIUtils';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import type {Report} from '@src/types/onyx';
import type LastSearchParams from '@src/types/onyx/ReportNavigation';
import useActionLoadingReportIDs from './useActionLoadingReportIDs';
import useArchivedReportsIdSet from './useArchivedReportsIdSet';
import useCurrentUserPersonalDetails from './useCurrentUserPersonalDetails';
import useLocalize from './useLocalize';
import useOnyx from './useOnyx';

/**
* Returns sorted keys of reports pending deletion.
* Sorted string[] keeps Onyx comparison cheap (PERF-11).
*/
const selectPendingDeleteReportKeys = (reports: OnyxCollection<Report>): string[] => {
Comment thread
TaduJR marked this conversation as resolved.
Resolved
const keys: string[] = [];
for (const [key, report] of Object.entries(reports ?? {})) {
if (isReportPendingDelete(report)) {
keys.push(key);
}
}
return keys.sort();
};

type UseSearchSectionsResult = {
allReports: Array<string | undefined>;
isSearchLoading: boolean;
Expand All @@ -18,6 +34,8 @@ type UseSearchSectionsResult = {
function useSearchSections(): UseSearchSectionsResult {
const [lastSearchQuery] = useOnyx(ONYXKEYS.REPORT_NAVIGATION_LAST_SEARCH_QUERY);
const [currentSearchResults] = useOnyx(`${ONYXKEYS.COLLECTION.SNAPSHOT}${lastSearchQuery?.queryJSON?.hash}`);
const [pendingDeleteReportKeys = CONST.EMPTY_ARRAY] = useOnyx(ONYXKEYS.COLLECTION.REPORT, {selector: selectPendingDeleteReportKeys});
const pendingDeleteReportKeysSet = new Set(pendingDeleteReportKeys);
const currentUserDetails = useCurrentUserPersonalDetails();
const {localeCompare, formatPhoneNumber, translate} = useLocalize();
const isActionLoadingSet = useActionLoadingReportIDs();
Expand All @@ -42,7 +60,7 @@ function useSearchSections(): UseSearchSectionsResult {
const currentUserEmail = currentUserDetails.email ?? '';
const searchKey = lastSearchQuery?.searchKey;

let allReports: Array<string | undefined> = [];
let results: Array<string | undefined> = [];
if (!!type && !!searchResultsData && !!searchResultsSearch) {
const [searchData] = getSections({
type,
Expand All @@ -62,10 +80,18 @@ function useSearchSections(): UseSearchSectionsResult {
cardList,
conciergeReportID,
});
allReports = getSortedSections(type, status ?? '', searchData, localeCompare, translate, sortBy, sortOrder, groupBy).map((value) => value.reportID);
results = getSortedSections(type, status ?? '', searchData, localeCompare, translate, sortBy, sortOrder, groupBy).map((value) => value.reportID);
}

const allReports = results.filter((id) => {
if (!id) {
return false;
}
return !pendingDeleteReportKeysSet.has(`${ONYXKEYS.COLLECTION.REPORT}${id}`);
});

return {allReports, isSearchLoading: !!currentSearchResults?.search?.isLoading, lastSearchQuery};
}

export {selectPendingDeleteReportKeys};
export default useSearchSections;
9 changes: 9 additions & 0 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1054,7 +1054,7 @@
};

let conciergeReportIDOnyxConnect: OnyxEntry<string>;
Onyx.connect({

Check warning on line 1057 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.CONCIERGE_REPORT_ID,
callback: (value) => {
conciergeReportIDOnyxConnect = value;
Expand All @@ -1062,7 +1062,7 @@
});

const defaultAvatarBuildingIconTestID = 'SvgDefaultAvatarBuilding Icon';
Onyx.connect({

Check warning on line 1065 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.SESSION,
callback: (value) => {
// When signed out, val is undefined
Expand All @@ -1080,7 +1080,7 @@
let allPersonalDetails: OnyxEntry<PersonalDetailsList>;
let allPersonalDetailLogins: string[];
let currentUserPersonalDetails: OnyxEntry<PersonalDetails>;
Onyx.connect({

Check warning on line 1083 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
callback: (value) => {
if (deprecatedCurrentUserAccountID) {
Expand All @@ -1092,7 +1092,7 @@
});

let allReportsDraft: OnyxCollection<Report>;
Onyx.connect({

Check warning on line 1095 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.REPORT_DRAFT,
waitForCollectionCallback: true,
callback: (value) => (allReportsDraft = value),
Expand All @@ -1100,7 +1100,7 @@

let allPolicies: OnyxCollection<Policy>;
let policiesArray: Policy[] = [];
Onyx.connect({

Check warning on line 1103 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.POLICY,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -1110,7 +1110,7 @@
});

let allPolicyDrafts: OnyxCollection<Policy>;
Onyx.connect({

Check warning on line 1113 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.POLICY_DRAFTS,
waitForCollectionCallback: true,
callback: (value) => (allPolicyDrafts = value),
Expand All @@ -1118,7 +1118,7 @@

let allReports: OnyxCollection<Report>;
let reportsByPolicyID: ReportByPolicyMap;
Onyx.connect({

Check warning on line 1121 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.REPORT,
waitForCollectionCallback: true,
callback: (value) => {
Expand Down Expand Up @@ -1154,14 +1154,14 @@
});

let betaConfiguration: OnyxEntry<BetaConfiguration> = {};
Onyx.connect({

Check warning on line 1157 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.BETA_CONFIGURATION,
callback: (value) => (betaConfiguration = value ?? {}),
});

let deprecatedAllTransactions: OnyxCollection<Transaction> = {};
let deprecatedReportsTransactions: Record<string, Transaction[]> = {};
Onyx.connect({

Check warning on line 1164 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.TRANSACTION,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -1187,7 +1187,7 @@
});

let allReportActions: OnyxCollection<ReportActions>;
Onyx.connect({

Check warning on line 1190 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.REPORT_ACTIONS,
waitForCollectionCallback: true,
callback: (actions) => {
Expand Down Expand Up @@ -10252,6 +10252,14 @@
return parentReportAction?.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE;
}

/**
* Check if a report itself is pending deletion via its own pendingAction or pendingFields.preview.
* Unlike isMoneyRequestReportPendingDeletion (which checks the parent report action), this checks the report directly.
*/
function isReportPendingDelete(report: OnyxEntry<Pick<Report, 'pendingAction' | 'pendingFields'>>): boolean {
return report?.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE || report?.pendingFields?.preview === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE;
}

function navigateToLinkedReportAction(
ancestor: Ancestor,
isInNarrowPaneModal: boolean,
Expand Down Expand Up @@ -13473,6 +13481,7 @@
isMoneyRequest,
isMoneyRequestReport,
isMoneyRequestReportPendingDeletion,
isReportPendingDelete,
isOneOnOneChat,
isOneTransactionThread,
isOpenExpenseReport,
Expand Down
27 changes: 27 additions & 0 deletions tests/unit/ReportUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ import {
isPayer,
isReportIneligibleForMoveExpenses,
isReportOutstanding,
isReportPendingDelete,
isRootGroupChat,
isSelfDMOrSelfDMThread,
isWorkspaceMemberLeavingWorkspaceRoom,
Expand Down Expand Up @@ -5006,6 +5007,32 @@ describe('ReportUtils', () => {
});
});

describe('isReportPendingDelete', () => {
it('should return true when pendingAction is DELETE', () => {
expect(isReportPendingDelete({pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE})).toBe(true);
});

it('should return true when pendingFields.preview is DELETE', () => {
expect(isReportPendingDelete({pendingFields: {preview: CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE}})).toBe(true);
});

it('should return true when both pendingAction and pendingFields.preview are DELETE', () => {
expect(isReportPendingDelete({pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE, pendingFields: {preview: CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE}})).toBe(true);
});

it('should return false when neither field indicates deletion', () => {
expect(isReportPendingDelete({pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD})).toBe(false);
});

it('should return false for undefined report', () => {
expect(isReportPendingDelete(undefined)).toBe(false);
});

it('should return false when pendingFields exists but preview is not DELETE', () => {
expect(isReportPendingDelete({pendingFields: {preview: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE}})).toBe(false);
});
});

describe('canEditMoneyRequest', () => {
it('it should return false for archived invoice', async () => {
const invoiceReport: Report = {
Expand Down
Loading
Loading