Skip to content

Commit c31d429

Browse files
committed
usign reportID from route
1 parent 9a23626 commit c31d429

4 files changed

Lines changed: 12 additions & 19 deletions

File tree

src/components/MoneyRequestReportView/MoneyRequestReportActionsList.tsx

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,11 @@ const DELAY_FOR_SCROLLING_TO_END = 100;
8080
const BACKFILL_MIN_ACTIONS_THRESHOLD = 50;
8181

8282
type MoneyRequestReportListProps = {
83-
/** The reportID of the report to display */
84-
reportID: string | undefined;
85-
8683
/** Callback executed on layout */
8784
onLayout?: (event: LayoutChangeEvent) => void;
8885
};
8986

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

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

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

111-
const allReportTransactions = useReportTransactionsCollection(reportIDProp);
109+
const allReportTransactions = useReportTransactionsCollection(reportIDFromRoute);
112110
const reportTransactions = useMemo(() => getAllNonDeletedTransactions(allReportTransactions, reportActions, isOffline, true), [allReportTransactions, reportActions, isOffline]);
113111
const transactions = useMemo(
114112
() => reportTransactions?.filter((transaction) => isOffline || transaction.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE) ?? [],

src/components/MoneyRequestReportView/MoneyRequestReportView.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -273,10 +273,7 @@ function MoneyRequestReportView({report, reportMetadata, shouldDisplayReportFoot
273273
)}
274274
<View style={[styles.overflowHidden, styles.justifyContentEnd, styles.flex1]}>
275275
{shouldDisplayMoneyRequestActionsList ? (
276-
<MoneyRequestReportActionsList
277-
reportID={reportID}
278-
onLayout={onLayout}
279-
/>
276+
<MoneyRequestReportActionsList onLayout={onLayout} />
280277
) : (
281278
<ReportActionsView
282279
reportID={reportID}

src/pages/inbox/ReportActionsList.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ function ReportActionsList() {
5050
}
5151

5252
if (shouldDisplayMoneyRequestActionsList) {
53-
return <MoneyRequestReportActionsList reportID={report.reportID} />;
53+
return <MoneyRequestReportActionsList />;
5454
}
5555

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

tests/ui/MoneyRequestReportActionsListRejectModalTest.tsx

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ jest.mock('@react-navigation/native', () => ({
2626
useNavigationState: () => true,
2727
usePreventRemove: jest.fn(),
2828
useRoute: () => ({
29-
params: {},
29+
key: 'test-key',
30+
name: 'Report' as never,
31+
params: {reportID: FAKE_REPORT_ID},
3032
}),
3133
}));
3234

@@ -194,7 +196,7 @@ const renderComponent = () => {
194196
<ComposeProviders components={[OnyxListItemProvider, LocaleContextProvider]}>
195197
<SearchContextProvider>
196198
<ScreenWrapper testID="test">
197-
<MoneyRequestReportActionsList reportID={FAKE_REPORT_ID} />
199+
<MoneyRequestReportActionsList />
198200
</ScreenWrapper>
199201
</SearchContextProvider>
200202
</ComposeProviders>,
@@ -210,17 +212,13 @@ describe('MoneyRequestReportActionsList - Reject Educational Modal', () => {
210212
keys: ONYXKEYS,
211213
evictableKeys: [ONYXKEYS.COLLECTION.REPORT_ACTIONS],
212214
});
213-
jest.spyOn(NativeNavigation, 'useRoute').mockReturnValue({
214-
key: 'test-key',
215-
name: 'Report' as never,
216-
params: {reportID: FAKE_REPORT_ID},
217-
});
218215
jest.spyOn(NativeNavigation, 'useIsFocused').mockReturnValue(true);
219216
await TestHelper.signInWithTestUser(FAKE_ACCOUNT_ID, FAKE_EMAIL);
220217
});
221218

222219
beforeEach(async () => {
223220
jest.clearAllMocks();
221+
jest.spyOn(NativeNavigation, 'useIsFocused').mockReturnValue(true);
224222
await act(async () => {
225223
await Onyx.clear();
226224
await waitForBatchedUpdatesWithAct();

0 commit comments

Comments
 (0)