mirror of
https://github.com/Sea-Haven-Industries/open-swe.git
synced 2026-10-07 08:09:07 +00:00
fix: Reset branch query param when switching repositories (#519)
* Apply patch * Apply patch * Apply patch * Apply patch * Apply patch * fix: clear branch when switching repos to set correct default branch * fix branch selector logic --------- Co-authored-by: open-swe[bot] <open-swe@users.noreply.github.com> Co-authored-by: Dylan Boudro <121908331+starmorph@users.noreply.github.com> Co-authored-by: starmorph <dylan@starmorph.com> Co-authored-by: Brace Sproul <braceasproul@gmail.com>
This commit is contained in:
parent
bd9e1969b3
commit
576d2553e3
3 changed files with 15 additions and 23 deletions
|
|
@ -90,7 +90,7 @@ export function BranchSelector({
|
||||||
}
|
}
|
||||||
setSelectedBranch(findDefaultBranch(branches, defaultBranch));
|
setSelectedBranch(findDefaultBranch(branches, defaultBranch));
|
||||||
});
|
});
|
||||||
} else if (!selectedBranch || !currentBranchExists) {
|
} else if (!selectedBranch) {
|
||||||
setSelectedBranch(findDefaultBranch(branches, defaultBranch));
|
setSelectedBranch(findDefaultBranch(branches, defaultBranch));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -99,7 +99,6 @@ export function BranchSelector({
|
||||||
selectedRepository?.repo,
|
selectedRepository?.repo,
|
||||||
branchesLoading,
|
branchesLoading,
|
||||||
branchesError,
|
branchesError,
|
||||||
branches.length,
|
|
||||||
selectedBranch,
|
selectedBranch,
|
||||||
setSelectedBranch,
|
setSelectedBranch,
|
||||||
defaultBranch,
|
defaultBranch,
|
||||||
|
|
|
||||||
|
|
@ -164,9 +164,9 @@ export function useGitHubApp(): UseGitHubAppReturn {
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (selectedRepository && !branchesLoading) {
|
if (selectedRepository && !branchesLoading) {
|
||||||
fetchBranches();
|
setBranches([]);
|
||||||
// Reset branch pagination when repository changes
|
|
||||||
setBranchesPage(1);
|
setBranchesPage(1);
|
||||||
|
fetchBranches();
|
||||||
} else if (!selectedRepository) {
|
} else if (!selectedRepository) {
|
||||||
setBranches([]);
|
setBranches([]);
|
||||||
setSelectedBranchParam(null);
|
setSelectedBranchParam(null);
|
||||||
|
|
@ -181,12 +181,10 @@ export function useGitHubApp(): UseGitHubAppReturn {
|
||||||
// Persist to localStorage whenever repository is selected
|
// Persist to localStorage whenever repository is selected
|
||||||
saveRepositoryToLocalStorage(repo);
|
saveRepositoryToLocalStorage(repo);
|
||||||
|
|
||||||
if (!repo) {
|
setSelectedBranchParam(null);
|
||||||
setSelectedBranchParam(null);
|
setBranches([]);
|
||||||
setBranches([]);
|
setBranchesPage(1);
|
||||||
setBranchesPage(1);
|
setBranchesHasMore(false);
|
||||||
setBranchesHasMore(false);
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
[setSelectedRepositoryParam, setSelectedBranchParam],
|
[setSelectedRepositoryParam, setSelectedBranchParam],
|
||||||
);
|
);
|
||||||
|
|
@ -314,7 +312,6 @@ export function useGitHubApp(): UseGitHubAppReturn {
|
||||||
);
|
);
|
||||||
|
|
||||||
if (branch) {
|
if (branch) {
|
||||||
// Add the found branch to the existing branches list if it's not already there
|
|
||||||
setBranches((prev) => {
|
setBranches((prev) => {
|
||||||
const exists = prev.some((b) => b.name === branch.name);
|
const exists = prev.some((b) => b.name === branch.name);
|
||||||
if (!exists) {
|
if (!exists) {
|
||||||
|
|
@ -354,15 +351,12 @@ export function useGitHubApp(): UseGitHubAppReturn {
|
||||||
hasCheckedLocalStorageRef.current = false;
|
hasCheckedLocalStorageRef.current = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update the previous installation ID reference
|
|
||||||
previousInstallationIdRef.current = currentInstallationId;
|
previousInstallationIdRef.current = currentInstallationId;
|
||||||
|
|
||||||
// Fetch repositories for the current installation
|
|
||||||
checkInstallation();
|
checkInstallation();
|
||||||
}
|
}
|
||||||
}, [currentInstallationId]);
|
}, [currentInstallationId]);
|
||||||
|
|
||||||
// Check localStorage for previously selected repository
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (
|
if (
|
||||||
!hasCheckedLocalStorageRef.current &&
|
!hasCheckedLocalStorageRef.current &&
|
||||||
|
|
@ -432,13 +426,13 @@ export function useGitHubApp(): UseGitHubAppReturn {
|
||||||
// Auto-select first repository on initial page load
|
// Auto-select first repository on initial page load
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (
|
if (
|
||||||
!hasAutoSelectedRef.current && // Haven't auto-selected yet
|
!hasAutoSelectedRef.current &&
|
||||||
!selectedRepository && // No repo currently selected
|
!selectedRepository &&
|
||||||
!isLoading && // Not loading repositories
|
!isLoading &&
|
||||||
!error && // No error occurred
|
!error &&
|
||||||
isInstalled === true && // GitHub App is installed
|
isInstalled === true &&
|
||||||
repositories.length > 0 && // Repositories are available
|
repositories.length > 0 &&
|
||||||
hasCheckedLocalStorageRef.current // Only after localStorage check is complete
|
hasCheckedLocalStorageRef.current
|
||||||
) {
|
) {
|
||||||
const firstRepo = repositories[0];
|
const firstRepo = repositories[0];
|
||||||
const targetRepo = {
|
const targetRepo = {
|
||||||
|
|
|
||||||
|
|
@ -105,8 +105,7 @@ export async function getRepositoryBranches(
|
||||||
const defaultBranchData = branches[defaultBranchIndex];
|
const defaultBranchData = branches[defaultBranchIndex];
|
||||||
branches.splice(defaultBranchIndex, 1);
|
branches.splice(defaultBranchIndex, 1);
|
||||||
branches.unshift(defaultBranchData);
|
branches.unshift(defaultBranchData);
|
||||||
} else {
|
} else if (defaultBranchIndex === -1) {
|
||||||
// Need to fetch default branch
|
|
||||||
const defaultBranchResponse = await fetch(
|
const defaultBranchResponse = await fetch(
|
||||||
`${getBaseApiUrl()}github/proxy/repos/${owner}/${repo}/branches/${defaultBranch}`,
|
`${getBaseApiUrl()}github/proxy/repos/${owner}/${repo}/branches/${defaultBranch}`,
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue