Skip to content

Feat: isEmptyReport derived value #60697

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

Merged

Conversation

kacper-mikolajczak
Copy link
Contributor

@kacper-mikolajczak kacper-mikolajczak commented Apr 23, 2025

Explanation of Change

This PR introduces implementation of isEmpty derived value as a part of #59350.

[Blocker] It is dependent on #60497 which contains fixes to how derived values work in general.

Fixed Issues

$ #59350
PROPOSAL: Proposal

Tests

  1. Create new chat
  2. Type in one new message
  3. [Native] Go back
  4. Chat should be visible in LHN
  5. Enter the very same chat
  6. Remove the message
  7. [Native] Go back
  8. Chat should be (re)moved from LHN

Offline tests

Same as in Tests

QA Steps

Same as in Tests

PR Author Checklist

  • I linked the correct issue in the ### Fixed Issues section above
  • I wrote clear testing steps that cover the changes made in this PR
    • I added steps for local testing in the Tests section
    • I added steps for the expected offline behavior in the Offline steps section
    • I added steps for Staging and/or Production testing in the QA steps section
    • I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
    • I tested this PR with a High Traffic account against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability).
  • I included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on:
    • Android: Native
    • Android: mWeb Chrome
    • iOS: Native
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
    • MacOS: Desktop
  • I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed)
  • I followed proper code patterns (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick)
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text shown in the product is localized by adding it to src/languages/* files and using the translation method
      • If any non-english text was added/modified, I used JaimeGPT to get English > Spanish translation. I then posted it in #expensify-open-source and it was approved by an internal Expensify engineer. Link to Slack message:
    • I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I followed the guidelines as stated in the Review Guidelines
  • I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar are working as expected)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.ts or at the top of the file that uses the constant) are defined as such
  • I verified that if a function's arguments changed that all usages have also been updated correctly
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • If a new page is added, I verified it's using the ScrollView component to make it scrollable when more elements are added to the page.
  • I added unit tests for any new feature or bug fix in this PR to help automatically prevent regressions in this user flow.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.

Screenshots/Videos

Android: Native
android.mp4
Android: mWeb Chrome
android_web.mp4
iOS: Native
ios.mp4
iOS: mWeb Safari
ios_web.mp4
MacOS: Chrome / Safari
web.mp4
MacOS: Desktop
desktop.mp4

@kacper-mikolajczak kacper-mikolajczak marked this pull request as ready for review April 24, 2025 07:06
@kacper-mikolajczak kacper-mikolajczak requested a review from a team as a code owner April 24, 2025 07:06
@melvin-bot melvin-bot bot requested review from hoangzinh and removed request for a team April 24, 2025 07:06
Copy link

melvin-bot bot commented Apr 24, 2025

@hoangzinh Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button]

@hoangzinh
Copy link
Contributor

PR #60497 was merged. You can try to merge latest main @kacper-mikolajczak

@kacper-mikolajczak
Copy link
Contributor Author

Thanks @hoangzinh! Latest main was merged - waiting for CI checks 🏁

@kacper-mikolajczak
Copy link
Contributor Author

kacper-mikolajczak commented Apr 25, 2025

@hoangzinh All checks have passed, PR is ready to be reviewed 👍 🆚 👎

@kacper-mikolajczak
Copy link
Contributor Author

Hi @hoangzinh! PR is ready to be reviewed

@hoangzinh
Copy link
Contributor

Yes, I will review it today. Btw, tbh, for final review, I would like to wait for this PR #60497 to be deployed to Prod. It could be reverted if there are regressions issues.

@kacper-mikolajczak
Copy link
Contributor Author

Btw, tbh, for final review, I would like to wait for this PR #60497 to be deployed to Prod. It could be reverted if there are regressions issues.

Agree, that makes sense! 👍

@hoangzinh
Copy link
Contributor

Btw, there are some conflicts, are you available to fix it please?

@kacper-mikolajczak
Copy link
Contributor Author

Btw, there are some conflicts, are you available to fix it please?

Done ✅

Comment on lines 28 to 29
// Add correct default value for REPORT_DRAFT collection
dependencies[7] ??= {};
Copy link
Contributor

Choose a reason for hiding this comment

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

With this custom, does it need to add ONYXKEYS.COLLECTION.REPORT_DRAFT to the dependencies list?

Copy link
Contributor Author

@kacper-mikolajczak kacper-mikolajczak Apr 30, 2025

Choose a reason for hiding this comment

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

Yes, this is really unfortunate to have that but at the same time it looks like a simplest way to get the fallback value.

Do you know what is the reason some onyx collections have empty value of {}, while some, like REPORT_DRAFT can result in undefined?

The reason it was required here is check in areAllDependenciesSet that checks against undefined and will bail out of all updates when REPORT_DRAFT collection is empty - making all the reportAttributes out of sync.

Copy link
Contributor Author

@kacper-mikolajczak kacper-mikolajczak Apr 30, 2025

Choose a reason for hiding this comment

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

CC @TMisiukiewicz who is the main man behind idea of reportAttributes - what do you think of this Tomek, could that be avoided? Thanks!

Did any other empty collection resulted in undefined? If yes, how did you solve it?

Copy link
Contributor

@hoangzinh hoangzinh Apr 30, 2025

Choose a reason for hiding this comment

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

Is it because reportDraft_ does not always exist?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it may be undefined, which will fail areAllDependenciesSet check.

Copy link
Contributor

Choose a reason for hiding this comment

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

I feel that PR will take time. What do you guys think if

  1. @kacper-mikolajczak go head and cherry-pick those code into this PR
  2. or @TMisiukiewicz will help to commit that commit into this PR
  3. or hold on that PR.

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am down for all of the options! @TMisiukiewicz how much time do you think PR with the improvement you mentioned needs to be completed?

Copy link
Contributor

Choose a reason for hiding this comment

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

@kacper-mikolajczak I just finished addressing all the comments from @hoangzinh, I hope we'll be able to push things forward quickly

Copy link
Contributor

Choose a reason for hiding this comment

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

The reportDrafts are there as a dependency, because isEmpty value calculation depends on them but they are not part of what we want to provide from this derived value.

With those reasons, I think we don't really need to add reportDrafts are there as a dependency, because when reportDrafts are updated, we don't recalculate anything, because updates will be empty here

if (updates.length > 0) {
dataToIterate = prepareReportKeys(updates);
recentlyUpdated = updates;

@kacper-mikolajczak
Copy link
Contributor Author

kacper-mikolajczak commented May 7, 2025

Hi @hoangzinh The PR is ready for final review round!

Thanks to @TMisiukiewicz support, the isEmptyReport is now integrated into reportAttributes 🎉 Tomek could I ask you to double check the changes as well so we are sure everything is as expected?

Thanks guys :)

@hoangzinh
Copy link
Contributor

Awesome @kacper-mikolajczak. Will try to review again today

@@ -107,6 +108,7 @@ export default createOnyxDerivedValueConfig({

acc[report.reportID] = {
reportName: generateReportName(report),
isEmpty: generateIsEmptyReport(report),
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you contribute to the unit test for Derived value here?

Copy link
Contributor Author

@kacper-mikolajczak kacper-mikolajczak May 8, 2025

Choose a reason for hiding this comment

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

Sure! I tried to add another test, but I've noticed that the tests are not working as expected (they are not failing regardless of assertion made). Will address it (and contact Tomek to double check if there is indeed a regression) and get back to you when resolved 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It turns out is something with async nature of tests because they are not correctly fulfilled (the async callback is not even ran).

Also, what would might help is waiting for Onyx.clear() in beforeEach.

We are still trying to figure out 100% what's happening.

Comment on lines 28 to 29
// Add correct default value for REPORT_DRAFT collection
dependencies[7] ??= {};
Copy link
Contributor

Choose a reason for hiding this comment

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

The reportDrafts are there as a dependency, because isEmpty value calculation depends on them but they are not part of what we want to provide from this derived value.

With those reasons, I think we don't really need to add reportDrafts are there as a dependency, because when reportDrafts are updated, we don't recalculate anything, because updates will be empty here

if (updates.length > 0) {
dataToIterate = prepareReportKeys(updates);
recentlyUpdated = updates;

@kacper-mikolajczak
Copy link
Contributor Author

kacper-mikolajczak commented May 8, 2025

With those reasons, I think we don't really need to add reportDrafts are there as a dependency, because when reportDrafts are updated, we don't recalculate anything, because updates will be empty here

You are right, it won't recalculate anything int this case. Thank you 👍 Wondering what are the implications there - am I assuming right that the isEmpty attribute recalculation will be triggered only via REPORT change?

Noticed however, the same happens for PERSONAL_DETAILS_LIST and COLLECTION.POLICY. @TMisiukiewicz is it the same mechanism behind?

@hoangzinh
Copy link
Contributor

@kacper-mikolajczak do you know how to create reportDraft_? I found this PR but I couldn't reproduce it #41465

@kacper-mikolajczak
Copy link
Contributor Author

kacper-mikolajczak commented May 9, 2025

@hoangzinh Sorry, I don't have knowledge about how the feature works in the app.

Maybe asking some folks at slack could help.

@hoangzinh
Copy link
Contributor

Yep, asking here https://expensify.slack.com/archives/C01GTK53T8Q/p1746795799334219

@kacper-mikolajczak
Copy link
Contributor Author

Yep, asking here https://expensify.slack.com/archives/C01GTK53T8Q/p1746795799334219

Let me know if anything has changed in that matter and how we should proceed (or how I can help you), thank you!

@kacper-mikolajczak
Copy link
Contributor Author

kacper-mikolajczak commented May 13, 2025

@TMisiukiewicz @hoangzinh I have created an issue regarding failing tests: #61897

As the regression is not only related to this PR, we might address it there separately, what do you think?

I have pushed changes to REPORT_DRAFTS, let's wait with the test issues to resolve before (I am trying in the meantime to understand what is happening but still in progress, so let's try to fix it together 👍 )

@hoangzinh
Copy link
Contributor

Yes, I think we can remove REPORT_DRAFTS atm a706bb0

Btw, does it mean we can cont process with this PR?

@kacper-mikolajczak
Copy link
Contributor Author

Btw, does it mean we can cont process with this PR?

If the QA is positive, then I am good with taking that further (the tests are not showing proper outcomes so we can't rely on them) 👍

@hoangzinh
Copy link
Contributor

Reviewer Checklist

  • I have verified the author checklist is complete (all boxes are checked off).
  • I verified the correct issue is linked in the ### Fixed Issues section above
  • I verified testing steps are clear and they cover the changes made in this PR
    • I verified the steps for local testing are in the Tests section
    • I verified the steps for Staging and/or Production testing are in the QA steps section
    • I verified the steps cover any possible failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
  • I checked that screenshots or videos are included for tests on all platforms
  • I included screenshots or videos for tests on all platforms
  • I verified that the composer does not automatically focus or open the keyboard on mobile unless explicitly intended. This includes checking that returning the app from the background does not unexpectedly open the keyboard.
  • I verified tests pass on all platforms & I tested again on:
    • Android: HybridApp
    • Android: mWeb Chrome
    • iOS: HybridApp
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
    • MacOS: Desktop
  • If there are any errors in the console that are unrelated to this PR, I either fixed them (preferred) or linked to where I reported them in Slack
  • I verified there are no new alerts related to the canBeMissing param for useOnyx
  • I verified proper code patterns were followed (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick).
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text shown in the product is localized by adding it to src/languages/* files and using the translation method
    • I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I verified that this PR follows the guidelines as stated in the Review Guidelines
  • I verified other components that can be impacted by these changes have been tested, and I retested again (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar have been tested & I retested again)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.ts or at the top of the file that uses the constant) are defined as such
  • If a new component is created I verified that:
    • A similar component doesn't exist in the codebase
    • All props are defined accurately and each prop has a /** comment above it */
    • The file is named correctly
    • The component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone
    • The only data being stored in the state is data necessary for rendering and nothing else
    • For Class Components, any internal methods passed to components event handlers are bound to this properly so there are no scoping issues (i.e. for onClick={this.submit} the method this.submit should be bound to this in the constructor)
    • Any internal methods bound to this are necessary to be bound (i.e. avoid this.submit = this.submit.bind(this); if this.submit is never passed to a component event handler like onClick)
    • All JSX used for rendering exists in the render method
    • The component has the minimum amount of code necessary for its purpose, and it is broken down into smaller components in order to separate concerns and functions
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG)
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • If a new page is added, I verified it's using the ScrollView component to make it scrollable when more elements are added to the page.
  • For any bug fix or new feature in this PR, I verified that sufficient unit tests are included to prevent regressions in this flow.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.
  • I have checked off every checkbox in the PR reviewer checklist, including those that don't apply to this PR.

