-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Feature/43097 - "Export onyx state" button in the troubleshoot section #43552
Merged
puneetlath
merged 24 commits into
Expensify:main
from
burczu:feature/43097-export-onyx-state
Jul 3, 2024
Merged
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
7890b03
export onyx state button added
burczu 62ef244
fetching onyx store key/value pairs PoC
burczu 95e118b
direct access to indexedDB instance possibility added
burczu fca2b12
distinction between web and native way of storing Onyx data taken int…
burczu 7eed281
saving as txt file added
burczu 3005ecc
masking fragile data added
burczu ed03efe
prettier
burczu 4160cc8
common part extracted
burczu 934346d
useCallback usage added
burczu 927eea5
Merge branch 'main' into feature/43097-export-onyx-state
burczu 6c0574d
const values extracted
burczu 56fe0cd
unnecessary variables removed
burczu 8423971
useMemo deps array updated
burczu 673dd59
additional comment added
burczu e07a5ce
filtering report actions out added
burczu 1acf989
masking messages inside report actions
burczu 37c960f
mask wording translation added
burczu d6047e6
eslint fixed
burczu 2607bb5
member access made safe instead suppressing it
burczu d1c6567
toggling onyx state masking simplified
burczu 363ac2d
Merge branch 'main' into feature/43097-export-onyx-state
burczu 0498474
eslint errors fix
burczu 9abd735
missing check for null added
burczu 6b49c85
failing on cancel disabled
burczu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import {Str} from 'expensify-common'; | ||
import ONYXKEYS from '@src/ONYXKEYS'; | ||
|
||
const maskFragileData = (data: Record<string, unknown>, parentKey?: string): Record<string, unknown> => { | ||
const maskedData: Record<string, unknown> = {}; | ||
|
||
if (!data) { | ||
return maskedData; | ||
} | ||
|
||
Object.keys(data).forEach((key) => { | ||
if (!Object.prototype.hasOwnProperty.call(data, key)) { | ||
return; | ||
} | ||
|
||
const value = data[key]; | ||
|
||
if (typeof value === 'string' && (Str.isValidEmail(value) || key === 'authToken' || key === 'encryptedAuthToken')) { | ||
maskedData[key] = '***'; | ||
} else if (parentKey && parentKey.includes(ONYXKEYS.COLLECTION.REPORT_ACTIONS) && (key === 'text' || key === 'html')) { | ||
maskedData[key] = '***'; | ||
} else if (typeof value === 'object') { | ||
maskedData[key] = maskFragileData(value as Record<string, unknown>, key.includes(ONYXKEYS.COLLECTION.REPORT_ACTIONS) ? key : parentKey); | ||
} else { | ||
maskedData[key] = value; | ||
} | ||
}); | ||
|
||
return maskedData; | ||
}; | ||
|
||
export default { | ||
maskFragileData, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import RNFS from 'react-native-fs'; | ||
import {open} from 'react-native-quick-sqlite'; | ||
import Share from 'react-native-share'; | ||
import CONST from '@src/CONST'; | ||
import common from './common'; | ||
|
||
const readFromOnyxDatabase = () => | ||
new Promise((resolve) => { | ||
const db = open({name: CONST.DEFAULT_DB_NAME}); | ||
const query = `SELECT * FROM ${CONST.DEFAULT_TABLE_NAME}`; | ||
|
||
db.executeAsync(query, []).then(({rows}) => { | ||
// eslint-disable-next-line no-underscore-dangle, @typescript-eslint/no-unsafe-member-access | ||
const result = rows?._array.map((row) => ({[row?.record_key]: JSON.parse(row?.valueJSON as string)})); | ||
|
||
resolve(result); | ||
}); | ||
}); | ||
|
||
const shareAsFile = (value: string) => { | ||
try { | ||
// Define new filename and path for the app info file | ||
const infoFileName = CONST.DEFAULT_ONYX_DUMP_FILE_NAME; | ||
const infoFilePath = `${RNFS.DocumentDirectoryPath}/${infoFileName}`; | ||
const actualInfoFile = `file://${infoFilePath}`; | ||
|
||
RNFS.writeFile(infoFilePath, value, 'utf8').then(() => { | ||
Share.open({ | ||
url: actualInfoFile, | ||
failOnCancel: false, | ||
}); | ||
}); | ||
} catch (error) { | ||
console.error('Error renaming and sharing file:', error); | ||
} | ||
}; | ||
|
||
export default { | ||
maskFragileData: common.maskFragileData, | ||
readFromOnyxDatabase, | ||
shareAsFile, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import CONST from '@src/CONST'; | ||
import common from './common'; | ||
|
||
const readFromOnyxDatabase = () => | ||
new Promise<Record<string, unknown>>((resolve) => { | ||
let db: IDBDatabase; | ||
const openRequest = indexedDB.open(CONST.DEFAULT_DB_NAME, 1); | ||
openRequest.onsuccess = () => { | ||
db = openRequest.result; | ||
const transaction = db.transaction(CONST.DEFAULT_TABLE_NAME); | ||
const objectStore = transaction.objectStore(CONST.DEFAULT_TABLE_NAME); | ||
const cursor = objectStore.openCursor(); | ||
|
||
const queryResult: Record<string, unknown> = {}; | ||
|
||
cursor.onerror = () => { | ||
console.error('Error reading cursor'); | ||
}; | ||
|
||
cursor.onsuccess = (event) => { | ||
const {result} = event.target as IDBRequest<IDBCursorWithValue>; | ||
if (result) { | ||
queryResult[result.primaryKey as string] = result.value; | ||
result.continue(); | ||
} else { | ||
// no results mean the cursor has reached the end of the data | ||
resolve(queryResult); | ||
} | ||
}; | ||
}; | ||
}); | ||
|
||
const shareAsFile = (value: string) => { | ||
const element = document.createElement('a'); | ||
element.setAttribute('href', `data:text/plain;charset=utf-8,${encodeURIComponent(value)}`); | ||
element.setAttribute('download', CONST.DEFAULT_ONYX_DUMP_FILE_NAME); | ||
|
||
element.style.display = 'none'; | ||
document.body.appendChild(element); | ||
|
||
element.click(); | ||
|
||
document.body.removeChild(element); | ||
}; | ||
|
||
export default { | ||
maskFragileData: common.maskFragileData, | ||
readFromOnyxDatabase, | ||
shareAsFile, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should not have had set the default version for database, this caused #45232. Database version was a optional parameter here.