2020-03-23 15:35:58 +01:00
|
|
|
/*
|
|
|
|
|
* 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.
|
|
|
|
|
*/
|
2019-10-20 18:02:52 +02:00
|
|
|
import React from "react";
|
|
|
|
|
import { connect } from "react-redux";
|
2019-10-23 15:47:08 +02:00
|
|
|
import { WithTranslation, withTranslation } from "react-i18next";
|
|
|
|
|
import { History } from "history";
|
2020-11-25 11:23:43 +01:00
|
|
|
import {
|
|
|
|
|
NamespaceStrategies,
|
|
|
|
|
Repository,
|
|
|
|
|
RepositoryCreation,
|
|
|
|
|
RepositoryImport,
|
|
|
|
|
RepositoryType
|
|
|
|
|
} from "@scm-manager/ui-types";
|
2020-11-25 15:08:30 +01:00
|
|
|
import { Loading, Notification, Page } from "@scm-manager/ui-components";
|
2018-08-02 16:09:58 +02:00
|
|
|
import {
|
|
|
|
|
fetchRepositoryTypesIfNeeded,
|
|
|
|
|
getFetchRepositoryTypesFailure,
|
|
|
|
|
getRepositoryTypes,
|
2019-10-20 18:02:52 +02:00
|
|
|
isFetchRepositoryTypesPending
|
|
|
|
|
} from "../modules/repositoryTypes";
|
2019-10-23 15:47:08 +02:00
|
|
|
import RepositoryForm from "../components/form";
|
2020-11-25 15:08:30 +01:00
|
|
|
import RepositoryFormSwitcher from "../components/form/RepositoryFormSwitcher";
|
2020-11-25 11:23:43 +01:00
|
|
|
import {
|
|
|
|
|
createRepo,
|
|
|
|
|
createRepoReset,
|
|
|
|
|
getCreateRepoFailure,
|
2020-11-25 12:12:16 +01:00
|
|
|
getImportRepoFailure,
|
2020-11-25 11:23:43 +01:00
|
|
|
importRepoFromUrl,
|
2020-11-25 15:08:30 +01:00
|
|
|
importRepoReset,
|
2020-11-25 12:12:16 +01:00
|
|
|
isCreateRepoPending,
|
|
|
|
|
isImportRepoPending
|
2020-11-25 11:23:43 +01:00
|
|
|
} from "../modules/repos";
|
2019-10-20 18:02:52 +02:00
|
|
|
import { getRepositoriesLink } from "../../modules/indexResource";
|
2019-03-11 16:39:48 +01:00
|
|
|
import {
|
|
|
|
|
fetchNamespaceStrategiesIfNeeded,
|
2019-10-19 16:38:07 +02:00
|
|
|
getFetchNamespaceStrategiesFailure,
|
|
|
|
|
getNamespaceStrategies,
|
2019-10-20 18:02:52 +02:00
|
|
|
isFetchNamespaceStrategiesPending
|
|
|
|
|
} from "../../admin/modules/namespaceStrategies";
|
2020-11-25 15:08:30 +01:00
|
|
|
import { RouteComponentProps, withRouter } from "react-router-dom";
|
|
|
|
|
import { compose } from "redux";
|
2018-08-02 16:09:58 +02:00
|
|
|
|
2020-11-25 15:08:30 +01:00
|
|
|
type Props = WithTranslation &
|
|
|
|
|
RouteComponentProps & {
|
|
|
|
|
repositoryTypes: RepositoryType[];
|
|
|
|
|
namespaceStrategies: NamespaceStrategies;
|
|
|
|
|
pageLoading: boolean;
|
|
|
|
|
createLoading: boolean;
|
|
|
|
|
importLoading: boolean;
|
|
|
|
|
error: Error;
|
|
|
|
|
repoLink: string;
|
|
|
|
|
indexResources: any;
|
|
|
|
|
|
|
|
|
|
// dispatch functions
|
|
|
|
|
fetchNamespaceStrategiesIfNeeded: () => void;
|
|
|
|
|
fetchRepositoryTypesIfNeeded: () => void;
|
|
|
|
|
createRepo: (
|
|
|
|
|
link: string,
|
|
|
|
|
repository: RepositoryCreation,
|
|
|
|
|
initRepository: boolean,
|
|
|
|
|
callback: (repo: Repository) => void
|
|
|
|
|
) => void;
|
|
|
|
|
importRepoFromUrl: (link: string, repository: RepositoryImport, callback: (repo: Repository) => void) => void;
|
|
|
|
|
resetForm: () => void;
|
|
|
|
|
|
|
|
|
|
// context props
|
|
|
|
|
history: History;
|
|
|
|
|
};
|
2018-08-02 16:09:58 +02:00
|
|
|
|
2020-11-25 11:23:43 +01:00
|
|
|
class AddRepository extends React.Component<Props> {
|
2018-08-02 16:09:58 +02:00
|
|
|
componentDidMount() {
|
2018-08-03 08:52:02 +02:00
|
|
|
this.props.resetForm();
|
2018-08-02 16:09:58 +02:00
|
|
|
this.props.fetchRepositoryTypesIfNeeded();
|
2019-03-11 16:39:48 +01:00
|
|
|
this.props.fetchNamespaceStrategiesIfNeeded();
|
2018-08-02 16:09:58 +02:00
|
|
|
}
|
|
|
|
|
|
2019-01-22 10:50:45 +01:00
|
|
|
repoCreated = (repo: Repository) => {
|
2018-08-03 08:52:02 +02:00
|
|
|
const { history } = this.props;
|
2019-01-22 11:58:31 +01:00
|
|
|
|
2019-10-20 18:02:52 +02:00
|
|
|
history.push("/repo/" + repo.namespace + "/" + repo.name);
|
2018-08-03 08:52:02 +02:00
|
|
|
};
|
|
|
|
|
|
2020-11-25 15:08:30 +01:00
|
|
|
resolveLocation = () => {
|
|
|
|
|
const currentUrl = this.props.location.pathname;
|
|
|
|
|
if (currentUrl.includes("/repos/create")) {
|
|
|
|
|
return "create";
|
|
|
|
|
}
|
|
|
|
|
if (currentUrl.includes("/repos/import")) {
|
|
|
|
|
return "import";
|
|
|
|
|
}
|
|
|
|
|
return "";
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
isImportPage = () => this.resolveLocation() === "import";
|
|
|
|
|
isCreatePage = () => this.resolveLocation() === "create";
|
|
|
|
|
|
|
|
|
|
getSubtitle = () => {
|
|
|
|
|
const { importLoading, t } = this.props;
|
|
|
|
|
let subtitle;
|
|
|
|
|
if (this.isCreatePage()) {
|
|
|
|
|
subtitle = t("create.subtitle");
|
|
|
|
|
} else if (!importLoading) {
|
|
|
|
|
subtitle = t("import.subtitle");
|
|
|
|
|
} else {
|
|
|
|
|
subtitle = t("import.pending.subtitle");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return subtitle;
|
|
|
|
|
};
|
|
|
|
|
|
2018-08-02 16:09:58 +02:00
|
|
|
render() {
|
2020-11-24 11:15:42 +01:00
|
|
|
const {
|
|
|
|
|
pageLoading,
|
|
|
|
|
createLoading,
|
2020-11-25 12:12:16 +01:00
|
|
|
importLoading,
|
2020-11-24 11:15:42 +01:00
|
|
|
repositoryTypes,
|
|
|
|
|
namespaceStrategies,
|
|
|
|
|
createRepo,
|
2020-11-25 11:23:43 +01:00
|
|
|
importRepoFromUrl,
|
2020-11-24 11:15:42 +01:00
|
|
|
error,
|
2020-11-25 11:23:43 +01:00
|
|
|
indexResources,
|
|
|
|
|
repoLink,
|
|
|
|
|
t
|
2020-11-24 11:15:42 +01:00
|
|
|
} = this.props;
|
2018-08-02 16:09:58 +02:00
|
|
|
|
|
|
|
|
return (
|
2020-11-25 15:08:30 +01:00
|
|
|
<Page
|
|
|
|
|
title={t("create.title")}
|
|
|
|
|
subtitle={this.getSubtitle()}
|
|
|
|
|
loading={pageLoading}
|
|
|
|
|
error={error}
|
|
|
|
|
showContentOnError={true}
|
|
|
|
|
>
|
2020-11-25 12:12:16 +01:00
|
|
|
{importLoading ? (
|
|
|
|
|
<>
|
|
|
|
|
<Notification type="info">{t("import.pending.infoText")}</Notification>
|
|
|
|
|
<Loading />
|
|
|
|
|
</>
|
|
|
|
|
) : (
|
2020-11-25 15:08:30 +01:00
|
|
|
<>
|
|
|
|
|
{!error && <RepositoryFormSwitcher creationMode={this.isImportPage() ? "IMPORT" : "CREATE"} />}
|
|
|
|
|
<RepositoryForm
|
|
|
|
|
repositoryTypes={repositoryTypes}
|
|
|
|
|
loading={createLoading}
|
|
|
|
|
namespaceStrategy={namespaceStrategies.current}
|
|
|
|
|
createRepository={(repo, initRepository) => {
|
|
|
|
|
createRepo(repoLink, repo, initRepository, (repo: Repository) => this.repoCreated(repo));
|
|
|
|
|
}}
|
|
|
|
|
importRepository={repo => {
|
|
|
|
|
importRepoFromUrl(repoLink, repo, (repo: Repository) => this.repoCreated(repo));
|
|
|
|
|
}}
|
|
|
|
|
indexResources={indexResources}
|
|
|
|
|
creationMode={this.isImportPage() ? "IMPORT" : "CREATE"}
|
|
|
|
|
/>
|
|
|
|
|
</>
|
2020-11-25 12:12:16 +01:00
|
|
|
)}
|
2018-08-02 16:09:58 +02:00
|
|
|
</Page>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-08 13:40:07 +01:00
|
|
|
const mapStateToProps = (state: any) => {
|
2018-08-02 16:09:58 +02:00
|
|
|
const repositoryTypes = getRepositoryTypes(state);
|
2019-03-11 16:39:48 +01:00
|
|
|
const namespaceStrategies = getNamespaceStrategies(state);
|
2019-10-21 10:57:56 +02:00
|
|
|
const pageLoading = isFetchRepositoryTypesPending(state) || isFetchNamespaceStrategiesPending(state);
|
2018-08-03 08:52:02 +02:00
|
|
|
const createLoading = isCreateRepoPending(state);
|
2020-11-25 12:12:16 +01:00
|
|
|
const importLoading = isImportRepoPending(state);
|
2019-10-19 16:38:07 +02:00
|
|
|
const error =
|
2020-11-25 12:12:16 +01:00
|
|
|
getFetchRepositoryTypesFailure(state) ||
|
|
|
|
|
getCreateRepoFailure(state) ||
|
|
|
|
|
getFetchNamespaceStrategiesFailure(state) ||
|
|
|
|
|
getImportRepoFailure(state);
|
2018-10-11 08:19:50 +02:00
|
|
|
const repoLink = getRepositoriesLink(state);
|
2020-09-07 15:40:14 +02:00
|
|
|
const indexResources = state?.indexResources;
|
|
|
|
|
|
2018-08-02 16:09:58 +02:00
|
|
|
return {
|
|
|
|
|
repositoryTypes,
|
2019-03-11 16:39:48 +01:00
|
|
|
namespaceStrategies,
|
|
|
|
|
pageLoading,
|
2018-08-03 08:52:02 +02:00
|
|
|
createLoading,
|
2020-11-25 12:12:16 +01:00
|
|
|
importLoading,
|
2018-10-11 08:19:50 +02:00
|
|
|
error,
|
2020-09-07 15:40:14 +02:00
|
|
|
repoLink,
|
|
|
|
|
indexResources
|
2018-08-02 16:09:58 +02:00
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
2020-01-08 13:40:07 +01:00
|
|
|
const mapDispatchToProps = (dispatch: any) => {
|
2018-08-02 16:09:58 +02:00
|
|
|
return {
|
|
|
|
|
fetchRepositoryTypesIfNeeded: () => {
|
|
|
|
|
dispatch(fetchRepositoryTypesIfNeeded());
|
2018-08-03 08:52:02 +02:00
|
|
|
},
|
2019-03-11 16:39:48 +01:00
|
|
|
fetchNamespaceStrategiesIfNeeded: () => {
|
|
|
|
|
dispatch(fetchNamespaceStrategiesIfNeeded());
|
|
|
|
|
},
|
2020-09-07 15:40:14 +02:00
|
|
|
createRepo: (link: string, repository: RepositoryCreation, initRepository: boolean, callback: () => void) => {
|
2020-01-17 13:56:42 +01:00
|
|
|
dispatch(createRepo(link, repository, initRepository, callback));
|
2018-08-03 08:52:02 +02:00
|
|
|
},
|
2020-11-25 11:23:43 +01:00
|
|
|
importRepoFromUrl: (link: string, repository: RepositoryImport, callback: () => void) => {
|
|
|
|
|
dispatch(importRepoFromUrl(link, repository, callback));
|
|
|
|
|
},
|
2018-08-03 08:52:02 +02:00
|
|
|
resetForm: () => {
|
|
|
|
|
dispatch(createRepoReset());
|
2020-11-25 15:08:30 +01:00
|
|
|
dispatch(importRepoReset());
|
2019-10-20 18:02:52 +02:00
|
|
|
}
|
2018-08-02 16:09:58 +02:00
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
2020-11-25 15:08:30 +01:00
|
|
|
export default compose(
|
|
|
|
|
withRouter,
|
|
|
|
|
withTranslation("repos"),
|
|
|
|
|
connect(mapStateToProps, mapDispatchToProps)
|
|
|
|
|
)(AddRepository);
|