Screenshots/Videos

Android: HybridApp
Screen.Recording.2025-05-14.at.21.41.29.android.mov
Android: mWeb Chrome
Screen.Recording.2025-05-14.at.21.49.24.mov
iOS: HybridApp
Screen.Recording.2025-05-14.at.21.39.04.ios.mov
iOS: mWeb Safari
Screen.Recording.2025-05-14.at.21.16.35.ios.safari.mov
MacOS: Chrome / Safari
Screen.Recording.2025-05-14.at.20.41.03.web.mov
MacOS: Desktop
Screen.Recording.2025-05-14.at.21.02.10.desktop.mov

Copy link
Contributor

@hoangzinh hoangzinh left a comment

Choose a reason for hiding this comment

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

LGTM

@melvin-bot melvin-bot bot requested a review from mjasikowski May 14, 2025 14:53
/**
* Check if the report is empty, meaning it has no visible messages (i.e. only a "created" report action).
* Added caching mechanism via derived values.
*/
function isEmptyReport(report: OnyxEntry<Report>): boolean {
Copy link
Contributor

Choose a reason for hiding this comment

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

NAB, but if all that isEmptyReport does is add caching on top generateEmptyReport, wouldn't it make more sense to concatenate them into a single function? Something like:

function isEmptyReport(report: OnyxEntry<Report>, useCache = true): boolean {
    if (!report) {
        return true;
    }

    if (useCache && reportAttributes?.[report.reportID]) {
        return reportAttributes?.[report.reportID].isEmpty;
    }

    if (report.lastMessageText) {
        return false;
    }
    
    const lastVisibleMessage = getLastVisibleMessage(report.reportID);
    return !lastVisibleMessage.lastMessageText;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @mjasikowski, thanks for the comment!

Why we need to separate them into two is that when generating reportAttributes under OnyxDerived, we need to make sure it is fresh value. In other words, we need to force cache refresh when cache expires.

I have followed the pattern that was used with generateReportName + getReportName combo.

Let me know if that makes sense, thanks!

@kacper-mikolajczak
Copy link
Contributor Author

@hoangzinh what's the next step for us with this PR?

@kacper-mikolajczak
Copy link
Contributor Author

Hi folks! Please let me know what are the next steps for this PR, thanks!

CC @mjasikowski @mountiny @hoangzinh

@hoangzinh
Copy link
Contributor

@kacper-mikolajczak all good here. We will wait for @mjasikowski to merge and deploy it to staging for testing.

Copy link
Contributor

@mountiny mountiny left a comment

Choose a reason for hiding this comment

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

I think we can move this one ahead

@kacper-mikolajczak
Copy link
Contributor Author

Awesome, thanks!

@mountiny mountiny merged commit eb86b5d into Expensify:main May 20, 2025
20 checks passed
Copy link
Contributor

🚀 Deployed to staging by https://github.com/mountiny in version: 9.1.48-0 🚀

platform result
🖥 desktop 🖥 failure ❌
🕸 web 🕸 success ✅
🤖 android 🤖 success ✅
🍎 iOS 🍎 failure ❌

Copy link
Contributor

🚀 Deployed to staging by https://github.com/mountiny in version: 9.1.48-0 🚀

platform result
🖥 desktop 🖥 success ✅
🕸 web 🕸 success ✅
🤖 android 🤖 success ✅
🍎 iOS 🍎 failure ❌

Copy link
Contributor

🚀 Deployed to staging by https://github.com/mountiny in version: 9.1.49-5 🚀

platform result
🖥 desktop 🖥 success ✅
🕸 web 🕸 success ✅
🤖 android 🤖 success ✅
🍎 iOS 🍎 success ✅

Copy link
Contributor

🚀 Deployed to production by https://github.com/arosiclair in version: 9.1.50-0 🚀

platform result
🖥 desktop 🖥 success ✅
🕸 web 🕸 success ✅
🤖 android 🤖 failure ❌
🍎 iOS 🍎 success ✅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants