Skip to content

Commit

Permalink
Appless non-PAT org dropdown clarity changes (#3628)
Browse files Browse the repository at this point in the history
  • Loading branch information
calvin-codecov committed Jan 22, 2025
1 parent b7ce614 commit b1d1f3b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
13 changes: 10 additions & 3 deletions src/ui/ContextSwitcher/ContextSwitcher.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ describe('ContextSwitcher', () => {
]}
currentUser={{
defaultOrgUsername: 'spotify',
username: 'laudna',
}}
src="imageUrl"
isLoading={false}
Expand All @@ -234,7 +235,9 @@ describe('ContextSwitcher', () => {
)
await user.click(button)

const laudnaUsers = await screen.findAllByText('laudna')
const laudnaUsers = await screen.findAllByText(
"laudna's personal organization"
)
expect(laudnaUsers.length).toBe(2)

const codecovOwner = await screen.findByText('codecov')
Expand Down Expand Up @@ -292,7 +295,9 @@ describe('ContextSwitcher', () => {
{ wrapper: wrapper() }
)

const installCopy = await screen.findByText(/Install Codecov GitHub app/)
const installCopy = await screen.findByText(
/To add another organization, install Codecov GitHub App/
)
expect(installCopy).toBeInTheDocument()
expect(installCopy).toHaveAttribute(
'href',
Expand Down Expand Up @@ -823,7 +828,9 @@ describe('ContextSwitcher', () => {
}
)

const installCopy = await screen.findByText(/Install Codecov GitHub app/)
const installCopy = await screen.findByText(
/To add another organization, install Codecov GitHub App/
)
expect(installCopy).toBeInTheDocument()
expect(installCopy).toHaveAttribute(
'href',
Expand Down
20 changes: 17 additions & 3 deletions src/ui/ContextSwitcher/ContextSwitcher.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,15 @@ function LoadMoreTrigger({

interface ContextItemProps {
context: Context
currentUserUsername: string | null
defaultOrgUsername: string | null
setToggle: (arg: boolean) => void
owner?: string | null
}

function ContextItem({
context,
currentUserUsername,
defaultOrgUsername,
setToggle,
owner,
Expand Down Expand Up @@ -76,7 +78,9 @@ function ContextItem({
>
<Avatar user={contextOwner} />
<div className={cs('mx-1', { 'font-semibold': owner === orgUsername })}>
{orgUsername}
{!!orgUsername && orgUsername === currentUserUsername
? `${orgUsername}'s personal organization`
: orgUsername || ''}
</div>
</Button>
</li>
Expand Down Expand Up @@ -141,6 +145,8 @@ export interface Props {
contexts: Context[]
currentUser: {
defaultOrgUsername: string | null
username: string | null
avatarUrl: string
}
activeContext: ReturnType<typeof useOwner>['data']
onLoadMore?: () => void
Expand All @@ -165,6 +171,7 @@ function ContextSwitcher({
const wrapperRef = useCloseOnLooseFocus({ setToggle })
const intersectionRef = useLoadMore({ onLoadMore })
const defaultOrgUsername = currentUser?.defaultOrgUsername
const currentUserUsername = currentUser?.username

const isGh = providerToName(provider) === 'GitHub'
const isSelfHosted = config.IS_SELF_HOSTED
Expand All @@ -173,6 +180,7 @@ function ContextSwitcher({
// self-hosted cannot use default "codecov" app (must set up custom one)
const shouldShowGitHubInstallLink =
isGh && (isSelfHosted ? isCustomGitHubApp : true)
const displayUsername = activeContext?.username ?? owner

return (
<div id="context-switcher" className="relative text-sm" ref={wrapperRef}>
Expand All @@ -189,7 +197,12 @@ function ContextSwitcher({
onClick={() => setToggle((toggle) => !toggle)}
>
<Avatar user={activeContext} />
<p className="ml-1">{activeContext?.username ?? owner}</p>
<p className="ml-1">
{displayUsername}
{displayUsername === currentUserUsername
? "'s personal organization"
: ''}
</p>
<span
aria-hidden="true"
className={cs('transition-transform', {
Expand Down Expand Up @@ -226,12 +239,13 @@ function ContextSwitcher({
hook="context-switcher-gh-install-link"
>
<Icon name="plusCircle" />
Install Codecov GitHub app
To add another organization, install Codecov GitHub App
</A>
</li>
) : null}
{contexts.map((context) => (
<ContextItem
currentUserUsername={currentUserUsername}
defaultOrgUsername={defaultOrgUsername}
context={context}
key={context?.owner?.username}
Expand Down

0 comments on commit b1d1f3b

Please sign in to comment.