mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-04 20:45:52 +01:00
Implemented editing of repos (in UI)
This commit is contained in:
80
scm-ui/src/repos/containers/Edit.js
Normal file
80
scm-ui/src/repos/containers/Edit.js
Normal file
@@ -0,0 +1,80 @@
|
||||
// @flow
|
||||
import React from "react";
|
||||
import { connect } from "react-redux";
|
||||
import { translate } from "react-i18next";
|
||||
import { Page } from "../../components/layout";
|
||||
import RepositoryForm from "../components/form";
|
||||
import type { Repository } from "../types/Repositories";
|
||||
import {
|
||||
modifyRepo,
|
||||
isModifyRepoPending,
|
||||
getModifyRepoFailure
|
||||
} from "../modules/repos";
|
||||
import { withRouter } from "react-router-dom";
|
||||
import type { History } from "history";
|
||||
|
||||
type Props = {
|
||||
repository: Repository,
|
||||
modifyRepo: (Repository, () => void) => void,
|
||||
modifyLoading: boolean,
|
||||
error: Error,
|
||||
|
||||
// context props
|
||||
t: string => string,
|
||||
history: History
|
||||
};
|
||||
|
||||
class Edit extends React.Component<Props> {
|
||||
componentDidMount() {}
|
||||
|
||||
repoModified = () => {
|
||||
const { history, repository } = this.props;
|
||||
history.push(`/repo/${repository.namespace}/${repository.name}`);
|
||||
};
|
||||
|
||||
render() {
|
||||
const { t, modifyLoading, error } = this.props;
|
||||
return (
|
||||
<Page
|
||||
title={t("edit.title")}
|
||||
subtitle={t("edit.subtitle")}
|
||||
error={error}
|
||||
showContentOnError={true}
|
||||
>
|
||||
<RepositoryForm
|
||||
repository={this.props.repository}
|
||||
loading={modifyLoading}
|
||||
submitForm={repo => {
|
||||
this.props.modifyRepo(repo, this.repoModified);
|
||||
}}
|
||||
/>
|
||||
</Page>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
const mapStateToProps = (state, ownProps) => {
|
||||
const { namespace, name } = ownProps.repository;
|
||||
|
||||
const modifyLoading = isModifyRepoPending(state, namespace, name);
|
||||
|
||||
const error = getModifyRepoFailure(state, namespace, name);
|
||||
|
||||
return {
|
||||
modifyLoading,
|
||||
error
|
||||
};
|
||||
};
|
||||
|
||||
const mapDispatchToProps = dispatch => {
|
||||
return {
|
||||
modifyRepo: (repo: Repository, callback: () => void) => {
|
||||
dispatch(modifyRepo(repo, callback));
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
export default connect(
|
||||
mapStateToProps,
|
||||
mapDispatchToProps
|
||||
)(translate("repos")(withRouter(Edit)));
|
||||
@@ -17,8 +17,10 @@ import { translate } from "react-i18next";
|
||||
import { Navigation, NavLink, Section } from "../../components/navigation";
|
||||
import RepositoryDetails from "../components/RepositoryDetails";
|
||||
import DeleteNavAction from "../components/DeleteNavAction";
|
||||
import Edit from "../containers/Edit";
|
||||
|
||||
import type { History } from "history";
|
||||
import EditNavLink from "../components/EditNavLink";
|
||||
|
||||
type Props = {
|
||||
namespace: string,
|
||||
@@ -91,10 +93,15 @@ class RepositoryRoot extends React.Component<Props> {
|
||||
exact
|
||||
component={() => <RepositoryDetails repository={repository} />}
|
||||
/>
|
||||
<Route
|
||||
path={`${url}/edit`}
|
||||
component={() => <Edit repository={repository} />}
|
||||
/>
|
||||
</div>
|
||||
<div className="column">
|
||||
<Navigation>
|
||||
<Section label={t("repository-root.actions-label")}>
|
||||
<EditNavLink repository={repository} editUrl={`${url}/edit`} />
|
||||
<DeleteNavAction repository={repository} delete={this.delete} />
|
||||
<NavLink to="/repos" label={t("repository-root.back-label")} />
|
||||
</Section>
|
||||
|
||||
Reference in New Issue
Block a user