-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
[No QA] Console error cleanup: fix require cycle warnings (part 1) #52561
Open
JKobrynski
wants to merge
11
commits into
Expensify:main
Choose a base branch
from
JKobrynski:fixRequireCycleWarnings_part1
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
86dbf16
fix cycles related to CONST.ts
JKobrynski eddc1d2
fix require cycles starting with Log.ts -> Network/index.ts
JKobrynski 14a8253
fix require cycles starting with API/index.ts -> Middleware/index.ts …
JKobrynski 172e2df
Fix require cycles starting with Navigation.ts -> ReportConnection.ts…
JKobrynski 1cd0315
fix the ReportConnection.ts -> PriorityMode.ts -> ReportConnection.ts…
JKobrynski 8dc09af
fix import cycles starting with (and containing) ReportConnection.ts …
JKobrynski d24daac
fix require cycles containing Navigation.ts -> reportUtils.ts -> ... …
JKobrynski eb5a8ff
fix the Navigation.ts -> ... -> saveLastRoute/index.ios.ts -> App.ts …
JKobrynski a103417
fix require cycles containing IOU.ts -> FileUtils.ts chain
JKobrynski 9d01ed0
add missing comment to dynamic import
JKobrynski b9b3681
Merge branch 'main' into fixRequireCycleWarnings_part1
JKobrynski 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
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 |
---|---|---|
|
@@ -5,8 +5,6 @@ import lodashSet from 'lodash/set'; | |
import type {OnyxCollection, OnyxEntry} from 'react-native-onyx'; | ||
import Onyx from 'react-native-onyx'; | ||
import type {ValueOf} from 'type-fest'; | ||
import {getPolicyCategoriesData} from '@libs/actions/Policy/Category'; | ||
import {getPolicyTagsData} from '@libs/actions/Policy/Tag'; | ||
import type {TransactionMergeParams} from '@libs/API/parameters'; | ||
import {getCurrencyDecimals} from '@libs/CurrencyUtils'; | ||
import DateUtils from '@libs/DateUtils'; | ||
|
@@ -32,6 +30,10 @@ import type DeepValueOf from '@src/types/utils/DeepValueOf'; | |
import {isEmptyObject} from '@src/types/utils/EmptyObject'; | ||
import getDistanceInMeters from './getDistanceInMeters'; | ||
|
||
// Dynamic Imports to avoid circular dependencies | ||
const CategoryActions = () => import('@libs/actions/Policy/Category'); | ||
const TagActions = () => import('@libs/actions/Policy/Tag'); | ||
|
||
let allTransactions: OnyxCollection<Transaction> = {}; | ||
Onyx.connect({ | ||
key: ONYXKEYS.COLLECTION.TRANSACTION, | ||
|
@@ -1136,37 +1138,41 @@ function compareDuplicateTransactionFields(transactionID: string, reportID: stri | |
} | ||
} else if (fieldName === 'category') { | ||
const differentValues = getDifferentValues(transactions, keys); | ||
const policyCategories = getPolicyCategoriesData(report?.policyID ?? '-1'); | ||
const availableCategories = Object.values(policyCategories) | ||
.filter((category) => differentValues.includes(category.name) && category.enabled && category.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE) | ||
.map((e) => e.name); | ||
|
||
if (!areAllFieldsEqualForKey && policy?.areCategoriesEnabled && (availableCategories.length > 1 || (availableCategories.length === 1 && differentValues.includes('')))) { | ||
change[fieldName] = [...availableCategories, ...(differentValues.includes('') ? [''] : [])]; | ||
} else if (areAllFieldsEqualForKey) { | ||
keep[fieldName] = firstTransaction?.[keys[0]] ?? firstTransaction?.[keys[1]]; | ||
} | ||
} else if (fieldName === 'tag') { | ||
const policyTags = getPolicyTagsData(report?.policyID ?? '-1'); | ||
const isMultiLevelTags = PolicyUtils.isMultiLevelTags(policyTags); | ||
if (isMultiLevelTags) { | ||
if (areAllFieldsEqualForKey || !policy?.areTagsEnabled) { | ||
keep[fieldName] = firstTransaction?.[keys[0]] ?? firstTransaction?.[keys[1]]; | ||
} else { | ||
processChanges(fieldName, transactions, keys); | ||
} | ||
} else { | ||
const differentValues = getDifferentValues(transactions, keys); | ||
const policyTagsObj = Object.values(Object.values(policyTags).at(0)?.tags ?? {}); | ||
const availableTags = policyTagsObj | ||
.filter((tag) => differentValues.includes(tag.name) && tag.enabled && tag.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE) | ||
CategoryActions().then((actions) => { | ||
const policyCategories = actions.getPolicyCategoriesData(report?.policyID ?? '-1'); | ||
const availableCategories = Object.values(policyCategories) | ||
.filter((category) => differentValues.includes(category.name) && category.enabled && category.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE) | ||
.map((e) => e.name); | ||
if (!areAllFieldsEqualForKey && policy?.areTagsEnabled && (availableTags.length > 1 || (availableTags.length === 1 && differentValues.includes('')))) { | ||
change[fieldName] = [...availableTags, ...(differentValues.includes('') ? [''] : [])]; | ||
|
||
if (!areAllFieldsEqualForKey && policy?.areCategoriesEnabled && (availableCategories.length > 1 || (availableCategories.length === 1 && differentValues.includes('')))) { | ||
change[fieldName] = [...availableCategories, ...(differentValues.includes('') ? [''] : [])]; | ||
} else if (areAllFieldsEqualForKey) { | ||
keep[fieldName] = firstTransaction?.[keys[0]] ?? firstTransaction?.[keys[1]]; | ||
} | ||
} | ||
}); | ||
} else if (fieldName === 'tag') { | ||
TagActions().then((module) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same |
||
const policyTags = module.getPolicyTagsData(report?.policyID ?? '-1'); | ||
const isMultiLevelTags = PolicyUtils.isMultiLevelTags(policyTags); | ||
if (isMultiLevelTags) { | ||
if (areAllFieldsEqualForKey || !policy?.areTagsEnabled) { | ||
keep[fieldName] = firstTransaction?.[keys[0]] ?? firstTransaction?.[keys[1]]; | ||
} else { | ||
processChanges(fieldName, transactions, keys); | ||
} | ||
} else { | ||
const differentValues = getDifferentValues(transactions, keys); | ||
const policyTagsObj = Object.values(Object.values(policyTags).at(0)?.tags ?? {}); | ||
const availableTags = policyTagsObj | ||
.filter((tag) => differentValues.includes(tag.name) && tag.enabled && tag.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE) | ||
.map((e) => e.name); | ||
if (!areAllFieldsEqualForKey && policy?.areTagsEnabled && (availableTags.length > 1 || (availableTags.length === 1 && differentValues.includes('')))) { | ||
change[fieldName] = [...availableTags, ...(differentValues.includes('') ? [''] : [])]; | ||
} else if (areAllFieldsEqualForKey) { | ||
keep[fieldName] = firstTransaction?.[keys[0]] ?? firstTransaction?.[keys[1]]; | ||
} | ||
} | ||
}); | ||
} else if (areAllFieldsEqualForKey) { | ||
keep[fieldName] = firstTransaction?.[keys[0]] ?? firstTransaction?.[keys[1]]; | ||
} else { | ||
|
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 |
---|---|---|
@@ -1,11 +1,12 @@ | ||
import debounce from 'lodash/debounce'; | ||
import Onyx from 'react-native-onyx'; | ||
import Log from '@libs/Log'; | ||
import * as ReportConnection from '@libs/ReportConnection'; | ||
import * as ReportUtils from '@libs/ReportUtils'; | ||
import CONST from '@src/CONST'; | ||
import ONYXKEYS from '@src/ONYXKEYS'; | ||
|
||
const ReportConnection = () => import('@libs/ReportConnection'); | ||
|
||
/** | ||
* This actions file is used to automatically switch a user into #focus mode when they exceed a certain number of reports. We do this primarily for performance reasons. | ||
* Similar to the "Welcome action" we must wait for a number of things to happen when the user signs in or refreshes the page: | ||
|
@@ -77,11 +78,13 @@ function resetHasReadRequiredDataFromStorage() { | |
} | ||
|
||
function checkRequiredData() { | ||
if (ReportConnection.getAllReports() === undefined || hasTriedFocusMode === undefined || isInFocusMode === undefined || isLoadingReportData) { | ||
return; | ||
} | ||
ReportConnection().then((module) => { | ||
if (module.getAllReports() === undefined || hasTriedFocusMode === undefined || isInFocusMode === undefined || isLoadingReportData) { | ||
return; | ||
} | ||
|
||
resolveIsReadyPromise(); | ||
resolveIsReadyPromise(); | ||
}); | ||
} | ||
|
||
function tryFocusModeUpdate() { | ||
|
@@ -98,33 +101,36 @@ function tryFocusModeUpdate() { | |
} | ||
|
||
const validReports = []; | ||
const allReports = ReportConnection.getAllReports(); | ||
Object.keys(allReports ?? {}).forEach((key) => { | ||
const report = allReports?.[key]; | ||
if (!report) { | ||
return; | ||
} | ||
|
||
if (!ReportUtils.isValidReport(report) || !ReportUtils.isReportParticipant(currentUserAccountID ?? -1, report)) { | ||
return; | ||
} | ||
ReportConnection().then((module) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same, |
||
const allReports = module.getAllReports(); | ||
Object.keys(allReports ?? {}).forEach((key) => { | ||
const report = allReports?.[key]; | ||
if (!report) { | ||
return; | ||
} | ||
|
||
validReports.push(report); | ||
}); | ||
if (!ReportUtils.isValidReport(report) || !ReportUtils.isReportParticipant(currentUserAccountID ?? -1, report)) { | ||
return; | ||
} | ||
|
||
const reportCount = validReports.length; | ||
if (reportCount < CONST.REPORT.MAX_COUNT_BEFORE_FOCUS_UPDATE) { | ||
Log.info('Not switching user to optimized focus mode as they do not have enough reports', false, {reportCount}); | ||
return; | ||
} | ||
validReports.push(report); | ||
}); | ||
|
||
Log.info('Switching user to optimized focus mode', false, {reportCount, hasTriedFocusMode, isInFocusMode}); | ||
const reportCount = validReports.length; | ||
if (reportCount < CONST.REPORT.MAX_COUNT_BEFORE_FOCUS_UPDATE) { | ||
Log.info('Not switching user to optimized focus mode as they do not have enough reports', false, {reportCount}); | ||
return; | ||
} | ||
|
||
Log.info('Switching user to optimized focus mode', false, {reportCount, hasTriedFocusMode, isInFocusMode}); | ||
|
||
// Record that we automatically switched them so we don't ask again. | ||
hasTriedFocusMode = true; | ||
// Record that we automatically switched them so we don't ask again. | ||
hasTriedFocusMode = true; | ||
|
||
// Setting this triggers a modal to open and notify the user. | ||
Onyx.set(ONYXKEYS.FOCUS_MODE_NOTIFICATION, true); | ||
// Setting this triggers a modal to open and notify the user. | ||
Onyx.set(ONYXKEYS.FOCUS_MODE_NOTIFICATION, true); | ||
}); | ||
}); | ||
} | ||
|
||
|
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.
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.
This doesn't look right because you are mutating
keep
andchange
to return them at the end of the function. If this code is wrapped in a promise we will have racing condition problems