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

[WIP] Align default IDs in IOU.ts file #54534

Draft
wants to merge 27 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 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
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 @@ -12,7 +12,6 @@ module.exports = {
{
files: [
'src/libs/ReportUtils.ts',
'src/libs/actions/IOU.ts',
'src/libs/actions/Report.ts',
'src/libs/actions/Task.ts',
'src/libs/OptionsListUtils.ts',
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/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
10 changes: 7 additions & 3 deletions src/libs/ReportActionsUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -771,7 +771,11 @@ function replaceBaseURLInPolicyChangeLogAction(reportAction: ReportAction): Repo
return updatedReportAction;
}

function getLastVisibleAction(reportID: string, canUserPerformWriteAction?: boolean, actionsToMerge: Record<string, NullishDeep<ReportAction> | null> = {}): OnyxEntry<ReportAction> {
function getLastVisibleAction(
reportID: string | undefined,
canUserPerformWriteAction?: boolean,
actionsToMerge: Record<string, NullishDeep<ReportAction> | null> = {},
): OnyxEntry<ReportAction> {
let reportActions: Array<ReportAction | null | undefined> = [];
if (!isEmpty(actionsToMerge)) {
reportActions = Object.values(fastMerge(allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`] ?? {}, actionsToMerge ?? {}, true)) as Array<
Expand Down Expand Up @@ -801,7 +805,7 @@ function formatLastMessageText(lastMessageText: string) {
}

function getLastVisibleMessage(
reportID: string,
reportID: string | undefined,
canUserPerformWriteAction?: boolean,
actionsToMerge: Record<string, NullishDeep<ReportAction> | null> = {},
reportAction: OnyxInputOrEntry<ReportAction> | undefined = undefined,
Expand Down Expand Up @@ -1122,7 +1126,7 @@ function doesReportHaveVisibleActions(reportID: string, canUserPerformWriteActio
return visibleReportActionsWithoutTaskSystemMessage.length > 0;
}

function getAllReportActions(reportID: string): ReportActions {
function getAllReportActions(reportID: string | undefined): ReportActions {
return allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`] ?? {};
}

Expand Down
25 changes: 16 additions & 9 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -787,7 +787,7 @@ function isDraftReport(reportID: string | undefined): boolean {
/**
* Returns the report
*/
function getReport(reportID: string): OnyxEntry<Report> {
function getReport(reportID: string | undefined): OnyxEntry<Report> {
return allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`];
}

Expand Down Expand Up @@ -3030,11 +3030,11 @@ function getReportFieldKey(reportFieldId: string) {
/**
* Get the report fields attached to the policy given policyID
*/
function getReportFieldsByPolicyID(policyID: string): Record<string, PolicyReportField> {
function getReportFieldsByPolicyID(policyID: string | undefined): Record<string, PolicyReportField> {
const policyReportFields = Object.entries(allPolicies ?? {}).find(([key]) => key.replace(ONYXKEYS.COLLECTION.POLICY, '') === policyID);
const fieldList = policyReportFields?.[1]?.fieldList;

if (!policyReportFields || !fieldList) {
if (!policyReportFields || !fieldList || !policyID) {
return {};
}

Expand Down Expand Up @@ -4587,7 +4587,7 @@ function buildOptimisticIOUReport(
payeeAccountID: number,
payerAccountID: number,
total: number,
chatReportID: string,
chatReportID: string | undefined,
currency: string,
isSendingMoney = false,
parentReportActionID?: string,
Expand Down Expand Up @@ -4659,7 +4659,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);

return {
Expand Down Expand Up @@ -4729,8 +4736,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 @@ -5323,7 +5330,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 @@ -6751,7 +6758,7 @@ function getChatByParticipants(newParticipantList: number[], reports: OnyxCollec
/**
* Attempts to find an invoice chat report in onyx with the provided policyID and receiverID.
*/
function getInvoiceChatByParticipants(policyID: string, receiverID: string | number, reports: OnyxCollection<Report> = allReports): OnyxEntry<Report> {
function getInvoiceChatByParticipants(policyID: string | undefined, receiverID: string | number, reports: OnyxCollection<Report> = allReports): OnyxEntry<Report> {
return Object.values(reports ?? {}).find((report) => {
if (!report || !isInvoiceRoom(report) || isArchivedRoom(report)) {
return false;
Expand Down
Loading
Loading