The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
Render GH profile image in NavigationBar if user is GH (#33476)
Joshen Lim4dcd9f36c142
diff --git a/apps/studio/components/interfaces/Organization/TeamSettings/MemberRow.tsx b/apps/studio/components/interfaces/Organization/TeamSettings/MemberRow.tsxindex af4c964549e..dc8b94ea948 100644--- a/apps/studio/components/interfaces/Organization/TeamSettings/MemberRow.tsx+++ b/apps/studio/components/interfaces/Organization/TeamSettings/MemberRow.tsx@@ -1,13 +1,13 @@import { ArrowRight, Check, Minus, User, X } from 'lucide-react'-import Image from 'next/legacy/image'-import { useState } from 'react'import Table from 'components/to-be-cleaned/Table'import PartnerIcon from 'components/ui/PartnerIcon'+import { ProfileImage } from 'components/ui/ProfileImage'import { useOrganizationRolesV2Query } from 'data/organization-members/organization-roles-query'import { OrganizationMember } from 'data/organizations/organization-members-query'import { useProjectsQuery } from 'data/projects/projects-query'import { useSelectedOrganization } from 'hooks/misc/useSelectedOrganization'+import { getGitHubProfileImgUrl } from 'lib/github'import { useProfile } from 'lib/profile'import Link from 'next/link'import {@@ -33,7 +33,6 @@ const MEMBER_ORIGIN_TO_MANAGED_BY = {export const MemberRow = ({ member }: MemberRowProps) => {const { profile } = useProfile()const selectedOrganization = useSelectedOrganization()- const [hasInvalidImg, setHasInvalidImg] = useState(false)const { data: projects } = useProjectsQuery()const { data: roles, isLoading: isLoadingRoles } = useOrganizationRolesV2Query({@@ -47,6 +46,9 @@ export const MemberRow = ({ member }: MemberRowProps) => {const isEmailUser = member.username === member.primary_emailconst isFlyUser = Boolean(member.primary_email?.endsWith('customer.fly.io'))+ const profileImageUrl =+ isInvitedUser || isEmailUser || isFlyUser ? undefined : getGitHubProfileImgUrl(member.username)+// [Joshen] From project role POV, mask any roles for other projectsconst isObfuscated =member.role_ids.filter((id) => {@@ -69,25 +71,22 @@ export const MemberRow = ({ member }: MemberRowProps) => {return (<Table.tr><Table.td>- <div className="flex items-center space-x-4">- <div className="w-[32px] h-[32px] md:w-[40px] md:h-[40px]">- {isInvitedUser || isEmailUser || isFlyUser || hasInvalidImg ? (- <div className="w-[32px] h-[32px] md:w-[40px] md:h-[40px] bg-surface-100 border border-overlay rounded-full text-foreground-lighter flex items-center justify-center">+ <div className="flex items-center gap-x-4">+ <ProfileImage+ alt={member.username}+ src={profileImageUrl}+ className="border rounded-full w-[32px] h-[32px] md:w-[40px] md:h-[40px]"+ placeholder={+ <div+ className={cn(+ 'w-[32px] h-[32px] md:w-[40px] md:h-[40px]',+ 'bg-surface-100 border border-overlay rounded-full text-foreground-lighter flex items-center justify-center'+ )}+ ><User size={20} strokeWidth={1.5} /></div>- ) : (- <Image- alt={member.username}- src={`https://github.com/${member.username}.png?size=80`}- width="40"- height="40"- className="border rounded-full w-[32px] h-[32px] md:w-[40px] md:h-[40px]"- onError={() => {- setHasInvalidImg(true)- }}- />- )}- </div>+ }+ /><div className="flex item-center gap-x-2">{isInvitedUser === undefined ? (<p className="text-foreground-light truncate">{member.primary_email}</p>diff --git a/apps/studio/components/layouts/ProjectLayout/NavigationBar/MobileNavigationBar.tsx b/apps/studio/components/layouts/ProjectLayout/NavigationBar/MobileNavigationBar.tsxindex efd1014ddae..8464ac57d6b 100644--- a/apps/studio/components/layouts/ProjectLayout/NavigationBar/MobileNavigationBar.tsx+++ b/apps/studio/components/layouts/ProjectLayout/NavigationBar/MobileNavigationBar.tsx@@ -1,19 +1,15 @@+import { Menu, Search } from 'lucide-react'import Link from 'next/link'import { useRouter } from 'next/router'-import { Search, Menu } from 'lucide-react'+import { useState } from 'react'import { useParams } from 'common'import { IS_PLATFORM } from 'lib/constants'import { useAppStateSnapshot } from 'state/app-state'--import { buttonVariants, cn, Sheet, SheetContent } from 'ui'+import { buttonVariants, cn } from 'ui'import { CommandMenuTrigger } from 'ui-patterns'-import { NavContent } from './NavigationBar'-import { useState } from 'react'import MobileSheetNav from 'ui-patterns/MobileSheetNav/MobileSheetNav'--export const ICON_SIZE = 20-export const ICON_STROKE_WIDTH = 1.5+import { NavContent } from './NavigationBar'const MobileNavigationBar = () => {const router = useRouter()diff --git a/apps/studio/components/layouts/ProjectLayout/NavigationBar/MobileViewNav.tsx b/apps/studio/components/layouts/ProjectLayout/NavigationBar/MobileViewNav.tsxindex b1f0a90e730..71dd9e7d3e0 100644--- a/apps/studio/components/layouts/ProjectLayout/NavigationBar/MobileViewNav.tsx+++ b/apps/studio/components/layouts/ProjectLayout/NavigationBar/MobileViewNav.tsx@@ -2,9 +2,6 @@ import { PropsWithChildren } from 'react'import { useAppStateSnapshot } from 'state/app-state'import { cn } from 'ui'-export const ICON_SIZE = 20-export const ICON_STROKE_WIDTH = 1.5-interface Props {title?: string}diff --git a/apps/studio/components/layouts/ProjectLayout/NavigationBar/NavigationBar.tsx b/apps/studio/components/layouts/ProjectLayout/NavigationBar/NavigationBar.tsxindex 1553d82a25e..40ae286e050 100644--- a/apps/studio/components/layouts/ProjectLayout/NavigationBar/NavigationBar.tsx+++ b/apps/studio/components/layouts/ProjectLayout/NavigationBar/NavigationBar.tsx@@ -1,4 +1,4 @@-import { Home, User } from 'icons'+import { Home } from 'icons'import { isUndefined } from 'lodash'import { Command, FileText, FlaskConical, Search, Settings } from 'lucide-react'import { useTheme } from 'next-themes'@@ -8,6 +8,7 @@ import { useState } from 'react'import { useParams } from 'common'import { useIsAPIDocsSidePanelEnabled } from 'components/interfaces/App/FeaturePreview/FeaturePreviewContext'+import { ProfileImage } from 'components/ui/ProfileImage'import { useProjectLintsQuery } from 'data/lint/lint-query'import { ProjectIndexPageLink } from 'data/prefetchers/project.$ref'import { useIsFeatureEnabled } from 'hooks/misc/useIsFeatureEnabled'@@ -58,8 +59,6 @@ export const ICON_STROKE_WIDTH = 1.5const NavigationBar = () => {const snap = useAppStateSnapshot()- const [userDropdownOpen, setUserDropdownOpenState] = useState(false)-const [storedAllowNavPanel] = useLocalStorageQuery(LOCAL_STORAGE_KEYS.EXPAND_NAVIGATION_PANEL,true@@ -78,9 +77,7 @@ const NavigationBar = () => {'hide-scrollbar flex flex-col justify-between overflow-y-auto')}onMouseEnter={() => allowNavPanelToExpand && snap.setNavigationPanelOpen(true)}- onMouseLeave={() => {- if (!userDropdownOpen && allowNavPanelToExpand) snap.setNavigationPanelOpen(false)- }}+ onMouseLeave={() => allowNavPanelToExpand && snap.setNavigationPanelOpen(false)}><NavContent /></nav>@@ -100,6 +97,7 @@ export const NavContent = () => {const signOut = useSignOut()const isNewAPIDocsEnabled = useIsAPIDocsSidePanelEnabled()+ const [hasInvalidImg, setHasInvalidImg] = useState(false)const [userDropdownOpen, setUserDropdownOpenState] = useState(false)const [storedAllowNavPanel] = useLocalStorageQuery(@@ -189,17 +187,19 @@ export const NavContent = () => {const UserAccountButton = (<Button+ blocktype="text"size="tiny"className={cn('mt-3 h-10 [&>span]:relative [&>span]:flex [&>span]:w-full [&>span]:h-full p-0')}- block><div className="relative w-full h-full flex items-center justify-center">- <figure className="absolute left-1.5 min-h-6 min-w-6 bg-foreground rounded-full flex items-center justify-center">- <User size={ICON_SIZE - 2} strokeWidth={ICON_STROKE_WIDTH} className="text-background" />- </figure>+ <ProfileImage+ alt={profile?.username}+ src={profile?.profileImageUrl}+ className="absolute left-1.5 w-6 h-6"+ /><spanclassName={cn('w-full md:w-[8rem] flex flex-col items-start text-sm truncate',diff --git a/apps/studio/components/ui/ProfileImage.tsx b/apps/studio/components/ui/ProfileImage.tsxnew file mode 100644index 00000000000..da31b8d0c9e--- /dev/null+++ b/apps/studio/components/ui/ProfileImage.tsx@@ -0,0 +1,35 @@+import Image from 'next/image'+import { ReactNode, useState } from 'react'++import { User } from 'icons'+import { cn } from 'ui'++interface ProfileImageProps {+ alt?: string+ src?: string+ placeholder?: ReactNode+ className?: string+}++export const ProfileImage = ({ alt, src, placeholder, className }: ProfileImageProps) => {+ const [hasInvalidImg, setHasInvalidImg] = useState(false)++ return !!src && !hasInvalidImg ? (+ <Image+ alt={alt ?? ''}+ src={src}+ width="24"+ height="24"+ className={cn('bg-foreground rounded-full', className)}+ onError={() => setHasInvalidImg(true)}+ />+ ) : (+ placeholder ?? (+ <figure+ className={cn('bg-foreground rounded-full flex items-center justify-center', className)}+ >+ <User size={18} strokeWidth={1.5} className="text-background" />+ </figure>+ )+ )+}diff --git a/apps/studio/data/profile/types.ts b/apps/studio/data/profile/types.tsindex c16127203bb..4b756ae7e08 100644--- a/apps/studio/data/profile/types.ts+++ b/apps/studio/data/profile/types.ts@@ -1,5 +1,7 @@import type { components } from 'data/api'-export type Profile = components['schemas']['ProfileResponse']+export type Profile = components['schemas']['ProfileResponse'] & {+ profileImageUrl?: string+}export type Feature = Profile['disabled_features'][number]diff --git a/apps/studio/lib/github.tsx b/apps/studio/lib/github.tsxindex e3c8702cb3c..8de3ef52368 100644--- a/apps/studio/lib/github.tsx+++ b/apps/studio/lib/github.tsx@@ -63,3 +63,7 @@ export function openInstallGitHubIntegrationWindow(type: 'install' | 'authorize'newWindow.focus()}}++export const getGitHubProfileImgUrl = (username: string) => {+ return `https://github.com/${username}.png?size=80`+}diff --git a/apps/studio/lib/profile.tsx b/apps/studio/lib/profile.tsxindex e303b69d0ba..97664b3756a 100644--- a/apps/studio/lib/profile.tsx+++ b/apps/studio/lib/profile.tsx@@ -12,6 +12,7 @@ import type { Profile } from 'data/profile/types'import { useSendEventMutation } from 'data/telemetry/send-event-mutation'import type { ResponseError } from 'types'import { useSignOut } from './auth'+import { getGitHubProfileImgUrl } from './github'export type ProfileContextType = {profile: Profile | undefined@@ -74,10 +75,12 @@ export const ProfileProvider = ({ children }: PropsWithChildren<{}>) => {const value = useMemo(() => {const isLoading = isLoadingProfile || isCreatingProfile || isLoadingPermissions+ const isGHUser = !!profile && 'auth0_id' in profile && profile?.auth0_id.startsWith('github')+ const profileImageUrl = isGHUser ? getGitHubProfileImgUrl(profile.username) : undefinedreturn {error,- profile,+ profile: !!profile ? { ...profile, profileImageUrl } : undefined,isLoading,isError,isSuccess,