Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

feat(review_hog): add the reviews table parts next to the recent reviews list (#114963)

Julian Bezeb51d97f9eb6
diff --git a/products/review_hog/frontend/CodeReviewScene.tsx b/products/review_hog/frontend/CodeReviewScene.tsx
index 0d1e413e383c..fe5e1e6b7868 100644
--- a/products/review_hog/frontend/CodeReviewScene.tsx
+++ b/products/review_hog/frontend/CodeReviewScene.tsx
@@ -7,6 +7,7 @@ import {
LemonInput,
LemonSegmentedButton,
LemonSkeleton,
+ LemonTab,
LemonTabs,
LemonTag,
Link,
@@ -1152,6 +1153,55 @@ function ReviewDetailDrawer(): JSX.Element {
const review = reviewDetail ?? openedReview
const singleAgent = isSingleAgentReview(review)
+ const tabs: (LemonTab<ReviewDrawerTab> | false)[] = [
+ {
+ key: 'published',
+ // "Published" is a claim about the PR — only make it when the review
+ // actually posted; findings a store-only run kept above the bar read
+ // "Kept". `review` falls back to the list row, so a published review
+ // doesn't flash "Kept" while its detail loads.
+ label: `${review?.published ? (singleAgent ? 'Posted' : 'Published') : 'Kept'}${
+ reviewFindingsSplit ? ` (${reviewFindingsSplit.published.length})` : ''
+ }`,
+ content: <DrawerPublishedTab />,
+ },
+ singleAgent && {
+ key: 'not_posted',
+ label: `Not posted${reviewDetail ? ` (${reviewDetail.dropped_findings.length})` : ''}`,
+ content: <DrawerNotPostedTab />,
+ },
+ // A single-agent turn publishes at every urgency, so nothing sits below a threshold.
+ !singleAgent && {
+ key: 'below_threshold',
+ label: `Below threshold${reviewFindingsSplit ? ` (${reviewFindingsSplit.belowThreshold.length})` : ''}`,
+ content: <DrawerBelowThresholdTab />,
+ },
+ // A single-agent turn has no validator, so there are no dismissals to show.
+ !singleAgent && {
+ key: 'dismissed',
+ label: `Dismissed${reviewDetail ? ` (${reviewDetail.dismissed_findings.length})` : ''}`,
+ content: <DrawerDismissedTab />,
+ },
+ singleAgent
+ ? { key: 'how_it_ran', label: 'How it ran', content: <DrawerHowItRanTab /> }
+ : { key: 'chunks', label: 'Chunks', content: <DrawerChunksTab /> },
+ {
+ key: 'review',
+ label: 'Review body',
+ content: reviewDetail ? (
+ reviewDetail.report_markdown ? (
+ <LemonMarkdown className="text-sm" disableImages>
+ {reviewDetail.report_markdown}
+ </LemonMarkdown>
+ ) : (
+ <div className="text-sm text-secondary">No review body was rendered for this pull request.</div>
+ )
+ ) : (
+ <LemonSkeleton className="h-40 w-full" />
+ ),
+ },
+ ]
+
return (
<LemonDrawer
isOpen={reviewDrawerOpen}
@@ -1207,67 +1257,11 @@ function ReviewDetailDrawer(): JSX.Element {
</div>
)}
<LemonTabs<ReviewDrawerTab>
- // Standard has no Dismissed tab and Deep has no Not posted tab, so a stale selection
- // falls back to the posted tab.
- activeKey={
- (singleAgent && reviewDrawerTab === 'dismissed') ||
- (!singleAgent && reviewDrawerTab === 'not_posted')
- ? 'published'
- : reviewDrawerTab
- }
+ // Standard and Deep show different tabs, and a deep link can pick a tab before the
+ // detail says which design ran, so a selection the design lacks falls back to the posted tab.
+ activeKey={tabs.some((tab) => tab && tab.key === reviewDrawerTab) ? reviewDrawerTab : 'published'}
onChange={setReviewDrawerTab}
- tabs={[
- {
- key: 'published',
- // "Published" is a claim about the PR — only make it when the review
- // actually posted; findings a store-only run kept above the bar read
- // "Kept". `review` falls back to the list row, so a published review
- // doesn't flash "Kept" while its detail loads.
- label: `${review?.published ? (singleAgent ? 'Posted' : 'Published') : 'Kept'}${
- reviewFindingsSplit ? ` (${reviewFindingsSplit.published.length})` : ''
- }`,
- content: <DrawerPublishedTab />,
- },
- singleAgent && {
- key: 'not_posted',
- label: `Not posted${reviewDetail ? ` (${reviewDetail.dropped_findings.length})` : ''}`,
- content: <DrawerNotPostedTab />,
- },
- // A single-agent turn publishes at every urgency, so nothing sits below a threshold.
- !singleAgent && {
- key: 'below_threshold',
- label: `Below threshold${
- reviewFindingsSplit ? ` (${reviewFindingsSplit.belowThreshold.length})` : ''
- }`,
- content: <DrawerBelowThresholdTab />,
- },
- // A single-agent turn has no validator, so there are no dismissals to show.
- !singleAgent && {
- key: 'dismissed',
- label: `Dismissed${reviewDetail ? ` (${reviewDetail.dismissed_findings.length})` : ''}`,
- content: <DrawerDismissedTab />,
- },
- singleAgent
- ? { key: 'how_it_ran', label: 'How it ran', content: <DrawerHowItRanTab /> }
- : { key: 'chunks', label: 'Chunks', content: <DrawerChunksTab /> },
- {
- key: 'review',
- label: 'Review body',
- content: reviewDetail ? (
- reviewDetail.report_markdown ? (
- <LemonMarkdown className="text-sm" disableImages>
- {reviewDetail.report_markdown}
- </LemonMarkdown>
- ) : (
- <div className="text-sm text-secondary">
- No review body was rendered for this pull request.
- </div>
- )
- ) : (
- <LemonSkeleton className="h-40 w-full" />
- ),
- },
- ]}
+ tabs={tabs}
/>
</div>
</LemonDrawer>
diff --git a/products/review_hog/frontend/ReviewModeTag.tsx b/products/review_hog/frontend/ReviewModeTag.tsx
new file mode 100644
index 000000000000..68f080eef1ae
--- /dev/null
+++ b/products/review_hog/frontend/ReviewModeTag.tsx
@@ -0,0 +1,15 @@
+import { LemonTag } from '@posthog/lemon-ui'
+
+import type { ReviewTriggerReviewModeEnumApi } from './generated/api.schemas'
+import { REVIEW_MODE_LABEL } from './reviewDisplay'
+
+export function ReviewModeTag({ mode }: { mode: ReviewTriggerReviewModeEnumApi | null }): JSX.Element | null {
+ if (!mode) {
+ return null
+ }
+ return (
+ <LemonTag type="muted" size="small">
+ {REVIEW_MODE_LABEL[mode]}
+ </LemonTag>
+ )
+}
diff --git a/products/review_hog/frontend/ReviewsFilters.tsx b/products/review_hog/frontend/ReviewsFilters.tsx
new file mode 100644
index 000000000000..22b79c9199d4
--- /dev/null
+++ b/products/review_hog/frontend/ReviewsFilters.tsx
@@ -0,0 +1,94 @@
+import { useActions, useValues } from 'kea'
+
+import { LemonButton, LemonSelect } from '@posthog/lemon-ui'
+
+import { ReviewHogReviewsTableRetrieveReviewMode, ReviewHogReviewsTableRetrieveStatus } from './generated/api.schemas'
+import { REVIEW_MODE_LABEL } from './reviewDisplay'
+import { reviewHogSettingsLogic } from './reviewHogSettingsLogic'
+
+const MODE_OPTIONS = [
+ { value: null, label: 'All modes' },
+ {
+ value: ReviewHogReviewsTableRetrieveReviewMode.Flash,
+ label: REVIEW_MODE_LABEL[ReviewHogReviewsTableRetrieveReviewMode.Flash],
+ },
+ {
+ value: ReviewHogReviewsTableRetrieveReviewMode.Full,
+ label: REVIEW_MODE_LABEL[ReviewHogReviewsTableRetrieveReviewMode.Full],
+ },
+]
+
+const STATUS_OPTIONS = [
+ { value: null, label: 'All statuses' },
+ { value: ReviewHogReviewsTableRetrieveStatus.Running, label: 'Running' },
+ { value: ReviewHogReviewsTableRetrieveStatus.Completed, label: 'Completed' },
+]
+
+const PUBLISHED_OPTIONS = [
+ { value: null, label: 'Posted or not' },
+ { value: true, label: 'Posted' },
+ { value: false, label: 'Not posted' },
+]
+
+export function ReviewsFilters(): JSX.Element {
+ const { reviewsPage, reviewsRepository, reviewsRepositoryOptions, reviewsMode, reviewsStatus, reviewsPublished } =
+ useValues(reviewHogSettingsLogic)
+ const { setReviewsRepository, setReviewsMode, setReviewsStatus, setReviewsPublished } =
+ useActions(reviewHogSettingsLogic)
+
+ const runningCount = reviewsPage?.running_count ?? 0
+ const runningActive = reviewsStatus === ReviewHogReviewsTableRetrieveStatus.Running
+
+ return (
+ <div className="@container/reviews-filters">
+ <div className="grid grid-cols-2 gap-2 @min-[44rem]/reviews-filters:flex @min-[44rem]/reviews-filters:flex-wrap @min-[44rem]/reviews-filters:items-center">
+ {(runningCount > 0 || runningActive) && (
+ <LemonButton
+ type="secondary"
+ size="small"
+ active={runningActive}
+ onClick={() =>
+ setReviewsStatus(runningActive ? null : ReviewHogReviewsTableRetrieveStatus.Running)
+ }
+ tooltip={runningActive ? 'Show every review' : 'Show only running reviews'}
+ data-attr="code-review-reviews-running-filter"
+ >
+ <span>{`Running · ${runningCount}`}</span>
+ </LemonButton>
+ )}
+ <LemonSelect
+ size="small"
+ value={reviewsRepository}
+ onChange={setReviewsRepository}
+ options={[
+ { value: null, label: 'All repositories' },
+ ...reviewsRepositoryOptions.map((repository) => ({ value: repository, label: repository })),
+ ]}
+ className="col-span-2 min-w-0 @min-[44rem]/reviews-filters:min-w-52"
+ data-attr="code-review-reviews-repository-filter"
+ />
+ <LemonSelect
+ size="small"
+ value={reviewsMode}
+ onChange={setReviewsMode}
+ options={MODE_OPTIONS}
+ data-attr="code-review-reviews-mode-filter"
+ />
+ <LemonSelect
+ size="small"
+ value={reviewsStatus}
+ onChange={setReviewsStatus}
+ options={STATUS_OPTIONS}
+ data-attr="code-review-reviews-status-filter"
+ />
+ <LemonSelect
+ size="small"
+ value={reviewsPublished}
+ onChange={setReviewsPublished}
+ options={PUBLISHED_OPTIONS}
+ data-attr="code-review-reviews-posted-filter"
+ />
+ </div>
+ </div>
+ )
+}
diff --git a/products/review_hog/frontend/ReviewsTable.tsx b/products/review_hog/frontend/ReviewsTable.tsx
new file mode 100644
index 000000000000..785773fb29a7
--- /dev/null
+++ b/products/review_hog/frontend/ReviewsTable.tsx
@@ -0,0 +1,224 @@
+import { useActions, useValues } from 'kea'
+
+import { LemonBanner, LemonButton, LemonTable, LemonTag, Link, Spinner } from '@posthog/lemon-ui'
+
+import { TZLabel } from 'lib/components/TZLabel'
+import { LemonTableColumns } from 'lib/lemon-ui/LemonTable'
+
+import { ReviewHogReviewsListScope, type ReviewRecentReviewApi } from './generated/api.schemas'
+import { reviewTitle, runningStageLabel } from './reviewDisplay'
+import { REVIEWS_PAGE_SIZE, reviewHogSettingsLogic } from './reviewHogSettingsLogic'
+import { ReviewModeTag } from './ReviewModeTag'
+
+const COUNT_CHIPS: {
+ key: 'must_fix_count' | 'should_fix_count' | 'consider_count'
+ label: string
+ dot: string
+ text: string
+}[] = [
+ { key: 'must_fix_count', label: 'must fix', dot: 'bg-danger', text: 'text-danger' },
+ { key: 'should_fix_count', label: 'should fix', dot: 'bg-warning', text: 'text-warning' },
+ { key: 'consider_count', label: 'consider', dot: 'bg-border-bold', text: 'text-secondary' },
+]
+
+/** A first review still running has no completed turn: no findings, no posted state, no drawer. */
+function hasCompletedTurn(review: ReviewRecentReviewApi): boolean {
+ return review.run_count > 0
+}
+
+function FindingCounts({ review }: { review: ReviewRecentReviewApi }): JSX.Element {
+ const total = review.must_fix_count + review.should_fix_count + review.consider_count
+ if (total === 0) {
+ return <span className="text-xs text-secondary">No findings</span>
+ }
+ return (
+ <span className="flex items-center gap-2.5 text-xs">
+ {COUNT_CHIPS.filter((chip) => review[chip.key] > 0).map((chip) => (
+ <span key={chip.key} className="flex items-center gap-1 whitespace-nowrap">
+ <span className={`size-1.5 rounded-full ${chip.dot}`} />
+ <span className={`font-semibold tabular-nums ${chip.text}`}>{review[chip.key]}</span>
+ <span className="text-secondary">{chip.label}</span>
+ </span>
+ ))}
+ </span>
+ )
+}
+
+function ReviewStatus({ review }: { review: ReviewRecentReviewApi }): JSX.Element {
+ if (review.in_progress) {
+ return (
+ <span className="flex items-center gap-1.5 whitespace-nowrap text-xs font-medium text-warning">
+ <Spinner className="text-sm" />
+ <span>{runningStageLabel(review)}</span>
+ </span>
+ )
+ }
+ const total = review.must_fix_count + review.should_fix_count + review.consider_count
+ const color = review.must_fix_count > 0 ? 'bg-danger' : total > 0 ? 'bg-warning' : 'bg-success'
+ return <span className={`inline-block size-2 rounded-full ${color}`} />
+}
+
+function ReviewsEmptyState(): JSX.Element {
+ const { reviewsScope, reviewsFiltered } = useValues(reviewHogSettingsLogic)
+ const { setReviewsScope, clearReviewsFilters } = useActions(reviewHogSettingsLogic)
+ if (reviewsFiltered) {
+ return (
+ <div className="flex flex-col items-center gap-2 py-4">
+ <span>No reviews match these filters.</span>
+ <LemonButton type="secondary" size="small" onClick={() => clearReviewsFilters()}>
+ Clear filters
+ </LemonButton>
+ </div>
+ )
+ }
+ if (reviewsScope === ReviewHogReviewsListScope.Mine) {
+ return (
+ <div className="flex flex-col items-center gap-2 py-4">
+ <span>No reviews of your pull requests or reviews you started yet.</span>
+ <LemonButton
+ type="secondary"
+ size="small"
+ onClick={() => setReviewsScope(ReviewHogReviewsListScope.Everyone)}
+ >
+ Show everyone's reviews
+ </LemonButton>
+ </div>
+ )
+ }
+ return <span>No reviews in this project yet. Paste a pull request URL above to start one.</span>
+}
+
+export function ReviewsTable(): JSX.Element {
+ const { reviewsPage, reviewsFailed, reviewsCurrentPage, reviewsScope } = useValues(reviewHogSettingsLogic)
+ const { setReviewsPage, loadReviews, openReviewDetail } = useActions(reviewHogSettingsLogic)
+
+ if (reviewsFailed && !reviewsPage) {
+ return (
+ <LemonBanner
+ type="error"
+ action={{ children: 'Try again', onClick: () => loadReviews() }}
+ data-attr="code-review-reviews-error"
+ >
+ Couldn't load reviews. Try again, and if it keeps failing, refresh the page.
+ </LemonBanner>
+ )
+ }
+
+ const columns: LemonTableColumns<ReviewRecentReviewApi> = [
+ {
+ title: 'Status',
+ key: 'status',
+ width: 0,
+ render: (_, review) => <ReviewStatus review={review} />,
+ },
+ {
+ title: 'Pull request',
+ key: 'pull_request',
+ render: (_, review) => (
+ <div className="flex min-w-0 items-center gap-2">
+ <Link
+ to={review.github_url}
+ target="_blank"
+ className="shrink-0 font-mono text-xs"
+ // The row opens the drawer; the number goes to GitHub instead.
+ onClick={(event) => event.stopPropagation()}
+ >
+ #{review.pr_number ?? review.head_branch}
+ </Link>
+ {hasCompletedTurn(review) ? (
+ // A real button, so keyboard users can open the findings the row click opens.
+ <Link
+ subtle
+ className="block max-w-80 truncate text-left font-semibold"
+ title={reviewTitle(review)}
+ onClick={(event) => {
+ event.stopPropagation()
+ openReviewDetail(review)
+ }}
+ >
+ {reviewTitle(review)}
+ </Link>
+ ) : (
+ <span className="block max-w-80 truncate font-semibold" title={reviewTitle(review)}>
+ {reviewTitle(review)}
+ </span>
+ )}
+ </div>
+ ),
+ },
+ {
+ title: 'Repository',
+ dataIndex: 'repository',
+ render: (_, review) => <span className="whitespace-nowrap font-mono text-xs">{review.repository}</span>,
+ },
+ ...(reviewsScope === ReviewHogReviewsListScope.Everyone
+ ? [
+ {
+ title: 'Author',
+ key: 'author',
+ render: (_: unknown, review: ReviewRecentReviewApi) => (
+ <span className="whitespace-nowrap font-mono text-xs">{review.pr_author}</span>
+ ),
+ },
+ ]
+ : []),
+ {
+ title: 'Mode',
+ key: 'mode',
+ render: (_, review) => <ReviewModeTag mode={review.review_mode} />,
+ },
+ {
+ title: 'Findings',
+ key: 'findings',
+ render: (_, review) => (hasCompletedTurn(review) ? <FindingCounts review={review} /> : null),
+ },
+ {
+ title: 'Posted',
+ key: 'posted',
+ render: (_, review) =>
+ !hasCompletedTurn(review) ? null : review.turn_published ? (
+ <LemonTag type="success" size="small">
+ Posted
+ </LemonTag>
+ ) : (
+ <span className="whitespace-nowrap text-xs text-secondary">Not posted</span>
+ ),
+ },
+ {
+ title: 'Last activity',
+ key: 'last_activity',
+ render: (_, review) =>
+ review.in_progress ? (
+ <span className="text-xs text-secondary">Now</span>
+ ) : review.last_run_at ? (
+ <TZLabel time={review.last_run_at} className="whitespace-nowrap text-xs" />
+ ) : null,
+ },
+ ]
+
+ return (
+ <LemonTable
+ columns={columns}
+ dataSource={reviewsPage?.results ?? []}
+ loading={!reviewsPage}
+ loadingSkeletonRows={5}
+ rowKey="id"
+ onRow={(review) =>
+ hasCompletedTurn(review) ? { onClick: () => openReviewDetail(review), className: 'cursor-pointer' } : {}
+ }
+ pagination={{
+ controlled: true,
+ pageSize: REVIEWS_PAGE_SIZE,
+ currentPage: reviewsCurrentPage,
+ entryCount: reviewsPage?.count ?? 0,
+ onForward: () => setReviewsPage(reviewsCurrentPage + 1),
+ onBackward: () => setReviewsPage(reviewsCurrentPage - 1),
+ // The logic keeps `reviews_page` in the URL; the table's own `page` param would overwrite it.
+ useUrl: false,
+ }}
+ nouns={['review', 'reviews']}
+ emptyState={<ReviewsEmptyState />}
+ data-attr="code-review-reviews-table"
+ />
+ )
+}
diff --git a/products/review_hog/frontend/reviewDisplay.ts b/products/review_hog/frontend/reviewDisplay.ts
new file mode 100644
index 000000000000..69897aa222ca
--- /dev/null
+++ b/products/review_hog/frontend/reviewDisplay.ts
@@ -0,0 +1,44 @@
+import type { ReviewRecentReviewApi, ReviewTriggerReviewModeEnumApi } from './generated/api.schemas'
+
+export const REVIEW_MODE_LABEL: Record<ReviewTriggerReviewModeEnumApi, string> = {
+ flash: 'Standard',
+ full: 'Deep',
+}
+
+export function reviewTitle(
+ review: Pick<ReviewRecentReviewApi, 'pr_title' | 'repository' | 'pr_number' | 'head_branch'>
+): string {
+ return review.pr_title ?? `${review.repository}#${review.pr_number ?? review.head_branch}`
+}
+
+function withCounter(label: string, done: number | null, total: number | null): string {
+ return done !== null && total !== null && total > 0 ? `${label} ${done}/${total}` : label
+}
+
+export function runningStageLabel(review: ReviewRecentReviewApi): string {
+ if (review.resolution?.resolution_status === 'resolving') {
+ return withCounter('Resolving', review.resolution.done, review.resolution.total)
+ }
+ if (!review.progress) {
+ return 'Starting'
+ }
+ const { review_stage, done, total } = review.progress
+ switch (review_stage) {
+ case 'fetching':
+ case 'chunking':
+ case 'single_agent_preparing':
+ return 'Preparing'
+ case 'selecting':
+ return 'Picking perspectives'
+ case 'reviewing':
+ case 'single_agent_reviewing':
+ return withCounter('Reviewing', done, total)
+ case 'deduplicating':
+ return 'Merging findings'
+ case 'validating':
+ return withCounter('Validating', done, total)
+ case 'finalizing':
+ case 'single_agent_finalizing':
+ return 'Finalizing'
+ }
+}
diff --git a/products/review_hog/frontend/reviewHogSettingsLogic.test.ts b/products/review_hog/frontend/reviewHogSettingsLogic.test.ts
index 0a2c5ff8122f..658388f40b91 100644
--- a/products/review_hog/frontend/reviewHogSettingsLogic.test.ts
+++ b/products/review_hog/frontend/reviewHogSettingsLogic.test.ts
@@ -38,6 +38,7 @@ function reviewDetail(id: string, runUrgencyThreshold: string | null): Record<st
// ceiling are reachable.
const everyoneReviews = Array.from({ length: MAX_REVIEWS_LIMIT + REVIEWS_PAGE_SIZE }, (_, i) => ({
id: `r${i}`,
+ repository: 'example-org/example-repo',
in_progress: false,
}))
@@ -55,6 +56,14 @@ describe('reviewHogSettingsLogic', () => {
url.searchParams.get('scope') === ReviewHogReviewsListScope.Everyone ? everyoneReviews : []
return [200, { results: pool.slice(0, limit), has_more: pool.length > limit }]
},
+ '/api/projects/:team_id/review_hog/reviews/table/': ({ request }) => {
+ const url = new URL(request.url)
+ const limit = Number(url.searchParams.get('limit'))
+ const offset = Number(url.searchParams.get('offset'))
+ const pool =
+ url.searchParams.get('scope') === ReviewHogReviewsListScope.Everyone ? everyoneReviews : []
+ return [200, { count: pool.length, running_count: 0, results: pool.slice(offset, offset + limit) }]
+ },
'/api/projects/:team_id/review_hog/reviews/perspective_stats/': () => [
200,
{ report_count: 0, perspectives: [] },
@@ -386,6 +395,64 @@ describe('reviewHogSettingsLogic', () => {
await expectLogic(logic).toMatchValues({ reviewsLimit: REVIEWS_PAGE_SIZE })
})
+ it('a table filter change resets the page and sends the filter with the request', async () => {
+ // Page 2 of every review is rarely a page at all once a filter narrows the set; a kept page
+ // number would land the reader on an empty table.
+ const requests: URLSearchParams[] = []
+ logic.mount()
+ await expectLogic(logic).toDispatchActions([
+ 'loadRecentReviewsSuccess',
+ 'applyDefaultReviewsScope',
+ 'loadRecentReviewsSuccess',
+ ])
+ useMocks({
+ get: {
+ '/api/projects/:team_id/review_hog/reviews/table/': ({ request }) => {
+ requests.push(new URL(request.url).searchParams)
+ return [200, { count: 0, running_count: 0, results: [] }]
+ },
+ },
+ })
+
+ await expectLogic(logic, () => logic.actions.setReviewsPage(2)).toDispatchActions(['loadReviewsSuccess'])
+ expect(requests[requests.length - 1].get('offset')).toBe(String(REVIEWS_PAGE_SIZE))
+
+ await expectLogic(logic, () => logic.actions.setReviewsRepository('example-org/example-repo'))
+ .toDispatchActions(['loadReviewsSuccess'])
+ .toMatchValues({ reviewsCurrentPage: 1 })
+ expect(requests[requests.length - 1].get('offset')).toBe('0')
+ expect(requests[requests.length - 1].get('repository')).toBe('example-org/example-repo')
+ expect(router.values.searchParams.reviews_repository).toBe('example-org/example-repo')
+ expect(router.values.searchParams.reviews_page).toBeUndefined()
+ })
+
+ it('restores table filters and the page from a link without resetting the page', async () => {
+ // Each filter setter resets the page, so an unguarded replay would drop every shared
+ // `reviews_page` back to page 1.
+ router.actions.push(urls.codeReview(), {
+ reviews_scope: 'everyone',
+ reviews_status: 'completed',
+ reviews_published: 'false',
+ reviews_page: '2',
+ })
+ logic.mount()
+ await expectLogic(logic).toDispatchActions(['loadReviewsSuccess']).toMatchValues({
+ reviewsStatus: 'completed',
+ reviewsPublished: false,
+ reviewsCurrentPage: 2,
+ })
+ expect(logic.values.reviews?.[0].id).toBe(`r${REVIEWS_PAGE_SIZE}`)
+ })
+
+ it('flags a failed table load so the table can show its error state', async () => {
+ // A first load that fails must not read as an empty table.
+ logic.mount()
+ useMocks({ get: { '/api/projects/:team_id/review_hog/reviews/table/': () => [500, {}] } })
+
+ await expectLogic(logic, () => logic.actions.setReviewsPage(2)).toDispatchActions(['loadReviewsFailure'])
+ expect(logic.values).toMatchObject({ reviewsPage: null, reviewsFailed: true })
+ })
+
it('buckets drawer findings by the stored run threshold, with the viewer proxy only for old rows', async () => {
// The run gated at must_fix while the viewer's own setting (mocked above) is should_fix.
// Bucketing by the viewer's setting would show the held-back should_fix finding as
diff --git a/products/review_hog/frontend/reviewHogSettingsLogic.ts b/products/review_hog/frontend/reviewHogSettingsLogic.ts
index 8aebe05e3a8e..6da4097fd7ff 100644
--- a/products/review_hog/frontend/reviewHogSettingsLogic.ts
+++ b/products/review_hog/frontend/reviewHogSettingsLogic.ts
@@ -22,6 +22,7 @@ import {
reviewHogReviewsList,
reviewHogReviewsPerspectiveStatsRetrieve,
reviewHogReviewsRetrieve,
+ reviewHogReviewsTableRetrieve,
reviewHogReviewsTriggerCreate,
reviewHogSettingsPartialUpdate,
reviewHogSettingsRetrieve,
@@ -40,12 +41,15 @@ import type {
ReviewRecentReviewApi,
ReviewRecentReviewsPageApi,
ReviewResolutionConfigApi,
+ ReviewReviewsTablePageApi,
ReviewUserSettingsApi,
ReviewValidatorConfigApi,
} from 'products/review_hog/frontend/generated/api.schemas'
import {
ReviewHogReviewsListScope,
ReviewHogReviewsPerspectiveStatsRetrieveScope,
+ ReviewHogReviewsTableRetrieveReviewMode,
+ ReviewHogReviewsTableRetrieveStatus,
ReviewTriggerRequestRunModeEnumApi,
} from 'products/review_hog/frontend/generated/api.schemas'
import { llmSkillsList, llmSkillsNameDuplicateCreate } from 'products/skills/frontend/generated/api'
@@ -280,10 +284,22 @@ export interface reviewHogSettingsLogicValues {
reviewDrawerOpen: boolean
reviewDrawerTab: ReviewDrawerTab
reviewFindingsSplit: ReviewFindingsSplit | null
+ reviews: ReviewRecentReviewApi[] | null
+ reviewsCurrentPage: number
reviewsExpanding: boolean
+ reviewsFailed: boolean
+ reviewsFiltered: boolean
reviewsLimit: number
+ reviewsMode: ReviewHogReviewsTableRetrieveReviewMode | null
+ reviewsPage: ReviewReviewsTablePageApi | null
+ reviewsPageLoading: boolean
+ reviewsPublished: boolean | null
+ reviewsRepository: string | null
+ reviewsRepositoryOptions: string[]
reviewsScope: ReviewHogReviewsListScope
+ reviewsStatus: ReviewHogReviewsTableRetrieveStatus | null
savingSkillNames: string[]
+ seenRepositories: string[]
settings: ReviewUserSettingsApi | null
settingsLoading: boolean
showReviewAuthor: (review: ReviewRecentReviewApi) => boolean
@@ -311,6 +327,9 @@ export interface reviewHogSettingsLogicActions {
chooseAdoptSource: (source: AdoptSource) => {
source: AdoptSource
}
+ clearReviewsFilters: () => {
+ value: true
+ }
closeAdoptSkillModal: () => {
value: true
}
@@ -446,6 +465,21 @@ export interface reviewHogSettingsLogicActions {
reviewDetail: ReviewDetailApi
payload?: string
}
+ loadReviews: (_?: any) => any
+ loadReviewsFailure: (
+ error: string,
+ errorObject?: any
+ ) => {
+ error: string
+ errorObject?: any
+ }
+ loadReviewsSuccess: (
+ reviewsPage: ReviewReviewsTablePageApi,
+ payload?: any
+ ) => {
+ reviewsPage: ReviewReviewsTablePageApi
+ payload?: any
+ }
loadSettings: () => any
loadSettingsFailure: (
error: string,
@@ -531,9 +565,24 @@ export interface reviewHogSettingsLogicActions {
setReviewDrawerTab: (tab: ReviewDrawerTab) => {
tab: ReviewDrawerTab
}
+ setReviewsMode: (mode: ReviewHogReviewsTableRetrieveReviewMode | null) => {
+ mode: ReviewHogReviewsTableRetrieveReviewMode | null
+ }
+ setReviewsPage: (page: number) => {
+ page: number
+ }
+ setReviewsPublished: (published: boolean | null) => {
+ published: boolean | null
+ }
+ setReviewsRepository: (repository: string | null) => {
+ repository: string | null
+ }
setReviewsScope: (scope: ReviewHogReviewsListScope) => {
scope: ReviewHogReviewsListScope
}
+ setReviewsStatus: (status: ReviewHogReviewsTableRetrieveStatus | null) => {
+ status: ReviewHogReviewsTableRetrieveStatus | null
+ }
setSkillSaving: (
skillName: string,
saving: boolean
@@ -637,6 +686,14 @@ export interface reviewHogSettingsLogicMeta {
) => string | null
recentReviews: (recentReviewsPage: ReviewRecentReviewsPageApi | null) => ReviewRecentReviewApi[] | null
moreReviewsAvailable: (recentReviewsPage: ReviewRecentReviewsPageApi | null, reviewsLimit: number) => boolean
+ reviews: (reviewsPage: ReviewReviewsTablePageApi | null) => ReviewRecentReviewApi[] | null
+ reviewsFiltered: (
+ reviewsRepository: string | null,
+ reviewsMode: ReviewHogReviewsTableRetrieveReviewMode | null,
+ reviewsStatus: ReviewHogReviewsTableRetrieveStatus | null,
+ reviewsPublished: boolean | null
+ ) => boolean
+ reviewsRepositoryOptions: (seenRepositories: string[], reviewsRepository: string | null) => string[]
reviewFindingsSplit: (
reviewDetail: ReviewDetailApi | null,
settings: ReviewUserSettingsApi | null
@@ -694,6 +751,12 @@ export const reviewHogSettingsLogic = kea<reviewHogSettingsLogicType>([
setReviewsScope: (scope: ReviewHogReviewsListScope) => ({ scope }),
showMoreReviews: true,
showFewerReviews: true,
+ setReviewsPage: (page: number) => ({ page }),
+ setReviewsRepository: (repository: string | null) => ({ repository }),
+ setReviewsMode: (mode: ReviewHogReviewsTableRetrieveReviewMode | null) => ({ mode }),
+ setReviewsStatus: (status: ReviewHogReviewsTableRetrieveStatus | null) => ({ status }),
+ setReviewsPublished: (published: boolean | null) => ({ published }),
+ clearReviewsFilters: true,
// Auto-select a default scope (Everyone when the user has no reviews of their own)
// without marking it as an explicit user choice, so a later real choice still wins.
applyDefaultReviewsScope: (scope: ReviewHogReviewsListScope) => ({ scope }),
@@ -809,6 +872,28 @@ export const reviewHogSettingsLogic = kea<reviewHogSettingsLogicType>([
},
},
],
+ reviewsPage: [
+ null as ReviewReviewsTablePageApi | null,
+ {
+ // The default param keeps the action zero-arg in the generated logic type.
+ loadReviews: async (_ = null, breakpoint) => {
+ // urlToAction replays each deep-link filter in turn; debounce so only the settled set loads.
+ await breakpoint(1)
+ const response = await reviewHogReviewsTableRetrieve(currentProjectId(), {
+ scope: values.reviewsScope,
+ limit: REVIEWS_PAGE_SIZE,
+ offset: (values.reviewsCurrentPage - 1) * REVIEWS_PAGE_SIZE,
+ ...(values.reviewsRepository ? { repository: values.reviewsRepository } : {}),
+ ...(values.reviewsMode ? { review_mode: values.reviewsMode } : {}),
+ ...(values.reviewsStatus ? { status: values.reviewsStatus } : {}),
+ ...(values.reviewsPublished !== null ? { published: values.reviewsPublished } : {}),
+ })
+ // A filter or page change mid-flight dispatched a newer load — drop this stale response.
+ breakpoint()
+ return response
+ },
+ },
+ ],
reviewDetail: [
null as ReviewDetailApi | null,
{
@@ -1001,6 +1086,80 @@ export const reviewHogSettingsLogic = kea<reviewHogSettingsLogicType>([
loadRecentReviewsFailure: () => false,
},
],
+ reviewsPage: {
+ // Drop rows that no longer match the controls so the table shows loading. Poll refreshes keep them.
+ setReviewsScope: () => null,
+ applyDefaultReviewsScope: () => null,
+ setReviewsPage: () => null,
+ setReviewsRepository: () => null,
+ setReviewsMode: () => null,
+ setReviewsStatus: () => null,
+ setReviewsPublished: () => null,
+ clearReviewsFilters: () => null,
+ },
+ // A failed poll keeps its rows; the table shows the error only when it has none.
+ reviewsFailed: [
+ false,
+ {
+ loadReviews: () => false,
+ loadReviewsSuccess: () => false,
+ loadReviewsFailure: () => true,
+ },
+ ],
+ // A page number rarely exists once the row set narrows, so every scope and filter change resets it.
+ reviewsCurrentPage: [
+ 1,
+ {
+ setReviewsPage: (_, { page }) => page,
+ setReviewsScope: () => 1,
+ applyDefaultReviewsScope: () => 1,
+ setReviewsRepository: () => 1,
+ setReviewsMode: () => 1,
+ setReviewsStatus: () => 1,
+ setReviewsPublished: () => 1,
+ clearReviewsFilters: () => 1,
+ },
+ ],
+ reviewsRepository: [
+ null as string | null,
+ {
+ setReviewsRepository: (_, { repository }) => repository,
+ clearReviewsFilters: () => null,
+ },
+ ],
+ reviewsMode: [
+ null as ReviewHogReviewsTableRetrieveReviewMode | null,
+ {
+ setReviewsMode: (_, { mode }) => mode,
+ clearReviewsFilters: () => null,
+ },
+ ],
+ reviewsStatus: [
+ null as ReviewHogReviewsTableRetrieveStatus | null,
+ {
+ setReviewsStatus: (_, { status }) => status,
+ clearReviewsFilters: () => null,
+ },
+ ],
+ reviewsPublished: [
+ null as boolean | null,
+ {
+ setReviewsPublished: (_, { published }) => published,
+ clearReviewsFilters: () => null,
+ },
+ ],
+ // Kept across filter changes so picking one repository does not empty the other options.
+ seenRepositories: [
+ [] as string[],
+ {
+ loadReviewsSuccess: (state, { reviewsPage }) => {
+ const merged = Array.from(
+ new Set([...state, ...reviewsPage.results.map((review) => review.repository)])
+ ).sort()
+ return merged.length === state.length ? state : merged
+ },
+ },
+ ],
// The "Mine / Everyone" filter on the recent-reviews list: it scopes the list AND every stat
// surface fed by perspectiveStats (proof card, effectiveness cards on the Settings tab).
// Skill lists and their toggles stay per-user regardless.
@@ -1226,6 +1385,28 @@ export const reviewHogSettingsLogic = kea<reviewHogSettingsLogicType>([
// offering it would send a limit the server rejects.
(recentReviewsPage?.has_more ?? false) && reviewsLimit < MAX_REVIEWS_LIMIT,
],
+ reviews: [
+ (s) => [s.reviewsPage],
+ (reviewsPage: ReviewReviewsTablePageApi | null): ReviewRecentReviewApi[] | null =>
+ reviewsPage?.results ?? null,
+ ],
+ reviewsFiltered: [
+ (s) => [s.reviewsRepository, s.reviewsMode, s.reviewsStatus, s.reviewsPublished],
+ (
+ repository: string | null,
+ mode: ReviewHogReviewsTableRetrieveReviewMode | null,
+ status: ReviewHogReviewsTableRetrieveStatus | null,
+ published: boolean | null
+ ): boolean => repository !== null || mode !== null || status !== null || published !== null,
+ ],
+ // The selected repository stays an option even before a page with it has loaded (a deep link).
+ reviewsRepositoryOptions: [
+ (s) => [s.seenRepositories, s.reviewsRepository],
+ (seenRepositories: string[], reviewsRepository: string | null): string[] =>
+ reviewsRepository && !seenRepositories.includes(reviewsRepository)
+ ? [...seenRepositories, reviewsRepository].sort()
+ : seenRepositories,
+ ],
// Splits the detail's valid findings by the threshold the run actually gated on
// (`run_urgency_threshold`, stamped at finalize). Only rows that predate the stamp fall
// back to the viewer's current setting — an approximation that can misbucket when the
@@ -1391,6 +1572,12 @@ export const reviewHogSettingsLogic = kea<reviewHogSettingsLogicType>([
},
showMoreReviews: () => actions.loadRecentReviews(),
showFewerReviews: () => actions.loadRecentReviews(),
+ setReviewsPage: () => actions.loadReviews(),
+ setReviewsRepository: () => actions.loadReviews(),
+ setReviewsMode: () => actions.loadReviews(),
+ setReviewsStatus: () => actions.loadReviews(),
+ setReviewsPublished: () => actions.loadReviews(),
+ clearReviewsFilters: () => actions.loadReviews(),
loadAll: () => {
actions.loadSettings()
actions.loadViewerGithubLogin()
@@ -1637,6 +1824,8 @@ export const reviewHogSettingsLogic = kea<reviewHogSettingsLogicType>([
// does NOT write the URL: hydrating from a link marks the scope as chosen (below), so mirroring
// the fallback would silently upgrade it into a permanent explicit choice on reload.
// The tab mirrors to `?tab=settings` so a link can open the Settings tab; Activity keeps the URL clean.
+ // The table's filters and page mirror to `reviews_*` params the same way, so a filtered view
+ // can be shared too; each default keeps its param out of the URL.
// The drawer mirrors to `?review=<report id>` the same way — a PERMANENT PUBLIC CONTRACT (PR
// status comments bake these links into GitHub, where they are never re-edited). Always
// `replace`, never push, so opening/closing the drawer doesn't stack history entries.
@@ -1649,17 +1838,28 @@ export const reviewHogSettingsLogic = kea<reviewHogSettingsLogicType>([
router.values.hashParams,
{ replace: true },
]
+ const withTableParams = (): [string, Record<string, any>, Record<string, any>, { replace: boolean }] => [
+ router.values.location.pathname,
+ {
+ ...router.values.searchParams,
+ reviews_scope: values.reviewsScope === ReviewHogReviewsListScope.Mine ? undefined : values.reviewsScope,
+ reviews_repository: values.reviewsRepository ?? undefined,
+ reviews_mode: values.reviewsMode ?? undefined,
+ reviews_status: values.reviewsStatus ?? undefined,
+ reviews_published: values.reviewsPublished === null ? undefined : String(values.reviewsPublished),
+ reviews_page: values.reviewsCurrentPage > 1 ? String(values.reviewsCurrentPage) : undefined,
+ },
+ router.values.hashParams,
+ { replace: true },
+ ]
return {
- setReviewsScope: (): [string, Record<string, any>, Record<string, any>, { replace: boolean }] => [
- router.values.location.pathname,
- {
- ...router.values.searchParams,
- reviews_scope:
- values.reviewsScope === ReviewHogReviewsListScope.Mine ? undefined : values.reviewsScope,
- },
- router.values.hashParams,
- { replace: true },
- ],
+ setReviewsScope: withTableParams,
+ setReviewsPage: withTableParams,
+ setReviewsRepository: withTableParams,
+ setReviewsMode: withTableParams,
+ setReviewsStatus: withTableParams,
+ setReviewsPublished: withTableParams,
+ clearReviewsFilters: withTableParams,
setActiveTab: (): [string, Record<string, any>, Record<string, any>, { replace: boolean }] => [
router.values.location.pathname,
{
@@ -1684,6 +1884,38 @@ export const reviewHogSettingsLogic = kea<reviewHogSettingsLogicType>([
) {
actions.setReviewsScope(parsed)
}
+ // Guard each against its current value: every filter setter resets the page, so
+ // replaying an unchanged filter on a deep link would knock the reader back to page 1.
+ // The page goes last for the same reason.
+ const repository =
+ typeof searchParams.reviews_repository === 'string' ? searchParams.reviews_repository : null
+ if (repository !== values.reviewsRepository) {
+ actions.setReviewsRepository(repository)
+ }
+ const mode = Object.values(ReviewHogReviewsTableRetrieveReviewMode).find(
+ (value) => value === searchParams.reviews_mode
+ )
+ if ((mode ?? null) !== values.reviewsMode) {
+ actions.setReviewsMode(mode ?? null)
+ }
+ const status = Object.values(ReviewHogReviewsTableRetrieveStatus).find(
+ (value) => value === searchParams.reviews_status
+ )
+ if ((status ?? null) !== values.reviewsStatus) {
+ actions.setReviewsStatus(status ?? null)
+ }
+ // kea-router parses `true` / `false` into booleans; the string forms cover a hand-edited link.
+ const publishedParam = String(searchParams.reviews_published)
+ const published = publishedParam === 'true' ? true : publishedParam === 'false' ? false : null
+ if (published !== values.reviewsPublished) {
+ actions.setReviewsPublished(published)
+ }
+ // A hand-edited link can carry 0, -1 or Infinity, which would send an offset the API rejects.
+ const pageParam = Number(searchParams.reviews_page ?? 1)
+ const page = Number.isSafeInteger(pageParam) && pageParam > 0 ? pageParam : 1
+ if (page !== values.reviewsCurrentPage) {
+ actions.setReviewsPage(page)
+ }
const tab: CodeReviewTab = searchParams.tab === 'settings' ? 'settings' : 'activity'
if (tab !== values.activeTab) {
actions.setActiveTab(tab)