From 03817dbb1d022961960856deb1396f62c14b6976 Mon Sep 17 00:00:00 2001 From: Codex Agent Date: Wed, 18 Feb 2026 14:12:16 +0000 Subject: [PATCH] Fix project form dropdowns without changing project routes --- apps/web/src/App.tsx | 16 -- .../src/components/project/ProjectForm.tsx | 172 +++++++++++++++--- apps/web/src/pages/CreateWorkspace.tsx | 21 +-- apps/web/tests/unit/app-routes.test.tsx | 74 ++++++++ .../unit/pages/create-workspace.test.tsx | 17 +- apps/web/tests/unit/pages/projects.test.tsx | 26 ++- ...ect-creation-dropdowns-and-navbar-links.md | 6 +- ...18-project-form-dropdown-regression-fix.md | 47 +++++ 8 files changed, 304 insertions(+), 75 deletions(-) create mode 100644 apps/web/tests/unit/app-routes.test.tsx create mode 100644 tasks/backlog/2026-02-18-project-form-dropdown-regression-fix.md diff --git a/apps/web/src/App.tsx b/apps/web/src/App.tsx index 7982ff3..c2f4c0d 100644 --- a/apps/web/src/App.tsx +++ b/apps/web/src/App.tsx @@ -33,14 +33,6 @@ export default function App() { } /> - - - - } - /> } /> - - - - } - /> >([]); + const [branchesLoading, setBranchesLoading] = useState(false); + const [branchesError, setBranchesError] = useState(null); const [error, setError] = useState(null); const isEditMode = mode === 'edit'; + const fetchBranches = useCallback(async (repository: string, installationId: string) => { + setBranchesLoading(true); + setBranches([]); + setBranchesError(null); + + try { + const result = await listBranches(repository, installationId || undefined); + setBranches(result); + + if (result.length === 0) { + setBranches([{ name: 'main' }, { name: 'master' }]); + setBranchesError('Could not fetch branches, showing common defaults'); + } + } catch { + setBranches([{ name: 'main' }, { name: 'master' }, { name: 'develop' }]); + setBranchesError('Unable to fetch branches. Common branch names provided.'); + } finally { + setBranchesLoading(false); + } + }, []); + const handleChange = (field: keyof ProjectFormValues, value: string) => { setValues((current) => ({ ...current, [field]: value })); }; + const handleRepositoryChange = (value: string) => { + setBranches([]); + setBranchesError(null); + handleChange('repository', value); + }; + + const handleRepoSelect = useCallback( + (repo: { fullName: string; defaultBranch: string } | null) => { + if (!repo) { + setBranches([]); + setBranchesError(null); + return; + } + + setValues((current) => ({ ...current, defaultBranch: repo.defaultBranch })); + void fetchBranches(repo.fullName, values.installationId); + }, + [fetchBranches, values.installationId] + ); + + const handleInstallationChange = (installationId: string) => { + handleChange('installationId', installationId); + + if (isEditMode) { + return; + } + + const normalizedRepository = normalizeRepository(values.repository); + if (!normalizedRepository || !normalizedRepository.includes('/')) { + setBranches([]); + setBranchesError(null); + return; + } + + void fetchBranches(normalizedRepository, installationId); + }; + const handleSubmit = async (event: FormEvent) => { event.preventDefault(); setError(null); @@ -79,11 +154,21 @@ export function ProjectForm({ name: values.name.trim(), description: values.description.trim(), installationId: values.installationId, - repository: values.repository.trim(), + repository: normalizeRepository(values.repository), defaultBranch: values.defaultBranch.trim(), }); }; + const selectStyle = { + width: '100%', + borderRadius: 'var(--sam-radius-md)', + border: '1px solid var(--sam-color-border-default)', + background: 'var(--sam-color-bg-surface)', + color: 'var(--sam-color-fg-primary)', + padding: '0.625rem 0.75rem', + minHeight: '2.75rem', + }; + return (
-