From f9e263fcf7b7b14592b2d41a53b24443ddd0b623 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maren=20S=C3=BCwer?= Date: Tue, 9 Oct 2018 16:46:39 +0200 Subject: [PATCH] use link for fetch repos --- scm-ui/src/repos/containers/Overview.js | 18 +++++++++++------- scm-ui/src/repos/modules/repos.js | 8 ++++---- scm-ui/src/repos/modules/repos.test.js | 22 +++++++++------------- 3 files changed, 24 insertions(+), 24 deletions(-) diff --git a/scm-ui/src/repos/containers/Overview.js b/scm-ui/src/repos/containers/Overview.js index 10230b29da..bbafe14539 100644 --- a/scm-ui/src/repos/containers/Overview.js +++ b/scm-ui/src/repos/containers/Overview.js @@ -18,6 +18,7 @@ import { CreateButton, Page, Paginator } from "@scm-manager/ui-components"; import RepositoryList from "../components/list"; import { withRouter } from "react-router-dom"; import type { History } from "history"; +import { getRepositoriesLink } from "../../modules/indexResource"; type Props = { page: number, @@ -25,10 +26,11 @@ type Props = { loading: boolean, error: Error, showCreateButton: boolean, + reposLink: string, // dispatched functions - fetchRepos: () => void, - fetchReposByPage: number => void, + fetchRepos: string => void, + fetchReposByPage: (string, number) => void, fetchReposByLink: string => void, // context props @@ -38,7 +40,7 @@ type Props = { class Overview extends React.Component { componentDidMount() { - this.props.fetchReposByPage(this.props.page); + this.props.fetchReposByPage(this.props.reposLink, this.props.page); } /** @@ -113,7 +115,9 @@ const mapStateToProps = (state, ownProps) => { const loading = isFetchReposPending(state); const error = getFetchReposFailure(state); const showCreateButton = isAbleToCreateRepos(state); + const reposLink = getRepositoriesLink(state); return { + reposLink, page, collection, loading, @@ -124,11 +128,11 @@ const mapStateToProps = (state, ownProps) => { const mapDispatchToProps = dispatch => { return { - fetchRepos: () => { - dispatch(fetchRepos()); + fetchRepos: (link: string) => { + dispatch(fetchRepos(link)); }, - fetchReposByPage: (page: number) => { - dispatch(fetchReposByPage(page)); + fetchReposByPage: (link: string, page: number) => { + dispatch(fetchReposByPage(link, page)); }, fetchReposByLink: (link: string) => { dispatch(fetchReposByLink(link)); diff --git a/scm-ui/src/repos/modules/repos.js b/scm-ui/src/repos/modules/repos.js index 1fb769f851..4be4d6e635 100644 --- a/scm-ui/src/repos/modules/repos.js +++ b/scm-ui/src/repos/modules/repos.js @@ -43,12 +43,12 @@ const CONTENT_TYPE = "application/vnd.scmm-repository+json;v=2"; const SORT_BY = "sortBy=namespaceAndName"; -export function fetchRepos() { - return fetchReposByLink(REPOS_URL); +export function fetchRepos(link: string) { + return fetchReposByLink(link); } -export function fetchReposByPage(page: number) { - return fetchReposByLink(`${REPOS_URL}?page=${page - 1}`); +export function fetchReposByPage(link: string, page: number) { + return fetchReposByLink(`${link}?page=${page - 1}`); } function appendSortByLink(url: string) { diff --git a/scm-ui/src/repos/modules/repos.test.js b/scm-ui/src/repos/modules/repos.test.js index e3ec9d48ac..204da73215 100644 --- a/scm-ui/src/repos/modules/repos.test.js +++ b/scm-ui/src/repos/modules/repos.test.js @@ -99,16 +99,13 @@ const hitchhikerRestatend: Repository = { type: "git", _links: { self: { - href: - "http://localhost:8081/api/v2/repositories/hitchhiker/restatend" + href: "http://localhost:8081/api/v2/repositories/hitchhiker/restatend" }, delete: { - href: - "http://localhost:8081/api/v2/repositories/hitchhiker/restatend" + href: "http://localhost:8081/api/v2/repositories/hitchhiker/restatend" }, update: { - href: - "http://localhost:8081/api/v2/repositories/hitchhiker/restatend" + href: "http://localhost:8081/api/v2/repositories/hitchhiker/restatend" }, permissions: { href: @@ -158,16 +155,14 @@ const slartiFjords: Repository = { href: "http://localhost:8081/api/v2/repositories/slarti/fjords/tags/" }, branches: { - href: - "http://localhost:8081/api/v2/repositories/slarti/fjords/branches/" + href: "http://localhost:8081/api/v2/repositories/slarti/fjords/branches/" }, changesets: { href: "http://localhost:8081/api/v2/repositories/slarti/fjords/changesets/" }, sources: { - href: - "http://localhost:8081/api/v2/repositories/slarti/fjords/sources/" + href: "http://localhost:8081/api/v2/repositories/slarti/fjords/sources/" } } }; @@ -221,6 +216,7 @@ const repositoryCollectionWithNames: RepositoryCollection = { }; describe("repos fetch", () => { + const URL = "repositories"; const REPOS_URL = "/api/v2/repositories"; const SORT = "sortBy=namespaceAndName"; const REPOS_URL_WITH_SORT = REPOS_URL + "?" + SORT; @@ -243,7 +239,7 @@ describe("repos fetch", () => { ]; const store = mockStore({}); - return store.dispatch(fetchRepos()).then(() => { + return store.dispatch(fetchRepos(URL)).then(() => { expect(store.getActions()).toEqual(expectedActions); }); }); @@ -262,7 +258,7 @@ describe("repos fetch", () => { const store = mockStore({}); - return store.dispatch(fetchReposByPage(43)).then(() => { + return store.dispatch(fetchReposByPage(URL, 43)).then(() => { expect(store.getActions()).toEqual(expectedActions); }); }); @@ -318,7 +314,7 @@ describe("repos fetch", () => { }); const store = mockStore({}); - return store.dispatch(fetchRepos()).then(() => { + return store.dispatch(fetchRepos(URL)).then(() => { const actions = store.getActions(); expect(actions[0].type).toEqual(FETCH_REPOS_PENDING); expect(actions[1].type).toEqual(FETCH_REPOS_FAILURE);