Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HIGH: (Comment linking: Step 4) Main "glue" PR for Comment Linking #30269

Merged
merged 191 commits into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from 116 commits
Commits
Show all changes
191 commits
Select commit Hold shift + click to select a range
5258cff
update openReport
perunt Sep 29, 2023
5cd7e4c
update the rest openReport calls
perunt Sep 29, 2023
65edb74
WIP linking utils
perunt Sep 30, 2023
2b2fd86
Merge branch 'main' of https://github.com/Expensify/App into feat/##2…
perunt Oct 2, 2023
03804db
WIP navigation, useRouteChangeHandler
perunt Oct 2, 2023
319bd9c
WIP linking
perunt Oct 3, 2023
4f42f2a
Merge branch 'main' of https://github.com/Expensify/App into feat/##2…
perunt Oct 4, 2023
0895706
Merge branch 'feat/##23220-bidirectional-pagination' of https://githu…
perunt Oct 5, 2023
241a299
still WIP
perunt Oct 5, 2023
39d1747
Merge branch 'feat/##23220-bidirectional-pagination' of https://githu…
perunt Oct 9, 2023
7ca7643
remove timer
perunt Oct 9, 2023
8ce9ca0
scroll to
perunt Oct 9, 2023
ab6350b
Merge branch 'feat/##23220-bidirectional-pagination' of https://githu…
perunt Oct 10, 2023
8efb8fd
fix getSlicedRangeFromArrayByID
perunt Oct 10, 2023
cfda4c0
update cutting method
perunt Oct 10, 2023
86e4a69
Merge branch 'feat/##23220-bidirectional-pagination' of https://githu…
perunt Oct 11, 2023
16c4231
remove comments
perunt Oct 11, 2023
00071da
Merge branch 'feat/##23220-bidirectional-pagination' of https://githu…
perunt Oct 23, 2023
adb4162
include deleted message in getRangeFromArrayByID
perunt Oct 24, 2023
60d4110
Merge branch 'main' of https://github.com/Expensify/App into feat/##2…
perunt Oct 24, 2023
bfb6da6
Merge branch 'main' of https://github.com/Expensify/App into feat/##2…
perunt Oct 25, 2023
8f9f32c
Merge branch 'main' of https://github.com/Expensify/App into feat/##2…
perunt Nov 3, 2023
b94dde2
Merge branch 'feat/##23220-web-adjustForMaintainVisibleContentPositio…
perunt Nov 3, 2023
07b40b0
Merge branch 'feat/##23229-linking' of https://github.com/margelo/exp…
perunt Nov 3, 2023
177b08c
Merge branch 'main' of https://github.com/Expensify/App into feat/##2…
perunt Nov 5, 2023
66a5c85
Merge branch 'main' of https://github.com/Expensify/App into feat/##2…
perunt Nov 7, 2023
1f073b0
fix sliding
perunt Nov 7, 2023
5ca9877
Merge branch 'main' of https://github.com/Expensify/App into feat/##2…
perunt Nov 8, 2023
8293266
Merge branch 'main' of https://github.com/Expensify/App into feat/##2…
perunt Nov 9, 2023
2b7a735
fix getSlicedRangeFromArrayByID
perunt Nov 12, 2023
a91ea76
Merge branch 'main' of https://github.com/Expensify/App into feat/##2…
perunt Nov 22, 2023
dae1aa6
Merge branch 'main' of https://github.com/Expensify/App into feat/##2…
perunt Nov 27, 2023
50df006
Merge branch 'main' of https://github.com/Expensify/App into feat/##2…
perunt Nov 28, 2023
9f86218
lint
perunt Nov 28, 2023
5a22a09
Merge branch 'feat/##23220-web-maintainVisibleContentPosition' of htt…
perunt Dec 7, 2023
f7b70da
Merge branch 'main' of https://github.com/Expensify/App into feat/##2…
perunt Dec 7, 2023
2571096
Merge branch 'perunt/fix-last-spacer' of https://github.com/margelo/e…
perunt Dec 11, 2023
dcfdf81
Merge branch 'perunt/fix-last-spacer' of https://github.com/margelo/e…
perunt Dec 11, 2023
f1fa435
Merge branch 'main' of https://github.com/Expensify/App into feat/##2…
perunt Dec 11, 2023
5033232
Merge branch 'perunt/fix-last-spacer' of https://github.com/margelo/e…
perunt Dec 12, 2023
6bc7064
Merge branch 'perunt/fix-last-spacer' of https://github.com/margelo/e…
perunt Dec 15, 2023
54cce24
Merge branch 'main' of https://github.com/Expensify/App into feat/##2…
perunt Dec 16, 2023
2d083d3
WIP pagination
perunt Dec 18, 2023
262e13c
Merge branch 'feat/##23220-web-maintainVisibleContentPosition' of htt…
perunt Dec 19, 2023
37b41c1
fix linking
perunt Dec 19, 2023
a42d360
remove autoscrollToTopThreshold
perunt Dec 19, 2023
67d530e
clean ReportActionsUtils
perunt Dec 19, 2023
aaf0377
update initialNumToRender for web and desktop
perunt Dec 19, 2023
d6a9f58
add listID for resetting
perunt Dec 19, 2023
45fbbf0
WIP: fix MVCPFlatList
perunt Dec 19, 2023
9d3ffa0
Merge branch 'perunt/bidirectional-list-loader-mobile-fix' of https:/…
perunt Dec 20, 2023
0550d26
Merge branch 'perunt/bidirectional-list-loader-mobile-fix' of https:/…
perunt Dec 20, 2023
e8c9f33
Merge branch 'feat/##23220-web-maintainVisibleContentPosition' of htt…
perunt Dec 20, 2023
8246afc
Merge branch 'main' of https://github.com/Expensify/App into feat/##2…
perunt Dec 20, 2023
736a1e6
fix after merge
perunt Dec 20, 2023
c175475
another fix after merge
perunt Dec 20, 2023
d94d8d6
add pending reportAction to sorted list
perunt Dec 21, 2023
338fe4a
explaining
perunt Dec 21, 2023
6cf2220
WIP: temporary clean onyx button
perunt Dec 21, 2023
a51f07a
Merge branch 'perunt/fix-last-spacer' of https://github.com/margelo/e…
perunt Dec 21, 2023
27fb371
Merge branch 'feat/##23220-web-maintainVisibleContentPosition' of htt…
perunt Dec 21, 2023
ee2b779
return patches
perunt Dec 22, 2023
8196979
block fetching newer actions if the screen size is too large
perunt Dec 22, 2023
0766784
Merge remote-tracking branch 'margelo/feat/##23220-web-maintainVisibl…
janicduplessis Dec 22, 2023
c7d27f1
Merge branch 'feat/##23229-linking' of https://github.com/margelo/exp…
perunt Dec 22, 2023
7f94ded
fix bottom loader for invisible actions
perunt Dec 23, 2023
91b8a48
run hover after interaction
perunt Dec 27, 2023
3f652b2
add types
perunt Dec 27, 2023
7ab464f
remove shouldMarkTheFirstItemAsNewest
perunt Dec 27, 2023
800b626
add runHoverAfterInteraction to report
perunt Dec 27, 2023
d594cec
adjust the chat cutting for proper layout
perunt Dec 27, 2023
96a1d42
bring back 'Inverted fix'
perunt Dec 27, 2023
8e7496e
Merge branch 'main' of https://github.com/Expensify/App into feat/##2…
perunt Dec 28, 2023
d001638
Merge branch 'feat/##23220-web-maintainVisibleContentPosition' of htt…
perunt Dec 30, 2023
89227b2
fix Safari
perunt Dec 30, 2023
ac7c0c4
bump WINDOW_SIZE
perunt Jan 3, 2024
6fb63e4
fix outdated loader data before navigating
perunt Jan 3, 2024
2c93365
refactor initialNumToRender
perunt Jan 3, 2024
17a6b90
add debounce for fetching newer actions
perunt Jan 3, 2024
b9e739a
add 'scroll to the bottom'
perunt Jan 3, 2024
2f7da44
refactor useMemo calculations
perunt Jan 5, 2024
dd1a395
Merge branch 'main' of https://github.com/Expensify/App into feat/##2…
perunt Jan 5, 2024
5a9bd2f
remove useMemo calculations
perunt Jan 6, 2024
7febd4a
Merge branch 'feat/##23220-web-maintainVisibleContentPosition' of htt…
perunt Jan 8, 2024
b3bd5d2
cleanup comments
perunt Jan 8, 2024
edd217c
fix setIsHovered warnings
perunt Jan 8, 2024
68ee0ab
use patches
perunt Jan 8, 2024
7cdc058
optional scrollToBottom
perunt Jan 8, 2024
a8f17f8
hovering issue
perunt Jan 8, 2024
5a3434a
Merge branch 'main' of https://github.com/Expensify/App into feat/##2…
perunt Jan 9, 2024
e8dc643
fix loader blinking
perunt Jan 9, 2024
3895f80
Merge branch 'main' of https://github.com/Expensify/App into feat/##2…
perunt Jan 9, 2024
2ac370d
temporary fix due to broken main
perunt Jan 9, 2024
fcf931e
Merge branch 'main' of https://github.com/Expensify/App into feat/##2…
perunt Jan 10, 2024
5549ffd
implement scrolling functionality prior to adding pagination
perunt Jan 10, 2024
a82f576
Merge branch 'main' of https://github.com/Expensify/App into feat/##2…
perunt Jan 10, 2024
8036bce
use memo for oldestReportAction after merge
perunt Jan 10, 2024
abe9dc4
scrollToOffsetWithoutAnimation
perunt Jan 10, 2024
4987167
undo runHoverAfterInteraction
perunt Jan 10, 2024
7aa008a
remove outdated test
perunt Jan 10, 2024
dda07b4
rename const
perunt Jan 11, 2024
4f9d65e
remove isLoadingInitialReportActions
perunt Jan 11, 2024
f459394
refactor getSortedReportActionsForDisplay
perunt Jan 11, 2024
8be49c4
refactor openReport action
perunt Jan 11, 2024
d67396f
refactor initialNumToRender
perunt Jan 11, 2024
fc7afc9
Merge branch 'main' of https://github.com/Expensify/App into feat/##2…
perunt Jan 11, 2024
5e2f008
replace getReportID in ReportScreen
perunt Jan 11, 2024
d6b6c11
renaming
perunt Jan 11, 2024
f18d81a
add tests
perunt Jan 11, 2024
44bba85
add prop types
perunt Jan 11, 2024
61a24c7
Merge branch 'main' of https://github.com/Expensify/App into feat/##2…
perunt Jan 11, 2024
9a54d64
MVCPFlatList fixes
janicduplessis Jan 11, 2024
a4d9a2e
More fixes
janicduplessis Jan 12, 2024
1f10abb
Use minIndexForVisible 1 to dodge loading views
janicduplessis Jan 12, 2024
a07c9a9
Add comment
janicduplessis Jan 12, 2024
03fc48b
Remove windowSize since 21 is the default
janicduplessis Jan 12, 2024
ae01d1a
Fix lint
janicduplessis Jan 12, 2024
b4bd752
Merge branch 'feat/##23229-linking' of https://github.com/margelo/exp…
perunt Jan 12, 2024
d08dea5
fix issue with navigating between different reports when actions are …
perunt Jan 12, 2024
7533b51
delete scrollToOffsetWithoutAnimation
perunt Jan 12, 2024
9478b80
delete getReportActionsWithoutRemoved
perunt Jan 12, 2024
67d0dc8
renaming and adding comments to pagination handler
perunt Jan 12, 2024
9c743dc
cleanup
perunt Jan 12, 2024
8887f7c
clean artifacts from patch
perunt Jan 12, 2024
c2fc773
add optional autoscrollToTopThreshold
perunt Jan 14, 2024
dbcc38b
avoid scrollToBottom while linking
perunt Jan 14, 2024
fbd2c9d
ensure Automatic Scrolling Works with Comment Linking
perunt Jan 15, 2024
f64e8c8
correct linking Issue for the first message in chat
perunt Jan 15, 2024
2d77e7d
fix test
perunt Jan 15, 2024
a5d0c4d
Merge branch 'main' of https://github.com/Expensify/App into feat/##2…
perunt Jan 15, 2024
0520876
fix console warning
perunt Jan 15, 2024
285275b
Merge branch 'main' of https://github.com/Expensify/App into feat/##2…
perunt Jan 15, 2024
008b7fc
correct scrolling issue during initial chat load
perunt Jan 15, 2024
29f7f23
bring back reportScrollManager to ReportActionList
perunt Jan 15, 2024
59aaf17
update naming conventions and typing
perunt Jan 16, 2024
c810dbf
Merge branch 'main' of https://github.com/Expensify/App into feat/##2…
perunt Jan 17, 2024
00b041c
fix typo and add CheckForPreviousReportActionID migration
perunt Jan 17, 2024
cc523b2
fix 'new message' appearing on initial loading
perunt Jan 17, 2024
f3b7090
lint
perunt Jan 17, 2024
c77d7b1
adjust gap handling in response to REPORTPREVIEW movement
perunt Jan 18, 2024
2b8a4d7
undo adjust gap handling in response to REPORTPREVIEW movement
perunt Jan 18, 2024
1fb4ae9
Merge branch 'main' of https://github.com/Expensify/App into feat/##2…
perunt Jan 18, 2024
104884a
implement a blocking view when the linked link does not belong to the…
perunt Jan 18, 2024
3ce1080
bring back 'adjust gap handling in response to REPORTPREVIEW movement'
perunt Jan 18, 2024
b0035bf
Merge branch 'main' of https://github.com/Expensify/App into feat/##2…
perunt Jan 19, 2024
825a543
lint
perunt Jan 19, 2024
1db6e8c
Merge branch 'main' of https://github.com/Expensify/App into feat/##2…
perunt Jan 19, 2024
e7ee260
lint after merge
perunt Jan 19, 2024
07929ee
fix test
perunt Jan 19, 2024
c1c260f
refactor autosScrollToTopThreshold
perunt Jan 20, 2024
14ab0d6
determine if a linked report action is deleted
perunt Jan 23, 2024
f5f2327
refactor linking loader
perunt Jan 24, 2024
c3d93ea
hide loading indicator when delete
perunt Jan 24, 2024
1d4aef1
fix scrolling to the bottom on action deletion from the same account …
perunt Jan 25, 2024
8c4b032
Merge branch 'main' of https://github.com/Expensify/App into feat/##2…
perunt Jan 25, 2024
4f4a2c2
move pagination size to getInitialPaginationSize
perunt Jan 29, 2024
48824e5
adjust getInitialPaginationSize
perunt Jan 29, 2024
82b7e8b
Merge branch 'main' of https://github.com/Expensify/App into feat/##2…
perunt Jan 30, 2024
1f90068
update after merge
perunt Jan 30, 2024
28eae1d
WIP handling whisperedToAccountIDs, INVITE_TO_ROOM, CLOSED, CREATED
perunt Feb 1, 2024
7bdf855
Merge branch 'main' of https://github.com/Expensify/App into feat/##2…
perunt Feb 2, 2024
150e9a4
lint
perunt Feb 2, 2024
6f9746a
Include 'INVITE_TO_ROOM' action for startIndex calculation
perunt Feb 2, 2024
b2acf1d
fix after merge (add allReportActions to memo)
perunt Feb 2, 2024
312f952
Merge branch 'main' of https://github.com/Expensify/App into feat/##2…
perunt Feb 6, 2024
ce1354e
Merge branch 'main' of https://github.com/Expensify/App into feat/##2…
perunt Feb 7, 2024
ddb682c
Merge branch 'perunt/onStartReached-fix' of https://github.com/margel…
perunt Feb 7, 2024
17c4fba
comment out DeleteWorkspace
perunt Feb 7, 2024
73c48aa
add route to memo
perunt Feb 7, 2024
c926703
Merge branch 'main' of https://github.com/Expensify/App into feat/##2…
perunt Feb 12, 2024
6660257
Merge branch 'main' of https://github.com/Expensify/App into feat/##2…
perunt Feb 19, 2024
3fbbb19
Merge branch 'main' of https://github.com/Expensify/App into feat/##2…
perunt Mar 1, 2024
485aad8
Merge branch 'main' of https://github.com/Expensify/App into feat/##2…
perunt Mar 12, 2024
a83cf6e
undo https://github.com/Expensify/App/pull/37839/files
perunt Mar 12, 2024
173c11b
sync package lock
perunt Mar 12, 2024
4461124
migrate to TS
perunt Mar 12, 2024
a747515
Merge branch 'main' of https://github.com/Expensify/App into feat/##2…
perunt Mar 12, 2024
27608f1
update tests
perunt Mar 12, 2024
a0e96e1
fix type
perunt Mar 12, 2024
ce55a7e
remove outdated test
perunt Mar 13, 2024
2b77edc
add selector for sortedAllReportActions
perunt Mar 13, 2024
2c809c4
lint
perunt Mar 13, 2024
ad44807
Merge branch 'main' of https://github.com/Expensify/App into feat/##2…
perunt Mar 13, 2024
c108d9d
add comments, move usePaginatedReportActionList to the utils
perunt Mar 19, 2024
a77f3de
Merge branch 'main' of https://github.com/Expensify/App into feat/##2…
perunt Mar 19, 2024
1e0386d
move usePaginatedReportActionList back
perunt Mar 20, 2024
7b9e7e3
renaming
perunt Mar 20, 2024
b4d1e39
remove unused layoutListHeight
perunt Mar 20, 2024
09dcee2
Merge branch 'main' of https://github.com/Expensify/App into feat/##2…
perunt Mar 20, 2024
acb2b06
move content of usePaginatedReportActionList to ReportActionsView
perunt Mar 20, 2024
cb86c85
update listID
perunt Mar 20, 2024
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
2 changes: 1 addition & 1 deletion patches/react-native-web+0.19.9+004+fixLastSpacer.patch
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ index faeb323..68d740a 100644

