diff --git a/scm-ui/src/repos/branches/components/BranchView.js b/scm-ui/src/repos/branches/components/BranchView.js new file mode 100644 index 0000000000..a7dd7dbd4b --- /dev/null +++ b/scm-ui/src/repos/branches/components/BranchView.js @@ -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 { + render() { + const { repository, branch } = this.props; + + return ( +
+ +
+
+ +
+
+ ); + } +} + +export default BranchView; diff --git a/scm-ui/src/repos/branches/containers/BranchView.js b/scm-ui/src/repos/branches/containers/BranchRoot.js similarity index 57% rename from scm-ui/src/repos/branches/containers/BranchView.js rename to scm-ui/src/repos/branches/containers/BranchRoot.js index 5e7fa9610a..f1570735e2 100644 --- a/scm-ui/src/repos/branches/containers/BranchView.js +++ b/scm-ui/src/repos/branches/containers/BranchRoot.js @@ -1,11 +1,10 @@ -// @flow +//@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 BranchView from "../components/BranchView"; import { connect } from "react-redux"; +import { Redirect, Route, Switch, withRouter } from "react-router-dom"; import { translate } from "react-i18next"; -import { withRouter } from "react-router-dom"; +import type { Repository, Branch } from "@scm-manager/ui-types"; import { fetchBranch, getBranch, @@ -13,32 +12,61 @@ import { isFetchBranchPending } from "../modules/branches"; import { ErrorPage, Loading } from "@scm-manager/ui-components"; +import type { History } from "history"; type Props = { repository: Repository, branchName: string, + branch: Branch, loading: boolean, error?: Error, - branch?: Branch, - - // dispatch functions - fetchBranch: (repository: Repository, branchName: string) => void, // context props - t: string => string + t: string => string, + history: History, + match: any, + location: any, + + // dispatch functions + fetchBranch: (repository: Repository, branchName: string) => void }; -class BranchView extends React.Component { +class BranchRoot extends React.Component { 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 { loading, error, t, repository, branch } = this.props; + const { + repository, + branch, + loading, + error, + t, + match, + location + } = this.props; + + const url = this.matchedUrl(); if (error) { + if(location.search.indexOf("?create=true") > -1) { + return ; + } + return ( { ); } - if (!branch || loading) { + if (loading || !branch) { return ; } return ( -
- -
-
- -
-
+ + + ( + + )} + /> + ); } } @@ -95,5 +121,5 @@ export default withRouter( connect( mapStateToProps, mapDispatchToProps - )(translate("repos")(BranchView)) + )(translate("repos")(BranchRoot)) ); diff --git a/scm-ui/src/repos/branches/containers/BranchesOverview.js b/scm-ui/src/repos/branches/containers/BranchesOverview.js index 3bc92deab4..f8c8be7529 100644 --- a/scm-ui/src/repos/branches/containers/BranchesOverview.js +++ b/scm-ui/src/repos/branches/containers/BranchesOverview.js @@ -4,9 +4,9 @@ import { fetchBranches, getBranches, getFetchBranchesFailure, - isFetchBranchesPending, - orderBranches + isFetchBranchesPending } from "../modules/branches"; +import { orderBranches } from "../util/orderBranches"; import { connect } from "react-redux"; import type { Branch, Repository } from "@scm-manager/ui-types"; import { compose } from "redux"; diff --git a/scm-ui/src/repos/branches/modules/branches.js b/scm-ui/src/repos/branches/modules/branches.js index d1e17191b1..b226ba7c0c 100644 --- a/scm-ui/src/repos/branches/modules/branches.js +++ b/scm-ui/src/repos/branches/modules/branches.js @@ -310,32 +310,3 @@ function createKey(repository: Repository): string { const { namespace, name } = repository; return `${namespace}/${name}`; } - -// master, default should always be the first one, -// followed by develop the rest should be ordered by its name -export function orderBranches(branches: Branch[]) { - branches.sort((a, b) => { - if (a.defaultBranch && !b.defaultBranch) { - return -20; - } else if (!a.defaultBranch && b.defaultBranch) { - return 20; - } else if (a.name === "master" && b.name !== "master") { - return -10; - } else if (a.name !== "master" && b.name === "master") { - return 10; - } else if (a.name === "default" && b.name !== "default") { - return -10; - } else if (a.name !== "default" && b.name === "default") { - return 10; - } else if (a.name === "develop" && b.name !== "develop") { - return -5; - } else if (a.name !== "develop" && b.name === "develop") { - return 5; - } else if (a.name < b.name) { - return -1; - } else if (a.name > b.name) { - return 1; - } - return 0; - }); -} diff --git a/scm-ui/src/repos/branches/modules/branches.test.js b/scm-ui/src/repos/branches/modules/branches.test.js index 8db4f6f83a..99c9bba60a 100644 --- a/scm-ui/src/repos/branches/modules/branches.test.js +++ b/scm-ui/src/repos/branches/modules/branches.test.js @@ -6,7 +6,6 @@ import reducer, { FETCH_BRANCHES_FAILURE, FETCH_BRANCHES_PENDING, FETCH_BRANCHES_SUCCESS, - FETCH_BRANCH, FETCH_BRANCH_PENDING, FETCH_BRANCH_SUCCESS, FETCH_BRANCH_FAILURE, @@ -16,8 +15,7 @@ import reducer, { getBranch, getBranches, getFetchBranchesFailure, - isFetchBranchesPending, - orderBranches + isFetchBranchesPending } from "./branches"; const namespace = "foo"; @@ -35,18 +33,7 @@ const repository = { const branch1 = { name: "branch1", revision: "revision1" }; const branch2 = { name: "branch2", revision: "revision2" }; -const branch3 = { name: "branch3", revision: "revision3", defaultBranch: true }; -const defaultBranch = { - name: "default", - revision: "revision4", - defaultBranch: false -}; -const developBranch = { - name: "develop", - revision: "revision5", - defaultBranch: false -}; -const masterBranch = { name: "master", revision: "revision6", defaultBranch: false }; +const branch3 = { name: "branch3", revision: "revision3" }; describe("branches", () => { describe("fetch branches", () => { @@ -293,30 +280,4 @@ describe("branches", () => { expect(getFetchBranchesFailure({}, repository)).toBeUndefined(); }); }); - - describe("sort branches", () => { - it("should return branches", () => { - let branches = [branch1, branch2]; - orderBranches(branches); - expect(branches).toEqual([branch1, branch2]); - }); - - it("should return defaultBranch first", () => { - let branches = [branch1, branch2, branch3]; - orderBranches(branches); - expect(branches).toEqual([branch3, branch1, branch2]); - }); - - it("should order special branches as follows: master > default > develop", () => { - let branches = [defaultBranch, developBranch, masterBranch]; - orderBranches(branches); - expect(branches).toEqual([masterBranch, defaultBranch, developBranch]); - }); - - it("should order special branches but starting with defaultBranch", () => { - let branches = [masterBranch, developBranch, defaultBranch, branch3]; - orderBranches(branches); - expect(branches).toEqual([branch3, masterBranch, defaultBranch, developBranch]); - }); - }); }); diff --git a/scm-ui/src/repos/branches/util/orderBranches.js b/scm-ui/src/repos/branches/util/orderBranches.js new file mode 100644 index 0000000000..a1c2f5e460 --- /dev/null +++ b/scm-ui/src/repos/branches/util/orderBranches.js @@ -0,0 +1,32 @@ +// @flow + +// master, default should always be the first one, +// followed by develop the rest should be ordered by its name +import type {Branch} from "@scm-manager/ui-types"; + +export function orderBranches(branches: Branch[]) { + branches.sort((a, b) => { + if (a.defaultBranch && !b.defaultBranch) { + return -20; + } else if (!a.defaultBranch && b.defaultBranch) { + return 20; + } else if (a.name === "master" && b.name !== "master") { + return -10; + } else if (a.name !== "master" && b.name === "master") { + return 10; + } else if (a.name === "default" && b.name !== "default") { + return -10; + } else if (a.name !== "default" && b.name === "default") { + return 10; + } else if (a.name === "develop" && b.name !== "develop") { + return -5; + } else if (a.name !== "develop" && b.name === "develop") { + return 5; + } else if (a.name < b.name) { + return -1; + } else if (a.name > b.name) { + return 1; + } + return 0; + }); +} diff --git a/scm-ui/src/repos/branches/util/orderBranches.test.js b/scm-ui/src/repos/branches/util/orderBranches.test.js new file mode 100644 index 0000000000..557cc8a4c5 --- /dev/null +++ b/scm-ui/src/repos/branches/util/orderBranches.test.js @@ -0,0 +1,51 @@ +import { orderBranches } from "./orderBranches"; + +const branch1 = { name: "branch1", revision: "revision1" }; +const branch2 = { name: "branch2", revision: "revision2" }; +const branch3 = { name: "branch3", revision: "revision3", defaultBranch: true }; +const defaultBranch = { + name: "default", + revision: "revision4", + defaultBranch: false +}; +const developBranch = { + name: "develop", + revision: "revision5", + defaultBranch: false +}; +const masterBranch = { + name: "master", + revision: "revision6", + defaultBranch: false +}; + +describe("order branches", () => { + it("should return branches", () => { + let branches = [branch1, branch2]; + orderBranches(branches); + expect(branches).toEqual([branch1, branch2]); + }); + + it("should return defaultBranch first", () => { + let branches = [branch1, branch2, branch3]; + orderBranches(branches); + expect(branches).toEqual([branch3, branch1, branch2]); + }); + + it("should order special branches as follows: master > default > develop", () => { + let branches = [defaultBranch, developBranch, masterBranch]; + orderBranches(branches); + expect(branches).toEqual([masterBranch, defaultBranch, developBranch]); + }); + + it("should order special branches but starting with defaultBranch", () => { + let branches = [masterBranch, developBranch, defaultBranch, branch3]; + orderBranches(branches); + expect(branches).toEqual([ + branch3, + masterBranch, + defaultBranch, + developBranch + ]); + }); +}); diff --git a/scm-ui/src/repos/containers/ChangesetsRoot.js b/scm-ui/src/repos/containers/ChangesetsRoot.js index c4f40e0d74..c4c310d94d 100644 --- a/scm-ui/src/repos/containers/ChangesetsRoot.js +++ b/scm-ui/src/repos/containers/ChangesetsRoot.js @@ -40,7 +40,7 @@ type Props = { t: string => string }; -class BranchRoot extends React.Component { +class ChangesetsRoot extends React.Component { componentDidMount() { this.props.fetchBranches(this.props.repository); } @@ -146,4 +146,4 @@ export default compose( mapStateToProps, mapDispatchToProps ) -)(BranchRoot); +)(ChangesetsRoot); diff --git a/scm-ui/src/repos/containers/RepositoryRoot.js b/scm-ui/src/repos/containers/RepositoryRoot.js index 8c481f1adc..418b43d144 100644 --- a/scm-ui/src/repos/containers/RepositoryRoot.js +++ b/scm-ui/src/repos/containers/RepositoryRoot.js @@ -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 { ( - { )} /> ( - @@ -187,7 +186,7 @@ class RepositoryRoot extends React.Component { ( -