-
Notifications
You must be signed in to change notification settings - Fork 3k
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
[HOLD for payment 2024-12-30] [$250] Undo defaults of -1 and "-1" for account/report/policy IDs #50360
Comments
ProposalPlease re-state the problem that we are trying to solve in this issue.Update default values for report/account/policy IDs from -1 to 0 and "-1" to empty string "". What is the root cause of that problem?
What changes do you think we should make in order to solve the problem?Fix all the occurrences where default report/account/policy IDs value is -1 or "-1" to 0 or empty string. What alternative solutions did you explore? (Optional)Reminder: Please use plain English, be brief and avoid jargon. Feel free to use images, charts or pseudo-code if necessary. Do not post large multi-line diffs or write walls of text. Do not create PRs unless you have been hired for this job. |
@iwiznia @neil-marcellini Based on our discussions on Slack, I did some experiments considering that we would want to remove default values for both strings and numbers, allowing them to be So first I did the following replaces in order in the codebase:
All these changes combined with Prettier format resulted in 377 changed files with 1127 additions and 1189 deletions, as we can see in this WIP PR. After running And after running It's worth noting that these changes and errors are only due to replacing the defaultings, and these numbers can be very different when we start fixing the codebase. The most common TS errors are: Argument of type 'X | undefined' is not assignable to parameter of type 'Y'.Let's take this example on ReportScreen.tsx
ReportActionsUtils.getOneTransactionThreadReportID() requires diff --git a/src/libs/ReportActionsUtils.ts b/src/libs/ReportActionsUtils.ts
index 8fe49eaa80e..9f9a146bda7 100644
--- a/src/libs/ReportActionsUtils.ts
+++ b/src/libs/ReportActionsUtils.ts
@@ -1021,7 +1021,7 @@ const iouRequestTypes = new Set<ValueOf<typeof CONST.IOU.REPORT_ACTION_TYPE>>([
* Gets the reportID for the transaction thread associated with a report by iterating over the reportActions and identifying the IOU report actions.
* Returns a reportID if there is exactly one transaction thread for the report, and null otherwise.
*/
-function getOneTransactionThreadReportID(reportID: string, reportActions: OnyxEntry<ReportActions> | ReportAction[], isOffline: boolean | undefined = undefined): string | undefined {
+function getOneTransactionThreadReportID(reportID: string | undefined, reportActions: OnyxEntry<ReportActions> | ReportAction[], isOffline: boolean | undefined = undefined): string | undefined {
// If the report is not an IOU, Expense report, or Invoice, it shouldn't be treated as one-transaction report.
const report = ReportConnection.getAllReports()?.[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`];
if (report?.type !== CONST.REPORT.TYPE.IOU && report?.type !== CONST.REPORT.TYPE.EXPENSE && report?.type !== CONST.REPORT.TYPE.INVOICE) { Now let's take this example on ReportActionsView.tsx
We need to change Report.getNewerActions() arguments to allow diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts
index f58f29d2640..4c8ab5be2cb 100644
--- a/src/libs/actions/Report.ts
+++ b/src/libs/actions/Report.ts
@@ -1163,7 +1163,11 @@ function getOlderActions(reportID: string, reportActionID: string) {
* Gets the newer actions that have not been read yet.
* Normally happens when you are not located at the bottom of the list and scroll down on a chat.
*/
-function getNewerActions(reportID: string, reportActionID: string) {
+function getNewerActions(reportID: string | undefined, reportActionID: string | undefined) {
+ if (!reportID || !reportActionID) {
+ return;
+ }
+
const optimisticData: OnyxUpdate[] = [
{
onyxMethod: Onyx.METHOD.MERGE, The cases and difficult can greatly vary in the codebase, but I think the best move would be to handle these 'X' is possibly 'undefined'.Let's take this example on ReconciliationAccountSettingsPage.tsx
This error is inside a component, so we can't just make conditions with early returns here. Also we can't do diff --git a/src/pages/workspace/accounting/reconciliation/ReconciliationAccountSettingsPage.tsx b/src/pages/workspace/accounting/reconciliation/ReconciliationAccountSettingsPage.tsx
index ee65d11e147..e4bf0138dfe 100644
--- a/src/pages/workspace/accounting/reconciliation/ReconciliationAccountSettingsPage.tsx
+++ b/src/pages/workspace/accounting/reconciliation/ReconciliationAccountSettingsPage.tsx
@@ -36,7 +36,7 @@ function ReconciliationAccountSettingsPage({route}: ReconciliationAccountSetting
const [cardSettings] = useOnyx(`${ONYXKEYS.COLLECTION.PRIVATE_EXPENSIFY_CARD_SETTINGS}${workspaceAccountID}`);
const paymentBankAccountID = cardSettings?.paymentBankAccountID;
- const selectedBankAccount = useMemo(() => bankAccountList?.[paymentBankAccountID.toString()], [paymentBankAccountID, bankAccountList]);
+ const selectedBankAccount = useMemo(() => bankAccountList?.[String(paymentBankAccountID)], [paymentBankAccountID, bankAccountList]);
const bankAccountNumber = useMemo(() => selectedBankAccount?.accountData?.accountNumber ?? '', [selectedBankAccount]);
const settlementAccountEnding = getLastFourDigits(bankAccountNumber); A possible solution would be using Type 'undefined' cannot be used as an index type.Let's take this example on Report.ts
Here the best solution is put a condition to make the function return early if diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts
index f58f29d2640..b32d5b6abdf 100644
--- a/src/libs/actions/Report.ts
+++ b/src/libs/actions/Report.ts
@@ -898,6 +898,10 @@ function openReport(
const participantAccountIDs = PersonalDetailsUtils.getAccountIDsByLogins(participantLoginList);
participantLoginList.forEach((login, index) => {
const accountID = participantAccountIDs.at(index);
+ if (!accountID) {
+ return;
+ }
+
const isOptimisticAccount = !allPersonalDetails?.[accountID];
if (!isOptimisticAccount) { We could use These are only some examples of errors with proposed solutions, but we will definitely have more complex scenarios that need to be evaluated individually. As you can see this is a big refactor in the application, so the cost and impact of this must be taken into consideration. Also we should decide if this is really the definitive move we want to do. I imagine that these would be the tasks:
|
@neil-marcellini Uh oh! This issue is overdue by 2 days. Don't forget to update your issues! |
Job added to Upwork: https://www.upwork.com/jobs/~021844825805028000985 |
Triggered auto assignment to Contributor-plus team member for initial proposal review - @paultsimura ( |
I guess this GH won't result in a large PR, right? Maybe we'll create a GH workflow though? |
@paultsimura I mentioned this idea on Friday, see -> https://expensify.slack.com/archives/C01GTK53T8Q/p1728662249916699?thread_ts=1728329641.957179&cid=C01GTK53T8Q |
@paultsimura, @neil-marcellini Uh oh! This issue is overdue by 2 days. Don't forget to update your issues! |
@iwiznia @neil-marcellini are we anywhere close to a consensus on the new approach? |
@paultsimura, @neil-marcellini Eep! 4 days overdue now. Issues have feelings too... |
Waiting for feedback here. |
I reviewed all messages since I last look and replied in that Slack thread. |
As discussed in the Slack thread here's the refined P/S statement. cc @iwiznia @neil-marcellini @aldo-expensify @paultsimura ProblemThroughout the app we default strings to Other problems:
Solution
|
@fabioh8010 we got a thumbs up in Slack from two other internal engineers, so I'm going to assign you to get started. There's only a very small possibility that others will come in an disagree in the next few days. |
Doing them in different PRs sounds good, but I don't think we need separate issues? |
@iwiznia No problem, could you please assign me to this issue? |
I'll jump in and help with the |
I'll jump in and help with the |
There are several files which different contributors complained on additionally:
Some of them overlapping with other utils requiring a lot of changes, some causing jest tests failing after updates. So it will be better to update these files separately as well. I've opened the PR to add the to exceptions list, let me know what you think! |
Updates:
|
Today I applied most of the suggestions I got in my PR but left some questions |
Updates:
|
Today I resolved the remaining eslint issues 😄 I left some replies to @VickyStash but I wasn't able to confirm what the API expects in some situations. I guess it should be face to pass undefined for those ids. I'll be away until January 2nd but someone should take care of my work 😄 Happy holidays! 🎉 |
I have not made much progress today as I needed to focus on another issue. |
|
The solution for this issue has been 🚀 deployed to production 🚀 in version 9.0.77-6 and is now subject to a 7-day regression period 📆. Here is the list of pull requests that resolve this issue:
If no regressions arise, payment will be issued on 2024-12-30. 🎊 For reference, here are some details about the assignees on this issue:
|
Updates:
Note: I'm going to be OOO Dec 25-29 🎄 |
Context https://expensify.slack.com/archives/C01GTK53T8Q/p1728329641957179
Problem
Here we decided to use
-1
or"-1"
as defaults for when there was no report/account/policy IDs (not sure if there are others), but in most places we don't check if the IDs are-1
, instead we do!id
which for-1
would return true. That means we are applying logic to the -1 ids when we are really intending to skip the logic for those altogether.Solution
Undo that and instead use
0
for numbers and""
for stringsUpwork Automation - Do Not Edit
Issue Owner
Current Issue Owner: @paultsimuraThe text was updated successfully, but these errors were encountered: