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

Client side pagination gap detection #41962

Merged
merged 130 commits into from
Jul 5, 2024
Merged
Show file tree
Hide file tree
Changes from 129 commits
Commits
Show all changes
130 commits
Select commit Hold shift + click to select a range
c88356f
Client previousReportActionID proof of concept
janicduplessis May 10, 2024
8f39e39
New implementation
janicduplessis May 24, 2024
273ec0f
wip
janicduplessis May 24, 2024
068f53e
Consolidate appversion in enhanceparameters
roryabraham May 24, 2024
49a1034
wip
janicduplessis May 24, 2024
e4be92c
DRY up applyOptimisticOnyxData
roryabraham May 24, 2024
d59db4b
Add API.paginate
roryabraham May 24, 2024
bf0d282
Handle delete / reordered actions, add more tests
janicduplessis May 25, 2024
450189f
Set up bulk of generalized Middleware
roryabraham May 24, 2024
867abfc
Implement PaginationUtils.mergeContinuousPages
roryabraham May 25, 2024
780f631
Implement API.paginate for GetOlderActions and GetNewerActions
roryabraham May 27, 2024
23558ae
Make API.pagination work for non-read request types
roryabraham May 27, 2024
1200cea
Rename CommandForRequestType
roryabraham May 27, 2024
b0cf310
Update existing usages of API.paginate
roryabraham May 27, 2024
8ca521e
Add API.paginate to openReport
roryabraham May 27, 2024
8eb364d
Merge branch 'main' into Rory-PaginationNation
roryabraham May 28, 2024
962d006
Upgrade typescript for ConditionalKeys fix
roryabraham May 28, 2024
1b70ee9
Remove duplicate comment
roryabraham May 28, 2024
4afecc6
Fix CommandOfType utility
roryabraham May 28, 2024
f317885
Fix generic type default in PaginatedRequest
roryabraham May 28, 2024
90aecb3
Move pusherSocketID from enhanceParameters back to API/index.js
roryabraham May 28, 2024
7fa3b2c
Consolidate PaginationConfig type
roryabraham May 28, 2024
3326fae
Misc cleanup
roryabraham May 28, 2024
c8b2f50
Add getContinuousChain in PaginationUtils
roryabraham May 28, 2024
4561beb
Save draft state - moving getContinuousChain to PaginationUtils
roryabraham May 29, 2024
f785b7e
Add a comment explaining the Pagination middleware
roryabraham May 29, 2024
5a8c40a
Merge branch 'main' into Rory-PaginationNation
roryabraham May 30, 2024
c20540b
fix package-lock.json
roryabraham May 30, 2024
e5038c1
Use new PaginationUtils.getContinuousChain
janicduplessis May 30, 2024
27cf878
Handle no cache entries
janicduplessis May 30, 2024
3de5595
Merge remote-tracking branch 'upstream/main' into @janic/client-actio…
janicduplessis Jun 6, 2024
2bc68fd
Fixes after update main
janicduplessis Jun 6, 2024
5428d94
Back in working state
janicduplessis Jun 6, 2024
77eff74
Ts fixes and minor api changes
janicduplessis Jun 6, 2024
8dd4dfe
Fix most tests
janicduplessis Jun 7, 2024
e908d64
Fix
janicduplessis Jun 7, 2024
1a4ec80
Fix scrolling from linked message
janicduplessis Jun 7, 2024
ba6358e
Move config outside of request object
janicduplessis Jun 7, 2024
2fa4d41
UI tests wip
janicduplessis Jun 8, 2024
fed68e1
Merge branch 'main' into @janic/client-action-chain
roryabraham Jun 10, 2024
84c1c6c
Bump type-fest
roryabraham Jun 10, 2024
4161096
Use Onyx.connect instead of OnyxCache
janicduplessis Jun 11, 2024
70aef20
Fixes
janicduplessis Jun 11, 2024
159f0a1
Simplify OnyxPagesKey type
roryabraham Jun 12, 2024
61f249c
Fix API.paginate type overloads
roryabraham Jun 12, 2024
43caf1e
Use a switch statement in API.paginate
roryabraham Jun 12, 2024
ff1883f
Remove outdated TODO
roryabraham Jun 12, 2024
9b33c67
Fix typo
roryabraham Jun 12, 2024
c3200a2
Add comments to explain local objects in Pagination actions file
roryabraham Jun 12, 2024
db30f6b
Extract ItemWithIndex type in PaginationUtils
roryabraham Jun 12, 2024
e8d5b41
Add comments to PaginationConfig type
roryabraham Jun 12, 2024
a527300
Remove type casts from Onyx.connect
roryabraham Jun 12, 2024
64c8161
remove TODO: TODONOTHING
roryabraham Jun 12, 2024
9155177
Merge branch 'main' into @janic/client-action-chain
roryabraham Jun 12, 2024
f9f4491
Document Pages shape
roryabraham Jun 12, 2024
c0fcffb
Remove duplicate ReportActionsPages type
roryabraham Jun 12, 2024
035e81c
Suppress lint for global fetch any type
roryabraham Jun 12, 2024
c67511c
Revert TS bump
roryabraham Jun 12, 2024
91025c6
Merge branch 'main' into @janic/client-action-chain
roryabraham Jun 12, 2024
bfa6dbd
Remove unnecessary optimistic previousReportActionID
roryabraham Jun 12, 2024
fa30c87
Remove unnecessary effect from ReportActionsView
roryabraham Jun 12, 2024
63e3a74
Fix some type errors
roryabraham Jun 12, 2024
20f5bd6
Fix mockFetch types
roryabraham Jun 12, 2024
f7671bf
Use regular for loop to iterate backwards without copy
roryabraham Jun 12, 2024
f8dc223
Update TS again
roryabraham Jun 12, 2024
cb796cd
Fix mock
janicduplessis Jun 13, 2024
6cb459c
Work on ui tests
janicduplessis Jun 14, 2024
fa845ca
Fix findLastItem
janicduplessis Jun 14, 2024
7c5bc5b
Merge branch 'main' into @janic/client-action-chain
roryabraham Jun 19, 2024
ad72970
Remove empty file
roryabraham Jun 19, 2024
40a3a6a
Make react-is a dev dependency
roryabraham Jun 19, 2024
bf3ef1d
Improve test mocks and assertions
janicduplessis Jun 19, 2024
3401769
Fix ts errors
roryabraham Jun 19, 2024
2bb077b
Add end marker
janicduplessis Jun 19, 2024
093c15f
Remove console.debug mock
janicduplessis Jun 19, 2024
5c521ac
make storybook plugins dev dependencies
roryabraham Jun 19, 2024
60f3798
Fix storybook
roryabraham Jun 19, 2024
e1b0b94
Merge branch 'main' into @janic/client-action-chain
roryabraham Jun 19, 2024
19c97f5
Update Podfile.lock
roryabraham Jun 19, 2024
2f3a152
DRY up listener mock
roryabraham Jun 19, 2024
1444238
Fix tsc and lint
roryabraham Jun 20, 2024
6e8b047
Merge branch 'main' into @janic/client-action-chain
roryabraham Jun 20, 2024
4a9b730
Merge branch 'main' into @janic/client-action-chain
roryabraham Jun 20, 2024
9e768af
Fix test ID (updated on main)
roryabraham Jun 20, 2024
97a39d9
Merge branch 'main' into @janic/client-action-chain
roryabraham Jun 20, 2024
c8e3dbe
WTF - why does this fix my test?
roryabraham Jun 20, 2024
29fcb8b
Use correct type in processRequest for side effect requests
roryabraham Jun 20, 2024
428ed08
Fix and add tests
janicduplessis Jun 20, 2024
ef6ba10
Finalize GetNewerActions test assertions
janicduplessis Jun 20, 2024
0fe243d
Add more mergeContinuousPages tests
janicduplessis Jun 21, 2024
ea552f5
Merge remote-tracking branch 'upstream/main' into @janic/client-actio…
janicduplessis Jun 24, 2024
829bc9d
Fix enhanceParametersTest
roryabraham Jun 24, 2024
54c2f91
Add back testID
roryabraham Jun 24, 2024
b69ee4c
Refactor and fixed tests#
roryabraham Jun 24, 2024
fd8b278
Fix empty reportID
janicduplessis Jun 25, 2024
72a3bf1
Merge remote-tracking branch 'upstream/main' into @janic/client-actio…
janicduplessis Jun 25, 2024
4e735de
Fix package lock after main merge
janicduplessis Jun 25, 2024
c51c369
Remove useless null coalescing
janicduplessis Jun 25, 2024
14610af
Remove unused import
roryabraham Jun 25, 2024
5a03bd9
Fix TestHelper type
roryabraham Jun 25, 2024
0d92f2d
Ignore lint warnings in test debug util
roryabraham Jun 25, 2024
9103a51
Merge branch 'main' into @janic/client-action-chain
roryabraham Jun 25, 2024
73249e8
Remove unrelated storybook diff
roryabraham Jun 25, 2024
367a0c1
Remove extra successData from bad merge
roryabraham Jun 25, 2024
c673561
Remove unrelated keyboard type change
roryabraham Jun 25, 2024
5905054
Fix perf test
janicduplessis Jun 25, 2024
df7dd20
Merge branch 'main' into @janic/client-action-chain
roryabraham Jun 25, 2024
86d4534
Merge branch 'main' into @janic/client-action-chain
roryabraham Jun 26, 2024
504d687
Fix comment
janicduplessis Jun 27, 2024
66bd418
Merge remote-tracking branch 'upstream/main' into @janic/client-actio…
janicduplessis Jun 27, 2024
93e8185
Merge remote-tracking branch 'upstream/main' into @janic/client-actio…
janicduplessis Jun 28, 2024
9f616be
Merge remote-tracking branch 'upstream/main' into @janic/client-actio…
janicduplessis Jun 28, 2024
abb0d3a
Revert change in CONFIG.ts
janicduplessis Jun 28, 2024
4eb350f
Remove it.only
janicduplessis Jun 28, 2024
2f76d05
Address review comments in Pagination.ts
janicduplessis Jun 28, 2024
c841bc4
Update PaginationConfig type
janicduplessis Jun 28, 2024
70ac619
Remove extracted debug util
janicduplessis Jun 28, 2024
815a63e
Cleanup package-lock
janicduplessis Jun 28, 2024
dec7e9a
Add comment to getPagesWithIndexes
janicduplessis Jun 28, 2024
74375cf
Rename to mergeAndSortContinuousPages
janicduplessis Jun 28, 2024
8fe8324
Fix test names
janicduplessis Jun 28, 2024
c74a87f
Fix ts error
janicduplessis Jun 28, 2024
6024176
Merge branch 'main' into @janic/client-action-chain
roryabraham Jun 28, 2024
80d4d7b
Rename validateReadyToRead to waitForWrites
roryabraham Jul 1, 2024
5b5aa7e
Apply clientUpdateID to all requests
roryabraham Jul 1, 2024
eaa7b19
Merge remote-tracking branch 'upstream/main' into @janic/client-actio…
janicduplessis Jul 4, 2024
a3d792f
Fixes
janicduplessis Jul 4, 2024
ceb584f
Fix tests
janicduplessis Jul 4, 2024
e592214
Merge remote-tracking branch 'upstream/main' into @janic/client-actio…
janicduplessis Jul 4, 2024
1fded14
Add comment
janicduplessis Jul 4, 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
66 changes: 61 additions & 5 deletions __mocks__/@react-navigation/native/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,65 @@
import {useIsFocused as realUseIsFocused, useTheme as realUseTheme} from '@react-navigation/native';
/* eslint-disable import/prefer-default-export, import/no-import-module-exports */
import type * as ReactNavigation from '@react-navigation/native';
import createAddListenerMock from '../../../tests/utils/createAddListenerMock';

