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

Update LHN/chat header to handle displayName not being set #27547

Merged

Conversation

lukemorawski
Copy link
Contributor

Details

Fixed Issues

$ #27393
PROPOSAL: No proposal

Tests

  • Verify that no errors appear in the JS console

Offline tests

QA Steps

  • Open the app (prefferably in a web browser)
  • Open dev tools and take a look in to the IndexedDB (Application tab in Chrome Dev Tools)
  • In personalDetailsList key, find the object that represents personal details of a contact you want to make hidden
  • In the dev console punch in the following command:
Onyx.merge('personalDetailsList', {<account id you want to change>: {accountID: <account id you want to change>, avatar: "https://d2k5nsl2zxldvw.cloudfront.net/images/avatars/default-avatar_24.png", displayName: "", firstName: "", lastName: "", login: "", phoneNumber: "", validated: true}})
  • Observe the LHN and look for "Hidden" instead of the name of the contact
  • Open the chat with that contact
  • Put the above command in the console again (Onyx probably overwrote the data with real ones by now)
  • Observe the header changing name to Hidden
  • Verify that no errors appear in the JS console

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 / Chrome
    • iOS / native
    • iOS / 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 the left part of a conditional rendering a React component is a boolean and NOT a string, e.g. myBool && <MyComponent />.
    • 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 verified the translation was requested/reviewed 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 approved by marketing by adding the Waiting for Copy label for a copy review on the original GH to get the correct copy.
    • 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.js 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 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
    • If we are not using the full Onyx data that we loaded, I've added the proper selector in order to ensure the component only re-renders when the data it is using changes
    • 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(themeColors.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 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.
  • 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 author checklist, including those that don't apply to this PR.

Screenshots/Videos

Web
Mobile Web - Chrome
Mobile Web - Safari
Desktop
iOS
Android

@lukemorawski lukemorawski marked this pull request as ready for review September 18, 2023 08:58
@lukemorawski lukemorawski requested a review from a team as a code owner September 18, 2023 08:58
@melvin-bot melvin-bot bot requested review from mananjadhav and removed request for a team September 18, 2023 08:58
@melvin-bot
Copy link

melvin-bot bot commented Sep 18, 2023

@mananjadhav 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]

@puneetlath
Copy link
Contributor

@mananjadhav hi! Do you have an ETA for reviewing?

@mananjadhav
Copy link
Collaborator

Will be reviewing this today within 2-3 hours.

@mananjadhav
Copy link
Collaborator

@puneetlath @lukemorawski The Hidden works as expected but I am not sure if we should be showing hidden when we search for a new user.

Steps to reproduce:

  1. Open the App
  2. Click on the Search icon
  3. Enter the email of the user you've never chatted before.
  4. Check the name of the user, and you'll see it shows Hidden
web-hidden-in-search

@puneetlath
Copy link
Contributor

Ah interesting. Yeah on the search page, let's just show the email address as the display name like we do today. Would you be able to make that update @lukemorawski?

@puneetlath
Copy link
Contributor

@lukemorawski think you'll be able to make that update today?

@lukemorawski
Copy link
Contributor Author

@puneetlath yep!

@lukemorawski
Copy link
Contributor Author

@puneetlath Added some changes. Please check :)

@puneetlath
Copy link
Contributor

Thanks! @mananjadhav mind giving it a quick look first?

@mananjadhav
Copy link
Collaborator

@lukemorawski Now for the valid ones too, we're seeing a blank.

  1. Create an iOU request with a user
  2. Set it's value as empty based on the Onyx.merge command
  3. Open the search bar and look for the user. You'll see the title shows blank.
Screenshot 2023-09-26 at 12 57 52 AM
web-hidden.mov

@puneetlath I think we should be able to differentiate between the new chat or existing hidden records. Can't backend send some flag from the backend, where we want to show Hidden?

@puneetlath
Copy link
Contributor

