Skip to content

Commit ce77b8e

Browse files
committed
Merge branch 'main' into remove-onyx-connect-in-EmojiUtils
2 parents d80456b + 85e8606 commit ce77b8e

6 files changed

Lines changed: 28 additions & 14 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
"test:debug": "TZ=utc NODE_OPTIONS='--inspect-brk --experimental-vm-modules' jest --runInBand",
4747
"perf-test": "NODE_OPTIONS=--experimental-vm-modules npx reassure",
4848
"typecheck": "NODE_OPTIONS=--max_old_space_size=8192 tsc",
49-
"lint": "NODE_OPTIONS=--max_old_space_size=8192 eslint . --max-warnings=290 --cache --cache-location=node_modules/.cache/eslint",
49+
"lint": "NODE_OPTIONS=--max_old_space_size=8192 eslint . --max-warnings=284 --cache --cache-location=node_modules/.cache/eslint",
5050
"lint-changed": "NODE_OPTIONS=--max_old_space_size=8192 ./scripts/lintChanged.sh",
5151
"lint-watch": "npx eslint-watch --watch --changed",
5252
"shellcheck": "./scripts/shellCheck.sh",

src/libs/Network/SequentialQueue.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ import type {ConflictData} from '@src/types/onyx/Request';
2121
import {isOffline, onReconnection} from './NetworkStore';
2222