// We only want these mocked for storybook, not jest
const useIsFocused: typeof realUseIsFocused = process.env.NODE_ENV === 'test' ? realUseIsFocused : () => true;
const isJestEnv = process.env.NODE_ENV === 'test';

roryabraham marked this conversation as resolved.
Show resolved Hide resolved
const useTheme = process.env.NODE_ENV === 'test' ? realUseTheme : () => ({});
const realReactNavigation = isJestEnv ? jest.requireActual<typeof ReactNavigation>('@react-navigation/native') : (require('@react-navigation/native') as typeof ReactNavigation);

const useIsFocused = isJestEnv ? realReactNavigation.useIsFocused : () => true;
const useTheme = isJestEnv ? realReactNavigation.useTheme : () => ({});

const {triggerTransitionEnd, addListener} = isJestEnv
? createAddListenerMock()
: {
triggerTransitionEnd: () => {},
addListener: () => {},
};

const useNavigation = () => ({
...realReactNavigation.useNavigation,
navigate: jest.fn(),
getState: () => ({
routes: [],
}),
addListener,
});

type NativeNavigationMock = typeof ReactNavigation & {
triggerTransitionEnd: () => void;
};

export * from '@react-navigation/core';
export {useIsFocused, useTheme};
const Link = realReactNavigation.Link;
const LinkingContext = realReactNavigation.LinkingContext;
const NavigationContainer = realReactNavigation.NavigationContainer;
const ServerContainer = realReactNavigation.ServerContainer;
const DarkTheme = realReactNavigation.DarkTheme;
const DefaultTheme = realReactNavigation.DefaultTheme;
const ThemeProvider = realReactNavigation.ThemeProvider;
const useLinkBuilder = realReactNavigation.useLinkBuilder;
const useLinkProps = realReactNavigation.useLinkProps;
const useLinkTo = realReactNavigation.useLinkTo;
const useScrollToTop = realReactNavigation.useScrollToTop;
export {
// Overriden modules
useIsFocused,
useTheme,
useNavigation,
triggerTransitionEnd,

// Theme modules are left alone
Link,
LinkingContext,
NavigationContainer,
ServerContainer,
DarkTheme,
DefaultTheme,
ThemeProvider,
useLinkBuilder,
useLinkProps,
useLinkTo,
useScrollToTop,
};

