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
30 changes: 23 additions & 7 deletions forge-web/components/repo/issues-content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

/**
* IssuesContent — the issue list (`platform-parity-spec.md` §1.2): Open / Closed tabs with exact
* counts, filters for label, author, assignee and "mentions me", sort, a search box with
* GitHub's qualifiers, pages of 50 past the first 100 issues, label chips and assignee avatars.
* counts, filters for label, milestone, author, assignee and "mentions me", sort, a search box
* with GitHub's qualifiers (`lib/view/issue-query`), pages of 50 past the first 100 issues, label
* chips and assignee avatars.
* Everything the list shows is in the URL (D-913), so a reload or a shared link shows the same.
*
* Reads go through the issue index (`lib/repo/issue-index`): one composite for the first 100
Expand All @@ -30,14 +31,15 @@ import {
issueQueryParams,
parseIssueQuery,
parseSearchText,
pastLastPage,
searchSubmitBase,
searchText,
unresolvedQualifiers,
BODY_MAX,
utf8Length,
type IssueListQuery,
} from '@/lib/view/issue-query'
import { createIssue, issueFirsts, queryIssues, repoContractIds, repoKey, type IssueListPage, type IssueSelection } from '@/lib/repo'
import { createIssue, issueFirsts, queryIssues, repoContractIds, repoKey, rowFiltersOf, type IssueListPage, type IssueSelection } from '@/lib/repo'
import { SupersededWriteError } from '@/lib/sdk'
import { useWriteGuard } from '@/hooks/use-write-guard'
import { useRepoWriteGeneration } from '@/hooks/use-repo-chrome'
Expand All @@ -58,11 +60,14 @@ import { MirrorComposeHint, MirrorNote } from '@/components/repo/mirror-note'
import { useRepoLinks } from '@/components/repo/target-href'
import { AssigneeAvatars, MarkdownEditor } from '@/components/repo/issue-bits'
import {
AuthorLoginNote,
CommentCount,
DroppedNote,
LabelChipFilter,
LabelFilter,
MilestoneFilter,
Pager,
PastLastPage,
PersonFilter,
RowLink,
SearchBox,
Expand All @@ -75,6 +80,7 @@ import {
} from '@/components/repo/list-controls'
import { IssueTemplatePicker } from '@/components/repo/issue-templates'
import { useRepoTotals } from '@/components/repo/use-repo-totals'
import { useMilestones } from '@/components/repo/use-milestones'
import { BodyCounter, SealedLimit, composeCost, privateComposeBlock } from '@/components/repo/private-compose'
import type { RepoAddress } from '@/hooks/use-query-param'
import { repoHref } from '@/hooks/use-query-param'
Expand All @@ -91,6 +97,7 @@ export function IssuesContent({ home, addr }: { home: RepoHome; addr: RepoAddres
const generation = useRepoWriteGeneration(home.repo)
const trust = useMirrorTrust(home.repo)
const totals = useRepoTotals(home.repo)
const milestones = useMilestones(home.repo)
// A private repo's issues are sealed on write (`lib/repo/private-writes.ts`); only a member
// holding the current key can open one, and non-members see no button (ux-dx-spec §9).
const canCompose = privateComposeBlock(home) === null
Expand All @@ -102,6 +109,9 @@ export function IssuesContent({ home, addr }: { home: RepoHome; addr: RepoAddres

// `me` needs a signed-in viewer; signed out, a `me` filter shows nothing rather than everything.
const needsViewer = query.author === 'me' || query.assignee === 'me' || query.mentions
// `author:<login>` matches only what a trusted mirror signed: until the trust set is read, every
// row would fail it (an empty list, after walking every chunk), so the read waits for it.
const awaitingTrust = query.authorLogin !== null && trust === null
const { data, loading, error, reload } = useAsync<IssueListPage>(
async () => {
const me = identity ?? ''
Expand All @@ -116,16 +126,18 @@ export function IssuesContent({ home, addr }: { home: RepoHome; addr: RepoAddres
text: query.q,
page: query.page,
pageSize: ISSUE_PAGE_SIZE,
...rowFiltersOf(query, trust),
}
return queryIssues(sdk!, home.repo, selection, totals, network)
},
[ready, repoKey(home.repo), generation, JSON.stringify(query), identity ?? '', totals ?? -1],
{ enabled: ready && sdk !== null && (!needsViewer || identity !== null) },
[ready, repoKey(home.repo), generation, JSON.stringify(query), identity ?? '', totals ?? -1, query.authorLogin !== null && trust !== null ? [...trust].sort().join(',') : null],
{ enabled: ready && sdk !== null && (!needsViewer || identity !== null) && !awaitingTrust },
)

const labelDefs = useMemo(() => new Map((data?.labels ?? []).map((l) => [l.name, l])), [data])
const empty = data !== null && data.rows.length === 0
const filtered = hasFilters(query)
const lastPage = empty ? pastLastPage(query.page, data?.matching ?? null, ISSUE_PAGE_SIZE) : null

return (
<div className="mx-auto max-w-4xl">
Expand All @@ -138,6 +150,7 @@ export function IssuesContent({ home, addr }: { home: RepoHome; addr: RepoAddres
) : null}
</div>
<DroppedNote search={search} reason={droppedQualifiersReason(search.dropped, search.notFound)} testId="issue-search-dropped" />
<AuthorLoginNote login={query.authorLogin} notFound={search.notFound} />

<MirrorNote home={home} kind="issue" />

Expand Down Expand Up @@ -181,11 +194,12 @@ export function IssuesContent({ home, addr }: { home: RepoHome; addr: RepoAddres
</div>
<div className="ml-auto flex flex-wrap items-center gap-2">
<LabelFilter labels={data?.labels ?? []} selected={query.labels} onChange={(labels) => change({ labels })} />
<MilestoneFilter milestones={milestones.data} value={query.milestone} none={query.noMilestone} onChange={(c) => change(c)} />
<PersonFilter
label="Author"
value={query.author}
signedIn={identity !== null}
onChange={(author) => change({ author })}
onChange={(author) => change({ author, authorLogin: null })}
/>
<PersonFilter
label="Assignee"
Expand All @@ -210,10 +224,12 @@ export function IssuesContent({ home, addr }: { home: RepoHome; addr: RepoAddres

{needsViewer && identity === null ? (
<p className="px-4 py-6 text-dense text-anvil-500 dark:text-anvil-400">Sign in to filter by your own issues, assignments and mentions.</p>
) : loading && !data ? (
) : (loading || awaitingTrust) && !data ? (
<LoadingBlock label="Reading issues" />
) : error ? (
<div className="p-4"><ErrorState message={error} onRetry={reload} /></div>
) : lastPage !== null ? (
<PastLastPage page={query.page} last={lastPage} onPage={(page) => change({ page })} />
) : empty ? (
<EmptyState
icon={CircleDot}
Expand Down
94 changes: 90 additions & 4 deletions forge-web/components/repo/list-controls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import type { EvoSDK } from '@dashevo/evo-sdk'
import type { Network } from '@/lib/constants'
import type { LabelDef } from '@/lib/repo'
import { plural, resolveDpnsId } from '@/lib/view'
import { dpnsAuthorCandidates, resolveSearchNames, withQuery } from '@/lib/view/issue-query'
import { dpnsAuthorCandidates, Q_MAX, resolveSearchNames, withQuery } from '@/lib/view/issue-query'
import type { RepoAddress } from '@/hooks/use-query-param'
import { Button } from '@/components/ui/button'
import { Input } from '@/components/ui/input'
Expand Down Expand Up @@ -90,7 +90,7 @@ export function useListQuery<Q extends { readonly page: number }>({
router.replace(`${pathname}?${q.toString()}`, { scroll: false })
}
// The linked `?q=`, capped as the query parsers cap it (a crafted link cannot force unbounded DPNS reads).
const linkedQ = params.get('q')?.slice(0, 200) ?? null
const linkedQ = params.get('q')?.slice(0, Q_MAX) ?? null

const [search, setSearch] = useState<string | null>(null)
const [dropped, setDropped] = useState<readonly string[]>(() => grammar.unresolved(linkedQ ?? ''))
Expand Down Expand Up @@ -406,14 +406,17 @@ export function Pager({
}): JSX.Element | null {
if (page === 1 && !hasNext) return null
const pages = matching === null ? null : Math.max(1, Math.ceil(matching / pageSize))
// Past the last page (a stale or hand-edited `?page=`), Previous goes to the last one rather
// than one back, and no "Page 9 of 6" is claimed (QW-068).
const past = pages !== null && page > pages
return (
<nav aria-label={label} className="mt-4 flex items-center justify-center gap-3 text-dense">
<Button variant="outline" size="sm" disabled={page <= 1} onClick={() => onPage(page - 1)}>
<Button variant="outline" size="sm" disabled={page <= 1} onClick={() => onPage(past ? pages : page - 1)}>
<ChevronLeft className="h-3.5 w-3.5" aria-hidden /> Previous
</Button>
<span className="text-anvil-500 dark:text-anvil-400" data-testid="page-indicator">
Page {page}
{pages !== null ? ` of ${pages}` : ''}
{pages !== null && !past ? ` of ${pages}` : ''}
</span>
<Button variant="outline" size="sm" disabled={!hasNext} onClick={() => onPage(page + 1)}>
Next <ChevronRight className="h-3.5 w-3.5" aria-hidden />
Expand All @@ -422,6 +425,89 @@ export function Pager({
)
}

/**
* The list body when `?page=` lies past the last page (QW-068): says so and offers the last page,
* rather than the empty list's "nothing has been merged yet".
*/
export function PastLastPage({ page, last, onPage }: { page: number; last: number; onPage: (p: number) => void }): JSX.Element {
return (
<div className="px-4 py-8 text-center text-dense text-anvil-600 dark:text-anvil-300" data-testid="page-past-end">
<p className="font-medium text-anvil-900 dark:text-anvil-50">There is no page {page}</p>
<p className="mt-1 text-anvil-500 dark:text-anvil-400">This list has {plural(last, 'page')}.</p>
<Button variant="outline" size="sm" className="mt-3" onClick={() => onPage(last)}>
Go to page {last}
</Button>
</div>
)
}

