Skip to content

Commit

Permalink
Update getUserDisplayName function to use email as the first fall…
Browse files Browse the repository at this point in the history
…back.
  • Loading branch information
azasypkin committed Aug 24, 2022
1 parent 19c9b77 commit 200f27e
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 6 deletions.
7 changes: 6 additions & 1 deletion packages/kbn-user-profile-components/src/user_profile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,11 @@ export interface GetUserDisplayNameParams {
/**
* Optional email of the user.
*/
email?: string;

/**
* Optional full name of the user.
*/
full_name?: string;
}

Expand All @@ -151,5 +156,5 @@ export interface GetUserDisplayNameParams {
* @param params Set of available user's name-related fields.
*/
export function getUserDisplayName(params: GetUserDisplayNameParams) {
return params.full_name || params.username;
return params.full_name || params.email || params.username;
}
12 changes: 11 additions & 1 deletion x-pack/plugins/security/common/model/user.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,22 @@ describe('#getUserDisplayName', () => {
expect(
getUserDisplayName({
full_name: 'my full name',
email: '[email protected]',
username: 'foo',
} as User)
).toEqual('my full name');
});

it(`uses the username when full name is not available`, () => {
it(`uses the email when full name is not available available`, () => {
expect(
getUserDisplayName({
email: '[email protected]',
username: 'foo',
} as User)
).toEqual('[email protected]');
});

it(`uses the username when full name and email are not available`, () => {
expect(
getUserDisplayName({
username: 'foo',
Expand Down
7 changes: 6 additions & 1 deletion x-pack/plugins/security/common/model/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ export interface GetUserDisplayNameParams {
/**
* Optional email of the user.
*/
email?: string;

/**
* Optional full name of the user.
*/
full_name?: string;
}

Expand All @@ -46,5 +51,5 @@ export interface GetUserDisplayNameParams {
* @param params Set of available user's name-related fields.
*/
export function getUserDisplayName(params: GetUserDisplayNameParams) {
return params.full_name || params.username;
return params.full_name || params.email || params.username;
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,20 +76,21 @@ export const EditUserPage: FunctionComponent<EditUserPageProps> = ({ username })

const isReservedUser = isUserReserved(user);
const isDeprecatedUser = isUserDeprecated(user);
const displayName = getUserDisplayName(user);

// We render email below the title already and don't need to duplicate it in the title itself.
const title = getUserDisplayName({ full_name: user.full_name, username: user.username });
return (
<>
<EuiPageHeader
bottomBorder
pageTitle={
<EuiFlexGroup alignItems="center" responsive={false}>
<EuiFlexItem grow={false}>
<EuiAvatar name={displayName!} size="xl" />
<EuiAvatar name={getUserDisplayName(user)} size="xl" />
</EuiFlexItem>
<EuiFlexItem>
<EuiTitle>
<h1>{displayName}</h1>
<h1>{title}</h1>
</EuiTitle>
<EuiText>{user.email}</EuiText>
</EuiFlexItem>
Expand Down

0 comments on commit 200f27e

Please sign in to comment.