Files
SCM-Manager/scm-ui/ui-webapp/src/repos/containers/EditRepo.tsx

97 lines
2.5 KiB
TypeScript
Raw Normal View History

import React from "react";
import { connect } from "react-redux";
import { withRouter } from "react-router-dom";
import RepositoryForm from "../components/form";
import DeleteRepo from "./DeleteRepo";
import { Repository } from "@scm-manager/ui-types";
import { getModifyRepoFailure, isModifyRepoPending, modifyRepo, modifyRepoReset } from "../modules/repos";
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";
2018-08-06 15:41:20 +02:00
type Props = {
loading: boolean;
error: Error;
2018-08-06 15:41:20 +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
repository: Repository;
history: History;
match: any;
2018-08-06 15:41:20 +02:00
};
2019-01-29 08:22:43 +01:00
class EditRepo extends React.Component<Props> {
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}`);
};
stripEndingSlash = (url: string) => {
if (url.endsWith("/")) {
return url.substring(0, url.length - 2);
}
return url;
};
matchedUrl = () => {
return this.stripEndingSlash(this.props.match.url);
};
2018-08-06 15:41:20 +02:00
render() {
2019-01-23 10:08:15 +01:00
const { loading, error, repository } = this.props;
const url = this.matchedUrl();
const extensionProps = {
repository,
url
};
2018-08-06 15:41:20 +02:00
return (
2018-08-07 15:08:44 +02:00
<div>
<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} />
2019-02-06 11:44:03 +01:00
<DeleteRepo repository={repository} />
2018-08-07 15:08:44 +02:00
</div>
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);
return {
2018-08-07 15:08:44 +02:00
loading,
error
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));
},
modifyRepoReset: (repo: Repository) => {
dispatch(modifyRepoReset(repo));
}
2018-08-06 15:41:20 +02:00
};
};
2020-01-08 13:40:07 +01:00
export default compose(connect(mapStateToProps, mapDispatchToProps), withRouter)(EditRepo);