mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-08 06:25:45 +01:00
Resolved branch revision in Source Extension Point (#1803)
This adds the "resolved revision" of the HEAD (of the current branch, if branches are supported) to the extension point repos.sources.extensions. This "resolved revision" holds the current HEAD revision of the repository (or the selected branch, if branches are supported). This means you can check, whether the release has changed since an extension has been rendered for the first time. Co-authored-by: Konstantin Schaper <konstantin.schaper@cloudogu.com>
This commit is contained in:
@@ -24,16 +24,21 @@
|
||||
import { AnnotatedSource, File, Link, Repository } from "@scm-manager/ui-types";
|
||||
import { useQuery } from "react-query";
|
||||
import { apiClient } from "./apiclient";
|
||||
import { ApiResult } from "./base";
|
||||
import { ApiResultWithFetching } from "./base";
|
||||
import { repoQueryKey } from "./keys";
|
||||
|
||||
export const useAnnotations = (repository: Repository, revision: string, file: File): ApiResult<AnnotatedSource> => {
|
||||
const { isLoading, error, data } = useQuery<AnnotatedSource, Error>(
|
||||
export const useAnnotations = (
|
||||
repository: Repository,
|
||||
revision: string,
|
||||
file: File
|
||||
): ApiResultWithFetching<AnnotatedSource> => {
|
||||
const { isLoading, isFetching, error, data } = useQuery<AnnotatedSource, Error>(
|
||||
repoQueryKey(repository, "annotations", revision, file.path),
|
||||
() => apiClient.get((file._links.annotate as Link).href).then((response) => response.json())
|
||||
);
|
||||
return {
|
||||
isLoading,
|
||||
isFetching,
|
||||
error,
|
||||
data,
|
||||
};
|
||||
|
||||
@@ -34,6 +34,11 @@ export type ApiResult<T> = {
|
||||
error: Error | null;
|
||||
data?: T;
|
||||
};
|
||||
|
||||
export type ApiResultWithFetching<T> = ApiResult<T> & {
|
||||
isFetching: boolean;
|
||||
};
|
||||
|
||||
export type DeleteFunction<T> = (entity: T) => void;
|
||||
|
||||
export const useIndex = (): ApiResult<IndexResources> => {
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
import { Branch, BranchCollection, BranchCreation, Link, Repository } from "@scm-manager/ui-types";
|
||||
import { requiredLink } from "./links";
|
||||
import { useMutation, useQuery, useQueryClient } from "react-query";
|
||||
import { ApiResult } from "./base";
|
||||
import { ApiResult, ApiResultWithFetching } from "./base";
|
||||
import { branchQueryKey, repoQueryKey } from "./keys";
|
||||
import { apiClient } from "./apiclient";
|
||||
import { concat } from "./urls";
|
||||
@@ -40,7 +40,7 @@ export const useBranches = (repository: Repository): ApiResult<BranchCollection>
|
||||
);
|
||||
};
|
||||
|
||||
export const useBranch = (repository: Repository, name: string): ApiResult<Branch> => {
|
||||
export const useBranch = (repository: Repository, name: string): ApiResultWithFetching<Branch> => {
|
||||
const link = requiredLink(repository, "branches");
|
||||
return useQuery<Branch, Error>(branchQueryKey(repository, name), () =>
|
||||
apiClient.get(concat(link, encodeURIComponent(name))).then((response) => response.json())
|
||||
|
||||
@@ -25,7 +25,7 @@ import { Branch, Changeset, ChangesetCollection, NamespaceAndName, Repository }
|
||||
import { useQuery, useQueryClient } from "react-query";
|
||||
import { requiredLink } from "./links";
|
||||
import { apiClient } from "./apiclient";
|
||||
import { ApiResult } from "./base";
|
||||
import { ApiResult, ApiResultWithFetching } from "./base";
|
||||
import { branchQueryKey, repoQueryKey } from "./keys";
|
||||
import { concat } from "./urls";
|
||||
|
||||
@@ -42,7 +42,7 @@ export const changesetQueryKey = (repository: NamespaceAndName, id: string) => {
|
||||
export const useChangesets = (
|
||||
repository: Repository,
|
||||
request?: UseChangesetsRequest
|
||||
): ApiResult<ChangesetCollection> => {
|
||||
): ApiResultWithFetching<ChangesetCollection> => {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
let link: string;
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
*/
|
||||
import { apiClient } from "./apiclient";
|
||||
import { useQuery } from "react-query";
|
||||
import { ApiResult } from "./base";
|
||||
import { ApiResultWithFetching } from "./base";
|
||||
|
||||
export type ContentType = {
|
||||
type: string;
|
||||
@@ -39,10 +39,13 @@ function getContentType(url: string): Promise<ContentType> {
|
||||
});
|
||||
}
|
||||
|
||||
export const useContentType = (url: string): ApiResult<ContentType> => {
|
||||
const { isLoading, error, data } = useQuery<ContentType, Error>(["contentType", url], () => getContentType(url));
|
||||
export const useContentType = (url: string): ApiResultWithFetching<ContentType> => {
|
||||
const { isLoading, isFetching, error, data } = useQuery<ContentType, Error>(["contentType", url], () =>
|
||||
getContentType(url)
|
||||
);
|
||||
return {
|
||||
isLoading,
|
||||
isFetching,
|
||||
error,
|
||||
data,
|
||||
};
|
||||
|
||||
@@ -34,7 +34,7 @@ import {
|
||||
} from "@scm-manager/ui-types";
|
||||
import { useMutation, useQuery, useQueryClient } from "react-query";
|
||||
import { apiClient } from "./apiclient";
|
||||
import { ApiResult, useIndexJsonResource, useRequiredIndexLink } from "./base";
|
||||
import { ApiResult, ApiResultWithFetching, useIndexJsonResource, useRequiredIndexLink } from "./base";
|
||||
import { createQueryString } from "./utils";
|
||||
import { objectLink, requiredLink } from "./links";
|
||||
import { repoQueryKey } from "./keys";
|
||||
@@ -253,10 +253,10 @@ export const useRunHealthCheck = () => {
|
||||
};
|
||||
};
|
||||
|
||||
export const useExportInfo = (repository: Repository): ApiResult<ExportInfo> => {
|
||||
export const useExportInfo = (repository: Repository): ApiResultWithFetching<ExportInfo> => {
|
||||
const link = requiredLink(repository, "exportInfo");
|
||||
//TODO Refetch while exporting to update the page
|
||||
const { isLoading, error, data } = useQuery<ExportInfo, Error>(
|
||||
const { isLoading, isFetching, error, data } = useQuery<ExportInfo, Error>(
|
||||
["repository", repository.namespace, repository.name, "exportInfo"],
|
||||
() => apiClient.get(link).then((response) => response.json()),
|
||||
{}
|
||||
@@ -264,6 +264,7 @@ export const useExportInfo = (repository: Repository): ApiResult<ExportInfo> =>
|
||||
|
||||
return {
|
||||
isLoading,
|
||||
isFetching,
|
||||
error: error instanceof NotFoundError ? null : error,
|
||||
data,
|
||||
};
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
import { ApiResult, useIndexJsonResource, useIndexLinks } from "./base";
|
||||
import { ApiResult, ApiResultWithFetching, useIndexJsonResource, useIndexLinks } from "./base";
|
||||
import { Link, QueryResult, SearchableType } from "@scm-manager/ui-types";
|
||||
import { apiClient } from "./apiclient";
|
||||
import { createQueryString } from "./utils";
|
||||
@@ -58,10 +58,11 @@ export const useSearchCounts = (types: string[], query: string) => {
|
||||
apiClient.get(`${findLink(searchLinks, type)}?q=${query}&countOnly=true`).then((response) => response.json()),
|
||||
}))
|
||||
);
|
||||
const result: { [type: string]: ApiResult<number> } = {};
|
||||
const result: { [type: string]: ApiResultWithFetching<number> } = {};
|
||||
queries.forEach((q, i) => {
|
||||
result[types[i]] = {
|
||||
isLoading: q.isLoading,
|
||||
isFetching: q.isFetching,
|
||||
error: q.error as Error,
|
||||
data: (q.data as QueryResult)?.totalHits,
|
||||
};
|
||||
@@ -141,6 +142,12 @@ const pickLang = (language: string) => {
|
||||
};
|
||||
|
||||
export const useSearchHelpContent = (language: string) =>
|
||||
useObserveAsync((lang) => import(`./help/search/modal.${pickLang(lang)}`).then((module) => module.default), [language]);
|
||||
useObserveAsync(
|
||||
(lang) => import(`./help/search/modal.${pickLang(lang)}`).then((module) => module.default),
|
||||
[language]
|
||||
);
|
||||
export const useSearchSyntaxContent = (language: string) =>
|
||||
useObserveAsync((lang) => import(`./help/search/syntax.${pickLang(lang)}`).then((module) => module.default), [language]);
|
||||
useObserveAsync(
|
||||
(lang) => import(`./help/search/syntax.${pickLang(lang)}`).then((module) => module.default),
|
||||
[language]
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user