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

Align default IDs in IOU.ts file #54534

Open
wants to merge 40 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
2cd62ce
chore: test commit for the linter
adhorodyski Dec 18, 2024
2f53a1a
chore: fix lint errors on missing CONST.DEFAULT_NUMBER_ID usages for …
adhorodyski Dec 18, 2024
9f0352f
chore: rm a dummy console log
adhorodyski Dec 18, 2024
dd0de46
chore: remove an eslint override for the IOU.ts file exclusion
adhorodyski Dec 18, 2024
661790f
chore: add an early return for transactionThreadReportIDs of undefined
adhorodyski Dec 18, 2024
1ddfa90
chore: add an early return on invalid input to the payInvoice function
adhorodyski Dec 18, 2024
529b1f6
chore: filter out undefiend values
adhorodyski Dec 19, 2024
17829b7
chore: allow undefined output from getIOURequestPolicyID
adhorodyski Dec 19, 2024
cf617bd
chore: remove a fallback index access on the failure data
adhorodyski Dec 19, 2024
1b42796
chore: early return on missing input to the cancelPayment func
adhorodyski Dec 19, 2024
2042569
chore: remove more onyx key fallbacks
adhorodyski Dec 19, 2024
c98da87
Merge branch 'Expensify:main' into chore/eslint-consistent-id-iou
adhorodyski Dec 19, 2024
d268002
chore: optionally push to the optimistic data
adhorodyski Dec 19, 2024
93d2cbd
chore: wrap a success data push in an if statement for undefined input
adhorodyski Dec 19, 2024
2c83daa
chore: wrap a failure data push in an if statement for undefined input
adhorodyski Dec 19, 2024
135baa7
chore: wrap L1831 failure data push
adhorodyski Dec 19, 2024
0ab1de1
chore: early return on missing splitData.createdReportActionID for th…
adhorodyski Dec 19, 2024
46e8c8e
chore: pass in undefined with a missing childReportID
adhorodyski Dec 19, 2024
390df26
chore: extract an optimisticData push to ensure a param
adhorodyski Dec 19, 2024
cdccb13
chore: use string or undefined as a value
adhorodyski Dec 19, 2024
de2c69b
chore: call 2 new optimistic updates only on conditions met
adhorodyski Dec 19, 2024
2ece26c
Merge branch 'refs/heads/main' into chore/eslint-consistent-id-iou
VickyStash Dec 20, 2024
2332beb
Update getLastVisibleAction and getLastVisibleMessage functions. Remo…
VickyStash Dec 20, 2024
871a257
Remove '-1' id from object keys
VickyStash Dec 20, 2024
80901b5
Fix test
VickyStash Dec 20, 2024
617f8b0
Merge branch 'refs/heads/main' into chore/eslint-consistent-id-iou
VickyStash Dec 24, 2024
0caab12
Fix params related lint errors
VickyStash Dec 24, 2024
ac221d1
Merge branch 'refs/heads/main' into chore/eslint-consistent-id-iou
VickyStash Dec 30, 2024
bf73430
Lint fix
VickyStash Dec 30, 2024
a0905d6
Code polish
VickyStash Dec 30, 2024
4a7725c
Merge branch 'refs/heads/main' into chore/eslint-consistent-id-iou
VickyStash Jan 2, 2025
3980ff6
Minor updates after merging main
VickyStash Jan 2, 2025
6c6026c
Remove null value merging
VickyStash Jan 2, 2025
435df71
Minor improvement
VickyStash Jan 2, 2025
64a3bb9
Fix reportPreviewAction type
VickyStash Jan 2, 2025
a870404
Merge branch 'refs/heads/main' into chore/eslint-consistent-id-iou
VickyStash Jan 2, 2025
f6e9122
Update Transaction type
VickyStash Jan 2, 2025
eebf2ed
Lint fix
VickyStash Jan 2, 2025
de9d29a
Apply reviewer feedback
VickyStash Jan 3, 2025
5c94b53
Add earlier return
VickyStash Jan 3, 2025
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
1 change: 0 additions & 1 deletion .eslintrc.changed.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ module.exports = {
overrides: [
{
files: [
'src/libs/actions/IOU.ts',
'src/libs/actions/Report.ts',
'src/libs/actions/Task.ts',
'src/libs/OptionsListUtils.ts',
Expand Down
2 changes: 1 addition & 1 deletion src/ROUTES.ts
Original file line number Diff line number Diff line change
Expand Up @@ -748,7 +748,7 @@ const ROUTES = {
},
WORKSPACE_PROFILE_ADDRESS: {
route: 'settings/workspaces/:policyID/profile/address',
getRoute: (policyID: string, backTo?: string) => getUrlWithBackToParam(`settings/workspaces/${policyID}/profile/address` as const, backTo),
getRoute: (policyID: string | undefined, backTo?: string) => getUrlWithBackToParam(`settings/workspaces/${policyID}/profile/address` as const, backTo),
Copy link
Contributor

Choose a reason for hiding this comment

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

Where did we eventually land in terms of the route configurations?

In a parallel PR, we talked that it doesn't make sense to allow nullable params in routes like this, and we'd rather handle the policyID absence where we call the route.
This looks like the same case to me unless you think this one's different.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There was one more similar discussion in the slack lately: link.

  1. The approach with undefined doesn't change the app logic, considering the invalid -1 id value was used before. In most of the cases the app behavior is left the same as before in this case - Not Found page is showing if you navigate to the page with invalid id.

  2. Another approach is to add a condition above and prevent navigation to the invalid page, + add a Log.warn so it can be catched and investigated.

if (policyID) {
   Navigation.navigate(ROUTES.WORKSPACE_PROFILE_ADDRESS.getRoute(policyID));
} else {
   Log.warn("Invalid policyID .....")
}

I think we need to stop on one of the approaches and add it to the guide.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@iwiznia @neil-marcellini what do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think I rather navigate to the error page AND log a warning so we can investigate

},
WORKSPACE_PROFILE_PLAN: {
route: 'settings/workspaces/:policyID/profile/plan',
Expand Down
12 changes: 6 additions & 6 deletions src/libs/API/parameters/CategorizeTrackedExpenseParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ type CategorizeTrackedExpenseParams = {
comment: string;
created: string;
merchant: string;
policyID: string;
transactionID: string;
moneyRequestPreviewReportActionID: string;
moneyRequestReportID: string;
moneyRequestCreatedReportActionID: string;
policyID: string | undefined;
transactionID: string | undefined;
moneyRequestPreviewReportActionID: string | undefined;
moneyRequestReportID: string | undefined;
moneyRequestCreatedReportActionID: string | undefined;
actionableWhisperReportActionID: string;
modifiedExpenseReportActionID: string;
reportPreviewReportActionID: string;
reportPreviewReportActionID: string | undefined;
category?: string;
tag?: string;
receipt?: Receipt;
Expand Down
2 changes: 1 addition & 1 deletion src/libs/API/parameters/CompleteSplitBillParams.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
type CompleteSplitBillParams = {
transactionID: string;
transactionID: string | undefined;
amount?: number;
currency?: string;
created?: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ type ConvertTrackedExpenseToRequestParams = {
chatReportID: string;
transactionID: string;
actionableWhisperReportActionID: string;
createdChatReportActionID: string;
createdChatReportActionID: string | undefined;
receipt?: Receipt;
moneyRequestReportID: string;
moneyRequestCreatedReportActionID: string;
moneyRequestCreatedReportActionID: string | undefined;
moneyRequestPreviewReportActionID: string;
reportPreviewReportActionID: string;
};
Expand Down
2 changes: 1 addition & 1 deletion src/libs/API/parameters/CreateDistanceRequestParams.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
type CreateDistanceRequestParams = {
transactionID: string;
chatReportID: string;
createdChatReportActionID: string;
createdChatReportActionID: string | undefined;
reportActionID: string;
waypoints: string;
customUnitRateID: string;
Expand Down
2 changes: 1 addition & 1 deletion src/libs/API/parameters/DeleteMoneyRequestParams.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
type DeleteMoneyRequestParams = {
transactionID: string;
transactionID: string | undefined;
reportActionID: string;
};

Expand Down
2 changes: 1 addition & 1 deletion src/libs/API/parameters/PayInvoiceParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type {PaymentMethodType} from '@src/types/onyx/OriginalMessage';
import type CreateWorkspaceParams from './CreateWorkspaceParams';

type PayInvoiceParams = Partial<CreateWorkspaceParams> & {
reportID: string;
reportID: string | undefined;
reportActionID: string;
paymentMethodType: PaymentMethodType;
payAsBusiness: boolean;
Expand Down
2 changes: 1 addition & 1 deletion src/libs/API/parameters/PayMoneyRequestParams.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type {PaymentMethodType} from '@src/types/onyx/OriginalMessage';

type PayMoneyRequestParams = {
iouReportID: string;
iouReportID: string | undefined;
chatReportID: string;
reportActionID: string;
paymentMethodType: PaymentMethodType;
Expand Down
6 changes: 3 additions & 3 deletions src/libs/API/parameters/RequestMoneyParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ type RequestMoneyParams = {
chatReportID: string;
transactionID: string;
reportActionID: string;
createdChatReportActionID: string;
createdIOUReportActionID: string;
createdChatReportActionID: string | undefined;
createdIOUReportActionID: string | undefined;
reportPreviewReportActionID: string;
receipt?: Receipt;
receiptState?: ValueOf<typeof CONST.IOU.RECEIPT_STATE>;
Expand All @@ -26,7 +26,7 @@ type RequestMoneyParams = {
billable?: boolean;
receiptGpsPoints?: string;
transactionThreadReportID: string;
createdReportActionIDForThread: string;
createdReportActionIDForThread: string | undefined;
reimbursible?: boolean;
};

Expand Down
4 changes: 2 additions & 2 deletions src/libs/API/parameters/SendInvoiceParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type {RequireAtLeastOne} from 'type-fest';

type SendInvoiceParams = RequireAtLeastOne<
{
senderWorkspaceID: string;
senderWorkspaceID: string | undefined;
accountID: number;
receiverEmail?: string;
receiverInvoiceRoomID?: string;
Expand All @@ -21,7 +21,7 @@ type SendInvoiceParams = RequireAtLeastOne<
companyName?: string;
companyWebsite?: string;
createdIOUReportActionID: string;
createdReportActionIDForThread: string;
createdReportActionIDForThread: string | undefined;
reportActionID: string;
},
'receiverEmail' | 'receiverInvoiceRoomID'
Expand Down
4 changes: 2 additions & 2 deletions src/libs/API/parameters/SendMoneyParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ type SendMoneyParams = {
paymentMethodType: PaymentMethodType;
transactionID: string;
newIOUReportDetails: string;
createdReportActionID: string;
createdReportActionID: string | undefined;
reportPreviewReportActionID: string;
createdIOUReportActionID: string;
transactionThreadReportID: string;
createdReportActionIDForThread: string;
createdReportActionIDForThread: string | undefined;
};

export default SendMoneyParams;
12 changes: 6 additions & 6 deletions src/libs/API/parameters/ShareTrackedExpenseParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ type ShareTrackedExpenseParams = {
comment: string;
created: string;
merchant: string;
policyID: string;
transactionID: string;
moneyRequestPreviewReportActionID: string;
moneyRequestReportID: string;
moneyRequestCreatedReportActionID: string;
policyID: string | undefined;
transactionID: string | undefined;
moneyRequestPreviewReportActionID: string | undefined;
moneyRequestReportID: string | undefined;
moneyRequestCreatedReportActionID: string | undefined;
actionableWhisperReportActionID: string;
modifiedExpenseReportActionID: string;
reportPreviewReportActionID: string;
reportPreviewReportActionID: string | undefined;
category?: string;
tag?: string;
receipt?: Receipt;
Expand Down
12 changes: 6 additions & 6 deletions src/libs/API/parameters/TrackExpenseParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ type TrackExpenseParams = {
created: string;
merchant: string;
iouReportID?: string;
chatReportID: string;
transactionID: string;
reportActionID: string;
createdChatReportActionID: string;
chatReportID: string | undefined;
transactionID: string | undefined;
reportActionID: string | undefined;
createdChatReportActionID: string | undefined;
createdIOUReportActionID?: string;
reportPreviewReportActionID?: string;
receipt?: Receipt;
Expand All @@ -23,8 +23,8 @@ type TrackExpenseParams = {
taxAmount: number;
billable?: boolean;
receiptGpsPoints?: string;
transactionThreadReportID: string;
createdReportActionIDForThread: string;
transactionThreadReportID: string | undefined;
createdReportActionIDForThread: string | undefined;
waypoints?: string;
actionableWhisperReportActionID?: string;
customUnitRateID?: string;
Expand Down
28 changes: 17 additions & 11 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,7 @@ Onyx.connect({

reportsTransactions = Object.values(value).reduce<Record<string, Transaction[]>>((all, transaction) => {
const reportsMap = all;
if (!transaction) {
if (!transaction?.reportID) {
return reportsMap;
}

Expand Down Expand Up @@ -3069,6 +3069,10 @@ function getReportFieldKey(reportFieldId: string | undefined) {
* Get the report fields attached to the policy given policyID
*/
function getReportFieldsByPolicyID(policyID: string | undefined): Record<string, PolicyReportField> {
if (!policyID) {
return {};
}

const policyReportFields = Object.entries(allPolicies ?? {}).find(([key]) => key.replace(ONYXKEYS.COLLECTION.POLICY, '') === policyID);
const fieldList = policyReportFields?.[1]?.fieldList;

Expand Down Expand Up @@ -4635,7 +4639,7 @@ function buildOptimisticIOUReport(
payeeAccountID: number,
payerAccountID: number,
total: number,
chatReportID: string,
chatReportID: string | undefined,
currency: string,
isSendingMoney = false,
parentReportActionID?: string,
Expand Down Expand Up @@ -4707,7 +4711,14 @@ function populateOptimisticReportFormula(formula: string, report: OptimisticExpe
}

/** Builds an optimistic invoice report with a randomly generated reportID */
function buildOptimisticInvoiceReport(chatReportID: string, policyID: string, receiverAccountID: number, receiverName: string, total: number, currency: string): OptimisticExpenseReport {
function buildOptimisticInvoiceReport(
chatReportID: string,
policyID: string | undefined,
receiverAccountID: number,
receiverName: string,
total: number,
currency: string,
): OptimisticExpenseReport {
const formattedTotal = CurrencyUtils.convertToDisplayString(total, currency);
const invoiceReport = {
reportID: generateReportID(),
Expand Down Expand Up @@ -4779,8 +4790,8 @@ function getExpenseReportStateAndStatus(policy: OnyxEntry<Policy>) {
* @param parentReportActionID – The parent ReportActionID of the PolicyExpenseChat
*/
function buildOptimisticExpenseReport(
chatReportID: string,
policyID: string,
chatReportID: string | undefined,
policyID: string | undefined,
payeeAccountID: number,
total: number,
currency: string,
Expand Down Expand Up @@ -5373,7 +5384,7 @@ function buildOptimisticModifiedExpenseReportAction(
* @param transactionThreadID - The reportID of the transaction thread
* @param movedToReportID - The reportID of the report the transaction is moved to
*/
function buildOptimisticMovedTrackedExpenseModifiedReportAction(transactionThreadID: string, movedToReportID: string): OptimisticModifiedExpenseReportAction {
function buildOptimisticMovedTrackedExpenseModifiedReportAction(transactionThreadID: string | undefined, movedToReportID: string | undefined): OptimisticModifiedExpenseReportAction {
const delegateAccountDetails = PersonalDetailsUtils.getPersonalDetailByEmail(delegateEmail);

return {
Expand Down Expand Up @@ -8404,10 +8415,6 @@ function canReportBeMentionedWithinPolicy(report: OnyxEntry<Report>, policyID: s
return isChatRoom(report) && !isInvoiceRoom(report) && !isThread(report);
}

function shouldShowMerchantColumn(transactions: Transaction[]) {
return transactions.some((transaction) => isExpenseReport(allReports?.[transaction.reportID] ?? null));
}

/**
* Whether a given report is used for onboarding tasks. In the past, it could be either the Concierge chat or the system
* DM, and we saved the report ID in the user's `onboarding` NVP. As a fallback for users who don't have the NVP, we now
Expand Down Expand Up @@ -8889,7 +8896,6 @@ export {
getTripIDFromTransactionParentReportID,
buildOptimisticInvoiceReport,
getInvoiceChatByParticipants,
shouldShowMerchantColumn,
isCurrentUserInvoiceReceiver,
isDraftReport,
changeMoneyRequestHoldStatus,
Expand Down
2 changes: 1 addition & 1 deletion src/libs/TransactionUtils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import getDistanceInMeters from './getDistanceInMeters';
type TransactionParams = {
amount: number;
currency: string;
reportID: string;
reportID: string | undefined;
comment?: string;
attendees?: Attendee[];
created?: string;
Expand Down
4 changes: 2 additions & 2 deletions src/libs/TripReservationUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ function getTripReservationIcon(reservationType?: ReservationType): IconAsset {
}
}

type ReservationData = {reservation: Reservation; transactionID: string; reportID: string; reservationIndex: number};
type ReservationData = {reservation: Reservation; transactionID: string; reportID: string | undefined; reservationIndex: number};

function getReservationsFromTripTransactions(transactions: Transaction[]): ReservationData[] {
return transactions
Expand Down Expand Up @@ -102,7 +102,7 @@ function bookATrip(translate: LocaleContextProps['translate'], setCtaErrorMessag
}
const policy = PolicyUtils.getPolicy(activePolicyID);
if (isEmptyObject(policy?.address)) {
Navigation.navigate(ROUTES.WORKSPACE_PROFILE_ADDRESS.getRoute(activePolicyID ?? '-1', Navigation.getActiveRoute()));
Navigation.navigate(ROUTES.WORKSPACE_PROFILE_ADDRESS.getRoute(activePolicyID, Navigation.getActiveRoute()));
return;
}
if (!travelSettings?.hasAcceptedTerms) {
Expand Down
Loading
Loading