Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
81 changes: 36 additions & 45 deletions src/libs/actions/Policy/Policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@

const deprecatedAllPolicies: OnyxCollection<Policy> = {};
Onyx.connect({
key: ONYXKEYS.COLLECTION.POLICY,

Check warning on line 209 in src/libs/actions/Policy/Policy.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
callback: (val, key) => {
if (!key) {
return;
Expand All @@ -222,7 +222,7 @@

let deprecatedAllReports: OnyxCollection<Report>;
Onyx.connect({
key: ONYXKEYS.COLLECTION.REPORT,

Check warning on line 225 in src/libs/actions/Policy/Policy.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
waitForCollectionCallback: true,
callback: (value) => {
deprecatedAllReports = value;
Expand All @@ -231,7 +231,7 @@

let deprecatedAllReportActions: OnyxCollection<ReportActions>;
Onyx.connect({
key: ONYXKEYS.COLLECTION.REPORT_ACTIONS,

Check warning on line 234 in src/libs/actions/Policy/Policy.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
waitForCollectionCallback: true,
callback: (actions) => {
deprecatedAllReportActions = actions;
Expand All @@ -241,7 +241,7 @@
let deprecatedSessionEmail = '';
let deprecatedSessionAccountID = 0;
Onyx.connect({
key: ONYXKEYS.SESSION,

Check warning on line 244 in src/libs/actions/Policy/Policy.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
callback: (val) => {
deprecatedSessionEmail = val?.email ?? '';
deprecatedSessionAccountID = val?.accountID ?? CONST.DEFAULT_NUMBER_ID;
Expand All @@ -250,25 +250,25 @@

let deprecatedAllPersonalDetails: OnyxEntry<PersonalDetailsList>;
Onyx.connect({
key: ONYXKEYS.PERSONAL_DETAILS_LIST,

Check warning on line 253 in src/libs/actions/Policy/Policy.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
callback: (val) => (deprecatedAllPersonalDetails = val),
});

let deprecatedAllRecentlyUsedCurrencies: string[];
Onyx.connect({
key: ONYXKEYS.RECENTLY_USED_CURRENCIES,

Check warning on line 259 in src/libs/actions/Policy/Policy.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
callback: (val) => (deprecatedAllRecentlyUsedCurrencies = val ?? []),
});

let deprecatedActivePolicyID: OnyxEntry<string>;
Onyx.connect({
key: ONYXKEYS.NVP_ACTIVE_POLICY_ID,

Check warning on line 265 in src/libs/actions/Policy/Policy.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
callback: (value) => (deprecatedActivePolicyID = value),
});

let deprecatedIntroSelected: OnyxEntry<IntroSelected>;
Onyx.connect({
key: ONYXKEYS.NVP_INTRO_SELECTED,

Check warning on line 271 in src/libs/actions/Policy/Policy.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
callback: (value) => (deprecatedIntroSelected = value),
});

Expand Down Expand Up @@ -486,8 +486,7 @@

const finallyData: OnyxUpdate[] = [];
const currentTime = DateUtils.getDBTime();
// eslint-disable-next-line unicorn/no-array-for-each
reportsToArchive.forEach((report) => {
for (const report of reportsToArchive) {
const {reportID, ownerAccountID, oldPolicyName} = report ?? {};
const isInvoiceReceiverReport = report?.invoiceReceiver && 'policyID' in report.invoiceReceiver && report.invoiceReceiver.policyID === policyID;
optimisticData.push({
Expand Down Expand Up @@ -576,14 +575,13 @@
value: transactionViolation,
});
}
});
}

// eslint-disable-next-line unicorn/no-array-for-each
Object.keys(lastUsedPaymentMethods ?? {})?.forEach((paymentMethodKey) => {
for (const paymentMethodKey of Object.keys(lastUsedPaymentMethods ?? {})) {
const lastUsedPaymentMethod = lastUsedPaymentMethods?.[paymentMethodKey];

if (typeof lastUsedPaymentMethod === 'string' || !lastUsedPaymentMethod) {
return;
continue;
}

if (lastUsedPaymentMethod?.iou?.name === policyID) {
Expand Down Expand Up @@ -617,8 +615,7 @@
},
});
}
});

}
const apiParams: DeleteWorkspaceParams = {policyID};

API.write(WRITE_COMMANDS.DELETE_WORKSPACE, apiParams, {optimisticData, finallyData, failureData});
Expand Down Expand Up @@ -1086,13 +1083,12 @@
const currentTime = DateUtils.getDBTime();
const pendingChatMembers = ReportUtils.getPendingChatMembers([deprecatedSessionAccountID], [], CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE);

// eslint-disable-next-line unicorn/no-array-for-each
workspaceChats.forEach((report) => {
for (const report of workspaceChats) {
const parentReport = ReportUtils.getRootParentReport({report});
const reportToCheckOwner = isEmptyObject(parentReport) ? report : parentReport;

if (ReportUtils.isPolicyExpenseChat(report) && !ReportUtils.isReportOwner(reportToCheckOwner)) {
return;
continue;
}

optimisticData.push(
Expand Down Expand Up @@ -1144,7 +1140,7 @@
pendingChatMembers: null,
},
});
});
}

const params: LeavePolicyParams = {
policyID,
Expand Down Expand Up @@ -1302,8 +1298,7 @@
reportCreationData: {},
};

// eslint-disable-next-line unicorn/no-array-for-each
Object.keys(invitedEmailsToAccountIDs).forEach((email) => {
for (const email of Object.keys(invitedEmailsToAccountIDs)) {
const accountID = invitedEmailsToAccountIDs[email];
const cleanAccountID = Number(accountID);
const login = PhoneNumber.addSMSDomainIfPhoneNumber(email);
Expand Down Expand Up @@ -1333,10 +1328,9 @@
});
const currentTime = DateUtils.getDBTime();
const reportActions = deprecatedAllReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${oldChat.reportID}`] ?? {};
// eslint-disable-next-line unicorn/no-array-for-each
Object.values(reportActions).forEach((action) => {
for (const action of Object.values(reportActions)) {
if (action.actionName !== CONST.REPORT.ACTIONS.TYPE.REPORT_PREVIEW) {
return;
continue;
}
workspaceMembersChats.onyxOptimisticData.push({
onyxMethod: Onyx.METHOD.MERGE,
Expand All @@ -1352,8 +1346,8 @@
private_isArchived: currentTime,
},
});
});
return;
}
continue;
}
const optimisticReport = ReportUtils.buildOptimisticChatReport({
participantList: [deprecatedSessionAccountID, cleanAccountID],
Expand Down Expand Up @@ -1457,7 +1451,7 @@
},
},
});
});
}
return workspaceMembersChats;
}

Expand Down Expand Up @@ -2423,30 +2417,27 @@
}

if (getAdminPolicies().length === 0 && lastUsedPaymentMethod) {
Object.values(deprecatedAllReports ?? {})
.filter((iouReport) => iouReport?.type === CONST.REPORT.TYPE.IOU)
// eslint-disable-next-line unicorn/no-array-for-each
.forEach((iouReport) => {
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
if (lastUsedPaymentMethod?.iou?.name || !iouReport?.policyID) {
return;
}
for (const report of Object.values(deprecatedAllReports ?? {})) {
if (report?.type !== CONST.REPORT.TYPE.IOU) {
continue;
}

successData.push({
onyxMethod: Onyx.METHOD.MERGE,
key: ONYXKEYS.NVP_LAST_PAYMENT_METHOD,
value: {
[iouReport?.policyID]: {
iou: {
name: policyID,
},
lastUsed: {
name: policyID,
},
if (lastUsedPaymentMethod?.iou?.name || !report?.policyID) {
continue;
}

successData.push({
onyxMethod: Onyx.METHOD.MERGE,
key: ONYXKEYS.NVP_LAST_PAYMENT_METHOD,
value: {
[report?.policyID]: {
iou: {
name: policyID,
},
},
});
},
});
}
}

// We need to clone the file to prevent non-indexable errors.
Expand Down Expand Up @@ -3771,16 +3762,15 @@
// For performance reasons, we are going to compose a merge collection data for transactions
const transactionsOptimisticData: Record<string, Transaction> = {};
const transactionFailureData: Record<string, Transaction> = {};
// eslint-disable-next-line unicorn/no-array-for-each
reportTransactions.forEach((transaction) => {
for (const transaction of reportTransactions) {
transactionsOptimisticData[`${ONYXKEYS.COLLECTION.TRANSACTION}${transaction.transactionID}`] = {
...transaction,
amount: -transaction.amount,
modifiedAmount: transaction.modifiedAmount ? -transaction.modifiedAmount : 0,
};

transactionFailureData[`${ONYXKEYS.COLLECTION.TRANSACTION}${transaction.transactionID}`] = transaction;
});
}

optimisticData.push({
onyxMethod: Onyx.METHOD.MERGE_COLLECTION,
Expand Down Expand Up @@ -6200,8 +6190,9 @@
if (!deprecatedAllPolicies) {
return;
}
// eslint-disable-next-line unicorn/no-array-for-each
Object.keys(deprecatedAllPolicies).forEach((key) => delete deprecatedAllPolicies[key]);
for (const key of Object.keys(deprecatedAllPolicies)) {
delete deprecatedAllPolicies[key];
}
}

function updateInvoiceCompanyName(policyID: string, companyName: string) {
Expand Down
72 changes: 40 additions & 32 deletions src/libs/actions/Search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -421,8 +421,7 @@ function search({

function holdMoneyRequestOnSearch(hash: number, transactionIDList: string[], comment: string, allTransactions: OnyxCollection<Transaction>, allReportActions: OnyxCollection<ReportActions>) {
const {optimisticData, finallyData} = getOnyxLoadingData(hash);
// eslint-disable-next-line unicorn/no-array-for-each
transactionIDList.forEach((transactionID) => {
for (const transactionID of transactionIDList) {
const transaction = allTransactions?.[`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`];
const reportActions = allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${transaction?.reportID}`] ?? {};
const iouReportAction = getIOUActionForTransactionID(Object.values(reportActions ?? {}), transactionID);
Expand All @@ -437,7 +436,7 @@ function holdMoneyRequestOnSearch(hash: number, transactionIDList: string[], com
},
});
}
});
}

API.write(WRITE_COMMANDS.HOLD_MONEY_REQUEST_ON_SEARCH, {hash, transactionIDList, comment}, {optimisticData, finallyData});
}
Expand Down Expand Up @@ -792,34 +791,46 @@ function rejectMoneyRequestsOnSearch(hash: number, selectedTransactions: Selecte
type Params = Record<string, ExportSearchItemsToCSVParams>;

function exportSearchItemsToCSV({query, jsonQuery, reportIDList, transactionIDList}: ExportSearchItemsToCSVParams, onDownloadFailed: () => void) {
const reportIDListParams: string[] = [];
// eslint-disable-next-line unicorn/no-array-for-each
reportIDList.forEach((reportID) => {
const allReportTransactions = getReportTransactions(reportID).filter((transaction) => transaction.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE);
const allTransactionIDs = allReportTransactions.map((transaction) => transaction.transactionID);
if (allTransactionIDs.every((transactionID) => transactionIDList.includes(transactionID))) {
if (reportIDListParams.includes(reportID)) {
return;
const reportIDSet = new Set<string>();
const transactionIDSet = new Set(transactionIDList);
for (const reportID of reportIDList) {
const allReportTransactions = getReportTransactions(reportID);

// We'll include the report if all of its transactions are included in the transactionIDList
let areAllTransactionsIncludedInList = true;
for (const transaction of allReportTransactions) {
// Ignore transactions that are pending deletion
if (transaction.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE) {
continue;
}

// If any transaction is not included in the transactionIDList, we'll exclude the report
if (!transactionIDSet.has(transaction.transactionID)) {
areAllTransactionsIncludedInList = false;
break;
}
reportIDListParams.push(reportID);
}
});

if (areAllTransactionsIncludedInList) {
reportIDSet.add(reportID);
}
}

const finalParameters = enhanceParameters(WRITE_COMMANDS.EXPORT_SEARCH_ITEMS_TO_CSV, {
query,
jsonQuery,
reportIDList: reportIDListParams,
reportIDList: Array.from(reportIDSet),
transactionIDList,
}) as Params;

const formData = new FormData();
// eslint-disable-next-line unicorn/no-array-for-each
Object.entries(finalParameters).forEach(([key, value]) => {
for (const [key, value] of Object.entries(finalParameters)) {
if (Array.isArray(value)) {
formData.append(key, value.join(','));
} else {
formData.append(key, SafeString(value));
}
});
}

fileDownload(getCommandURL({command: WRITE_COMMANDS.EXPORT_SEARCH_ITEMS_TO_CSV}), 'Expensify.csv', '', false, formData, CONST.NETWORK.METHOD.POST, onDownloadFailed);
}
Expand Down Expand Up @@ -920,23 +931,20 @@ function clearAllFilters() {

function clearAdvancedFilters() {
const values: Partial<Nullable<SearchAdvancedFiltersForm>> = {};
Object.values(FILTER_KEYS)
.filter((key) => key !== FILTER_KEYS.GROUP_BY)
// eslint-disable-next-line unicorn/no-array-for-each
.forEach((key) => {
if (key === FILTER_KEYS.TYPE) {
for (const key of Object.values(FILTER_KEYS)) {
switch (key) {
case FILTER_KEYS.GROUP_BY:
continue;
case FILTER_KEYS.TYPE:
values[key] = CONST.SEARCH.DATA_TYPES.EXPENSE;
return;
}

if (key === FILTER_KEYS.STATUS) {
continue;
case FILTER_KEYS.STATUS:
values[key] = CONST.SEARCH.STATUS.EXPENSE.ALL;
return;
}

values[key] = null;
});

continue;
default:
values[key] = null;
}
}
Onyx.merge(ONYXKEYS.FORMS.SEARCH_ADVANCED_FILTERS_FORM, values);
}

Expand Down
28 changes: 14 additions & 14 deletions src/libs/actions/User.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@

let currentUserAccountID = -1;
let currentEmail = '';
Onyx.connect({

Check warning on line 66 in src/libs/actions/User.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.SESSION,
callback: (value) => {
currentUserAccountID = value?.accountID ?? CONST.DEFAULT_NUMBER_ID;
Expand All @@ -72,7 +72,7 @@
});

let myPersonalDetails: OnyxEntry<OnyxPersonalDetails>;
Onyx.connect({

Check warning on line 75 in src/libs/actions/User.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
callback: (value) => {
if (!value || currentUserAccountID === -1) {
Expand Down Expand Up @@ -568,10 +568,9 @@
],
);

// eslint-disable-next-line unicorn/no-array-for-each
Object.values(allPolicies ?? {}).forEach((policy) => {
for (const policy of Object.values(allPolicies ?? {})) {
if (!policy) {
return;
continue;
}

let optimisticPolicyDataValue;
Expand Down Expand Up @@ -600,7 +599,7 @@
value: optimisticPolicyDataValue,
});
}
});
}
}

const failureData: OnyxUpdate[] = [
Expand Down Expand Up @@ -662,18 +661,20 @@
}

function triggerNotifications(onyxUpdates: OnyxServerUpdate[]) {
// eslint-disable-next-line unicorn/no-array-for-each
onyxUpdates.forEach((update) => {
for (const update of onyxUpdates) {
if (!update.shouldNotify && !update.shouldShowPushNotification) {
return;
continue;
}

const reportID = update.key.replace(ONYXKEYS.COLLECTION.REPORT_ACTIONS, '');
const reportActions = Object.values((update.value as OnyxCollection<ReportAction>) ?? {});

// eslint-disable-next-line unicorn/no-array-for-each
reportActions.forEach((action) => action && showReportActionNotification(reportID, action));
});
for (const action of reportActions) {
if (action) {
showReportActionNotification(reportID, action);
}
}
}
}

const isChannelMuted = (reportId: string) =>
Expand Down Expand Up @@ -1211,10 +1212,9 @@
},
];

// eslint-disable-next-line unicorn/no-array-for-each
Object.values(allPolicies ?? {}).forEach((policy) => {
for (const policy of Object.values(allPolicies ?? {})) {
if (!policy) {
return;
continue;
}

let optimisticPolicyDataValue;
Expand Down Expand Up @@ -1259,7 +1259,7 @@
value: failurePolicyDataValue,
});
}
});
}
const parameters: SetContactMethodAsDefaultParams = {
partnerUserID: newDefaultContactMethod,
};
Expand Down
Loading
Loading