use link for fetch repos

This commit is contained in:
Maren Süwer
2018-10-09 16:46:39 +02:00
parent 89be4039bf
commit f9e263fcf7
3 changed files with 24 additions and 24 deletions

View File

@@ -18,6 +18,7 @@ import { CreateButton, Page, Paginator } from "@scm-manager/ui-components";
import RepositoryList from "../components/list"; import RepositoryList from "../components/list";
import { withRouter } from "react-router-dom"; import { withRouter } from "react-router-dom";
import type { History } from "history"; import type { History } from "history";
import { getRepositoriesLink } from "../../modules/indexResource";
type Props = { type Props = {
page: number, page: number,
@@ -25,10 +26,11 @@ type Props = {
loading: boolean, loading: boolean,
error: Error, error: Error,
showCreateButton: boolean, showCreateButton: boolean,
reposLink: string,
// dispatched functions // dispatched functions
fetchRepos: () => void, fetchRepos: string => void,
fetchReposByPage: number => void, fetchReposByPage: (string, number) => void,
fetchReposByLink: string => void, fetchReposByLink: string => void,
// context props // context props
@@ -38,7 +40,7 @@ type Props = {
class Overview extends React.Component<Props> { class Overview extends React.Component<Props> {
componentDidMount() { 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 loading = isFetchReposPending(state);
const error = getFetchReposFailure(state); const error = getFetchReposFailure(state);
const showCreateButton = isAbleToCreateRepos(state); const showCreateButton = isAbleToCreateRepos(state);
const reposLink = getRepositoriesLink(state);
return { return {
reposLink,
page, page,
collection, collection,
loading, loading,
@@ -124,11 +128,11 @@ const mapStateToProps = (state, ownProps) => {
const mapDispatchToProps = dispatch => { const mapDispatchToProps = dispatch => {
return { return {
fetchRepos: () => { fetchRepos: (link: string) => {
dispatch(fetchRepos()); dispatch(fetchRepos(link));
}, },
fetchReposByPage: (page: number) => { fetchReposByPage: (link: string, page: number) => {
dispatch(fetchReposByPage(page)); dispatch(fetchReposByPage(link, page));
}, },
fetchReposByLink: (link: string) => { fetchReposByLink: (link: string) => {
dispatch(fetchReposByLink(link)); dispatch(fetchReposByLink(link));

View File

@@ -43,12 +43,12 @@ const CONTENT_TYPE = "application/vnd.scmm-repository+json;v=2";
const SORT_BY = "sortBy=namespaceAndName"; const SORT_BY = "sortBy=namespaceAndName";
export function fetchRepos() { export function fetchRepos(link: string) {
return fetchReposByLink(REPOS_URL); return fetchReposByLink(link);
} }
export function fetchReposByPage(page: number) { export function fetchReposByPage(link: string, page: number) {
return fetchReposByLink(`${REPOS_URL}?page=${page - 1}`); return fetchReposByLink(`${link}?page=${page - 1}`);
} }
function appendSortByLink(url: string) { function appendSortByLink(url: string) {

View File

@@ -99,16 +99,13 @@ const hitchhikerRestatend: Repository = {
type: "git", type: "git",
_links: { _links: {
self: { self: {
href: href: "http://localhost:8081/api/v2/repositories/hitchhiker/restatend"
"http://localhost:8081/api/v2/repositories/hitchhiker/restatend"
}, },
delete: { delete: {
href: href: "http://localhost:8081/api/v2/repositories/hitchhiker/restatend"
"http://localhost:8081/api/v2/repositories/hitchhiker/restatend"
}, },
update: { update: {
href: href: "http://localhost:8081/api/v2/repositories/hitchhiker/restatend"
"http://localhost:8081/api/v2/repositories/hitchhiker/restatend"
}, },
permissions: { permissions: {
href: href:
@@ -158,16 +155,14 @@ const slartiFjords: Repository = {
href: "http://localhost:8081/api/v2/repositories/slarti/fjords/tags/" href: "http://localhost:8081/api/v2/repositories/slarti/fjords/tags/"
}, },
branches: { branches: {
href: href: "http://localhost:8081/api/v2/repositories/slarti/fjords/branches/"
"http://localhost:8081/api/v2/repositories/slarti/fjords/branches/"
}, },
changesets: { changesets: {
href: href:
"http://localhost:8081/api/v2/repositories/slarti/fjords/changesets/" "http://localhost:8081/api/v2/repositories/slarti/fjords/changesets/"
}, },
sources: { sources: {
href: href: "http://localhost:8081/api/v2/repositories/slarti/fjords/sources/"
"http://localhost:8081/api/v2/repositories/slarti/fjords/sources/"
} }
} }
}; };
@@ -221,6 +216,7 @@ const repositoryCollectionWithNames: RepositoryCollection = {
}; };
describe("repos fetch", () => { describe("repos fetch", () => {
const URL = "repositories";
const REPOS_URL = "/api/v2/repositories"; const REPOS_URL = "/api/v2/repositories";
const SORT = "sortBy=namespaceAndName"; const SORT = "sortBy=namespaceAndName";
const REPOS_URL_WITH_SORT = REPOS_URL + "?" + SORT; const REPOS_URL_WITH_SORT = REPOS_URL + "?" + SORT;
@@ -243,7 +239,7 @@ describe("repos fetch", () => {
]; ];
const store = mockStore({}); const store = mockStore({});
return store.dispatch(fetchRepos()).then(() => { return store.dispatch(fetchRepos(URL)).then(() => {
expect(store.getActions()).toEqual(expectedActions); expect(store.getActions()).toEqual(expectedActions);
}); });
}); });
@@ -262,7 +258,7 @@ describe("repos fetch", () => {
const store = mockStore({}); const store = mockStore({});
return store.dispatch(fetchReposByPage(43)).then(() => { return store.dispatch(fetchReposByPage(URL, 43)).then(() => {
expect(store.getActions()).toEqual(expectedActions); expect(store.getActions()).toEqual(expectedActions);
}); });
}); });
@@ -318,7 +314,7 @@ describe("repos fetch", () => {
}); });
const store = mockStore({}); const store = mockStore({});
return store.dispatch(fetchRepos()).then(() => { return store.dispatch(fetchRepos(URL)).then(() => {
const actions = store.getActions(); const actions = store.getActions();
expect(actions[0].type).toEqual(FETCH_REPOS_PENDING); expect(actions[0].type).toEqual(FETCH_REPOS_PENDING);
expect(actions[1].type).toEqual(FETCH_REPOS_FAILURE); expect(actions[1].type).toEqual(FETCH_REPOS_FAILURE);