2323
let shouldFailAllRequests: boolean;
24-
Onyx.connect({
24+
// Use connectWithoutView since this is for network data and don't affect to any UI
25+
Onyx.connectWithoutView({
2526
key: ONYXKEYS.NETWORK,
2627
callback: (network) => {
2728
if (!network) {
@@ -78,7 +79,8 @@ function flushOnyxUpdatesQueue() {
7879

7980
let queueFlushedDataToStore: OnyxUpdate[] = [];
8081

81-
Onyx.connect({
82+
// Use connectWithoutView since this is for network queue and don't affect to any UI
83+
Onyx.connectWithoutView({
8284
key: ONYXKEYS.QUEUE_FLUSHED_DATA,
8385
callback: (val) => {
8486
if (!val) {
@@ -227,7 +229,8 @@ function flush(shouldResetPromise = true) {
227229
}
228230

229231
// Ensure persistedRequests are read from storage before proceeding with the queue
230-
const connection = Onyx.connect({
232+
// Use connectWithoutView since this is for network queue and don't affect to any UI
233+
const connection = Onyx.connectWithoutView({
231234
key: ONYXKEYS.PERSISTED_REQUESTS,
232235
// We exceptionally opt out of reusing the connection here to avoid extra callback calls due to
233236
// an existing connection already made in PersistedRequests.ts.

src/libs/actions/MapboxToken.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ import ONYXKEYS from '@src/ONYXKEYS';
1111
import type {MapboxAccessToken, Network} from '@src/types/onyx';
1212

1313
let authToken: string | undefined;
14-
Onyx.connect({
14+
// Use connectWithoutView since this is only for auth token and don't affect to any UI
15+
Onyx.connectWithoutView({
1516
key: ONYXKEYS.SESSION,
1617
callback: (value) => {
1718
authToken = value?.authToken;
@@ -64,7 +65,8 @@ const init = () => {
6465
}
6566

6667
// When the token changes in Onyx, the expiration needs to be checked so a new token can be retrieved.
67-
tokenConnection = Onyx.connect({
68+
// Use connectWithoutView since this is only for mapbox token and don't affect to any UI
69+
tokenConnection = Onyx.connectWithoutView({
6870
key: ONYXKEYS.MAPBOX_ACCESS_TOKEN,
6971
callback: (token) => {
7072
// Only the leader should be in charge of the mapbox token, or else when you have multiple tabs open, the Onyx connection fires multiple times
@@ -119,7 +121,8 @@ const init = () => {
119121

120122
if (!networkConnection) {
121123
let network: Network | undefined;
122-
networkConnection = Onyx.connect({
124+
// Use connectWithoutView since the network state and don't affect to any UI
125+
networkConnection = Onyx.connectWithoutView({
123126
key: ONYXKEYS.NETWORK,
124127
callback: (value) => {
125128
// When the network reconnects, check if the token has expired. If it has, then clearing the token will

src/libs/actions/Policy/Member.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import type {InvitedEmailsToAccountIDs, PersonalDetailsList, Policy, PolicyEmplo
3232
import type {PendingAction} from '@src/types/onyx/OnyxCommon';
3333
import type {JoinWorkspaceResolution} from '@src/types/onyx/OriginalMessage';
3434
import type {ApprovalRule} from '@src/types/onyx/Policy';
35-
import type {Participant} from '@src/types/onyx/Report';
35+
import type {NotificationPreference, Participant} from '@src/types/onyx/Report';
3636
import type {OnyxData} from '@src/types/onyx/Request';
3737
import {isEmptyObject} from '@src/types/utils/EmptyObject';
3838
import {createPolicyExpenseChats} from './Policy';
@@ -880,6 +880,7 @@ function buildAddMembersToWorkspaceOnyxData(
880880
policyMemberAccountIDs: number[],
881881
role: string,
882882
formatPhoneNumber: LocaleContextProps['formatPhoneNumber'],
883+
policyExpenseChatNotificationPreference?: NotificationPreference,
883884
) {
884885
const logins = Object.keys(invitedEmailsToAccountIDs).map((memberLogin) => PhoneNumber.addSMSDomainIfPhoneNumber(memberLogin));
885886
const accountIDs = Object.values(invitedEmailsToAccountIDs);
@@ -899,7 +900,7 @@ function buildAddMembersToWorkspaceOnyxData(
899900
const announceRoomChat = optimisticAnnounceChat.announceChatData;
900901

901902
// create onyx data for policy expense chats for each new member
902-
const membersChats = createPolicyExpenseChats(policyID, invitedEmailsToAccountIDs);
903+
const membersChats = createPolicyExpenseChats(policyID, invitedEmailsToAccountIDs, undefined, policyExpenseChatNotificationPreference);
903904

904905
const optimisticMembersState: OnyxCollectionInputValue<PolicyEmployee> = {};
905906
const successMembersState: OnyxCollectionInputValue<PolicyEmployee> = {};

src/libs/actions/Policy/Policy.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ import type {
110110
import type {Errors} from '@src/types/onyx/OnyxCommon';
111111
import type {Attributes, CompanyAddress, CustomUnit, NetSuiteCustomList, NetSuiteCustomSegment, ProhibitedExpenses, Rate, TaxRate} from '@src/types/onyx/Policy';
112112
import type {CustomFieldType} from '@src/types/onyx/PolicyEmployee';
113+
import type {NotificationPreference} from '@src/types/onyx/Report';
113114
import type {OnyxData} from '@src/types/onyx/Request';
114115
import {isEmptyObject} from '@src/types/utils/EmptyObject';
115116
import {buildOptimisticMccGroup, buildOptimisticPolicyCategories} from './Category';
@@ -1159,7 +1160,12 @@ function verifySetupIntentAndRequestPolicyOwnerChange(policyID: string) {
11591160
*
11601161
* @returns - object with onyxSuccessData, onyxOptimisticData, and optimisticReportIDs (map login to reportID)
11611162
*/
1162-
function createPolicyExpenseChats(policyID: string, invitedEmailsToAccountIDs: InvitedEmailsToAccountIDs, hasOutstandingChildRequest = false): WorkspaceMembersChats {
1163+
function createPolicyExpenseChats(
1164+
policyID: string,
1165+
invitedEmailsToAccountIDs: InvitedEmailsToAccountIDs,
1166+
hasOutstandingChildRequest = false,
1167+
notificationPreference: NotificationPreference = CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN,
1168+
): WorkspaceMembersChats {
11631169
const workspaceMembersChats: WorkspaceMembersChats = {
11641170
onyxSuccessData: [],
11651171
onyxOptimisticData: [],
@@ -1222,7 +1228,7 @@ function createPolicyExpenseChats(policyID: string, invitedEmailsToAccountIDs: I
12221228
chatType: CONST.REPORT.CHAT_TYPE.POLICY_EXPENSE_CHAT,
12231229
policyID,
12241230
ownerAccountID: cleanAccountID,
1225-
notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN,
1231+
notificationPreference,
12261232
});
12271233

12281234
// Set correct notification preferences: visible for the submitter, hidden for others until there's activity

src/libs/actions/Report.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5509,7 +5509,7 @@ function navigateToTrainingModal(dismissedProductTrainingNVP: OnyxEntry<Dismisse
55095509
Navigation.navigate(ROUTES.CHANGE_POLICY_EDUCATIONAL.getRoute(ROUTES.REPORT_WITH_ID.getRoute(reportID)));
55105510
}
55115511

5512-
function buildOptimisticChangePolicyData(report: Report, policyID: string, reportNextStep?: ReportNextStep) {
5512+
function buildOptimisticChangePolicyData(report: Report, policyID: string, reportNextStep?: ReportNextStep, optimisticPolicyExpenseChatReport?: Report) {
55135513
const optimisticData: OnyxUpdate[] = [];
55145514
const successData: OnyxUpdate[] = [];
55155515
const failureData: OnyxUpdate[] = [];
@@ -5637,7 +5637,7 @@ function buildOptimisticChangePolicyData(report: Report, policyID: string, repor
56375637

56385638
// 3. Optimistically create a new REPORT_PREVIEW reportAction with the newReportPreviewActionID
56395639
// and set it as a parent of the moved report
5640-
const policyExpenseChat = getPolicyExpenseChat(currentUserAccountID, policyID);
5640+
const policyExpenseChat = optimisticPolicyExpenseChatReport ?? getPolicyExpenseChat(report.ownerAccountID, policyID);
56415641
const optimisticReportPreviewAction = buildOptimisticReportPreview(policyExpenseChat, report);
56425642

56435643
const newPolicyExpenseChatReportID = policyExpenseChat?.reportID;
@@ -5776,6 +5776,7 @@ function changeReportPolicyAndInviteSubmitter(report: Report, policyID: string,
57765776
policyMemberAccountIDs,
57775777
CONST.POLICY.ROLE.USER,
57785778
formatPhoneNumber,
5779+
CONST.REPORT.NOTIFICATION_PREFERENCE.ALWAYS,
57795780
);
57805781
const optimisticPolicyExpenseChatReportID = membersChats.reportCreationData[submitterEmail].reportID;
57815782
const optimisticPolicyExpenseChatCreatedReportActionID = membersChats.reportCreationData[submitterEmail].reportActionID;
@@ -5790,7 +5791,7 @@ function changeReportPolicyAndInviteSubmitter(report: Report, policyID: string,
57905791
failureData: failureChangePolicyData,
57915792
optimisticReportPreviewAction,
57925793
optimisticMovedReportAction,
5793-
} = buildOptimisticChangePolicyData(report, policyID);
5794+
} = buildOptimisticChangePolicyData(report, policyID, undefined, membersChats.reportCreationData[submitterEmail]);
57945795
optimisticData.push(...optimisticChangePolicyData);
57955796
successData.push(...successChangePolicyData);
57965797
failureData.push(...failureChangePolicyData);

0 commit comments

Comments
 (0)