/**
* Base implementation for the more convenient [`<FlatList>`](https://reactnative.dev/docs/flatlist)
@@ -1119,7 +1111,8 @@ class VirtualizedList extends StateSafePureComponent {
@@ -1107,7 +1099,8 @@ class VirtualizedList extends StateSafePureComponent {
_keylessItemComponentName = '';
var spacerKey = this._getSpacerKey(!horizontal);
var renderRegions = this.state.renderMask.enumerateRegions();
Expand Down
20 changes: 9 additions & 11 deletions src/components/FlatList/MVCPFlatList.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const MVCPFlatList = React.forwardRef(({maintainVisibleContentPosition, horizont
return horizontal ? scrollRef.current.getScrollableNode().scrollLeft : scrollRef.current.getScrollableNode().scrollTop;
}, [horizontal]);

const getContentView = React.useCallback(() => scrollRef.current?.getScrollableNode().childNodes[0], []);
const getContentView = React.useCallback(() => scrollRef.current?.getScrollableNode()?.childNodes[0], []);

const scrollToOffset = React.useCallback(
(offset, animated) => {
Expand All @@ -67,12 +67,13 @@ const MVCPFlatList = React.forwardRef(({maintainVisibleContentPosition, horizont
}

const scrollOffset = getScrollOffset();
lastScrollOffsetRef.current = scrollOffset;

const contentViewLength = contentView.childNodes.length;
for (let i = mvcpMinIndexForVisible; i < contentViewLength; i++) {
const subview = contentView.childNodes[i];
const subviewOffset = horizontal ? subview.offsetLeft : subview.offsetTop;
if (subviewOffset > scrollOffset || i === contentViewLength - 1) {
if (subviewOffset > scrollOffset) {
prevFirstVisibleOffsetRef.current = subviewOffset;
firstVisibleViewRef.current = subview;
break;
Expand Down Expand Up @@ -125,6 +126,7 @@ const MVCPFlatList = React.forwardRef(({maintainVisibleContentPosition, horizont
}

adjustForMaintainVisibleContentPosition();
prepareForMaintainVisibleContentPosition();
});
});
mutationObserver.observe(contentView, {
Expand All @@ -134,13 +136,11 @@ const MVCPFlatList = React.forwardRef(({maintainVisibleContentPosition, horizont
});

mutationObserverRef.current = mutationObserver;
}, [adjustForMaintainVisibleContentPosition, getContentView, getScrollOffset, scrollToOffset]);
}, [adjustForMaintainVisibleContentPosition, prepareForMaintainVisibleContentPosition, getContentView, getScrollOffset, scrollToOffset]);

React.useEffect(() => {
requestAnimationFrame(() => {
prepareForMaintainVisibleContentPosition();
setupMutationObserver();
});
React.useLayoutEffect(() => {
prepareForMaintainVisibleContentPosition();
setupMutationObserver();
}, [prepareForMaintainVisibleContentPosition, setupMutationObserver]);

const setMergedRef = useMergeRefs(scrollRef, forwardedRef);
Expand Down Expand Up @@ -168,13 +168,11 @@ const MVCPFlatList = React.forwardRef(({maintainVisibleContentPosition, horizont

const onScrollInternal = React.useCallback(
(ev) => {
lastScrollOffsetRef.current = getScrollOffset();

prepareForMaintainVisibleContentPosition();

onScroll?.(ev);
},
[getScrollOffset, prepareForMaintainVisibleContentPosition, onScroll],
[prepareForMaintainVisibleContentPosition, onScroll],
);

return (
Expand Down
8 changes: 2 additions & 6 deletions src/components/InvertedFlatList/BaseInvertedFlatList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,15 @@ import React, {forwardRef} from 'react';
import type {FlatListProps} from 'react-native';
import FlatList from '@components/FlatList';

const WINDOW_SIZE = 15;
const AUTOSCROLL_TO_TOP_THRESHOLD = 128;

function BaseInvertedFlatList<T>(props: FlatListProps<T>, ref: ForwardedRef<FlatList>) {
return (
<FlatList
// eslint-disable-next-line react/jsx-props-no-spreading
{...props}
ref={ref}
windowSize={WINDOW_SIZE}
maintainVisibleContentPosition={{
minIndexForVisible: 0,
autoscrollToTopThreshold: AUTOSCROLL_TO_TOP_THRESHOLD,
// This needs to be 1 to avoid using loading views as anchors.
minIndexForVisible: 1,
}}
inverted
/>
Expand Down
2 changes: 1 addition & 1 deletion src/components/ReportActionItem/MoneyRequestAction.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ function MoneyRequestAction({
if (!childReportID) {
const thread = ReportUtils.buildTransactionThread(action, requestReportID);
const userLogins = PersonalDetailsUtils.getLoginsByAccountIDs(thread.participantAccountIDs);
Report.openReport(thread.reportID, userLogins, thread, action.reportActionID);
Report.openReport(thread.reportID, '', userLogins, thread, action.reportActionID);
Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(thread.reportID));
return;
}
Expand Down
16 changes: 15 additions & 1 deletion src/hooks/useReportScrollManager/index.native.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,21 @@ function useReportScrollManager(): ReportScrollManagerData {
flatListRef.current?.scrollToOffset({animated: false, offset: 0});
}, [flatListRef, setScrollPosition]);

return {ref: flatListRef, scrollToIndex, scrollToBottom};
/**
* Scroll to the offset of the flatlist.
*/
const scrollToOffsetWithoutAnimation = useCallback(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Few things:

  • I'm a bit confused why this is necessary. You say below:

This is a workaround because 'autoscrollToTopThreshold' does not always function correctly

But ... is this something we can fix? I'm pretty confused by its usage in useHandleList so maybe that will become more clear as I spend more time with this code...

  • I see the only place where this is called is in ReportActionsView with an offset of 1. Could we instead just use the existing scrollToBottom function from this hook and remove this new function? scrollToBottom already using animated: false on web and native platforms.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But ... is this something we can fix? I'm pretty confused by its usage in useHandleList so maybe that will become more clear as I spend more time with this code...

This issue is currently under investigation. We can't use the 'scroll to bottom' approach because we need to trigger scroll computation. That's why I'm implementing a scroll of 1 pixel.
Also, I'd like to mention that this isn't noticeable during render time

(offset: number) => {
if (!flatListRef?.current) {
return;
}

flatListRef.current.scrollToOffset({animated: false, offset});
},
[flatListRef],
);

