From d6ead4fa8234f69c4ce631c636f031ec158b71cd Mon Sep 17 00:00:00 2001 From: Florian Scholdei Date: Mon, 1 Apr 2019 15:25:55 +0200 Subject: [PATCH] created repo specific xhangeset and sourceslink --- .../branches/components/BranchButtonGroup.js | 5 ++-- scm-ui/src/repos/modules/branches.js | 23 +++++++++++++++++-- scm-ui/src/repos/modules/branches.test.js | 5 ---- 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/scm-ui/src/repos/branches/components/BranchButtonGroup.js b/scm-ui/src/repos/branches/components/BranchButtonGroup.js index 2ed49d7b1f..b7c7a843ec 100644 --- a/scm-ui/src/repos/branches/components/BranchButtonGroup.js +++ b/scm-ui/src/repos/branches/components/BranchButtonGroup.js @@ -3,6 +3,7 @@ import React from "react"; import type { Repository, Branch } from "@scm-manager/ui-types"; import { ButtonGroup, Button } from "@scm-manager/ui-components"; import { translate } from "react-i18next"; +import { createChangesetLink, createSourcesLink } from "../../modules/branches"; type Props = { repository: Repository, @@ -16,8 +17,8 @@ class BranchButtonGroup extends React.Component { render() { const { repository, branch, t } = this.props; - const changesetLink = ""; - const sourcesLink = ""; + const changesetLink = createChangesetLink(repository, branch); + const sourcesLink = createSourcesLink(repository, branch); return ( diff --git a/scm-ui/src/repos/modules/branches.js b/scm-ui/src/repos/modules/branches.js index 5c9a63b5d6..8397ac3011 100644 --- a/scm-ui/src/repos/modules/branches.js +++ b/scm-ui/src/repos/modules/branches.js @@ -5,7 +5,12 @@ import { SUCCESS_SUFFIX } from "../../modules/types"; import { apiClient } from "@scm-manager/ui-components"; -import type { Action, Branch, Repository } from "@scm-manager/ui-types"; +import type { + Action, + Branch, + Changeset, + Repository +} from "@scm-manager/ui-types"; import { isPending } from "../../modules/pending"; import { getFailure } from "../../modules/failure"; @@ -22,7 +27,9 @@ export const FETCH_BRANCH_FAILURE = `${FETCH_BRANCH}_${FAILURE_SUFFIX}`; // Fetching branches export function fetchBranchByName(link: string, name: string) { - const branchUrl = link.endsWith("/") ? link + encodeURIComponent(name) : link + "/" + encodeURIComponent(name); + const branchUrl = link.endsWith("/") + ? link + encodeURIComponent(name) + : link + "/" + encodeURIComponent(name); return fetchBranch(branchUrl, name); } @@ -203,3 +210,15 @@ function createKey(repository: Repository): string { const { namespace, name } = repository; return `${namespace}/${name}`; } + +export function createChangesetLink(repository: Repository, branch: Branch) { + return `/repo/${repository.namespace}/${ + repository.name + }/branch/${encodeURIComponent(branch.name)}/changesets/`; +} + +export function createSourcesLink(repository: Repository, branch: Branch) { + return `/repo/${repository.namespace}/${ + repository.name + }/sources/${encodeURIComponent(branch.name)}/`; +} diff --git a/scm-ui/src/repos/modules/branches.test.js b/scm-ui/src/repos/modules/branches.test.js index 1f33992b65..5e9b4e0f1f 100644 --- a/scm-ui/src/repos/modules/branches.test.js +++ b/scm-ui/src/repos/modules/branches.test.js @@ -161,11 +161,6 @@ describe("branches", () => { const newState = reducer({}, fetchBranchSuccess(branch3)); expect(newState["branch3"]).toBe(branch3); }); - - it("should update state according to FETCH_BRANCH_SUCCESS action", () => { - const newState = reducer({}, fetchBranch(URL + "/branch1", "branch1")); - expect(newState["branch1"]).toBe(branch1); - }); }); describe("branch selectors", () => {