Skip to content

Commit

Permalink
issue-177204: show username when fullName is empty string (#186298)
Browse files Browse the repository at this point in the history
## Summary

We could find and edge case on ESS Custom User doing QA on the issue:
#177204.
When user's full name is an empty string (not undefined or null) the
greeting message was not displaying.

In this PR, we change the logic and display user's username whenever the
user's fullName value is an empty string.

Before:

![image](https://github.com/elastic/kibana/assets/61565784/9138a923-647c-4c6d-9300-340040545e55)


How it looks now:

![image](https://github.com/elastic/kibana/assets/61565784/d451ed60-cdcf-41f1-a01a-12f5d0c4202a)


### **Checklist**


- [ ] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios.
  • Loading branch information
agusruidiazgd authored Jun 18, 2024
1 parent f694306 commit ef91afd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,16 @@ describe('WelcomeHeaderComponent', () => {
expect(titleElement).toBeInTheDocument();
});

it('should render username when fullName is an empty string', () => {
const fullName = '';
const username = 'jd';
mockUseCurrentUser.mockReturnValue({ fullName, username });

const { getByText } = render(<WelcomeHeader />);
const titleElement = getByText(`Hi ${username}!`);
expect(titleElement).toBeInTheDocument();
});

it('should render username when fullName is not provided', () => {
const username = 'jd';
mockUseCurrentUser.mockReturnValue({ username });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const WelcomeHeaderComponent: React.FC<{ productTier?: ProductTier }> = ({ produ
const userName = useCurrentUser();

// Full name could be null, user name should always exist
const name = userName?.fullName ?? userName?.username;
const name = userName?.fullName || userName?.username;

const projectFeaturesUrl = useProjectFeaturesUrl();

Expand Down

0 comments on commit ef91afd

Please sign in to comment.