Skip to content

Commit

Permalink
feat(auth): profile picture (#4724)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeldking authored Sep 24, 2024
1 parent ba2ab86 commit a26a9e9
Show file tree
Hide file tree
Showing 12 changed files with 124 additions and 29 deletions.
1 change: 1 addition & 0 deletions app/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -1469,6 +1469,7 @@ type User implements Node {
passwordNeedsReset: Boolean!
email: String!
username: String
profilePictureUrl: String
createdAt: DateTime!
authMethod: AuthMethod!
role: UserRole!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,18 @@ import { css } from "@emotion/react";

import { useWordColor } from "@phoenix/hooks/useWordColor";

export function ProfilePicture({ name }: { name: string }) {
export function UserPicture({
name,
profilePictureUrl,
size = 75,
}: {
name: string;
profilePictureUrl: string | null;
/**
* The diameter of the profile picture
**/
size?: number;
}) {
const firstLetter = name.length ? name[0].toUpperCase() : "?";
const wordColor = useWordColor(name);
const gradientColors: [string, string] = useMemo(() => {
Expand All @@ -14,10 +25,10 @@ export function ProfilePicture({ name }: { name: string }) {
return (
<div
css={css`
width: 75px;
height: 75px;
width: ${size}px;
height: ${size}px;
border-radius: 50%;
font-size: 36px;
font-size: ${Math.floor(size / 2)}px;
display: flex;
flex-direction: column;
justify-content: center;
Expand All @@ -29,9 +40,15 @@ export function ProfilePicture({ name }: { name: string }) {
${gradientColors[0]},
${gradientColors[1]}
);
overflow: hidden;
img {
width: 100%;
height: 100%;
object-fit: cover;
}
`}
>
{firstLetter}
{profilePictureUrl ? <img src={profilePictureUrl} /> : firstLetter}
</div>
);
}
1 change: 1 addition & 0 deletions app/src/contexts/ViewerContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export function ViewerProvider({
id
username
email
profilePictureUrl
role {
name
}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 10 additions & 2 deletions app/src/contexts/__generated__/ViewerContext_viewer.graphql.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions app/src/pages/profile/ViewerProfileCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ import {
View,
} from "@arizeai/components";

import { UserPicture } from "@phoenix/components/user/UserPicture";
import { useNotifyError, useNotifySuccess } from "@phoenix/contexts";
import { useViewer } from "@phoenix/contexts/ViewerContext";

import { ViewerProfileCardMutation } from "./__generated__/ViewerProfileCardMutation.graphql";
import { ProfilePicture } from "./ProfilePicture";

type EditProfileFormParams = {
username: string;
Expand Down Expand Up @@ -94,7 +94,10 @@ export function ViewerProfileCard() {
>
<View paddingTop="size-200" paddingStart="size-200" paddingEnd="size-200">
<Flex direction="row" gap="size-200" alignItems="center">
<ProfilePicture name={viewer.username || viewer.email} />
<UserPicture
name={viewer.username || viewer.email}
profilePictureUrl={viewer.profilePictureUrl}
/>
<Flex direction="column" gap="size-50">
<Heading level={2} weight="heavy">
{viewer.username || viewer.email}
Expand Down
35 changes: 31 additions & 4 deletions app/src/pages/settings/UsersTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { RolePicker } from "@phoenix/components/settings/RolePicker";
import { tableCSS } from "@phoenix/components/table/styles";
import { TableEmpty } from "@phoenix/components/table/TableEmpty";
import { TimestampCell } from "@phoenix/components/table/TimestampCell";
import { UserPicture } from "@phoenix/components/user/UserPicture";
import { isUserRole, normalizeUserRole } from "@phoenix/constants";

import { UsersTable_users$key } from "./__generated__/UsersTable_users.graphql";
Expand All @@ -30,6 +31,15 @@ import { UserRoleChangeDialog } from "./UserRoleChangeDialog";

const USER_TABLE_ROW_HEIGHT = 55;

const emailLinkCSS = css`
text-decoration: none;
color: var(--ac-global-color-grey-600);
font-size: 12px;
&:hover {
text-decoration: underline;
}
`;

/**
* Rows may render different content depending on the user so we normalize the height
*/
Expand Down Expand Up @@ -59,6 +69,7 @@ export function UsersTable({ query }: { query: UsersTable_users$key }) {
username
createdAt
authMethod
profilePictureUrl
role {
name
}
Expand All @@ -75,6 +86,7 @@ export function UsersTable({ query }: { query: UsersTable_users$key }) {
id: user.id,
email: user.email,
username: user.username,
profilePictureUrl: user.profilePictureUrl,
createdAt: user.createdAt,
role: user.role.name,
authMethod: user.authMethod,
Expand All @@ -91,12 +103,27 @@ export function UsersTable({ query }: { query: UsersTable_users$key }) {
const columns = useMemo((): ColumnDef<TableRow>[] => {
return [
{
header: "email",
accessorKey: "email",
header: "user",
accessorKey: "username",
cell: ({ row }) => (
<Flex direction="row" gap="size-50" alignItems="center">
<UserPicture
name={row.original.username || row.original.email}
profilePictureUrl={row.original.profilePictureUrl}
size={20}
/>
<span>{row.original.username || "--"}</span>
<a href={`mailto:${row.original.email}`} css={emailLinkCSS}>
{row.original.email}
</a>
</Flex>
),
},
{
header: "username",
accessorKey: "username",
header: "method",
accessorKey: "authMethod",
size: 10,
cell: ({ row }) => row.original.authMethod.toLowerCase(),
},
{
header: "role",
Expand Down
13 changes: 10 additions & 3 deletions app/src/pages/settings/__generated__/UsersCardQuery.graphql.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 11 additions & 4 deletions app/src/pages/settings/__generated__/UsersTableQuery.graphql.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 10 additions & 2 deletions app/src/pages/settings/__generated__/UsersTable_users.graphql.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit a26a9e9

Please sign in to comment.