diff --git a/app/src/domain/demo.rs b/app/src/domain/demo.rs index 57ae4391..7dd08b7d 100644 --- a/app/src/domain/demo.rs +++ b/app/src/domain/demo.rs @@ -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)] @@ -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))" diff --git a/frontend/src/__tests__/picker-notes.test.tsx b/frontend/src/__tests__/picker-notes.test.tsx new file mode 100644 index 00000000..77847ef9 --- /dev/null +++ b/frontend/src/__tests__/picker-notes.test.tsx @@ -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> = {}) => ({ + 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() + 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() + expect(container.textContent).toBe('') + }) + it('says nothing when every account was listed in full', () => { + const { container } = render() + expect(container.innerHTML).toBe('') + }) + it('says when searches are rate limited', () => { + const { getByRole } = render() + 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() + const link = getByRole('link', { name: 'Sign in with GitHub again to search' }) + expect(link.getAttribute('href')).toBe('/auth/github?x') + }) +}) diff --git a/frontend/src/api/types.ts b/frontend/src/api/types.ts index e2688647..50113b9a 100644 --- a/frontend/src/api/types.ts +++ b/frontend/src/api/types.ts @@ -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 }[] diff --git a/frontend/src/components/PickerNotes.tsx b/frontend/src/components/PickerNotes.tsx new file mode 100644 index 00000000..a0f47c6f --- /dev/null +++ b/frontend/src/components/PickerNotes.tsx @@ -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; 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 ( +
+ {partial.map((i) => ( +

+ Showing the first {count(i.listed)} of {count(i.total ?? 0)} on {i.account_login}; search finds the rest. +

+ ))} + {searched} +
+ ) +} + +function searchNote(search: PickerSearch, signIn: string) { + switch (search) { + case 'rate_limited': + return ( +

+ Too many searches, try again in a minute. This lists only what your last sign-in found. +

+ ) + case 'sign_in_again': + return ( +

+ Searching GitHub needs a fresh sign-in. + + Sign in with GitHub again to search + +

+ ) + case 'unavailable': + return ( +

+ GitHub’s search didn’t answer, so this lists only what your last sign-in found. Try again in a moment. +

+ ) + default: + return null + } +} + +const count = (n: number) => n.toLocaleString('en-US') diff --git a/frontend/src/pages/RepositoriesPage.tsx b/frontend/src/pages/RepositoriesPage.tsx index 7ed87857..1a3e6800 100644 --- a/frontend/src/pages/RepositoriesPage.tsx +++ b/frontend/src/pages/RepositoriesPage.tsx @@ -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 @@ -150,6 +151,8 @@ export function RepositoriesPage() { + + {p.total === 0 && !p.query && p.sync === 'syncing' ? null : p.total === 0 ? ( {!p.query && ( diff --git a/frontend/src/styles.css b/frontend/src/styles.css index 498b86a6..6386deb0 100644 --- a/frontend/src/styles.css +++ b/frontend/src/styles.css @@ -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); +} diff --git a/scripts/screenshots/pages.mjs b/scripts/screenshots/pages.mjs index c6eca8b8..e2989b9c 100644 --- a/scripts/screenshots/pages.mjs +++ b/scripts/screenshots/pages.mjs @@ -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],