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

Onyx File handling - preparation #4908

Merged
merged 38 commits into from
Jan 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
9c287f3
Package updates add localforage and updated Onyx
kidroca Aug 27, 2021
ee4f659
Omit `function` values from the persisted request
kidroca Aug 27, 2021
f37b502
Persist all `addAction` requests
kidroca Aug 27, 2021
5fd5dab
Add Expo File System to be used for mobile persistence
kidroca Aug 27, 2021
b677931
Use Onyx.prepareFile in addAction
kidroca Aug 28, 2021
4a484ec
Fix: AttachmentPicker Capture size information correctly
kidroca Aug 28, 2021
91d8f40
Update onyx hash, update lock file
kidroca Aug 28, 2021
a2ac108
Run pod install and add expo-file-system
kidroca Aug 30, 2021
e474acd
Remove storage event listener and logic
kidroca Aug 30, 2021
3ea51ec
Update onyx hash, update lock file
kidroca Aug 30, 2021
e9c5d50
Merge branch 'main' into kidroca/file-handling-poc
kidroca Oct 19, 2021
4073718
Update Onyx hash with the latest file storage POC
kidroca Nov 1, 2021
5971da5
Merge branch 'main' into kidroca/file-handling-poc
kidroca Nov 1, 2021
044278d
Remove expo-file-system
kidroca Nov 2, 2021
1da8e87
Report.js remove Onyx.prepareFile call
kidroca Nov 2, 2021
62de152
AttachmentPicker copy document attachments to cache
kidroca Nov 2, 2021
8d0f6cd
Bump react-native-flipper version
kidroca Nov 2, 2021
d33702c
Update Pods after package changes
kidroca Nov 2, 2021
7805eb0
Update Onyx hash after file handling changes
kidroca Nov 2, 2021
bbfdc5c
Update image picker and document picker libraries
kidroca Nov 2, 2021
2a02fb1
Revert reanimated to the previous version
kidroca Nov 2, 2021
06ef491
Merge branch 'main' into kidroca/file-handling-poc
kidroca Nov 2, 2021
29565c6
Run pod install
kidroca Nov 2, 2021
f862014
Update Onyx hash after file handling changes
kidroca Nov 3, 2021
f5de171
Remove SignoutManager.js - no longer needed
kidroca Nov 3, 2021
2ba8109
Merge branch 'main' into kidroca/file-handling-poc
kidroca Nov 15, 2021
4f322dd
Merge branch 'main' into kidroca/file-handling-poc
kidroca Dec 13, 2021
48c80d2
Revert "Persist all `addAction` requests"
kidroca Dec 13, 2021
1db1d72
Update onyx hash (file storage)
kidroca Dec 14, 2021
13083c8
Merge branch 'main' into kidroca/file-handling-poc
kidroca Dec 28, 2021
2539f47
Refactor: remove setShouldSignOut unused leftover
kidroca Dec 28, 2021
769141b
Add MoveToIndexedDB migration
kidroca Dec 28, 2021
856dd1e
Add MoveToIndexedDB tests
kidroca Dec 28, 2021
bd00a83
MigrateToIndexedDB: Don't remove non Onyx keys from localStorage
kidroca Dec 28, 2021
1e548cb
Package - add `inquirer` back
kidroca Dec 28, 2021
41004ea
MoveToIndexedDB - refactor to be more self-explanatory and add docs
kidroca Jan 6, 2022
555d9ae
Merge branch 'main' into kidroca/file-handling-poc
kidroca Jan 6, 2022
3266600
Add flipper 0.117.0 to match the pod speck
kidroca Jan 6, 2022
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
6 changes: 3 additions & 3 deletions ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -441,11 +441,11 @@ PODS:
- react-native-config/App (= 1.4.5)
- react-native-config/App (1.4.5):
- React-Core
- react-native-document-picker (5.1.0):
- react-native-document-picker (7.1.1):
- React-Core
- react-native-flipper (0.103.0):
- react-native-flipper (0.117.0):
- React-Core
- react-native-image-picker (4.0.3):
- react-native-image-picker (4.1.2):
- React-Core
- react-native-netinfo (7.1.3):
- React-Core
Expand Down
46 changes: 35 additions & 11 deletions package-lock.json

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

