mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-01 19:15:52 +01:00
Update RouteDelegate only conditionally
This commit is contained in:
@@ -48,7 +48,7 @@ class BranchChooser extends React.Component<Props, State> {
|
|||||||
render() {
|
render() {
|
||||||
console.log("Branch chooser render");
|
console.log("Branch chooser render");
|
||||||
|
|
||||||
const { loading, error, t } = this.props;
|
const { loading, error, t, repository } = this.props;
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
return (
|
return (
|
||||||
@@ -60,6 +60,10 @@ class BranchChooser extends React.Component<Props, State> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!repository) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
if (loading) {
|
if (loading) {
|
||||||
return <Loading />;
|
return <Loading />;
|
||||||
}
|
}
|
||||||
@@ -85,8 +89,7 @@ class BranchChooser extends React.Component<Props, State> {
|
|||||||
|
|
||||||
renderBranchChooser() {
|
renderBranchChooser() {
|
||||||
const { label, match, branches } = this.props;
|
const { label, match, branches } = this.props;
|
||||||
const selectedBranchName = "";
|
const selectedBranchName = match.params.branch;
|
||||||
// const selectedBranchName = match.params.branch;
|
|
||||||
|
|
||||||
if (!branches || branches.length === 0) {
|
if (!branches || branches.length === 0) {
|
||||||
return null;
|
return null;
|
||||||
@@ -127,12 +130,11 @@ const mapStateToProps = (state: any, ownProps: Props) => {
|
|||||||
const { repository, match } = ownProps;
|
const { repository, match } = ownProps;
|
||||||
const loading = isFetchBranchesPending(state, repository);
|
const loading = isFetchBranchesPending(state, repository);
|
||||||
const error = getFetchBranchesFailure(state, repository);
|
const error = getFetchBranchesFailure(state, repository);
|
||||||
// const selectedBranch = getBranch(
|
const selectedBranch = getBranch(
|
||||||
// state,
|
state,
|
||||||
// repository,
|
repository,
|
||||||
// decodeURIComponent(match.params.branch)
|
decodeURIComponent(match.params.branch)
|
||||||
// );
|
);
|
||||||
const selectedBranch = "";
|
|
||||||
const branches = getBranches(state, repository);
|
const branches = getBranches(state, repository);
|
||||||
return {
|
return {
|
||||||
// loading,
|
// loading,
|
||||||
@@ -142,7 +144,9 @@ const mapStateToProps = (state: any, ownProps: Props) => {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
export default connect(
|
export default withRouter(
|
||||||
mapStateToProps,
|
connect(
|
||||||
mapDispatchToProps
|
mapStateToProps,
|
||||||
)(translate("repos")(BranchChooser));
|
mapDispatchToProps
|
||||||
|
)(translate("repos")(BranchChooser))
|
||||||
|
);
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
// @flow
|
// @flow
|
||||||
|
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import type { Repository } from "@scm-manager/ui-types";
|
import type { Repository, Branch } from "@scm-manager/ui-types";
|
||||||
import BranchChooser from "./BranchChooser";
|
import BranchChooser from "./BranchChooser";
|
||||||
import { Route, withRouter } from "react-router-dom";
|
import { Route, withRouter } from "react-router-dom";
|
||||||
import Changesets from "./Changesets";
|
import Changesets from "./Changesets";
|
||||||
@@ -36,28 +36,48 @@ class BranchRoot extends React.Component<Props> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
const { repository } = this.props;
|
||||||
const url = this.matchedUrl();
|
const url = this.matchedUrl();
|
||||||
|
if (!repository) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
return (
|
return (
|
||||||
<BranchChooser
|
<BranchChooser
|
||||||
repository={this.props.repository}
|
repository={this.props.repository}
|
||||||
label={"Branches"}
|
label={"Branches"}
|
||||||
branchSelected={this.branchSelected}
|
branchSelected={this.branchSelected}
|
||||||
>
|
>
|
||||||
<Changesets repository={this.props.repository} />
|
<RouteDelegate repository={this.props.repository} url={url} />
|
||||||
{/*<RouteDelegate repository={this.props.repository} url={url} />*/}
|
|
||||||
</BranchChooser>
|
</BranchChooser>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function RouteDelegate(props) {
|
type RDProps = {
|
||||||
return (
|
repository: Repository,
|
||||||
<Route
|
branch: Branch,
|
||||||
path={`${props.url}/:branch/changesets/:page?`}
|
url: string
|
||||||
component={() => <Changesets repository={props.repository} {...props} />}
|
};
|
||||||
/>
|
|
||||||
);
|
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} />}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default withRouter(BranchRoot);
|
export default withRouter(BranchRoot);
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ type Props = {
|
|||||||
|
|
||||||
type State = {};
|
type State = {};
|
||||||
|
|
||||||
class ChangesetContainer extends React.Component<Props, State> {
|
class Changesets extends React.Component<Props, State> {
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
const {
|
const {
|
||||||
fetchChangesetsByBranch,
|
fetchChangesetsByBranch,
|
||||||
@@ -45,6 +45,9 @@ class ChangesetContainer extends React.Component<Props, State> {
|
|||||||
branch,
|
branch,
|
||||||
match
|
match
|
||||||
} = this.props;
|
} = this.props;
|
||||||
|
|
||||||
|
console.log("branch");
|
||||||
|
console.log(branch);
|
||||||
const { page } = match.params;
|
const { page } = match.params;
|
||||||
if (!page) {
|
if (!page) {
|
||||||
fetchChangesetsByBranch(repository, branch);
|
fetchChangesetsByBranch(repository, branch);
|
||||||
@@ -54,7 +57,11 @@ class ChangesetContainer extends React.Component<Props, State> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { changesets, loading, error, t } = this.props;
|
const { repository, branch, changesets, loading, error, t } = this.props;
|
||||||
|
|
||||||
|
if (!repository || !branch) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
return (
|
return (
|
||||||
@@ -121,5 +128,5 @@ export default withRouter(
|
|||||||
connect(
|
connect(
|
||||||
mapStateToProps,
|
mapStateToProps,
|
||||||
mapDispatchToProps
|
mapDispatchToProps
|
||||||
)(translate("repos")(ChangesetContainer))
|
)(translate("repos")(Changesets))
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user