Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions app/src/domain/demo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -629,9 +629,9 @@ fn feed(items: usize) -> String {
text
}

/// The repository picker's data: the GitHub App installed on Acme (set up for acme, 60 repositories Ada can reach, web
/// already a project, some she can only write to, two archived) and on her own account (set up for side-project, with a
/// pick of five repositories half made, for the progress page).
/// The repository picker's data: the GitHub App installed on Acme (set up for acme; 60 of its 1,260 repositories listed
/// for Ada, web already a project, some she can only write to, two archived) and on her own account (set up for
/// side-project, with a pick of five repositories half made, for the progress page).
async fn seed_repository_picker(ada: i64, acme: i64, side: i64) -> laravel::Result<()> {
for (installation, account_id, login, kind, org) in
[("1", "5005", "acme", "Organization", acme), ("2", "1001", "ada", "User", side)]
Expand All @@ -650,6 +650,14 @@ async fn seed_repository_picker(ada: i64, acme: i64, side: i64) -> laravel::Resu
.insert()
.await?;
}
// Acme's listing stopped short: 60 of its 1,260 repositories, so the picker says search finds the rest, and its
// search (Ada's seed has no GitHub token) offers signing in again.
db::query!(
"UPDATE user_installations SET repositories_listed = 60, repositories_total = 1260, \
repositories_complete = false WHERE user_id = {ada} AND installation_id = '1'"
)
.update()
.await?;
db::query!(
"UPDATE github_installations SET setup_result = jsonb_set(setup_result, '{{organization}}', \
to_jsonb(CASE installation_id WHEN '1' THEN 'acme' ELSE 'side-project' END))"
Expand Down
40 changes: 40 additions & 0 deletions frontend/src/__tests__/picker-notes.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { afterEach, describe, expect, it } from 'vitest'
import { cleanup, render } from '@testing-library/react'
import { PickerNotes } from '../components/PickerNotes'
import type { RepositoryPicker } from '../api/types'

// The picker says what its list leaves out: an account the last GitHub sign-in listed only in part, and a search that
// couldn't reach GitHub.
const acme = { installation_id: '1', account_login: 'acme', listed: 1000, total: 4210 }
const small = { installation_id: '2', account_login: 'small', listed: 12, total: 12 }
const picker = (over: Partial<Pick<RepositoryPicker, 'installations' | 'query' | 'search'>> = {}) => ({
installations: [acme, small],
query: '',
search: 'local' as const,
...over,
})

describe('the picker notes', () => {
afterEach(cleanup)
it('names an account listed only in part, and only that one', () => {
const { container } = render(<PickerNotes picker={picker()} signIn="/auth/github" />)
expect(container.textContent).toBe('Showing the first 1,000 of 4,210 on acme; search finds the rest.')
})
it('leaves out an account the tab filter hides', () => {
const { container } = render(<PickerNotes picker={picker()} installation="2" signIn="/auth/github" />)
expect(container.textContent).toBe('')
})
it('says nothing when every account was listed in full', () => {
const { container } = render(<PickerNotes picker={picker({ installations: [small] })} signIn="/auth/github" />)
expect(container.innerHTML).toBe('')
})
it('says when searches are rate limited', () => {
const { getByRole } = render(<PickerNotes picker={picker({ installations: [small], query: 'api', search: 'rate_limited' })} signIn="/auth/github" />)
expect(getByRole('status').textContent).toContain('Too many searches, try again in a minute')
})
it('offers a fresh sign-in when the search needs one', () => {
const { getByRole } = render(<PickerNotes picker={picker({ installations: [small], query: 'api', search: 'sign_in_again' })} signIn="/auth/github?x" />)
const link = getByRole('link', { name: 'Sign in with GitHub again to search' })
expect(link.getAttribute('href')).toBe('/auth/github?x')
})
})
9 changes: 8 additions & 1 deletion frontend/src/api/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,18 @@ export type RepositoryPicker = {
page: number
per_page: number
query: string
installations: { installation_id: string; account_login: string }[]
/** Each installation, with how many of its repositories the last sign-in listed (`total` null: it didn't count). */
installations: { installation_id: string; account_login: string; listed: number; total: number | null }[]
running: RepositoryImport | null
sync: GithubSync
/** How a search reached the repositories the sign-in didn't list: see `PickerSearch`. */
search: PickerSearch
}

/** `local`: every installation was listed in full, so no GitHub call; `github`: GitHub was searched too;
* `rate_limited`, `sign_in_again` (the sign-in's GitHub token expired) and `unavailable`: it wasn't. */
export type PickerSearch = 'local' | 'github' | 'rate_limited' | 'sign_in_again' | 'unavailable'

/** The "Set up VisualCI" checklist: each step ticks itself from what happened. */
export type Setup = {
steps: { key: SetupStepKey; done: boolean }[]
Expand Down
54 changes: 54 additions & 0 deletions frontend/src/components/PickerNotes.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import type { PickerSearch, RepositoryPicker } from '../api/types'

/**
* What the picker's list leaves out, under its search box: an account whose repositories the last GitHub sign-in
* listed only in part ("Showing the first 1,000 of 4,210 on acme; search finds the rest"), and why a search didn't
* reach GitHub (rate limited, the sign-in's token expired, GitHub not answering).
*/
export function PickerNotes({ picker, installation, signIn }: { picker: Pick<RepositoryPicker, 'installations' | 'query' | 'search'>; installation?: string; signIn: string }) {
const partial = picker.installations.filter(
(i) => (!installation || i.installation_id === installation) && i.total != null && i.listed < i.total,
)
const searched = picker.query.trim().length >= 2 ? searchNote(picker.search, signIn) : null
if (partial.length === 0 && !searched) return null
return (
<div className="picker-notes">
{partial.map((i) => (
<p key={i.installation_id} className="muted">
Showing the first {count(i.listed)} of {count(i.total ?? 0)} on <b>{i.account_login}</b>; search finds the rest.
</p>
))}
{searched}
</div>
)
}

function searchNote(search: PickerSearch, signIn: string) {
switch (search) {
case 'rate_limited':
return (
<p className="muted" role="status">
Too many searches, try again in a minute. This lists only what your last sign-in found.
</p>
)
case 'sign_in_again':
return (
<p className="muted picker-note-action" role="status">
<span>Searching GitHub needs a fresh sign-in.</span>
<a className="btn btn-sm" href={signIn}>
Sign in with GitHub again to search
</a>
</p>
)
case 'unavailable':
return (
<p className="muted" role="status">
GitHub’s search didn’t answer, so this lists only what your last sign-in found. Try again in a moment.
</p>
)
default:
return null
}
}

const count = (n: number) => n.toLocaleString('en-US')
5 changes: 4 additions & 1 deletion frontend/src/pages/RepositoriesPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ import type { PickerRepository, RepositoryImport, SetupStepKey } from '../api/ty
import { QueryState } from '../components/QueryState'
import { Button, Empty, Help } from '../components/ui'
import { GithubSyncNotice } from '../components/GithubSyncNotice'
import { PickerNotes } from '../components/PickerNotes'

const route = getRouteApi('/_app/$org/repositories')

/** The most repositories one pick makes into projects (the server's IMPORT_LIMIT). */
const PICK_LIMIT = 50
const PICK_LIMIT = 500

/**
* The repository picker: the repositories the person can reach through the organization's GitHub App installations
Expand Down Expand Up @@ -150,6 +151,8 @@ export function RepositoriesPage() {
</span>
</div>

<PickerNotes picker={p} installation={search.installation} signIn={refresh} />

{p.total === 0 && !p.query && p.sync === 'syncing' ? null : p.total === 0 ? (
<Empty title={p.query ? `Nothing matches “${p.query}”` : 'No repositories yet'}>
{!p.query && (
Expand Down
19 changes: 19 additions & 0 deletions frontend/src/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -5889,3 +5889,22 @@ html.vci-signed-in .site-auth-out {
flex: 1 1 0;
}
}

.picker-notes {
display: grid;
gap: var(--space-1);
margin-bottom: var(--space-3);
font-size: var(--text-sm);
}

.picker-notes p {
margin: 0;
}

/* A note with a button: the button follows the text, or wraps under it flush left on a phone. */
.picker-notes .picker-note-action {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: var(--space-2);
}
5 changes: 3 additions & 2 deletions scripts/screenshots/pages.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,9 @@ export function pages() {
['app/snapshot/text', snapshot('web', 3, 'cli/help.txt'), true, ALL],
// The slider view, last of the snapshot pages: a ?mode= link is remembered, like the buttons.
['app/snapshot/slider', async (api) => `${await snapshot('web', 3, 'dashboard/1440-light')(api)}?mode=slider`, true, ALL],
// The repository picker: Acme's 60 repositories (web already a project, some only written to, some archived), a
// search, and side-project's pick half made
// The repository picker: 60 of Acme's 1,260 repositories, so it says search finds the rest (web already a project,
// some only written to, some archived), a search that offers signing in again to search GitHub,
// and side-project's pick half made
['app/repositories', '/acme/repositories', true, ALL],
['app/repositories/search', '/acme/repositories?q=pdf', true, ALL],
['app/repositories/progress', '/side-project/repositories', true, ALL],
Expand Down
Loading