Can't backend send some flag from the backend, where we want to show Hidden?

It's not really so simple. The back-end will send the data that the user should have access to. Which sometimes will be just accountID. Sometimes will be accountID and displayName. Sometimes will be accountID, displayName, and login.

Can we not do this based on what information we have locally?

@puneetlath
Copy link
Contributor

@lukemorawski what are your thoughts? Would love to get this wrapped up this week!

@lukemorawski
Copy link
Contributor Author

@puneetlath Sorry, had some more urgent tickets. Will check this out today!

@lukemorawski
Copy link
Contributor Author

@puneetlath @mananjadhav tricky thing, but there might be a way to deal with that locally

@lukemorawski
Copy link
Contributor Author

@puneetlath @mananjadhav OK, made some fixes. Looks good for me, but please do check it out!

@puneetlath
Copy link
Contributor

@mananjadhav thoughts on the approach?

/**
* Get the displayName for a single report participant.
*
* @param {Number} accountID
* @param {Boolean} [shouldUseShortForm]
* @param {Boolean} shouldNotFallbackToHidden
Copy link
Member

Choose a reason for hiding this comment

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

Prefer using no negated condition https://eslint.org/docs/latest/rules/no-negated-condition
We have this as an eslint rule, but it didn't catch this because it's a function param.

Suggested change
* @param {Boolean} shouldNotFallbackToHidden
* @param {Boolean} shouldFallbackToHidden

Copy link
Collaborator

Choose a reason for hiding this comment

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

Agreed with @rushatgabhane here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok, though it made more sense like that, as falling back to hidden is the default :)

if (!accountID) {
return '';
}
const personalDetails = getPersonalDetailsForAccountID(accountID);
// check if it's invite account
if (hasOnlyAvatarField(personalDetails)) {
return '';
Copy link
Member

Choose a reason for hiding this comment

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

question: could you please help me understand this. In which cases a user will have only Avatar field?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure! Say a user is entering an email address into the search field, and that address has not yet been registered as Expensify user, it will, in that scenario have no other details than automatically created avatar. This is how I detect a "new invite account", because the can't fallback to "Hidden" displayName value.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Thanks for the explanation @lukemorawski. Let's add a comment as a JSDoc for the method.

@@ -1089,32 +1089,46 @@ function getPersonalDetailsForAccountID(accountID) {
);
}

function hasOnlyAvatarField(obj) {
const keys = _.keys(obj);
return keys.length === 1 && keys[0] === 'avatar';
Copy link
Member

Choose a reason for hiding this comment

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

should we use lodash get to access keys[0]?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

not sure why. This is safe and very readable. Lodash would be something like this

_.isEqual(_.keys(obj), ['avatar']);

Copy link
Contributor

Choose a reason for hiding this comment

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

What happens to this personalDetails object post-invite once the API responds. Does it get cleared out? If so, perhaps we can add an explicit isOptimistc key to it instead of having to infer it.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Not sure what you mean by cleared out? But when we search for a non-existing account we see this.
image

Once we receive the object again post-invite, it includes all the keys. For example,

{
    "accountID": 15820244,
    "avatar": "https://d2k5nsl2zxldvw.cloudfront.net/images/avatars/default-avatar_4.png",
    "displayName": "[email protected]",
    "firstName": "",
    "lastName": "",
    "status": null
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, I think I'm confused by what an "invite" account is.

From what I can see, when I invite a new user, we create an optimistic personalDetails object for that user that looks like this:
Screenshot 2023-10-13 at 10 35 27 AM

Then when the API responds, the optimistic personalDetail gets removed and the real personalDetail with the real accountID for that user is added:
image

So I'm just trying to understand what this "invite" account that has only the avatar field is and when it would exist. Sorry if I'm missing something obvious!

@@ -1089,32 +1089,46 @@ function getPersonalDetailsForAccountID(accountID) {
);
}

function hasOnlyAvatarField(obj) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you explain how this method helps us?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

answered above

Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's add a comment as a JSDoc for the method.

@@ -1089,32 +1089,46 @@ function getPersonalDetailsForAccountID(accountID) {
);
}

function hasOnlyAvatarField(obj) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we rename obj to something more meaningful?

@mananjadhav
Copy link
Collaborator

@lukemorawski quick bump on the changes requested.

Copy link
Contributor

@puneetlath puneetlath left a comment

Choose a reason for hiding this comment

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

Looks good to me!

One small comment and @mananjadhav it'd be great to do a quick re-test.

src/libs/ReportUtils.js Outdated Show resolved Hide resolved
@mananjadhav
Copy link
Collaborator

I'll retest this by eod.

@mananjadhav
Copy link
Collaborator

@lukemorawski Thanks for the changes.

@puneetlath I retested this and it looks to be working as expected

@mananjadhav
Copy link
Collaborator

Web web-hidden-display-name
Mobile Web - Chrome mweb-hidden-display-name
Mobile Web - Safari mweb-safari-hidden-display-name
Desktop desktop-hidden-display-name
iOS NA
Android NA

@melvin-bot melvin-bot bot requested a review from puneetlath October 18, 2023 17:18
@puneetlath
Copy link
Contributor

Great, good with me too!

@lukemorawski looks like you have a Jest test failing though. Not sure if that is because of your changes or if you just need to merge main. Once you fix that, we should be good to merge.

@puneetlath puneetlath merged commit fd169e2 into Expensify:main Oct 19, 2023
13 checks passed
@melvin-bot
Copy link

melvin-bot bot commented Oct 19, 2023

Congrats, that’s your 5th PR merged! 🎉 Do you know about the ContributorPlus role? It’s an opportunity to earn more in the Expensify Open Source community. Keep up the great work - thanks!

@OSBotify
Copy link
Contributor

✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release.

@situchan
Copy link
Contributor

This PR caused serious regression - Not able to submit distance request at all.
I confirmed that is not reproducible after reverting this PR locally.
@lukemorawski can you please raise quick PR?

@OSBotify
Copy link
Contributor

🚀 Deployed to staging by https://github.com/puneetlath in version: 1.3.88-0 🚀

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

@OSBotify
Copy link
Contributor

🚀 Deployed to production by https://github.com/chiragsalian in version: 1.3.88-11 🚀

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

Comment on lines -73 to +79
_.map(props.iou.participants, (participant) => {
const isPolicyExpenseChat = lodashGet(participant, 'isPolicyExpenseChat', false);
return isPolicyExpenseChat ? OptionsListUtils.getPolicyExpenseReportOption(participant) : OptionsListUtils.getParticipantsOption(participant, props.personalDetails);
}),
_.chain(props.iou.participants)
.map((participant) => {
const isPolicyExpenseChat = lodashGet(participant, 'isPolicyExpenseChat', false);
return isPolicyExpenseChat ? OptionsListUtils.getPolicyExpenseReportOption(participant) : OptionsListUtils.getParticipantsOption(participant, props.personalDetails);
})
.filter((participant) => !!participant.login)
.value(),
Copy link
Contributor

@s77rt s77rt Nov 24, 2023

Choose a reason for hiding this comment

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

@lukemorawski Can you please clarify why we need to filter participants on login? cc @mananjadhav

(Coming from #31792)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@s77rt You probably meant filtering "by login". It' there to filter out user without login so the would not appear in the money request as "Hidden". Also the process of creating a money request requires that field and allowing "Hidden" users to make a money request caused an error.

Copy link
Contributor

Choose a reason for hiding this comment

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

@lukemorawski Thanks for your reply. It looks like making money requests to "Hidden" accounts works and it's actually a wanted functionality. Since this filter was only done to avoid an error that no longer occurs I think it's safe to remove it. Let us know if disagree.

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.

7 participants