Skip to content

Commit

Permalink
Merge pull request #53743 from bernhardoj/fix/52861-chat-doesnt-scrol…
Browse files Browse the repository at this point in the history
…l-after-delete-attachment

Fix chat isn't scrolled down when deleting attachment
  • Loading branch information
puneetlath authored Dec 11, 2024
2 parents 001a6e2 + 6c1d45d commit cf7a4b9
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 17 deletions.
18 changes: 4 additions & 14 deletions src/pages/home/report/ReportActionsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ type ReportActionsListProps = {
/** Sorted actions prepared for display */
sortedReportActions: OnyxTypes.ReportAction[];

/** Sorted actions that should be visible to the user */
sortedVisibleReportActions: OnyxTypes.ReportAction[];

/** The ID of the most recent IOU report action connected with the shown report */
mostRecentIOUReportActionID?: string | null;

Expand Down Expand Up @@ -138,6 +141,7 @@ function ReportActionsList({
isLoadingNewerReportActions = false,
hasLoadingNewerReportActionsError = false,
sortedReportActions,
sortedVisibleReportActions,
onScroll,
mostRecentIOUReportActionID = '',
loadNewerChats,
Expand Down Expand Up @@ -182,20 +186,6 @@ function ReportActionsList({
const hasFooterRendered = useRef(false);
const linkedReportActionID = route?.params?.reportActionID ?? '-1';

const canUserPerformWriteAction = ReportUtils.canUserPerformWriteAction(report);

const sortedVisibleReportActions = useMemo(
() =>
sortedReportActions.filter(
(reportAction) =>
(isOffline ||
ReportActionsUtils.isDeletedParentAction(reportAction) ||
reportAction.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE ||
reportAction.errors) &&
ReportActionsUtils.shouldReportActionBeVisible(reportAction, reportAction.reportActionID, canUserPerformWriteAction),
),
[sortedReportActions, isOffline, canUserPerformWriteAction],
);
const lastAction = sortedVisibleReportActions.at(0);
const sortedVisibleReportActionsObjects: OnyxTypes.ReportActions = useMemo(
() =>
Expand Down
17 changes: 16 additions & 1 deletion src/pages/home/report/ReportActionsView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,19 @@ function ReportActionsView({
// currentReportActionID is needed to trigger batching once the report action has been positioned
// eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps
}, [reportActionID, combinedReportActions, indexOfLinkedAction, currentReportActionID]);
const canUserPerformWriteAction = ReportUtils.canUserPerformWriteAction(report);
const visibleReportActions = useMemo(
() =>
reportActions.filter(
(reportAction) =>
(isOffline ||
ReportActionsUtils.isDeletedParentAction(reportAction) ||
reportAction.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE ||
reportAction.errors) &&
ReportActionsUtils.shouldReportActionBeVisible(reportAction, reportAction.reportActionID, canUserPerformWriteAction),
),
[reportActions, isOffline, canUserPerformWriteAction],
);

const reportActionIDMap = useMemo(() => {
const reportActionIDs = allReportActions.map((action) => action.reportActionID);
Expand Down Expand Up @@ -285,7 +298,8 @@ function ReportActionsView({
const hasMoreCached = reportActions.length < combinedReportActions.length;
const newestReportAction = useMemo(() => reportActions?.at(0), [reportActions]);
const mostRecentIOUReportActionID = useMemo(() => ReportActionsUtils.getMostRecentIOURequestActionID(reportActions), [reportActions]);
const hasNewestReportAction = reportActions.at(0)?.created === report.lastVisibleActionCreated || reportActions.at(0)?.created === transactionThreadReport?.lastVisibleActionCreated;
const hasNewestReportAction =
visibleReportActions.at(0)?.created === report.lastVisibleActionCreated || visibleReportActions.at(0)?.created === transactionThreadReport?.lastVisibleActionCreated;
const oldestReportAction = useMemo(() => reportActions?.at(-1), [reportActions]);

useEffect(() => {
Expand Down Expand Up @@ -479,6 +493,7 @@ function ReportActionsView({
parentReportActionForTransactionThread={parentReportActionForTransactionThread}
onLayout={recordTimeToMeasureItemLayout}
sortedReportActions={reportActions}
sortedVisibleReportActions={visibleReportActions}
mostRecentIOUReportActionID={mostRecentIOUReportActionID}
loadOlderChats={loadOlderChats}
loadNewerChats={loadNewerChats}
Expand Down
6 changes: 4 additions & 2 deletions tests/perf-test/ReportActionsList.perf-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,16 @@ beforeEach(() => {
});

function ReportActionsListWrapper() {
const reportActions = ReportTestUtils.getMockedSortedReportActions(500);
return (
<ComposeProviders components={[OnyxProvider, LocaleContextProvider, ReportAttachmentsProvider]}>
<ReactionListContext.Provider value={mockRef}>
<ActionListContext.Provider value={mockRef}>
<ReportActionsList
parentReportAction={createRandomReportAction(1)}
parentReportActionForTransactionThread={undefined}
sortedReportActions={ReportTestUtils.getMockedSortedReportActions(500)}
sortedReportActions={reportActions}
sortedVisibleReportActions={reportActions}
report={LHNTestUtilsModule.getFakeReport()}
onLayout={mockOnLayout}
onScroll={mockOnScroll}
Expand All @@ -95,7 +97,7 @@ function ReportActionsListWrapper() {
loadOlderChats={mockLoadChats}
loadNewerChats={mockLoadChats}
transactionThreadReport={LHNTestUtilsModule.getFakeReport()}
reportActions={ReportTestUtils.getMockedSortedReportActions(500)}
reportActions={reportActions}
/>
</ActionListContext.Provider>
</ReactionListContext.Provider>
Expand Down

0 comments on commit cf7a4b9

Please sign in to comment.