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";
|
2020-09-18 17:38:10 +02:00
|
|
|
import { RouteComponentProps, withRouter } from "react-router-dom";
|
2019-10-20 18:02:52 +02:00
|
|
|
import RepositoryForm from "../components/form";
|
2020-06-29 10:41:31 +02:00
|
|
|
import { Repository, Links } from "@scm-manager/ui-types";
|
2020-01-08 15:57:13 +01:00
|
|
|
import { getModifyRepoFailure, isModifyRepoPending, modifyRepo, modifyRepoReset } from "../modules/repos";
|
2019-10-20 18:02:52 +02:00
|
|
|
import { History } from "history";
|
|
|
|
|
import { ErrorNotification } from "@scm-manager/ui-components";
|
|
|
|
|
import { ExtensionPoint } from "@scm-manager/ui-extensions";
|
2020-01-08 13:40:07 +01:00
|
|
|
import { compose } from "redux";
|
2020-06-24 10:39:00 +02:00
|
|
|
import DangerZone from "./DangerZone";
|
2020-06-29 10:41:31 +02:00
|
|
|
import { getLinks } from "../../modules/indexResource";
|
2020-09-18 17:20:54 +02:00
|
|
|
import { urls } from "@scm-manager/ui-components";
|
2018-08-06 15:41:20 +02:00
|
|
|
|
2020-09-18 17:38:10 +02:00
|
|
|
type Props = RouteComponentProps & {
|
2019-10-19 16:38:07 +02:00
|
|
|
loading: boolean;
|
|
|
|
|
error: Error;
|
2020-06-29 10:41:31 +02:00
|
|
|
indexLinks: Links;
|
2018-08-06 15:41:20 +02:00
|
|
|
|
2019-10-19 16:38:07 +02:00
|
|
|
modifyRepo: (p1: Repository, p2: () => void) => void;
|
|
|
|
|
modifyRepoReset: (p: Repository) => void;
|
2019-01-23 10:08:15 +01:00
|
|
|
|
2018-08-06 15:41:20 +02:00
|
|
|
// context props
|
2019-10-19 16:38:07 +02:00
|
|
|
repository: Repository;
|
|
|
|
|
history: History;
|
2018-08-06 15:41:20 +02:00
|
|
|
};
|
|
|
|
|
|
2019-01-29 08:22:43 +01:00
|
|
|
class EditRepo extends React.Component<Props> {
|
2018-11-06 11:24:01 +01:00
|
|
|
componentDidMount() {
|
|
|
|
|
const { modifyRepoReset, repository } = this.props;
|
|
|
|
|
modifyRepoReset(repository);
|
|
|
|
|
}
|
2019-01-23 12:07:28 +01:00
|
|
|
|
2018-08-06 15:41:20 +02:00
|
|
|
repoModified = () => {
|
|
|
|
|
const { history, repository } = this.props;
|
|
|
|
|
history.push(`/repo/${repository.namespace}/${repository.name}`);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
render() {
|
2020-06-29 10:41:31 +02:00
|
|
|
const { loading, error, repository, indexLinks } = this.props;
|
2019-02-06 09:51:31 +01:00
|
|
|
|
2020-09-18 17:38:10 +02:00
|
|
|
const url = urls.matchedUrl(this.props);
|
2019-02-06 09:51:31 +01:00
|
|
|
|
|
|
|
|
const extensionProps = {
|
|
|
|
|
repository,
|
2019-10-20 18:02:52 +02:00
|
|
|
url
|
2019-02-06 09:51:31 +01:00
|
|
|
};
|
|
|
|
|
|
2018-08-06 15:41:20 +02:00
|
|
|
return (
|
2020-06-24 10:39:00 +02:00
|
|
|
<>
|
2018-08-07 15:08:44 +02:00
|
|
|
<ErrorNotification error={error} />
|
2018-08-06 15:41:20 +02:00
|
|
|
<RepositoryForm
|
|
|
|
|
repository={this.props.repository}
|
2018-08-07 15:08:44 +02:00
|
|
|
loading={loading}
|
2018-08-06 15:41:20 +02:00
|
|
|
submitForm={repo => {
|
|
|
|
|
this.props.modifyRepo(repo, this.repoModified);
|
|
|
|
|
}}
|
|
|
|
|
/>
|
2019-10-21 10:57:56 +02:00
|
|
|
<ExtensionPoint name="repo-config.route" props={extensionProps} renderAll={true} />
|
2020-06-29 10:41:31 +02:00
|
|
|
<DangerZone repository={repository} indexLinks={indexLinks} />
|
2020-06-24 10:39:00 +02:00
|
|
|
</>
|
2018-08-06 15:41:20 +02:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-08 13:40:07 +01:00
|
|
|
const mapStateToProps = (state: any, ownProps: Props) => {
|
2018-08-06 15:41:20 +02:00
|
|
|
const { namespace, name } = ownProps.repository;
|
2018-08-07 15:08:44 +02:00
|
|
|
const loading = isModifyRepoPending(state, namespace, name);
|
2018-08-06 15:41:20 +02:00
|
|
|
const error = getModifyRepoFailure(state, namespace, name);
|
2020-06-29 10:41:31 +02:00
|
|
|
const indexLinks = getLinks(state);
|
|
|
|
|
|
2018-08-06 15:41:20 +02:00
|
|
|
return {
|
2018-08-07 15:08:44 +02:00
|
|
|
loading,
|
2020-06-29 10:41:31 +02:00
|
|
|
error,
|
|
|
|
|
indexLinks
|
2018-08-06 15:41:20 +02:00
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
2020-01-08 13:40:07 +01:00
|
|
|
const mapDispatchToProps = (dispatch: any) => {
|
2018-08-06 15:41:20 +02:00
|
|
|
return {
|
|
|
|
|
modifyRepo: (repo: Repository, callback: () => void) => {
|
|
|
|
|
dispatch(modifyRepo(repo, callback));
|
2018-11-06 11:24:01 +01:00
|
|
|
},
|
|
|
|
|
modifyRepoReset: (repo: Repository) => {
|
|
|
|
|
dispatch(modifyRepoReset(repo));
|
2019-10-20 18:02:52 +02:00
|
|
|
}
|
2018-08-06 15:41:20 +02:00
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
2020-06-26 09:24:13 +02:00
|
|
|
export default compose(connect(mapStateToProps, mapDispatchToProps), withRouter)(EditRepo);
|