2019-10-20 18:02:52 +02:00
|
|
|
import React from "react";
|
|
|
|
|
import { connect } from "react-redux";
|
|
|
|
|
import { translate } from "react-i18next";
|
|
|
|
|
import { Page } from "@scm-manager/ui-components";
|
|
|
|
|
import RepositoryForm from "../components/form";
|
2019-10-19 16:38:07 +02:00
|
|
|
import {
|
|
|
|
|
Repository,
|
|
|
|
|
RepositoryType,
|
2019-10-20 18:02:52 +02:00
|
|
|
NamespaceStrategies
|
|
|
|
|
} from "@scm-manager/ui-types";
|
2018-08-02 16:09:58 +02:00
|
|
|
import {
|
|
|
|
|
fetchRepositoryTypesIfNeeded,
|
|
|
|
|
getFetchRepositoryTypesFailure,
|
|
|
|
|
getRepositoryTypes,
|
2019-10-20 18:02:52 +02:00
|
|
|
isFetchRepositoryTypesPending
|
|
|
|
|
} from "../modules/repositoryTypes";
|
2018-08-03 08:52:02 +02:00
|
|
|
import {
|
|
|
|
|
createRepo,
|
|
|
|
|
createRepoReset,
|
|
|
|
|
getCreateRepoFailure,
|
2019-10-20 18:02:52 +02:00
|
|
|
isCreateRepoPending
|
|
|
|
|
} from "../modules/repos";
|
|
|
|
|
import { History } from "history";
|
|
|
|
|
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";
|
2018-08-02 16:09:58 +02:00
|
|
|
|
|
|
|
|
type Props = {
|
2019-10-19 16:38:07 +02:00
|
|
|
repositoryTypes: RepositoryType[];
|
|
|
|
|
namespaceStrategies: NamespaceStrategies;
|
|
|
|
|
pageLoading: boolean;
|
|
|
|
|
createLoading: boolean;
|
|
|
|
|
error: Error;
|
|
|
|
|
repoLink: string;
|
2018-08-02 16:09:58 +02:00
|
|
|
|
|
|
|
|
// dispatch functions
|
2019-10-19 16:38:07 +02:00
|
|
|
fetchNamespaceStrategiesIfNeeded: () => void;
|
|
|
|
|
fetchRepositoryTypesIfNeeded: () => void;
|
2019-01-22 11:58:31 +01:00
|
|
|
createRepo: (
|
|
|
|
|
link: string,
|
2019-10-19 16:38:07 +02:00
|
|
|
p2: Repository,
|
2019-10-20 18:02:52 +02:00
|
|
|
callback: (repo: Repository) => void
|
2019-10-19 16:38:07 +02:00
|
|
|
) => void;
|
|
|
|
|
resetForm: () => void;
|
2018-08-02 16:09:58 +02:00
|
|
|
|
|
|
|
|
// context props
|
2019-10-19 16:38:07 +02:00
|
|
|
t: (p: string) => string;
|
|
|
|
|
history: History;
|
2018-08-02 16:09:58 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class Create extends React.Component<Props> {
|
|
|
|
|
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
|
|
|
};
|
|
|
|
|
|
2018-08-02 16:09:58 +02:00
|
|
|
render() {
|
2018-08-03 08:52:02 +02:00
|
|
|
const {
|
2019-03-11 16:39:48 +01:00
|
|
|
pageLoading,
|
2018-08-03 08:52:02 +02:00
|
|
|
createLoading,
|
|
|
|
|
repositoryTypes,
|
2019-03-11 16:39:48 +01:00
|
|
|
namespaceStrategies,
|
2018-08-03 08:52:02 +02:00
|
|
|
createRepo,
|
2019-10-20 18:02:52 +02:00
|
|
|
error
|
2018-08-03 08:52:02 +02:00
|
|
|
} = this.props;
|
2018-08-02 16:09:58 +02:00
|
|
|
|
2018-10-11 08:19:50 +02:00
|
|
|
const { t, repoLink } = this.props;
|
2018-08-02 16:09:58 +02:00
|
|
|
return (
|
|
|
|
|
<Page
|
2019-10-20 18:02:52 +02:00
|
|
|
title={t("create.title")}
|
|
|
|
|
subtitle={t("create.subtitle")}
|
2019-03-11 16:39:48 +01:00
|
|
|
loading={pageLoading}
|
2018-08-02 16:09:58 +02:00
|
|
|
error={error}
|
2018-08-03 08:52:02 +02:00
|
|
|
showContentOnError={true}
|
2018-08-02 16:09:58 +02:00
|
|
|
>
|
2018-08-03 08:52:02 +02:00
|
|
|
<RepositoryForm
|
|
|
|
|
repositoryTypes={repositoryTypes}
|
|
|
|
|
loading={createLoading}
|
2019-03-11 16:39:48 +01:00
|
|
|
namespaceStrategy={namespaceStrategies.current}
|
2018-08-03 08:52:02 +02:00
|
|
|
submitForm={repo => {
|
2019-01-22 11:58:31 +01:00
|
|
|
createRepo(repoLink, repo, (repo: Repository) =>
|
2019-10-20 18:02:52 +02:00
|
|
|
this.repoCreated(repo)
|
2019-01-22 11:58:31 +01:00
|
|
|
);
|
2018-08-03 08:52:02 +02:00
|
|
|
}}
|
|
|
|
|
/>
|
2018-08-02 16:09:58 +02:00
|
|
|
</Page>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const mapStateToProps = state => {
|
|
|
|
|
const repositoryTypes = getRepositoryTypes(state);
|
2019-03-11 16:39:48 +01:00
|
|
|
const namespaceStrategies = getNamespaceStrategies(state);
|
2019-10-19 16:38:07 +02:00
|
|
|
const pageLoading =
|
|
|
|
|
isFetchRepositoryTypesPending(state) ||
|
|
|
|
|
isFetchNamespaceStrategiesPending(state);
|
2018-08-03 08:52:02 +02:00
|
|
|
const createLoading = isCreateRepoPending(state);
|
2019-10-19 16:38:07 +02:00
|
|
|
const error =
|
|
|
|
|
getFetchRepositoryTypesFailure(state) ||
|
|
|
|
|
getCreateRepoFailure(state) ||
|
|
|
|
|
getFetchNamespaceStrategiesFailure(state);
|
2018-10-11 08:19:50 +02:00
|
|
|
const repoLink = getRepositoriesLink(state);
|
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,
|
2018-10-11 08:19:50 +02:00
|
|
|
error,
|
2019-10-20 18:02:52 +02:00
|
|
|
repoLink
|
2018-08-02 16:09:58 +02:00
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const mapDispatchToProps = dispatch => {
|
|
|
|
|
return {
|
|
|
|
|
fetchRepositoryTypesIfNeeded: () => {
|
|
|
|
|
dispatch(fetchRepositoryTypesIfNeeded());
|
2018-08-03 08:52:02 +02:00
|
|
|
},
|
2019-03-11 16:39:48 +01:00
|
|
|
fetchNamespaceStrategiesIfNeeded: () => {
|
|
|
|
|
dispatch(fetchNamespaceStrategiesIfNeeded());
|
|
|
|
|
},
|
2018-10-11 08:19:50 +02:00
|
|
|
createRepo: (
|
|
|
|
|
link: string,
|
|
|
|
|
repository: Repository,
|
2019-10-20 18:02:52 +02:00
|
|
|
callback: () => void
|
2018-10-11 08:19:50 +02:00
|
|
|
) => {
|
|
|
|
|
dispatch(createRepo(link, repository, callback));
|
2018-08-03 08:52:02 +02:00
|
|
|
},
|
|
|
|
|
resetForm: () => {
|
|
|
|
|
dispatch(createRepoReset());
|
2019-10-20 18:02:52 +02:00
|
|
|
}
|
2018-08-02 16:09:58 +02:00
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default connect(
|
|
|
|
|
mapStateToProps,
|
2019-10-20 18:02:52 +02:00
|
|
|
mapDispatchToProps
|
|
|
|
|
)(translate("repos")(Create));
|