Add extension point to branches overview (#1888)

Prepare branches overview to show additional branch details.

Co-authored-by: René Pfeuffer <rene.pfeuffer@cloudogu.com>
This commit is contained in:
Eduard Heimbuch
2021-12-10 11:04:59 +01:00
committed by GitHub
parent b2d7ed88e4
commit b8d6c219ee
21 changed files with 249 additions and 78 deletions

View File

@@ -26,7 +26,7 @@ import {
BranchCollection,
BranchCreation,
BranchDetailsCollection,
Link,
Link, NamespaceAndName,
Repository
} from "@scm-manager/ui-types";
import { requiredLink } from "./links";
@@ -61,13 +61,6 @@ export const useBranch = (repository: Repository, name: string): ApiResultWithFe
);
};
export const useBranchDetails = (repository: Repository, branch: string) => {
const link = requiredLink(repository, "branchDetails");
return useQuery<Branch, Error>(branchQueryKey(repository, branch, "details"), () =>
apiClient.get(concat(link, encodeURIComponent(branch))).then(response => response.json())
);
};
function chunkBranches(branches: Branch[]) {
const chunks: Branch[][] = [];
const chunkSize = 5;
@@ -84,6 +77,20 @@ function chunkBranches(branches: Branch[]) {
return chunks;
}
const branchDetailsQueryKey = (
repository: NamespaceAndName,
branch: string | undefined = undefined,
...values: unknown[]
) => {
let branchName;
if (!branch) {
branchName = "_";
} else {
branchName = branch;
}
return [...repoQueryKey(repository), "branch-details", branchName, ...values];
};
export const useBranchDetailsCollection = (repository: Repository, branches: Branch[]) => {
const link = requiredLink(repository, "branchDetailsCollection");
const chunks = chunkBranches(branches);
@@ -93,7 +100,7 @@ export const useBranchDetailsCollection = (repository: Repository, branches: Bra
Error,
BranchDetailsCollection
>(
branchQueryKey(repository, "details"),
branchDetailsQueryKey(repository),
({ pageParam = 0 }) => {
const encodedBranches = chunks[pageParam]?.map(b => encodeURIComponent(b.name)).join("&branches=");
return apiClient.get(concat(link, `?branches=${encodedBranches}`)).then(response => response.json());