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 all 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
3 changes: 3 additions & 0 deletions src/CONST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3414,6 +3414,9 @@ const CONST = {

REPORT_FIELD_TITLE_FIELD_ID: 'text_title',

MOBILE_PAGINATION_SIZE: 15,
WEB_PAGINATION_SIZE: 50,

/** Dimensions for illustration shown in Confirmation Modal */
CONFIRM_CONTENT_SVG_SIZE: {
HEIGHT: 220,
Expand Down
16 changes: 8 additions & 8 deletions src/components/FlatList/MVCPFlatList.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@ const MVCPFlatList = React.forwardRef(({maintainVisibleContentPosition, horizont
if (scrollRef.current == null) {
return 0;
}
return horizontal ? scrollRef.current.getScrollableNode().scrollLeft : scrollRef.current.getScrollableNode().scrollTop;
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) => {
const behavior = animated ? 'smooth' : 'instant';
scrollRef.current?.getScrollableNode().scroll(horizontal ? {left: offset, behavior} : {top: offset, behavior});
scrollRef.current?.getScrollableNode()?.scroll(horizontal ? {left: offset, behavior} : {top: offset, behavior});
},
[horizontal],
);
Expand All @@ -68,12 +68,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 @@ -126,6 +127,7 @@ const MVCPFlatList = React.forwardRef(({maintainVisibleContentPosition, horizont
}

adjustForMaintainVisibleContentPosition();
prepareForMaintainVisibleContentPosition();
});
});
mutationObserver.observe(contentView, {
Expand All @@ -135,7 +137,7 @@ const MVCPFlatList = React.forwardRef(({maintainVisibleContentPosition, horizont
});

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

React.useEffect(() => {
if (!isListRenderedRef.current) {
Expand Down Expand Up @@ -172,13 +174,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
34 changes: 24 additions & 10 deletions src/components/InvertedFlatList/BaseInvertedFlatList.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,35 @@
import type {ForwardedRef} from 'react';
import React, {forwardRef} from 'react';
import type {FlatListProps} from 'react-native';
import React, {forwardRef, useMemo} from 'react';
import type {FlatListProps, ScrollViewProps} from 'react-native';
import FlatList from '@components/FlatList';

const WINDOW_SIZE = 15;
type BaseInvertedFlatListProps<T> = FlatListProps<T> & {
shouldEnableAutoScrollToTopThreshold?: boolean;
};

const AUTOSCROLL_TO_TOP_THRESHOLD = 128;

const maintainVisibleContentPosition = {
minIndexForVisible: 0,
autoscrollToTopThreshold: AUTOSCROLL_TO_TOP_THRESHOLD,
};
function BaseInvertedFlatList<T>(props: BaseInvertedFlatListProps<T>, ref: ForwardedRef<FlatList>) {
const {shouldEnableAutoScrollToTopThreshold, ...rest} = props;

const maintainVisibleContentPosition = useMemo(() => {
const config: ScrollViewProps['maintainVisibleContentPosition'] = {
// This needs to be 1 to avoid using loading views as anchors.
minIndexForVisible: 1,
};

if (shouldEnableAutoScrollToTopThreshold) {
config.autoscrollToTopThreshold = AUTOSCROLL_TO_TOP_THRESHOLD;
}

return config;
}, [shouldEnableAutoScrollToTopThreshold]);

function BaseInvertedFlatList<T>(props: FlatListProps<T>, ref: ForwardedRef<FlatList>) {
return (
<FlatList
// eslint-disable-next-line react/jsx-props-no-spreading
{...props}
{...rest}
ref={ref}
windowSize={WINDOW_SIZE}
maintainVisibleContentPosition={maintainVisibleContentPosition}
inverted
/>
Expand All @@ -27,3 +39,5 @@ function BaseInvertedFlatList<T>(props: FlatListProps<T>, ref: ForwardedRef<Flat
BaseInvertedFlatList.displayName = 'BaseInvertedFlatList';

export default forwardRef(BaseInvertedFlatList);

export {AUTOSCROLL_TO_TOP_THRESHOLD};
6 changes: 5 additions & 1 deletion src/components/InvertedFlatList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@ import CONST from '@src/CONST';
import BaseInvertedFlatList from './BaseInvertedFlatList';
import CellRendererComponent from './CellRendererComponent';

type InvertedFlatListProps<T> = FlatListProps<T> & {
shouldEnableAutoScrollToTopThreshold?: boolean;
};

// This is adapted from https://codesandbox.io/s/react-native-dsyse
// It's a HACK alert since FlatList has inverted scrolling on web
function InvertedFlatList<T>({onScroll: onScrollProp = () => {}, ...props}: FlatListProps<T>, ref: ForwardedRef<FlatList>) {
function InvertedFlatList<T>({onScroll: onScrollProp = () => {}, ...props}: InvertedFlatListProps<T>, ref: ForwardedRef<FlatList>) {
const lastScrollEvent = useRef<number | null>(null);
const scrollEndTimeout = useRef<NodeJS.Timeout | null>(null);
const updateInProgress = useRef<boolean>(false);
Expand Down
1 change: 1 addition & 0 deletions src/libs/API/parameters/OpenReportParams.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
type OpenReportParams = {
reportID: string;
reportActionID?: string;
emailList?: string;
accountIDList?: string;
parentReportActionID?: string;
Expand Down
10 changes: 9 additions & 1 deletion src/libs/NumberUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,12 @@ function clamp(value: number, min: number, max: number): number {
return Math.min(Math.max(value, min), max);
}

export {rand64, generateHexadecimalValue, generateRandomInt, parseFloatAnyLocale, roundDownToLargestMultiple, roundToTwoDecimalPlaces, clamp};
function generateNewRandomInt(old: number, min: number, max: number): number {
let newNum = old;
while (newNum === old) {
newNum = generateRandomInt(min, max);
}
return newNum;
}

export {rand64, generateHexadecimalValue, generateRandomInt, parseFloatAnyLocale, roundDownToLargestMultiple, roundToTwoDecimalPlaces, clamp, generateNewRandomInt};
81 changes: 68 additions & 13 deletions src/libs/ReportActionsUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ type MemberChangeMessageElement = MessageTextElement | MemberChangeMessageUserMe
const policyChangeActionsSet = new Set<string>(Object.values(CONST.REPORT.ACTIONS.TYPE.POLICYCHANGELOG));

const allReports: OnyxCollection<Report> = {};

Onyx.connect({
key: ONYXKEYS.COLLECTION.REPORT,
callback: (report, key) => {
Expand Down Expand Up @@ -218,7 +219,7 @@ function isTransactionThread(parentReportAction: OnyxEntry<ReportAction> | Empty
* 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 @@ -246,15 +247,58 @@ 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.
* Note: sortedReportActions sorted in descending order
*/
function getContinuousReportActionChain(sortedReportActions: ReportAction[], id?: string): ReportAction[] {
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) ||
!!sortedReportActions[endIndex + 1]?.whisperedToAccountIDs?.length ||
!!sortedReportActions[endIndex]?.whisperedToAccountIDs?.length ||
sortedReportActions[endIndex]?.actionName === CONST.REPORT.ACTIONS.TYPE.ROOMCHANGELOG.INVITE_TO_ROOM ||
sortedReportActions[endIndex + 1]?.actionName === CONST.REPORT.ACTIONS.TYPE.CLOSED ||
sortedReportActions[endIndex + 1]?.actionName === CONST.REPORT.ACTIONS.TYPE.CREATED
Comment on lines +281 to +283
Copy link
Contributor

@ishpaul777 ishpaul777 Feb 2, 2024

Choose a reason for hiding this comment

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

When creating a consecutive action list, I compare the reportActionID of one action with the previousReportActionID of another. However, actions like INVITE_TO_ROOM, CLOSED, and whispered actions have incorrect previousReportActionIDs, leading to inconsistencies.

quick question does this happens with these cases, not with other action types like iou, task action types etc.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I saw it only for the whisper action. Also the whisper action that brings inconsistency is located next to the INVITE_TO_ROOM or CLOSED action. That's why this fix works.

) {
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 ||
sortedReportActions[startIndex - 1]?.actionName === CONST.REPORT.ACTIONS.TYPE.ROOMCHANGELOG.INVITE_TO_ROOM
) {
startIndex--;
}

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

/**
Expand Down Expand Up @@ -524,12 +568,22 @@ 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 | ReportAction[] | null, shouldMarkTheFirstItemAsNewest = false): ReportAction[] {
const filteredReportActions = Object.entries(reportActions ?? {})
.filter(([key, reportAction]) => shouldReportActionBeVisible(reportAction, key))
.map((entry) => entry[1]);
function getSortedReportActionsForDisplay(reportActions: ReportActions | null | ReportAction[], shouldIncludeInvisibleActions = false): ReportAction[] {
let filteredReportActions: ReportAction[] = [];
if (!reportActions) {
return [];
}

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(([, reportAction]) => reportAction);
}

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

/**
Expand Down Expand Up @@ -1006,6 +1060,7 @@ export {
shouldReportActionBeVisible,
shouldHideNewMarker,
shouldReportActionBeVisibleAsLastAction,
getContinuousReportActionChain,
hasRequestFromCurrentAccount,
getFirstVisibleReportActionID,
isMemberChangeAction,
Expand Down
15 changes: 8 additions & 7 deletions src/libs/actions/Policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -866,13 +866,14 @@ function removeMembers(accountIDs: number[], policyID: string) {
},
});
});
optimisticClosedReportActions.forEach((reportAction, index) => {
optimisticData.push({
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${workspaceChats?.[index]?.reportID}`,
value: {[reportAction.reportActionID]: reportAction as ReportAction},
});
});
// comment out for time this issue would be resolved https://github.com/Expensify/App/issues/35952
// optimisticClosedReportActions.forEach((reportAction, index) => {
// optimisticData.push({
// onyxMethod: Onyx.METHOD.MERGE,
// key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${workspaceChats?.[index]?.reportID}`,
// value: {[reportAction.reportActionID]: reportAction as ReportAction},
// });
// });

// If the policy has primaryLoginsInvited, then it displays informative messages on the members page about which primary logins were added by secondary logins.
// If we delete all these logins then we should clear the informative messages since they are no longer relevant.
Expand Down
Loading
Loading