export type {NativeNavigationMock};
7 changes: 5 additions & 2 deletions __mocks__/react-native.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ jest.doMock('react-native', () => {
},
Dimensions: {
...ReactNative.Dimensions,
addEventListener: jest.fn(),
addEventListener: jest.fn(() => ({remove: jest.fn()})),
get: () => dimensions,
set: (newDimensions: Record<string, number>) => {
dimensions = newDimensions;
Expand All @@ -98,7 +98,10 @@ jest.doMock('react-native', () => {
// so it seems easier to just run the callback immediately in tests.
InteractionManager: {
...ReactNative.InteractionManager,
runAfterInteractions: (callback: () => void) => callback(),
runAfterInteractions: (callback: () => void) => {
callback();
return {cancel: () => {}};
},
},
},
ReactNative,
Expand Down
17 changes: 17 additions & 0 deletions jest/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import '@shopify/flash-list/jestSetup';
import 'react-native-gesture-handler/jestSetup';
import type * as RNKeyboardController from 'react-native-keyboard-controller';
import mockStorage from 'react-native-onyx/dist/storage/__mocks__';
import type Animated from 'react-native-reanimated';
import 'setimmediate';
import mockFSLibrary from './setupMockFullstoryLib';
import setupMockImages from './setupMockImages';
Expand All @@ -21,6 +22,16 @@ jest.mock('react-native-onyx/dist/storage', () => mockStorage);
// Mock NativeEventEmitter as it is needed to provide mocks of libraries which include it
jest.mock('react-native/Libraries/EventEmitter/NativeEventEmitter');

// Needed for: https://stackoverflow.com/questions/76903168/mocking-libraries-in-jest
jest.mock('react-native/Libraries/LogBox/LogBox', () => ({
// eslint-disable-next-line @typescript-eslint/naming-convention
__esModule: true,
default: {
ignoreLogs: jest.fn(),
ignoreAllLogs: jest.fn(),
},
}));

// Turn off the console logs for timing events. They are not relevant for unit tests and create a lot of noise
jest.spyOn(console, 'debug').mockImplementation((...params: string[]) => {
if (params[0].startsWith('Timing:')) {
Expand Down Expand Up @@ -55,4 +66,10 @@ jest.mock('react-native-share', () => ({
default: jest.fn(),
}));

jest.mock('react-native-reanimated', () => ({
...jest.requireActual<typeof Animated>('react-native-reanimated/mock'),
createAnimatedPropAdapter: jest.fn,
useReducedMotion: jest.fn,
}));

jest.mock('react-native-keyboard-controller', () => require<typeof RNKeyboardController>('react-native-keyboard-controller/jest'));
7 changes: 4 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@
"ts-jest": "^29.1.2",
"ts-node": "^10.9.2",
"tsconfig-paths": "^4.2.0",
"type-fest": "^4.10.2",
"type-fest": "4.20.0",
"typescript": "^5.4.5",
"wait-port": "^0.2.9",
"webpack": "^5.76.0",
Expand Down
3 changes: 3 additions & 0 deletions src/CONST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5081,6 +5081,9 @@ const CONST = {

SUBSCRIPTION_SIZE_LIMIT: 20000,

PAGINATION_START_ID: '-1',
PAGINATION_END_ID: '-2',
janicduplessis marked this conversation as resolved.
Show resolved Hide resolved

PAYMENT_CARD_CURRENCY: {
USD: 'USD',
AUD: 'AUD',
Expand Down
5 changes: 4 additions & 1 deletion src/ONYXKEYS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,7 @@ const ONYXKEYS = {
REPORT_METADATA: 'reportMetadata_',
REPORT_ACTIONS: 'reportActions_',
REPORT_ACTIONS_DRAFTS: 'reportActionsDrafts_',
REPORT_ACTIONS_PAGES: 'reportActionsPages_',
REPORT_ACTIONS_REACTIONS: 'reportActionsReactions_',
REPORT_DRAFT_COMMENT: 'reportDraftComment_',
REPORT_IS_COMPOSER_FULL_SIZE: 'reportIsComposerFullSize_',
Expand Down Expand Up @@ -649,6 +650,7 @@ type OnyxCollectionValuesMapping = {
[ONYXKEYS.COLLECTION.REPORT_METADATA]: OnyxTypes.ReportMetadata;
[ONYXKEYS.COLLECTION.REPORT_ACTIONS]: OnyxTypes.ReportActions;
[ONYXKEYS.COLLECTION.REPORT_ACTIONS_DRAFTS]: OnyxTypes.ReportActionsDrafts;
[ONYXKEYS.COLLECTION.REPORT_ACTIONS_PAGES]: OnyxTypes.Pages;
[ONYXKEYS.COLLECTION.REPORT_ACTIONS_REACTIONS]: OnyxTypes.ReportActionReactions;
[ONYXKEYS.COLLECTION.REPORT_DRAFT_COMMENT]: string;
[ONYXKEYS.COLLECTION.REPORT_IS_COMPOSER_FULL_SIZE]: boolean;
Expand Down Expand Up @@ -811,11 +813,12 @@ type OnyxFormDraftKey = keyof OnyxFormDraftValuesMapping;
type OnyxValueKey = keyof OnyxValuesMapping;

type OnyxKey = OnyxValueKey | OnyxCollectionKey | OnyxFormKey | OnyxFormDraftKey;
type OnyxPagesKey = typeof ONYXKEYS.COLLECTION.REPORT_ACTIONS_PAGES;

type MissingOnyxKeysError = `Error: Types don't match, OnyxKey type is missing: ${Exclude<AllOnyxKeys, OnyxKey>}`;
/** If this type errors, it means that the `OnyxKey` type is missing some keys. */
// eslint-disable-next-line @typescript-eslint/no-unused-vars
type AssertOnyxKeys = AssertTypesEqual<AllOnyxKeys, OnyxKey, MissingOnyxKeysError>;

export default ONYXKEYS;
export type {OnyxCollectionKey, OnyxCollectionValuesMapping, OnyxFormDraftKey, OnyxFormKey, OnyxFormValuesMapping, OnyxKey, OnyxValueKey, OnyxValues};
export type {OnyxCollectionKey, OnyxCollectionValuesMapping, OnyxFormDraftKey, OnyxFormKey, OnyxFormValuesMapping, OnyxKey, OnyxPagesKey, OnyxValueKey, OnyxValues};
Loading
Loading