Skip to content

Commit

Permalink
fix not logged in case
Browse files Browse the repository at this point in the history
  • Loading branch information
suejung-sentry committed Oct 29, 2024
1 parent 8f4d638 commit f803d0d
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 7 deletions.
15 changes: 15 additions & 0 deletions src/layouts/Header/components/Navigator/Navigator.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,21 @@ describe('Header Navigator', () => {
expect(sentryOrg).toBeInTheDocument()
})
})

it.only('should show the fallback if not logged in', async () => {
const { user } = setup({ isMyOrg: false })
render(<Navigator currentUser={undefined} />, {
wrapper: wrapper('/gh/not-codecov'),
})

const org = await screen.findByText('not-codecov')
expect(org).toBeInTheDocument()

await user.click(org)

const dropdownText = screen.queryByText('Install Codecov GitHub app')
expect(dropdownText).not.toBeInTheDocument()
})
})

describe('when on owner analytics page', () => {
Expand Down
30 changes: 24 additions & 6 deletions src/layouts/Header/components/Navigator/Navigator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { useParams, useRouteMatch } from 'react-router-dom'
import { useOwnerPageData } from 'pages/OwnerPage/hooks'
import { useCrumbs } from 'pages/RepoPage/context'
import { Me } from 'services/user'
import Avatar from 'ui/Avatar'
import Breadcrumb from 'ui/Breadcrumb'
import Label from 'ui/Label'

Expand All @@ -18,18 +19,20 @@ function Navigator({ currentUser }: NavigatorProps) {
const { path } = useRouteMatch()
const { breadcrumbs } = useCrumbs()

const isCurrentUserPartOfOrg = ownerData && ownerData.isCurrentUserPartOfOrg
const isCurrentUserPartOfOrg = ownerData?.isCurrentUserPartOfOrg

// Repo page
if (path.startsWith('/:provider/:owner/:repo')) {
return (
<div className="flex items-center">
<Breadcrumb paths={breadcrumbs} largeFont />{' '}
{isCurrentUserPartOfOrg ? null : (
<span className="inline-block">
<Breadcrumb paths={breadcrumbs} largeFont />{' '}
</span>
{isCurrentUserPartOfOrg === false ? (
<Label variant="plain" className="hidden sm:block">
Viewing as visitor
</Label>
)}
) : null}
</div>
)
}
Expand All @@ -53,6 +56,21 @@ function Navigator({ currentUser }: NavigatorProps) {
)
}

// Fallback instead of MyContextSwitcher if not logged in
if (!currentUser) {
return (
<div className="flex items-center">
<Avatar user={ownerData} />
<h2 className="mx-2 text-xl font-semibold">{ownerData?.username}</h2>
{isCurrentUserPartOfOrg === false ? (
<Label variant="plain" className="hidden sm:block">
Viewing as visitor
</Label>
) : null}
</div>
)
}

let pageName = 'owner'
if (path.startsWith('/analytics/:provider/:owner')) {
pageName = 'analytics'
Expand All @@ -67,11 +85,11 @@ function Navigator({ currentUser }: NavigatorProps) {
return (
<div className="flex items-center">
<MyContextSwitcher pageName={pageName} />
{isCurrentUserPartOfOrg ? null : (
{isCurrentUserPartOfOrg === false ? (
<Label variant="plain" className="hidden sm:block">
Viewing as visitor
</Label>
)}
) : null}
</div>
)
}
Expand Down
2 changes: 1 addition & 1 deletion src/ui/Label/Label.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const Label: React.FC<React.PropsWithChildren<LabelProps>> = ({
variant,
className,
}) => {
return <span className={cn(label({ variant }), className)}>{children}</span>
return <span className={cn(label({ variant, className }))}>{children}</span>
}

export default Label

0 comments on commit f803d0d

Please sign in to comment.