: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(wizard): use a searchable repository dropdown (#97741)
Fernando Gomese286aa191efe
diff --git a/frontend/src/lib/integrations/GitHubRepositoryCombobox.test.tsx b/frontend/src/lib/integrations/GitHubRepositoryCombobox.test.tsxnew file mode 100644index 000000000000..c5a42b4cd922--- /dev/null+++ b/frontend/src/lib/integrations/GitHubRepositoryCombobox.test.tsx@@ -0,0 +1,96 @@+import '@testing-library/jest-dom'++import { cleanup, render, screen } from '@testing-library/react'+import userEvent from '@testing-library/user-event'+import { Provider } from 'kea'++import { useMocks } from '~/mocks/jest'+import { initKeaTests } from '~/test/init'++import { GitHubRepositoryCombobox } from './GitHubRepositoryCombobox'++describe('GitHubRepositoryCombobox', () => {+ let hasMore: boolean+ let requests: number++ beforeEach(() => {+ hasMore = false+ requests = 0+ useMocks({+ get: {+ '/api/environments/:team_id/integrations/:id/github_repos': () => {+ const firstPage = requests++ === 0+ return [+ 200,+ {+ repositories: [+ {+ id: firstPage ? 1 : 2,+ name: firstPage ? 'archived' : 'active',+ full_name: firstPage ? 'example-org/archived' : 'example-org/active',+ archived: firstPage,+ },+ ],+ has_more: firstPage && hasMore,+ },+ ]+ },+ },+ })+ initKeaTests()+ })++ afterEach(cleanup)++ function renderFilteredPicker(onChange = jest.fn()): void {+ render(+ <Provider>+ <GitHubRepositoryCombobox+ integrationId={123}+ value=""+ onChange={onChange}+ repositoryFilter={(repo) => !repo.archived}+ />+ </Provider>+ )+ }++ it.each([+ { more: false, message: 'No repositories found.' },+ { more: true, message: 'No available repositories in these results. Load more to keep looking.' },+ ])('describes empty filtered results with hasMore=$more', async ({ more, message }) => {+ hasMore = more+ renderFilteredPicker()+ await userEvent.click(screen.getByRole('combobox'))+ expect(await screen.findByText(message)).toBeVisible()+ expect(!!screen.queryByText('Load more')).toBe(more)+ })++ it('can select an available repository after loading past an archived-only page', async () => {+ hasMore = true+ const onChange = jest.fn()+ renderFilteredPicker(onChange)+ await userEvent.click(screen.getByRole('combobox'))+ await userEvent.click(await screen.findByText('Load more'))+ await userEvent.click(await screen.findByText('example-org/active'))+ expect(onChange).toHaveBeenCalledWith('example-org/active')+ })++ it('disables the trigger and exposes its explanation', async () => {+ render(+ <Provider>+ <GitHubRepositoryCombobox+ integrationId={123}+ value="example-org/active"+ onChange={jest.fn()}+ disabledReason="A cloud run is starting."+ />+ </Provider>+ )+ expect(screen.getByRole('combobox')).toHaveAttribute('aria-disabled', 'true')+ expect(screen.getByRole('combobox')).toHaveAccessibleDescription('A cloud run is starting.')+ expect(screen.getByRole('status')).toHaveTextContent('A cloud run is starting.')+ await userEvent.click(screen.getByRole('combobox'))+ expect(screen.getByRole('combobox')).toHaveAttribute('aria-expanded', 'false')+ })+})diff --git a/frontend/src/lib/integrations/GitHubRepositoryCombobox.tsx b/frontend/src/lib/integrations/GitHubRepositoryCombobox.tsxindex 4a1a4b2fb18f..d047326d96e8 100644--- a/frontend/src/lib/integrations/GitHubRepositoryCombobox.tsx+++ b/frontend/src/lib/integrations/GitHubRepositoryCombobox.tsx@@ -1,5 +1,5 @@import { useActions, useValues } from 'kea'-import { useRef, useState } from 'react'+import { useId, useRef, useState } from 'react'import { IconGithub } from '@posthog/icons'import {@@ -12,6 +12,8 @@ import {ComboboxTrigger,} from '@posthog/quill'+import type { GitHubRepoApi } from 'products/integrations/frontend/generated/api.schemas'+import { ComboboxLoadMoreFooter, ComboboxSearchField } from './ComboboxSearchChrome'import { githubRepositorySearchLogic } from './githubRepositorySearchLogic'@@ -21,9 +23,12 @@ export interface GitHubRepositoryComboboxProps {value: stringonChange: (value: string | null) => voiddisabled?: boolean+ disabledReason?: stringplaceholder?: string/** When true, prepends a "— No repository —" item so users can explicitly clear the selection. */showNoneOption?: boolean+ repositoryFilter?: (repository: GitHubRepoApi) => boolean+ fullWidth?: boolean}/**@@ -39,40 +44,27 @@ export function GitHubRepositoryCombobox({value,onChange,disabled = false,+ disabledReason,placeholder = 'Select repository...',showNoneOption = false,+ repositoryFilter,+ fullWidth = false,}: GitHubRepositoryComboboxProps): JSX.Element {const logic = githubRepositorySearchLogic({ id: integrationId })- const { repositoryNames, loading, hasMore, searchQuery, error } = useValues(logic)+ const { repositories, loading, hasMore, searchQuery, error } = useValues(logic)+ const repositoryNames = (repositoryFilter ? repositories.filter(repositoryFilter) : repositories).map(+ (repo) => repo.full_name+ )const { setSearchQuery, loadMore, refresh } = useActions(logic)const triggerRef = useRef<HTMLButtonElement>(null)+ const disabledReasonId = useId()+ const isDisabled = disabled || !!disabledReasonconst [open, setOpen] = useState(false)const trimmedSearchQuery = searchQuery.trim()- // While the popover is open we surface loading inline in the list; closed-and-loading shows a disabled- // button so the trigger never flickers an empty selection.+ // Keep the selected target visible while searching, loading, or refreshing.const showInlineLoadingState = open && loading- // Distinguish "this account genuinely has no repos" from "the search/refresh just hasn't returned yet".- const hasActiveSearchContext = open || trimmedSearchQuery.length > 0-- if (loading && !showInlineLoadingState && repositoryNames.length === 0) {- return (- <Button variant="outline" size="sm" disabled>- <IconGithub className="shrink-0" />- Loading repos...- </Button>- )- }-- if (repositoryNames.length === 0 && !showInlineLoadingState && !hasActiveSearchContext && !error) {- return (- <Button variant="outline" size="sm" disabled>- <IconGithub className="shrink-0" />- No GitHub repos- </Button>- )- }const items = showNoneOption ? [NONE_SENTINEL, ...repositoryNames] : repositoryNames@@ -95,11 +87,19 @@ export function GitHubRepositoryCombobox({}}inputValue={searchQuery}onInputValueChange={(next: string) => setSearchQuery(next)}- disabled={disabled}+ disabled={isDisabled}><ComboboxTriggerrender={- <Button ref={triggerRef} variant="outline" size="sm" disabled={disabled} aria-label="Repository">+ <Button+ ref={triggerRef}+ variant="outline"+ size="sm"+ disabled={isDisabled}+ aria-label="Repository"+ aria-describedby={disabledReason ? disabledReasonId : undefined}+ className={fullWidth ? 'min-h-10 w-full justify-start' : undefined}+ ><IconGithub className="shrink-0" /><span className="min-w-0 truncate">{value || placeholder}</span></Button>@@ -109,11 +109,16 @@ export function GitHubRepositoryCombobox({<ComboboxSearchFielditemsLabel="repositories"loading={loading}- disabled={disabled}+ disabled={isDisabled}onRefresh={refresh}/><ComboboxEmpty>- {showInlineLoadingState ? 'Loading repositories...' : (error ?? 'No repositories found.')}+ {showInlineLoadingState+ ? 'Loading repositories...'+ : (error ??+ (hasMore+ ? 'No available repositories in these results. Load more to keep looking.'+ : 'No repositories found.'))}</ComboboxEmpty><ComboboxList>{(repo: string) =>@@ -123,7 +128,7 @@ export function GitHubRepositoryCombobox({</ComboboxItem>) : (<ComboboxItem key={repo} value={repo}>- {repo}+ <span className="min-w-0 break-all">{repo}</span></ComboboxItem>)}@@ -139,6 +144,11 @@ export function GitHubRepositoryCombobox({/>)}</ComboboxContent>+ {disabledReason && (+ <p id={disabledReasonId} className="mb-0 mt-1 text-xs text-muted" role="status">+ {disabledReason}+ </p>+ )}</Combobox>)}diff --git a/products/wizard/frontend/library/WizardRepositoryPicker.test.ts b/products/wizard/frontend/library/WizardRepositoryPicker.test.tsnew file mode 100644index 000000000000..c0b543722c9f--- /dev/null+++ b/products/wizard/frontend/library/WizardRepositoryPicker.test.ts@@ -0,0 +1,18 @@+import { isWizardRepositoryEligible } from './WizardRepositoryPicker'++describe('isWizardRepositoryEligible', () => {+ it.each([+ { archived: false, can_push: false, expected: true },+ { archived: true, can_push: true, expected: false },+ ])('returns $expected for archived=$archived and can_push=$can_push', ({ archived, can_push, expected }) => {+ expect(+ isWizardRepositoryEligible({+ id: 1,+ name: 'posthog',+ full_name: 'PostHog/posthog',+ archived,+ can_push,+ })+ ).toBe(expected)+ })+})diff --git a/products/wizard/frontend/library/WizardRepositoryPicker.tsx b/products/wizard/frontend/library/WizardRepositoryPicker.tsxindex f45fbf8a629c..1acb75b2f284 100644--- a/products/wizard/frontend/library/WizardRepositoryPicker.tsx+++ b/products/wizard/frontend/library/WizardRepositoryPicker.tsx@@ -1,9 +1,10 @@-import { useActions, useValues } from 'kea'+import { GitHubRepositoryCombobox } from 'lib/integrations/GitHubRepositoryCombobox'-import { IconCheck, IconRefresh, IconSearch } from '@posthog/icons'-import { LemonBanner, LemonButton, LemonInput, LemonSkeleton, Spinner } from '@posthog/lemon-ui'+import type { GitHubRepoApi } from 'products/integrations/frontend/generated/api.schemas'-import { githubRepositorySearchLogic } from 'lib/integrations/githubRepositorySearchLogic'+export function isWizardRepositoryEligible(repository: GitHubRepoApi): boolean {+ return !repository.archived+}export function WizardRepositoryPicker({integrationId,@@ -16,66 +17,15 @@ export function WizardRepositoryPicker({onChange: (repository: string) => voiddisabledReason?: string}): JSX.Element {- const logic = githubRepositorySearchLogic({ id: integrationId })- const { repositories, loading, hasMore, searchQuery, error } = useValues(logic)- const { setSearchQuery, loadMore, refresh } = useActions(logic)-- // Archived and read-only repositories cannot receive the run's pull request.- const eligible = repositories.filter((repository) => !repository.archived && repository.can_push !== false)-return (- <div className="flex flex-col gap-1">- <LemonInput- value={searchQuery}- onChange={setSearchQuery}- prefix={<IconSearch />}- placeholder="Search repositories"- fullWidth- data-attr="wizard-cloud-repository-search"- />- {error ? (- <LemonBanner type="error" action={{ children: 'Try again', onClick: refresh }}>- {error}- </LemonBanner>- ) : loading && repositories.length === 0 ? (- <LemonSkeleton repeat={3} className="h-10 w-full" />- ) : (- <div className="max-h-44 overflow-y-auto rounded border border-primary">- {eligible.length === 0 ? (- <p className="m-0 px-3 py-2 text-sm text-muted">- {searchQuery ? 'No matching repositories.' : 'No repositories available.'}- </p>- ) : (- eligible.map((repository) => (- <LemonButton- key={repository.id}- onClick={() => onChange(repository.full_name)}- active={repository.full_name === value}- disabledReason={disabledReason}- fullWidth- icon={repository.full_name === value ? <IconCheck /> : undefined}- className="justify-start"- data-attr="wizard-cloud-repository-option"- >- {repository.full_name}- </LemonButton>- ))- )}- </div>- )}- <div className="flex items-center gap-2">- {hasMore && !error && (- <LemonButton size="small" onClick={loadMore} loading={loading} disabledReason={disabledReason}>- Load more- </LemonButton>- )}- {hasMore && !error && !loading && (- <LemonButton size="small" icon={<IconRefresh />} onClick={refresh} disabledReason={disabledReason}>- Refresh- </LemonButton>- )}- {loading && repositories.length > 0 && <Spinner className="size-4" />}- </div>- </div>+ <GitHubRepositoryCombobox+ integrationId={integrationId}+ value={value}+ onChange={(repository) => onChange(repository ?? '')}+ disabledReason={disabledReason}+ repositoryFilter={isWizardRepositoryEligible}+ placeholder="Select a repository"+ fullWidth+ />)}