/** What a milestone filter offers: the repo's milestones (open first), or null while they are read. */
export interface MilestoneChoice {
readonly title: string
readonly closed: boolean
}

/** The milestone filter (QW-018): any, none, or one of the repo's milestones (open ones first). */
export function MilestoneFilter({
milestones,
value,
none,
onChange,
}: {
milestones: readonly MilestoneChoice[] | null
value: string | null
none: boolean
onChange: (c: { milestone: string | null; noMilestone: boolean }) => void
}): JSX.Element {
const known = milestones ?? []
const open = known.filter((m) => !m.closed)
const closed = known.filter((m) => m.closed)
// A milestone named in the URL that the repo does not define (yet) stays selectable.
const extra = value !== null && !known.some((m) => m.title === value) ? [value] : []
return (
<span className="inline-flex items-center gap-1">
<label htmlFor="filter-milestone" className="text-dense text-anvil-600 dark:text-anvil-300">Milestone</label>
<select
id="filter-milestone"
// A milestone's option is `m:<title>`, so no title can read as "any" or "none".
value={none ? 'none' : value !== null ? `m:${value}` : ''}
onChange={(e) => {
const v = e.target.value
onChange(v === 'none' ? { milestone: null, noMilestone: true } : { milestone: v.startsWith('m:') ? v.slice(2) : null, noMilestone: false })
}}
className="max-w-[10rem] rounded-md border border-anvil-300 bg-white px-2 py-1 text-dense dark:border-anvil-700 dark:bg-anvil-950 coarse:h-11"
>
<option value="">any</option>
<option value="none">none</option>
{[...extra, ...open.map((m) => m.title)].map((t) => (
<option key={t} value={`m:${t}`}>{t}</option>
))}
{closed.length > 0 ? (
<optgroup label="Closed">
{closed.map((m) => (
<option key={m.title} value={`m:${m.title}`}>{m.title}</option>
))}
</optgroup>
) : null}
</select>
</span>
)
}

