2018-10-11 17:29:50 +02:00
|
|
|
// @flow
|
|
|
|
|
|
|
|
|
|
import React from "react";
|
2018-10-12 16:07:24 +02:00
|
|
|
import type { Repository, Branch } from "@scm-manager/ui-types";
|
2018-10-11 17:29:50 +02:00
|
|
|
import BranchChooser from "./BranchChooser";
|
|
|
|
|
import { Route, withRouter } from "react-router-dom";
|
|
|
|
|
import Changesets from "./Changesets";
|
|
|
|
|
|
|
|
|
|
type Props = {
|
|
|
|
|
repository: Repository,
|
|
|
|
|
history: History,
|
|
|
|
|
match: any
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class BranchRoot extends React.Component<Props> {
|
|
|
|
|
stripEndingSlash = (url: string) => {
|
|
|
|
|
if (url.endsWith("/")) {
|
|
|
|
|
return url.substring(0, url.length - 2);
|
|
|
|
|
}
|
|
|
|
|
return url;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
matchedUrl = () => {
|
|
|
|
|
return this.stripEndingSlash(this.props.match.url);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
branchSelected = (branchName: string) => {
|
|
|
|
|
const url = this.matchedUrl();
|
|
|
|
|
if (branchName === "") {
|
|
|
|
|
this.props.history.push(`${url}/changesets/`);
|
|
|
|
|
} else {
|
|
|
|
|
this.props.history.push(
|
|
|
|
|
`${url}/${encodeURIComponent(branchName)}/changesets/`
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
render() {
|
2018-10-12 16:07:24 +02:00
|
|
|
const { repository } = this.props;
|
2018-10-11 17:29:50 +02:00
|
|
|
const url = this.matchedUrl();
|
2018-10-12 16:07:24 +02:00
|
|
|
if (!repository) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2018-10-11 17:29:50 +02:00
|
|
|
return (
|
|
|
|
|
<BranchChooser
|
|
|
|
|
repository={this.props.repository}
|
|
|
|
|
label={"Branches"}
|
|
|
|
|
branchSelected={this.branchSelected}
|
|
|
|
|
>
|
2018-10-12 16:07:24 +02:00
|
|
|
<RouteDelegate repository={this.props.repository} url={url} />
|
2018-10-11 17:29:50 +02:00
|
|
|
</BranchChooser>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-12 16:07:24 +02:00
|
|
|
type RDProps = {
|
|
|
|
|
repository: Repository,
|
|
|
|
|
branch: Branch,
|
|
|
|
|
url: string
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class RouteDelegate extends React.Component<RDProps> {
|
|
|
|
|
shouldComponentUpdate(nextProps: RDProps, nextState: any) {
|
|
|
|
|
return (
|
|
|
|
|
nextProps.repository !== this.props.repository ||
|
|
|
|
|
nextProps.branch !== this.props.branch ||
|
|
|
|
|
nextProps.url !== this.props.url
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
render() {
|
|
|
|
|
const { url, repository, branch } = this.props;
|
|
|
|
|
return (
|
|
|
|
|
<Route
|
|
|
|
|
exact
|
|
|
|
|
path={`${url}/:branch/changesets/:page?`}
|
|
|
|
|
component={() => <Changesets repository={repository} branch={branch} />}
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
}
|
2018-10-11 17:29:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default withRouter(BranchRoot);
|