mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-12 00:15:44 +01:00
outsourced single branch routing to branchroot
This commit is contained in:
32
scm-ui/src/repos/branches/components/BranchView.js
Normal file
32
scm-ui/src/repos/branches/components/BranchView.js
Normal file
@@ -0,0 +1,32 @@
|
||||
// @flow
|
||||
import React from "react";
|
||||
import BranchDetail from "./BranchDetail";
|
||||
import { ExtensionPoint } from "@scm-manager/ui-extensions";
|
||||
import type { Repository, Branch } from "@scm-manager/ui-types";
|
||||
|
||||
type Props = {
|
||||
repository: Repository,
|
||||
branch: Branch
|
||||
};
|
||||
|
||||
class BranchView extends React.Component<Props> {
|
||||
render() {
|
||||
const { repository, branch } = this.props;
|
||||
|
||||
return (
|
||||
<div>
|
||||
<BranchDetail repository={repository} branch={branch} />
|
||||
<hr />
|
||||
<div className="content">
|
||||
<ExtensionPoint
|
||||
name="repos.branch-details.information"
|
||||
renderAll={true}
|
||||
props={{ repository, branch }}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export default BranchView;
|
||||
@@ -0,0 +1,117 @@
|
||||
//@flow
|
||||
import React from "react";
|
||||
import BranchView from "../components/BranchView";
|
||||
import { connect } from "react-redux";
|
||||
import { Redirect, Route, Switch, withRouter } from "react-router-dom";
|
||||
import { translate } from "react-i18next";
|
||||
import type { Repository, Branch } from "@scm-manager/ui-types";
|
||||
import {
|
||||
fetchBranch,
|
||||
getBranch,
|
||||
getFetchBranchFailure,
|
||||
isFetchBranchPending
|
||||
} from "../modules/branches";
|
||||
import { ErrorPage, Loading } from "@scm-manager/ui-components";
|
||||
import CreateBranch from "./CreateBranch";
|
||||
import type { History } from "history";
|
||||
|
||||
type Props = {
|
||||
repository: Repository,
|
||||
branchName: string,
|
||||
branch: Branch,
|
||||
loading: boolean,
|
||||
error?: Error,
|
||||
|
||||
// context props
|
||||
t: string => string,
|
||||
history: History,
|
||||
match: any,
|
||||
|
||||
// dispatch functions
|
||||
fetchBranch: (repository: Repository, branchName: string) => void
|
||||
};
|
||||
|
||||
class BranchRoot extends React.Component<Props> {
|
||||
componentDidMount() {
|
||||
const { fetchBranch, repository, branchName } = this.props;
|
||||
|
||||
fetchBranch(repository, branchName);
|
||||
}
|
||||
|
||||
stripEndingSlash = (url: string) => {
|
||||
if (url.endsWith("/")) {
|
||||
return url.substring(0, url.length - 1);
|
||||
}
|
||||
return url;
|
||||
};
|
||||
|
||||
matchedUrl = () => {
|
||||
return this.stripEndingSlash(this.props.match.url);
|
||||
};
|
||||
|
||||
render() {
|
||||
const { repository, branch, loading, error, t } = this.props;
|
||||
|
||||
if (error) {
|
||||
return (
|
||||
<ErrorPage
|
||||
title={t("branches.errorTitle")}
|
||||
subtitle={t("branches.errorSubtitle")}
|
||||
error={error}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
if (loading || !branch) {
|
||||
return <Loading />;
|
||||
}
|
||||
|
||||
const url = this.matchedUrl();
|
||||
|
||||
return (
|
||||
<Switch>
|
||||
<Redirect exact from={url} to={`${url}/info`} />
|
||||
<Route
|
||||
path={`${url}?create=true`}
|
||||
render={() => (
|
||||
<CreateBranch repository={repository} branch={branch} />
|
||||
)}
|
||||
/>
|
||||
<Route
|
||||
path={`${url}/info`}
|
||||
render={() => <BranchView repository={repository} branch={branch} />}
|
||||
/>
|
||||
</Switch>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
const mapStateToProps = (state, ownProps) => {
|
||||
const { repository } = ownProps;
|
||||
const branchName = decodeURIComponent(ownProps.match.params.branch);
|
||||
const branch = getBranch(state, repository, branchName);
|
||||
const loading = isFetchBranchPending(state, repository, branchName);
|
||||
const error = getFetchBranchFailure(state, repository, branchName);
|
||||
return {
|
||||
repository,
|
||||
branchName,
|
||||
branch,
|
||||
loading,
|
||||
error
|
||||
};
|
||||
};
|
||||
|
||||
const mapDispatchToProps = dispatch => {
|
||||
return {
|
||||
fetchBranch: (repository: Repository, branchName: string) => {
|
||||
dispatch(fetchBranch(repository, branchName));
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
export default withRouter(
|
||||
connect(
|
||||
mapStateToProps,
|
||||
mapDispatchToProps
|
||||
)(translate("repos")(BranchRoot))
|
||||
);
|
||||
|
||||
@@ -1,99 +0,0 @@
|
||||
// @flow
|
||||
import React from "react";
|
||||
import BranchDetail from "../components/BranchDetail";
|
||||
import { ExtensionPoint } from "@scm-manager/ui-extensions";
|
||||
import type { Repository, Branch } from "@scm-manager/ui-types";
|
||||
import { connect } from "react-redux";
|
||||
import { translate } from "react-i18next";
|
||||
import { withRouter } from "react-router-dom";
|
||||
import {
|
||||
fetchBranch,
|
||||
getBranch,
|
||||
getFetchBranchFailure,
|
||||
isFetchBranchPending
|
||||
} from "../modules/branches";
|
||||
import { ErrorPage, Loading } from "@scm-manager/ui-components";
|
||||
|
||||
type Props = {
|
||||
repository: Repository,
|
||||
branchName: string,
|
||||
loading: boolean,
|
||||
error?: Error,
|
||||
branch?: Branch,
|
||||
|
||||
// dispatch functions
|
||||
fetchBranch: (repository: Repository, branchName: string) => void,
|
||||
|
||||
// context props
|
||||
t: string => string
|
||||
};
|
||||
|
||||
class BranchView extends React.Component<Props> {
|
||||
componentDidMount() {
|
||||
const { fetchBranch, repository, branchName } = this.props;
|
||||
|
||||
fetchBranch(repository, branchName);
|
||||
}
|
||||
|
||||
render() {
|
||||
const { loading, error, t, repository, branch } = this.props;
|
||||
|
||||
if (error) {
|
||||
return (
|
||||
<ErrorPage
|
||||
title={t("branches.errorTitle")}
|
||||
subtitle={t("branches.errorSubtitle")}
|
||||
error={error}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
if (!branch || loading) {
|
||||
return <Loading />;
|
||||
}
|
||||
|
||||
return (
|
||||
<div>
|
||||
<BranchDetail repository={repository} branch={branch} />
|
||||
<hr />
|
||||
<div className="content">
|
||||
<ExtensionPoint
|
||||
name="repos.branch-details.information"
|
||||
renderAll={true}
|
||||
props={{ repository, branch }}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
const mapStateToProps = (state, ownProps) => {
|
||||
const { repository } = ownProps;
|
||||
const branchName = decodeURIComponent(ownProps.match.params.branch);
|
||||
const branch = getBranch(state, repository, branchName);
|
||||
const loading = isFetchBranchPending(state, repository, branchName);
|
||||
const error = getFetchBranchFailure(state, repository, branchName);
|
||||
return {
|
||||
repository,
|
||||
branchName,
|
||||
branch,
|
||||
loading,
|
||||
error
|
||||
};
|
||||
};
|
||||
|
||||
const mapDispatchToProps = dispatch => {
|
||||
return {
|
||||
fetchBranch: (repository: Repository, branchName: string) => {
|
||||
dispatch(fetchBranch(repository, branchName));
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
export default withRouter(
|
||||
connect(
|
||||
mapStateToProps,
|
||||
mapDispatchToProps
|
||||
)(translate("repos")(BranchView))
|
||||
);
|
||||
@@ -40,7 +40,7 @@ type Props = {
|
||||
t: string => string
|
||||
};
|
||||
|
||||
class BranchRoot extends React.Component<Props> {
|
||||
class ChangesetsRoot extends React.Component<Props> {
|
||||
componentDidMount() {
|
||||
this.props.fetchBranches(this.props.repository);
|
||||
}
|
||||
@@ -146,4 +146,4 @@ export default compose(
|
||||
mapStateToProps,
|
||||
mapDispatchToProps
|
||||
)
|
||||
)(BranchRoot);
|
||||
)(ChangesetsRoot);
|
||||
|
||||
@@ -24,14 +24,13 @@ import { translate } from "react-i18next";
|
||||
import RepositoryDetails from "../components/RepositoryDetails";
|
||||
import EditRepo from "./EditRepo";
|
||||
import BranchesOverview from "../branches/containers/BranchesOverview";
|
||||
import BranchView from "../branches/containers/BranchView";
|
||||
import CreateBranch from "../branches/containers/CreateBranch";
|
||||
import Permissions from "../permissions/containers/Permissions";
|
||||
|
||||
import type { History } from "history";
|
||||
import EditRepoNavLink from "../components/EditRepoNavLink";
|
||||
|
||||
import BranchRoot from "./ChangesetsRoot";
|
||||
import BranchRoot from "../branches/containers/BranchRoot";
|
||||
import ChangesetsRoot from "./ChangesetsRoot";
|
||||
import ChangesetView from "./ChangesetView";
|
||||
import PermissionsNavLink from "../components/PermissionsNavLink";
|
||||
import Sources from "../sources/containers/Sources";
|
||||
@@ -168,7 +167,7 @@ class RepositoryRoot extends React.Component<Props> {
|
||||
<Route
|
||||
path={`${url}/changesets`}
|
||||
render={() => (
|
||||
<BranchRoot
|
||||
<ChangesetsRoot
|
||||
repository={repository}
|
||||
baseUrlWithBranch={`${url}/branch`}
|
||||
baseUrlWithoutBranch={`${url}/changesets`}
|
||||
@@ -176,9 +175,9 @@ class RepositoryRoot extends React.Component<Props> {
|
||||
)}
|
||||
/>
|
||||
<Route
|
||||
path={`${url}/branch/:branch/info`}
|
||||
path={`${url}/branch/:branch`}
|
||||
render={() => (
|
||||
<BranchView
|
||||
<BranchRoot
|
||||
repository={repository}
|
||||
baseUrl={`${url}/branch`}
|
||||
/>
|
||||
@@ -187,7 +186,7 @@ class RepositoryRoot extends React.Component<Props> {
|
||||
<Route
|
||||
path={`${url}/branch/:branch/changesets`}
|
||||
render={() => (
|
||||
<BranchRoot
|
||||
<ChangesetsRoot
|
||||
repository={repository}
|
||||
baseUrlWithBranch={`${url}/branch`}
|
||||
baseUrlWithoutBranch={`${url}/changesets`}
|
||||
|
||||
Reference in New Issue
Block a user