9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
"file-loader": "^6.0.0",
"html-entities": "^1.3.1",
"htmlparser2": "^7.2.0",
"localforage": "^1.10.0",
"lodash": "4.17.21",
"metro-config": "^0.64.0",
"moment": "^2.27.0",
Expand All @@ -83,17 +84,17 @@
"react-native-bootsplash": "^3.2.7",
"react-native-collapsible": "^1.6.0",
"react-native-config": "^1.4.5",
"react-native-document-picker": "^5.1.0",
"react-native-document-picker": "^7.1.1",
"react-native-fast-image": "^8.5.11",
"react-native-gesture-handler": "1.9.0",
"react-native-google-places-autocomplete": "^2.4.1",
"react-native-haptic-feedback": "^1.13.0",
"react-native-image-pan-zoom": "^2.1.12",
"react-native-image-picker": "^4.0.3",
"react-native-image-picker": "^4.1.2",
"react-native-image-size": "^1.1.3",
"react-native-keyboard-spacer": "^0.4.1",
"react-native-modal": "^11.10.0",
"react-native-onyx": "git+https://github.com/Expensify/react-native-onyx.git#00bcc1520cf6cf7846d8aa40b5161bd1f407341f",
"react-native-onyx": "git+https://github.com/Expensify/react-native-onyx.git#40c5b14dcc77e1193d027ecc9dd5f2563516e148",
"react-native-pdf": "^6.2.2",
"react-native-performance": "^2.0.0",
"react-native-permissions": "^3.0.1",
Expand Down Expand Up @@ -170,7 +171,7 @@
"pusher-js-mock": "^0.3.3",
"react-hot-loader": "^4.12.21",
"react-native-clean-project": "^4.0.0-alpha4.0",
"react-native-flipper": "^0.103.0",
"react-native-flipper": "^0.117.0",
"react-native-performance-flipper-reporter": "^2.0.0",
"react-native-svg-transformer": "^0.14.3",
"react-test-renderer": "16.13.1",
Expand Down
3 changes: 0 additions & 3 deletions src/ONYXKEYS.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,6 @@ export default {
// Stores Workspace ID that will be tied to reimbursement account during setup
REIMBURSEMENT_ACCOUNT_WORKSPACE_ID: 'reimbursementAccountWorkspaceID',

// Notifies all tabs that they should sign out and clear storage.
SHOULD_SIGN_OUT: 'shouldSignOut',

Comment on lines -148 to -150
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this just not used? Not seeing it in any changes from this PR

Copy link
Contributor Author

@kidroca kidroca Jan 14, 2022

Choose a reason for hiding this comment

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

This was used here: src/libs/SignoutManager.js
But now the file is deleted - no longer necessary

What the SignoutManager did was to synchronize the logout across multiple tabs
But now with localForage this is no longer needed
We're touching on this here: Expensify/react-native-onyx#102 (comment)

// Set when we are loading payment methods
IS_LOADING_PAYMENT_METHODS: 'isLoadingPaymentMethods',

Expand Down
19 changes: 11 additions & 8 deletions src/components/AttachmentPicker/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ function getImagePickerOptions(type) {
*/
const documentPickerOptions = {
type: [RNDocumentPicker.types.allFiles],
copyTo: 'cachesDirectory',
Copy link
Contributor

Choose a reason for hiding this comment

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

Does android have a cachesDirectory? I only see it for IOS

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Documentation says:

[iOS and Android only] copyTo:"cachesDirectory" | "documentDirectory"
https://www.npmjs.com/package/react-native-document-picker#ios-and-android-only-copytocachesdirectory--documentdirectory

I take it the option copyTo and the value cachesDirectory is available in both

};

/**
Expand All @@ -66,7 +67,7 @@ function getDataForUpload(fileData) {
const fileResult = {
name: fileData.fileName || fileData.name || 'chat_attachment',
type: fileData.type,
uri: fileData.uri,
uri: fileData.fileCopyUri || fileData.uri,
Copy link
Contributor Author

@kidroca kidroca Nov 2, 2021

Choose a reason for hiding this comment

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

The document picker makes the attachment available until the application is terminated
To persist Document Attachments and be able to use them on the next app launch we need to move them to the cache dir
This way we can persist a reference for the attachment in Onyx and support offline files

The ImagePicker library is already making a copy in cache by default

size: fileData.fileSize || fileData.size,
};

Expand Down Expand Up @@ -127,20 +128,22 @@ class AttachmentPicker extends Component {
* Handles the image/document picker result and
* sends the selected attachment to the caller (parent component)
*
* @param {ImagePickerResponse|DocumentPickerResponse} attachment
* @param {Array<ImagePickerResponse|DocumentPickerResponse>} attachments
* @returns {Promise}
*/
pickAttachment(attachment) {
if (!attachment) {
pickAttachment(attachments = []) {
if (attachments.length === 0) {
return;
}

if (attachment.width === -1 || attachment.height === -1) {
const fileData = _.first(attachments);

if (fileData.width === -1 || fileData.height === -1) {
this.showImageCorruptionAlert();
return;
}

return getDataForUpload(attachment).then((result) => {
return getDataForUpload(fileData).then((result) => {
this.completeAttachmentSelection(result);
}).catch((error) => {
this.showGeneralAlert(error.message);
Expand Down Expand Up @@ -196,7 +199,7 @@ class AttachmentPicker extends Component {
}

// Resolve with the first (and only) selected file
return resolve(response.assets[0]);
return resolve(response.assets);
});
});
}
Expand Down Expand Up @@ -225,7 +228,7 @@ class AttachmentPicker extends Component {
/**
* Launch the DocumentPicker. Results are in the same format as ImagePicker
*
* @returns {Promise<DocumentPickerResponse>}
* @returns {Promise<DocumentPickerResponse[]>}
*/
showDocumentPicker() {
return RNDocumentPicker.pick(documentPickerOptions).catch((error) => {
Expand Down
4 changes: 3 additions & 1 deletion src/libs/Network.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,9 @@ function processNetworkRequestQueue() {
networkRequestQueue = _.reject(networkRequestQueue, (request) => {
const shouldRetry = lodashGet(request, 'data.shouldRetry');
if (shouldRetry && request.data.persist) {
retryableRequests.push(request);
// exclude functions as they cannot be persisted
const requestToPersist = _.omit(request, val => _.isFunction(val));
retryableRequests.push(requestToPersist);
return true;
}
});
Expand Down
34 changes: 0 additions & 34 deletions src/libs/SignoutManager.js

This file was deleted.

4 changes: 2 additions & 2 deletions src/libs/actions/Report.js
Original file line number Diff line number Diff line change
Expand Up @@ -1079,7 +1079,7 @@ function fetchAllReports(
*
* @param {Number} reportID
* @param {String} text
* @param {Object} [file]
* @param {File} [file]
*/
function addAction(reportID, text, file) {
// Convert the comment from MD into HTML because that's how it is stored in the database
Expand Down Expand Up @@ -1158,8 +1158,8 @@ function addAction(reportID, text, file) {

API.Report_AddComment({
reportID,
reportComment: commentText,
file,
reportComment: commentText,
clientID: optimisticReportActionID,

// The persist flag enables this request to be retried if we are offline and the app is completely killed. We do
Expand Down
9 changes: 0 additions & 9 deletions src/libs/actions/Session/setShouldSignOut.js

This file was deleted.

5 changes: 1 addition & 4 deletions src/libs/actions/SignInRedirect.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import Onyx from 'react-native-onyx';
import SignoutManager from '../SignoutManager';
import ONYXKEYS from '../../ONYXKEYS';

let currentActiveClients;
Expand Down Expand Up @@ -38,16 +37,14 @@ function clearStorageAndRedirect(errorMessage) {
});
}

SignoutManager.registerSignoutCallback(clearStorageAndRedirect);

/**
* Clears the Onyx store and redirects to the sign in page.
* Normally this method would live in Session.js, but that would cause a circular dependency with Network.js.
*
* @param {String} [errorMessage] error message to be displayed on the sign in page
*/
function redirectToSignIn(errorMessage) {
SignoutManager.signOut(errorMessage);
clearStorageAndRedirect(errorMessage);
}

export default redirectToSignIn;
23 changes: 0 additions & 23 deletions src/libs/listenToStorageEvents/index.js

This file was deleted.

8 changes: 0 additions & 8 deletions src/libs/listenToStorageEvents/index.native.js

This file was deleted.

2 changes: 2 additions & 0 deletions src/libs/migrateOnyx.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import Log from './Log';
import AddEncryptedAuthToken from './migrations/AddEncryptedAuthToken';
import RenameActiveClientsKey from './migrations/RenameActiveClientsKey';
import RenamePriorityModeKey from './migrations/RenamePriorityModeKey';
import MoveToIndexedDB from './migrations/MoveToIndexedDB';

export default function () {
const startTime = Date.now();
Expand All @@ -11,6 +12,7 @@ export default function () {
return new Promise((resolve) => {
// Add all migrations to an array so they are executed in order
const migrationPromises = [
MoveToIndexedDB,
kidroca marked this conversation as resolved.
Show resolved Hide resolved
RenameActiveClientsKey,
RenamePriorityModeKey,
AddEncryptedAuthToken,
Expand Down
Loading