mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-01 19:15:52 +01:00
Add extension point for repository creators (#1657)
Adds an extension point for repository creator such as repository create, repository import or repository mirror.
This commit is contained in:
120
scm-ui/ui-webapp/src/repos/containers/CreateRepositoryRoot.tsx
Normal file
120
scm-ui/ui-webapp/src/repos/containers/CreateRepositoryRoot.tsx
Normal file
@@ -0,0 +1,120 @@
|
||||
/*
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2020-present Cloudogu GmbH and Contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
import React, { FC } from "react";
|
||||
import { Route, Switch } from "react-router-dom";
|
||||
import CreateRepository from "./CreateRepository";
|
||||
import ImportRepository from "./ImportRepository";
|
||||
import { useBinder } from "@scm-manager/ui-extensions";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { Page, urls } from "@scm-manager/ui-components";
|
||||
import RepositoryFormSwitcher from "../components/form/RepositoryFormSwitcher";
|
||||
import { useIndex, useNamespaceStrategies, useRepositoryTypes } from "@scm-manager/ui-api";
|
||||
import NamespaceAndNameFields from "../components/NamespaceAndNameFields";
|
||||
import RepositoryInformationForm from "../components/RepositoryInformationForm";
|
||||
import { extensionPoints } from "@scm-manager/ui-extensions/";
|
||||
|
||||
type CreatorRouteProps = {
|
||||
creator: extensionPoints.RepositoryCreatorExtension;
|
||||
creators: extensionPoints.RepositoryCreatorExtension[];
|
||||
};
|
||||
|
||||
const useCreateRepositoryData = () => {
|
||||
const { isLoading: isLoadingNS, error: errorNS, data: namespaceStrategies } = useNamespaceStrategies();
|
||||
const { isLoading: isLoadingRT, error: errorRT, data: repositoryTypes } = useRepositoryTypes();
|
||||
const { isLoading: isLoadingIdx, error: errorIdx, data: index } = useIndex();
|
||||
return {
|
||||
isPageLoading: isLoadingNS || isLoadingRT || isLoadingIdx,
|
||||
pageLoadingError: errorNS || errorRT || errorIdx || undefined,
|
||||
namespaceStrategies,
|
||||
repositoryTypes,
|
||||
index
|
||||
};
|
||||
};
|
||||
|
||||
const CreatorRoute: FC<CreatorRouteProps> = ({ creator, creators }) => {
|
||||
const { isPageLoading, pageLoadingError, namespaceStrategies, repositoryTypes, index } = useCreateRepositoryData();
|
||||
const [t] = useTranslation(["repos", "plugins"]);
|
||||
|
||||
const Component = creator.component;
|
||||
|
||||
return (
|
||||
<Page
|
||||
title={t("repos:create.title")}
|
||||
subtitle={t(`plugins:${creator.subtitle}`, creator.subtitle)}
|
||||
afterTitle={<RepositoryFormSwitcher forms={creators} />}
|
||||
loading={isPageLoading}
|
||||
error={pageLoadingError}
|
||||
>
|
||||
{namespaceStrategies && repositoryTypes && index ? (
|
||||
<Component
|
||||
namespaceStrategies={namespaceStrategies}
|
||||
repositoryTypes={repositoryTypes}
|
||||
index={index}
|
||||
nameForm={NamespaceAndNameFields}
|
||||
informationForm={RepositoryInformationForm}
|
||||
/>
|
||||
) : null}
|
||||
</Page>
|
||||
);
|
||||
};
|
||||
|
||||
const CreateRepositoryRoot: FC = () => {
|
||||
const [t] = useTranslation("repos");
|
||||
const binder = useBinder();
|
||||
|
||||
const creators: extensionPoints.RepositoryCreatorExtension[] = [
|
||||
{
|
||||
subtitle: t("create.subtitle"),
|
||||
path: "",
|
||||
icon: "plus",
|
||||
label: t("repositoryForm.createButton"),
|
||||
component: CreateRepository
|
||||
},
|
||||
{
|
||||
subtitle: t("import.subtitle"),
|
||||
path: "import",
|
||||
icon: "file-upload",
|
||||
label: t("repositoryForm.importButton"),
|
||||
component: ImportRepository
|
||||
}
|
||||
];
|
||||
|
||||
const extCreators = binder.getExtensions<extensionPoints.RepositoryCreator>("repos.creator");
|
||||
if (extCreators) {
|
||||
creators.push(...extCreators);
|
||||
}
|
||||
|
||||
return (
|
||||
<Switch>
|
||||
{creators.map(creator => (
|
||||
<Route key={creator.path} exact path={urls.concat("/repos/create", creator.path)}>
|
||||
<CreatorRoute creator={creator} creators={creators} />
|
||||
</Route>
|
||||
))}
|
||||
</Switch>
|
||||
);
|
||||
};
|
||||
|
||||
export default CreateRepositoryRoot;
|
||||
Reference in New Issue
Block a user