Skip to content

Commit b1d1f3b

Browse files
Appless non-PAT org dropdown clarity changes (#3628)
1 parent b7ce614 commit b1d1f3b

File tree

2 files changed

+27
-6
lines changed

2 files changed

+27
-6
lines changed

src/ui/ContextSwitcher/ContextSwitcher.test.jsx

+10-3
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ describe('ContextSwitcher', () => {
220220
]}
221221
currentUser={{
222222
defaultOrgUsername: 'spotify',
223+
username: 'laudna',
223224
}}
224225
src="imageUrl"
225226
isLoading={false}
@@ -234,7 +235,9 @@ describe('ContextSwitcher', () => {
234235
)
235236
await user.click(button)
236237

237-
const laudnaUsers = await screen.findAllByText('laudna')
238+
const laudnaUsers = await screen.findAllByText(
239+
"laudna's personal organization"
240+
)
238241
expect(laudnaUsers.length).toBe(2)
239242

240243
const codecovOwner = await screen.findByText('codecov')
@@ -292,7 +295,9 @@ describe('ContextSwitcher', () => {
292295
{ wrapper: wrapper() }
293296
)
294297

295-
const installCopy = await screen.findByText(/Install Codecov GitHub app/)
298+
const installCopy = await screen.findByText(
299+
/To add another organization, install Codecov GitHub App/
300+
)
296301
expect(installCopy).toBeInTheDocument()
297302
expect(installCopy).toHaveAttribute(
298303
'href',
@@ -823,7 +828,9 @@ describe('ContextSwitcher', () => {
823828
}
824829
)
825830

826-
const installCopy = await screen.findByText(/Install Codecov GitHub app/)
831+
const installCopy = await screen.findByText(
832+
/To add another organization, install Codecov GitHub App/
833+
)
827834
expect(installCopy).toBeInTheDocument()
828835
expect(installCopy).toHaveAttribute(
829836
'href',

src/ui/ContextSwitcher/ContextSwitcher.tsx

+17-3
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,15 @@ function LoadMoreTrigger({
4242

4343
interface ContextItemProps {
4444
context: Context
45+
currentUserUsername: string | null
4546
defaultOrgUsername: string | null
4647
setToggle: (arg: boolean) => void
4748
owner?: string | null
4849
}
4950

5051
function ContextItem({
5152
context,
53+
currentUserUsername,
5254
defaultOrgUsername,
5355
setToggle,
5456
owner,
@@ -76,7 +78,9 @@ function ContextItem({
7678
>
7779
<Avatar user={contextOwner} />
7880
<div className={cs('mx-1', { 'font-semibold': owner === orgUsername })}>
79-
{orgUsername}
81+
{!!orgUsername && orgUsername === currentUserUsername
82+
? `${orgUsername}'s personal organization`
83+
: orgUsername || ''}
8084
</div>
8185
</Button>
8286
</li>
@@ -141,6 +145,8 @@ export interface Props {
141145
contexts: Context[]
142146
currentUser: {
143147
defaultOrgUsername: string | null
148+
username: string | null
149+
avatarUrl: string
144150
}
145151
activeContext: ReturnType<typeof useOwner>['data']
146152
onLoadMore?: () => void
@@ -165,6 +171,7 @@ function ContextSwitcher({
165171
const wrapperRef = useCloseOnLooseFocus({ setToggle })
166172
const intersectionRef = useLoadMore({ onLoadMore })
167173
const defaultOrgUsername = currentUser?.defaultOrgUsername
174+
const currentUserUsername = currentUser?.username
168175

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

177185
return (
178186
<div id="context-switcher" className="relative text-sm" ref={wrapperRef}>
@@ -189,7 +197,12 @@ function ContextSwitcher({
189197
onClick={() => setToggle((toggle) => !toggle)}
190198
>
191199
<Avatar user={activeContext} />
192-
<p className="ml-1">{activeContext?.username ?? owner}</p>
200+
<p className="ml-1">
201+
{displayUsername}
202+
{displayUsername === currentUserUsername
203+
? "'s personal organization"
204+
: ''}
205+
</p>
193206
<span
194207
aria-hidden="true"
195208
className={cs('transition-transform', {
@@ -226,12 +239,13 @@ function ContextSwitcher({
226239
hook="context-switcher-gh-install-link"
227240
>
228241
<Icon name="plusCircle" />
229-
Install Codecov GitHub app
242+
To add another organization, install Codecov GitHub App
230243
</A>
231244
</li>
232245
) : null}
233246
{contexts.map((context) => (
234247
<ContextItem
248+
currentUserUsername={currentUserUsername}
235249
defaultOrgUsername={defaultOrgUsername}
236250
context={context}
237251
key={context?.owner?.username}

0 commit comments

Comments
 (0)