/**
* What `author:login` matched (QW-062): a name with no identity behind it is the login an
* import recorded, so the list shows the items a trusted mirror imported from that author.
*/
export function AuthorLoginNote({ login, notFound }: { login: string | null; notFound: readonly string[] }): JSX.Element | null {
if (login === null) return null
const noName = notFound.some((n) => n.toLowerCase() === login.toLowerCase())
return (
<p role="note" className="mb-3 text-[12px] text-anvil-500 dark:text-anvil-400" data-testid="author-login-note">
author:{login} matches items mirrored from @{login} on the source forge{noName ? ` (no DPNS name ${login}.dash exists)` : ''}.
</p>
)
}

/** "Searched the newest N of M …": a search or comment sort that looked at part of the repo. */
export function SearchedNote({ searchedOf, noun }: { searchedOf: { readonly searched: number; readonly total: number | null } | null | undefined; noun: string }): JSX.Element | null {
if (!searchedOf) return null
Expand Down
64 changes: 60 additions & 4 deletions forge-web/components/repo/pulls-content.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ vi.mock('next/navigation', () => ({
}))
vi.mock('@/hooks/use-sdk', () => ({ useSdk: () => ({ sdk: {}, ready: true, network: 'devnet', status: { phase: 'ready' } }) }))
vi.mock('@/contexts/auth-context', () => ({ useAuth: () => ({ identity: null }) }))
vi.mock('@/hooks/use-mirror-trust', () => ({ useMirrorTrust: () => null }))
/** The mirror trust set the list reads (null: not read yet). */
let mirrorTrust: ReadonlySet<string> | null = null
vi.mock('@/hooks/use-mirror-trust', () => ({ useMirrorTrust: () => mirrorTrust }))
vi.mock('@/hooks/use-repo-chrome', () => ({ useRepoWriteGeneration: () => 0 }))
vi.mock('@/components/repo/use-repo-totals', () => ({ useRepoTotals: () => 203 }))
vi.mock('@/components/repo/mirror-note', () => ({ MirrorNote: () => null }))
Expand Down Expand Up @@ -118,6 +120,7 @@ let el: HTMLDivElement
beforeEach(() => {
;(globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true
search = ''
mirrorTrust = null
lookupGate = null
dotGate = null
dotReads.length = 0
Expand Down Expand Up @@ -232,10 +235,10 @@ describe('PullsContent (L-44)', () => {

it('says which qualifiers it could not apply, and why', async () => {
await render()
await submit('author:bobby mentions:@me fix')
await submit('author:bobby.dash mentions:@me fix')
const note = el.querySelector('[data-testid="pull-search-dropped"]')?.textContent ?? ''
expect(note).toContain('author:bobby')
expect(note).toContain('bobby')
expect(note).toContain('author:bobby.dash')
expect(note).toContain('No DPNS name `bobby.dash` was found.')
expect(note).toContain('mentions: is an Issues filter.')
expect(replaced.at(-1)).toBe('/repo/pulls/?owner=o&name=n&q=fix')
// Clear filters drops the note with the filters.
Expand All @@ -245,6 +248,59 @@ describe('PullsContent (L-44)', () => {
expect(el.querySelector('[data-testid="pull-search-dropped"]')).toBeNull()
})

it('matches a name DPNS does not know as a mirrored author login, and says so (QW-062)', async () => {
await render()
await submit('author:thephez fix')
expect(replaced.at(-1)).toBe('/repo/pulls/?owner=o&name=n&q=author%3Athephez+fix')
expect(el.querySelector('[data-testid="pull-search-dropped"]')).toBeNull()
search = 'owner=o&name=n&q=author%3Athephez+fix'
// Until the mirror trust set is read, no row could match: the list waits rather than read.
asked.length = 0
await render()
expect(asked).toEqual([])
expect(el.textContent).toContain('Reading pull requests')
mirrorTrust = new Set(['owner'])
await render()
expect(asked.at(-1)).toMatchObject({ author: null, authorLogin: 'thephez', text: 'fix' })
expect(el.querySelector('[data-testid="author-login-note"]')?.textContent).toContain('mirrored from @thephez')
})

it('reports review: and a bad draft: value instead of searching for them as text (QW-020)', async () => {
await render()
await submit('review:approved draft:maybe in:comments fix')
const note = el.querySelector('[data-testid="pull-search-dropped"]')?.textContent ?? ''
expect(note).toContain('review:approved')
expect(note).toContain('draft: takes true or false.')
expect(note).toContain('in: takes title or body')
expect(replaced.at(-1)).toBe('/repo/pulls/?owner=o&name=n&q=fix')
})

it('applies draft:, review-requested:@me, -label:, milestone: and comments: from the URL', async () => {
search = `owner=o&name=n&q=draft%3Afalse+review-requested%3A${ALICE}+-label%3Awontfix+milestone%3A%22v1+0%22+comments%3A%3E2`
await render()
expect(asked.at(-1)).toMatchObject({ draft: false, reviewRequested: ALICE, notLabels: ['wontfix'], milestone: 'v1 0', comments: { min: 3, max: Infinity } })
expect((el.querySelector('#pull-search') as HTMLInputElement).value).toBe(`is:open -label:wontfix milestone:"v1 0" comments:>2 draft:false review-requested:${ALICE}`)
// `review-requested:@me` needs a viewer: signed out, nothing is read.
asked.length = 0
search = 'owner=o&name=n&q=review-requested%3A%40me'
await render()
expect(asked).toEqual([])
expect(el.textContent).toContain('Sign in to filter by your own pull requests')
})

it('says a page past the last one does not exist and offers the last page (QW-068)', async () => {
answer = { ...answer, rows: [], matching: 150, hasNext: false }
search = 'owner=o&name=n&state=merged&page=9'
await render()
const past = el.querySelector('[data-testid="page-past-end"]')
expect(past?.textContent).toContain('There is no page 9')
expect(past?.textContent).toContain('6 pages')
expect(el.textContent).not.toContain('Nothing has been merged yet')
expect(el.querySelector('[data-testid="page-indicator"]')?.textContent).toBe('Page 9')
act(() => button('Go to page 6').click())
expect(replaced.at(-1)).toBe('/repo/pulls/?owner=o&name=n&state=merged&page=6')
})

it('a tab change overtaking a slow name lookup stops the spinner, and the lookup is dropped', async () => {
let finish!: () => void
lookupGate = new Promise((r) => (finish = r))
Expand Down
Loading
Loading