Files
SCM-Manager/scm-ui/src/repos/containers/GeneralRepo.js

83 lines
2.0 KiB
JavaScript
Raw Normal View History

2018-08-06 15:41:20 +02:00
// @flow
import React from "react";
import { connect } from "react-redux";
2019-01-23 10:08:15 +01:00
import { withRouter } from "react-router-dom";
2018-08-06 15:41:20 +02:00
import RepositoryForm from "../components/form";
2019-01-23 10:08:15 +01:00
import DeleteRepo from "../components/DeleteRepo";
import type { Repository } from "@scm-manager/ui-types";
2018-08-06 15:41:20 +02:00
import {
modifyRepo,
isModifyRepoPending,
getModifyRepoFailure,
modifyRepoReset
2018-08-06 15:41:20 +02:00
} from "../modules/repos";
import type { History } from "history";
import { ErrorNotification } from "@scm-manager/ui-components";
2018-08-06 15:41:20 +02:00
type Props = {
2018-08-07 15:08:44 +02:00
loading: boolean,
2018-08-06 15:41:20 +02:00
error: Error,
2019-01-23 10:08:15 +01:00
modifyRepo: (Repository, () => void) => void,
modifyRepoReset: Repository => void,
2018-08-06 15:41:20 +02:00
// context props
2019-01-23 10:08:15 +01:00
repository: Repository,
2018-08-06 15:41:20 +02:00
history: History
};
2019-01-23 10:08:15 +01:00
class GeneralRepo extends React.Component<Props> {
componentDidMount() {
const { modifyRepoReset, repository } = this.props;
modifyRepoReset(repository);
}
2018-08-06 15:41:20 +02:00
repoModified = () => {
const { history, repository } = this.props;
history.push(`/repo/${repository.namespace}/${repository.name}`);
};
render() {
2019-01-23 10:08:15 +01:00
const { loading, error, repository } = this.props;
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);
}}
/>
<hr />
2019-01-23 10:08:15 +01:00
<DeleteRepo repository={repository} />
2018-08-07 15:08:44 +02:00
</div>
2018-08-06 15:41:20 +02:00
);
}
}
const mapStateToProps = (state, ownProps) => {
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,
2018-08-06 15:41:20 +02:00
error
};
};
const mapDispatchToProps = dispatch => {
return {
modifyRepo: (repo: Repository, callback: () => void) => {
dispatch(modifyRepo(repo, callback));
},
modifyRepoReset: (repo: Repository) => {
dispatch(modifyRepoReset(repo));
2018-08-06 15:41:20 +02:00
}
};
};
export default connect(
mapStateToProps,
mapDispatchToProps
2019-01-23 10:08:15 +01:00
)(withRouter(GeneralRepo));