Do not fail without default branch

This selects the first branch, if no default
branch is present.

Committed-by: Eduard Heimbuch <eduard.heimbuch@cloudogu.com>
Co-authored-by: Eduard Heimbuch <eduard.heimbuch@cloudogu.com>
Co-authored-by: René Pfeuffer <rene.pfeuffer@cloudogu.com>
This commit is contained in:
Rene Pfeuffer
2023-04-03 08:14:23 +02:00
committed by SCM-Manager
parent d4e03c6f70
commit e679dac94d
2 changed files with 7 additions and 2 deletions

View File

@@ -0,0 +1,3 @@
- type: fixed
description: Error in frontend without 'default' branch in hg repositories

View File

@@ -63,8 +63,10 @@ const Sources: FC<Props> = ({ repository, branches, selectedBranch, baseUrl }) =
// redirect to default branch if no branch selected
useEffect(() => {
if (branches && branches.length > 0 && !selectedBranch) {
const defaultBranch = branches?.filter(b => b.defaultBranch === true)[0];
history.replace(`${baseUrl}/sources/${encodeURIComponent(defaultBranch.name)}/`);
const defaultBranch = branches?.filter((b) => b.defaultBranch === true)[0];
history.replace(
`${baseUrl}/sources/${defaultBranch ? encodeURIComponent(defaultBranch.name) : encodeURIComponent(branches[0].name)}/`
);
}
}, [branches, selectedBranch, history, baseUrl]);
const { isLoading, error, data: file, isFetchingNextPage, fetchNextPage } = useSources(repository, {