return {ref: flatListRef, scrollToIndex, scrollToBottom, scrollToOffsetWithoutAnimation};
}

export default useReportScrollManager;
16 changes: 15 additions & 1 deletion src/hooks/useReportScrollManager/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,21 @@ function useReportScrollManager(): ReportScrollManagerData {
flatListRef.current.scrollToOffset({animated: false, offset: 0});
}, [flatListRef]);

return {ref: flatListRef, scrollToIndex, scrollToBottom};
/**
* Scroll to the bottom of the flatlist.
*/
const scrollToOffsetWithoutAnimation = useCallback(
perunt marked this conversation as resolved.
Show resolved Hide resolved
(offset: number) => {
if (!flatListRef?.current) {
return;
}

flatListRef.current.scrollToOffset({animated: false, offset});
},
[flatListRef],
);

return {ref: flatListRef, scrollToIndex, scrollToBottom, scrollToOffsetWithoutAnimation};
}

export default useReportScrollManager;
1 change: 1 addition & 0 deletions src/hooks/useReportScrollManager/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ type ReportScrollManagerData = {
ref: FlatListRefType;
scrollToIndex: (index: number, isEditing?: boolean) => void;
scrollToBottom: () => void;
scrollToOffsetWithoutAnimation: (offset: number) => void;
};

export default ReportScrollManagerData;
74 changes: 61 additions & 13 deletions src/libs/ReportActionsUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ function isTransactionThread(parentReportAction: OnyxEntry<ReportAction>): boole
* This gives us a stable order even in the case of multiple reportActions created on the same millisecond
*
*/
function getSortedReportActions(reportActions: ReportAction[] | null, shouldSortInDescendingOrder = false, shouldMarkTheFirstItemAsNewest = false): ReportAction[] {
function getSortedReportActions(reportActions: ReportAction[] | null, shouldSortInDescendingOrder = false): ReportAction[] {
if (!Array.isArray(reportActions)) {
throw new Error(`ReportActionsUtils.getSortedReportActions requires an array, received ${typeof reportActions}`);
}
Expand Down Expand Up @@ -214,15 +214,47 @@ function getSortedReportActions(reportActions: ReportAction[] | null, shouldSort
return (first.reportActionID < second.reportActionID ? -1 : 1) * invertedMultiplier;
});

// If shouldMarkTheFirstItemAsNewest is true, label the first reportAction as isNewestReportAction
if (shouldMarkTheFirstItemAsNewest && sortedActions?.length > 0) {
sortedActions[0] = {
...sortedActions[0],
isNewestReportAction: true,
};
return sortedActions;
}
// Returns the largest gapless range of reportActions including a the provided reportActionID, where a "gap" is defined as a reportAction's `previousReportActionID` not matching the previous reportAction in the sortedReportActions array.
// See unit tests for example of inputs and expected outputs.
perunt marked this conversation as resolved.
Show resolved Hide resolved
// Note: sortedReportActions sorted in descending order
function getContinuousReportActionChain(sortedReportActions: ReportAction[], id?: string): ReportAction[] {
perunt marked this conversation as resolved.
Show resolved Hide resolved
let index;

if (id) {
index = sortedReportActions.findIndex((obj) => obj.reportActionID === id);
} else {
index = sortedReportActions.findIndex((obj) => obj.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD);
roryabraham marked this conversation as resolved.
Show resolved Hide resolved
}

return sortedActions;
if (index === -1) {
return [];
perunt marked this conversation as resolved.
Show resolved Hide resolved
}

let startIndex = index;
let endIndex = index;

// Iterate forwards through the array, starting from endIndex. This loop checks the continuity of actions by:
// 1. Comparing the current item's previousReportActionID with the next item's reportActionID.
// This ensures that we are moving in a sequence of related actions from newer to older.
while (endIndex < sortedReportActions.length - 1 && sortedReportActions[endIndex].previousReportActionID === sortedReportActions[endIndex + 1].reportActionID) {
endIndex++;
}

// Iterate backwards through the sortedReportActions, starting from startIndex. This loop has two main checks:
// 1. It compares the current item's reportActionID with the previous item's previousReportActionID.
// This is to ensure continuity in a sequence of actions.
// 2. If the first condition fails, it then checks if the previous item has a pendingAction of 'add'.
// This additional check is to include recently sent messages that might not yet be part of the established sequence.
while (
(startIndex > 0 && sortedReportActions[startIndex].reportActionID === sortedReportActions[startIndex - 1].previousReportActionID) ||
sortedReportActions[startIndex - 1]?.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD
) {
startIndex--;
}

return sortedReportActions.slice(startIndex, endIndex + 1);
}

/**
Expand Down Expand Up @@ -494,12 +526,26 @@ function filterOutDeprecatedReportActions(reportActions: ReportActions | null):
* to ensure they will always be displayed in the same order (in case multiple actions have the same timestamp).
* This is all handled with getSortedReportActions() which is used by several other methods to keep the code DRY.
*/
function getSortedReportActionsForDisplay(reportActions: ReportActions | null, shouldMarkTheFirstItemAsNewest = false): ReportAction[] {
const filteredReportActions = Object.entries(reportActions ?? {})
.filter(([key, reportAction]) => shouldReportActionBeVisible(reportAction, key))
.map((entry) => entry[1]);
function getSortedReportActionsForDisplay(reportActions: ReportActions | null, shouldIncludeInvisibleActions = false): ReportAction[] {
let filteredReportActions;

if (shouldIncludeInvisibleActions) {
perunt marked this conversation as resolved.
Show resolved Hide resolved
filteredReportActions = Object.values(reportActions ?? {});
} else {
filteredReportActions = Object.entries(reportActions ?? {})
.filter(([key, reportAction]) => shouldReportActionBeVisible(reportAction, key))
.map((entry) => entry[1]);
}

const baseURLAdjustedReportActions = filteredReportActions.map((reportAction) => replaceBaseURL(reportAction));
return getSortedReportActions(baseURLAdjustedReportActions, true, shouldMarkTheFirstItemAsNewest);
return getSortedReportActions(baseURLAdjustedReportActions, true);
}

function getReportActionsWithoutRemoved(reportActions: ReportAction[] | null): ReportAction[] {
perunt marked this conversation as resolved.
Show resolved Hide resolved
if (!reportActions) {
return [];
}
return reportActions.filter((item) => shouldReportActionBeVisible(item, item.reportActionID));
}

/**
Expand Down Expand Up @@ -827,6 +873,7 @@ export {
getReportPreviewAction,
getSortedReportActions,
getSortedReportActionsForDisplay,
getReportActionsWithoutRemoved,
isConsecutiveActionMadeByPreviousActor,
isCreatedAction,
isCreatedTaskReportAction,
Expand All @@ -853,6 +900,7 @@ export {
shouldReportActionBeVisible,
shouldHideNewMarker,
shouldReportActionBeVisibleAsLastAction,
getContinuousReportActionChain,
hasRequestFromCurrentAccount,
getFirstVisibleReportActionID,
isMemberChangeAction,
Expand Down
15 changes: 10 additions & 5 deletions src/libs/actions/Report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,8 @@ function reportActionsExist(reportID: string): boolean {
* Gets the latest page of report actions and updates the last read message
* If a chat with the passed reportID is not found, we will create a chat based on the passed participantList
*
* @param reportID The ID of the report to open
* @param reportActionID The ID of the report action to navigate to
perunt marked this conversation as resolved.
Show resolved Hide resolved
* @param participantLoginList The list of users that are included in a new chat, not including the user creating it
* @param newReportObject The optimistic report object created when making a new chat, saved as optimistic data
* @param parentReportActionID The parent report action that a thread was created from (only passed for new threads)
Expand All @@ -472,6 +474,7 @@ function reportActionsExist(reportID: string): boolean {
*/
function openReport(
reportID: string,
reportActionID?: string,
Copy link
Contributor

@ishpaul777 ishpaul777 Mar 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@perunt Is there a reason why you add reportActionID in between the params, it leads to create huge diffs can we add in the end to avoid unrealated code diffs

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For comment linking, we need to be able to open a report with a specific range of report actions. When we pass the reportActionID, we can select a specific range around this report action

Copy link
Contributor

@ishpaul777 ishpaul777 Mar 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i mean why you didn't add in the last so we can make it as optional param 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, now I understand what you mean.
I made this change because we usually don't use more than two parameters in the code. To be honest, I prefer using destructuring there. It would make things clearer.
If you insist, I can change it as you suggested.
image

participantLoginList: string[] = [],
newReportObject: Partial<Report> = {},
parentReportActionID = '0',
Expand Down Expand Up @@ -544,6 +547,7 @@ function openReport(
type OpenReportParameters = {
reportID: string;
emailList?: string;
reportActionID?: string;
accountIDList?: string;
parentReportActionID?: string;
shouldRetry?: boolean;
Expand All @@ -554,6 +558,7 @@ function openReport(

const parameters: OpenReportParameters = {
reportID,
reportActionID,
emailList: participantLoginList ? participantLoginList.join(',') : '',
accountIDList: participantAccountIDList ? participantAccountIDList.join(',') : '',
parentReportActionID,
Expand Down Expand Up @@ -689,7 +694,7 @@ function navigateToAndOpenReport(userLogins: string[], shouldDismissModal = true
const reportID = chat ? chat.reportID : newChat.reportID;

// We want to pass newChat here because if anything is passed in that param (even an existing chat), we will try to create a chat on the server
openReport(reportID, userLogins, newChat);
openReport(reportID, '', userLogins, newChat);
if (shouldDismissModal) {
Navigation.dismissModal(reportID);
} else {
Expand All @@ -711,7 +716,7 @@ function navigateToAndOpenReportWithAccountIDs(participantAccountIDs: number[])
const reportID = chat ? chat.reportID : newChat.reportID;

// We want to pass newChat here because if anything is passed in that param (even an existing chat), we will try to create a chat on the server
openReport(reportID, [], newChat, '0', false, participantAccountIDs);
openReport(reportID, '', [], newChat, '0', false, participantAccountIDs);
Navigation.dismissModal(reportID);
}

Expand Down Expand Up @@ -745,7 +750,7 @@ function navigateToAndOpenChildReport(childReportID = '0', parentReportAction: P
);

const participantLogins = PersonalDetailsUtils.getLoginsByAccountIDs(newChat?.participantAccountIDs ?? []);
openReport(newChat.reportID, participantLogins, newChat, parentReportAction.reportActionID);
openReport(newChat.reportID, '', participantLogins, newChat, parentReportAction.reportActionID);
Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(newChat.reportID));
}
}
Expand Down Expand Up @@ -1474,7 +1479,7 @@ function toggleSubscribeToChildReport(childReportID = '0', parentReportAction: P
);

const participantLogins = PersonalDetailsUtils.getLoginsByAccountIDs(participantAccountIDs);
openReport(newChat.reportID, participantLogins, newChat, parentReportAction.reportActionID);
openReport(newChat.reportID, '', participantLogins, newChat, parentReportAction.reportActionID);
const notificationPreference =
prevNotificationPreference === CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN ? CONST.REPORT.NOTIFICATION_PREFERENCE.ALWAYS : CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN;
updateNotificationPreference(newChat.reportID, prevNotificationPreference, notificationPreference, false, parentReportID, parentReportAction?.reportActionID);
Expand Down Expand Up @@ -2022,7 +2027,7 @@ function openReportFromDeepLink(url: string, isAuthenticated: boolean) {

if (reportID && !isAuthenticated) {
// Call the OpenReport command to check in the server if it's a public room. If so, we'll open it as an anonymous user
openReport(reportID, [], {}, '0', true);
openReport(reportID, '', [], {}, '0', true);

// Show the sign-in page if the app is offline
if (isNetworkOffline) {
Expand Down
Loading
Loading