Skip to content
Closed
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 @@ -80,11 +80,14 @@ const DELAY_FOR_SCROLLING_TO_END = 100;
const BACKFILL_MIN_ACTIONS_THRESHOLD = 50;

type MoneyRequestReportListProps = {
/** The reportID of the report to display */
reportID: string | undefined;

/** Callback executed on layout */
onLayout?: (event: LayoutChangeEvent) => void;
};

function MoneyRequestReportActionsList({onLayout}: MoneyRequestReportListProps) {
function MoneyRequestReportActionsList({reportID: reportIDProp, onLayout}: MoneyRequestReportListProps) {
const styles = useThemeStyles();
const {translate, getLocalDateFromDatetime} = useLocalize();
const {isOffline, lastOfflineAt, lastOnlineAt} = useNetworkWithOfflineStatus();
Expand All @@ -94,19 +97,18 @@ function MoneyRequestReportActionsList({onLayout}: MoneyRequestReportListProps)
const [isVisible, setIsVisible] = useState(Visibility.isVisible);
const isFocused = useIsFocused();
const route = useRoute<PlatformStackRouteProp<ReportsSplitNavigatorParamList, typeof SCREENS.REPORT>>();
const reportIDFromRoute = route.params.reportID;

// Self-subscribe to report, policy, metadata, actions, transactions
// report is guaranteed to exist — callers only render this component when report is loaded
const [report] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${reportIDFromRoute}`) as unknown as [OnyxTypes.Report];
const [report] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${reportIDProp}`) as unknown as [OnyxTypes.Report];
const [policy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${getNonEmptyStringOnyxID(report?.policyID)}`);
const [reportMetadata] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_METADATA}${reportIDFromRoute}`);
const [reportMetadata] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_METADATA}${reportIDProp}`);
const reportID = report?.reportID;

const {reportActions: unfilteredReportActions, hasNewerActions, hasOlderActions} = usePaginatedReportActions(reportID, route?.params?.reportActionID);
const reportActions = useMemo(() => getFilteredReportActionsForReportView(unfilteredReportActions), [unfilteredReportActions]);

const allReportTransactions = useReportTransactionsCollection(reportIDFromRoute);
const allReportTransactions = useReportTransactionsCollection(reportIDProp);
const reportTransactions = useMemo(() => getAllNonDeletedTransactions(allReportTransactions, reportActions, isOffline, true), [allReportTransactions, reportActions, isOffline]);
const transactions = useMemo(
() => reportTransactions?.filter((transaction) => isOffline || transaction.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE) ?? [],
Expand Down Expand Up @@ -670,7 +672,7 @@ function MoneyRequestReportActionsList({onLayout}: MoneyRequestReportListProps)
ref={wrapperViewRef}
>
<SelectionToolbar
reportID={reportIDFromRoute}
reportID={report.reportID}
transactions={transactions}
reportActions={reportActions}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,10 @@ function MoneyRequestReportView({report, reportMetadata, shouldDisplayReportFoot
)}
<View style={[styles.overflowHidden, styles.justifyContentEnd, styles.flex1]}>
{shouldDisplayMoneyRequestActionsList ? (
<MoneyRequestReportActionsList onLayout={onLayout} />
<MoneyRequestReportActionsList
reportID={reportID}
onLayout={onLayout}
/>
) : (
<ReportActionsView
reportID={reportID}
Expand Down
4 changes: 2 additions & 2 deletions src/pages/inbox/ReportActionsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ function ReportActionsList() {
}

if (shouldDisplayMoneyRequestActionsList) {
return <MoneyRequestReportActionsList />;
return <MoneyRequestReportActionsList reportID={report.reportID} />;
}

return <ReportActionsView reportID={reportIDFromRoute} />;
return <ReportActionsView reportID={report.reportID} />;
}

export default ReportActionsList;
8 changes: 4 additions & 4 deletions src/pages/inbox/report/ReportFooter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ function ReportFooter() {
const isSystemChat = isSystemChatUtil(report);
const isAdminsOnlyPostingRoom = isAdminsOnlyPostingRoomUtil(report);

if (!isCurrentReportLoadedFromOnyx || !report || !reportIDFromRoute) {
if (!isCurrentReportLoadedFromOnyx || !report) {
return null;
}

Expand All @@ -91,7 +91,7 @@ function ReportFooter() {
return (
<View style={[chatFooterStyles, isComposerFullSize && styles.chatFooterFullCompose]}>
<SwipeableView onSwipeDown={Keyboard.dismiss}>
<ReportActionCompose reportID={reportIDFromRoute} />
<ReportActionCompose reportID={report.reportID} />
</SwipeableView>
</View>
);
Expand All @@ -101,7 +101,7 @@ function ReportFooter() {
if (isArchivedRoom) {
return (
<View style={[styles.chatFooter, styles.mt4, shouldUseNarrowLayout && styles.mb5]}>
<ArchivedReportFooter reportID={reportIDFromRoute} />
<ArchivedReportFooter reportID={report.reportID} />
{!shouldUseNarrowLayout && (
<View style={styles.offlineIndicatorContainer}>
<OfflineIndicator containerStyles={[styles.chatItemComposeSecondaryRow]} />
Expand All @@ -115,7 +115,7 @@ function ReportFooter() {
if (isAnonymousUser) {
return (
<View style={[styles.chatFooter, styles.mt4, shouldUseNarrowLayout && styles.mb5]}>
<AnonymousReportFooter reportID={reportIDFromRoute} />
<AnonymousReportFooter reportID={report.reportID} />
{!shouldUseNarrowLayout && (
<View style={styles.offlineIndicatorContainer}>
<OfflineIndicator containerStyles={[styles.chatItemComposeSecondaryRow]} />
Expand Down
12 changes: 7 additions & 5 deletions tests/ui/MoneyRequestReportActionsListRejectModalTest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ jest.mock('@react-navigation/native', () => ({
useNavigationState: () => true,
usePreventRemove: jest.fn(),
useRoute: () => ({
key: 'test-key',
name: 'Report' as never,
params: {reportID: FAKE_REPORT_ID},
params: {},
}),
}));

Expand Down Expand Up @@ -196,7 +194,7 @@ const renderComponent = () => {
<ComposeProviders components={[OnyxListItemProvider, LocaleContextProvider]}>
<SearchContextProvider>
<ScreenWrapper testID="test">
<MoneyRequestReportActionsList />
<MoneyRequestReportActionsList reportID={FAKE_REPORT_ID} />
</ScreenWrapper>
</SearchContextProvider>
</ComposeProviders>,
Expand All @@ -212,13 +210,17 @@ describe('MoneyRequestReportActionsList - Reject Educational Modal', () => {
keys: ONYXKEYS,
evictableKeys: [ONYXKEYS.COLLECTION.REPORT_ACTIONS],
});
jest.spyOn(NativeNavigation, 'useRoute').mockReturnValue({
key: 'test-key',
name: 'Report' as never,
params: {reportID: FAKE_REPORT_ID},
});
jest.spyOn(NativeNavigation, 'useIsFocused').mockReturnValue(true);
await TestHelper.signInWithTestUser(FAKE_ACCOUNT_ID, FAKE_EMAIL);
});

beforeEach(async () => {
jest.clearAllMocks();
jest.spyOn(NativeNavigation, 'useIsFocused').mockReturnValue(true);
await act(async () => {
await Onyx.clear();
await waitForBatchedUpdatesWithAct();
Expand Down
Loading