diff --git a/scm-ui/src/repos/containers/Create.js b/scm-ui/src/repos/containers/Create.js index ed1de39b75..4cf8d468de 100644 --- a/scm-ui/src/repos/containers/Create.js +++ b/scm-ui/src/repos/containers/Create.js @@ -18,16 +18,18 @@ import { isCreateRepoPending } from "../modules/repos"; import type { History } from "history"; +import { getRepositoriesLink } from "../../modules/indexResource"; type Props = { repositoryTypes: RepositoryType[], typesLoading: boolean, createLoading: boolean, error: Error, + repoLink: string, // dispatch functions fetchRepositoryTypesIfNeeded: () => void, - createRepo: (Repository, callback: () => void) => void, + createRepo: (link: string, Repository, callback: () => void) => void, resetForm: () => void, // context props @@ -55,7 +57,7 @@ class Create extends React.Component { error } = this.props; - const { t } = this.props; + const { t, repoLink } = this.props; return ( { repositoryTypes={repositoryTypes} loading={createLoading} submitForm={repo => { - createRepo(repo, this.repoCreated); + createRepo(repoLink, repo, this.repoCreated); }} /> @@ -82,11 +84,13 @@ const mapStateToProps = state => { const createLoading = isCreateRepoPending(state); const error = getFetchRepositoryTypesFailure(state) || getCreateRepoFailure(state); + const repoLink = getRepositoriesLink(state); return { repositoryTypes, typesLoading, createLoading, - error + error, + repoLink }; }; @@ -95,8 +99,12 @@ const mapDispatchToProps = dispatch => { fetchRepositoryTypesIfNeeded: () => { dispatch(fetchRepositoryTypesIfNeeded()); }, - createRepo: (repository: Repository, callback: () => void) => { - dispatch(createRepo(repository, callback)); + createRepo: ( + link: string, + repository: Repository, + callback: () => void + ) => { + dispatch(createRepo(link, repository, callback)); }, resetForm: () => { dispatch(createRepoReset()); diff --git a/scm-ui/src/repos/containers/RepositoryRoot.js b/scm-ui/src/repos/containers/RepositoryRoot.js index 8119071ac1..188b71fb74 100644 --- a/scm-ui/src/repos/containers/RepositoryRoot.js +++ b/scm-ui/src/repos/containers/RepositoryRoot.js @@ -27,6 +27,7 @@ import Permissions from "../permissions/containers/Permissions"; import type { History } from "history"; import EditNavLink from "../components/EditNavLink"; import PermissionsNavLink from "../components/PermissionsNavLink"; +import { getRepositoriesLink } from "../../modules/indexResource"; type Props = { namespace: string, @@ -34,9 +35,10 @@ type Props = { repository: Repository, loading: boolean, error: Error, + repoLink: string, // dispatch functions - fetchRepo: (namespace: string, name: string) => void, + fetchRepo: (link: string, namespace: string, name: string) => void, deleteRepo: (repository: Repository, () => void) => void, // context props @@ -47,9 +49,9 @@ type Props = { class RepositoryRoot extends React.Component { componentDidMount() { - const { fetchRepo, namespace, name } = this.props; + const { fetchRepo, namespace, name, repoLink } = this.props; - fetchRepo(namespace, name); + fetchRepo(repoLink, namespace, name); } stripEndingSlash = (url: string) => { @@ -140,19 +142,21 @@ const mapStateToProps = (state, ownProps) => { const repository = getRepository(state, namespace, name); const loading = isFetchRepoPending(state, namespace, name); const error = getFetchRepoFailure(state, namespace, name); + const repoLink = getRepositoriesLink(state); return { namespace, name, repository, loading, - error + error, + repoLink }; }; const mapDispatchToProps = dispatch => { return { - fetchRepo: (namespace: string, name: string) => { - dispatch(fetchRepo(namespace, name)); + fetchRepo: (link: string, namespace: string, name: string) => { + dispatch(fetchRepo(link, namespace, name)); }, deleteRepo: (repository: Repository, callback: () => void) => { dispatch(deleteRepo(repository, callback)); diff --git a/scm-ui/src/repos/modules/repos.js b/scm-ui/src/repos/modules/repos.js index 4be4d6e635..6f9f4a0e4d 100644 --- a/scm-ui/src/repos/modules/repos.js +++ b/scm-ui/src/repos/modules/repos.js @@ -35,8 +35,6 @@ export const DELETE_REPO_PENDING = `${DELETE_REPO}_${types.PENDING_SUFFIX}`; export const DELETE_REPO_SUCCESS = `${DELETE_REPO}_${types.SUCCESS_SUFFIX}`; export const DELETE_REPO_FAILURE = `${DELETE_REPO}_${types.FAILURE_SUFFIX}`; -const REPOS_URL = "repositories"; - const CONTENT_TYPE = "application/vnd.scmm-repository+json;v=2"; // fetch repos @@ -102,11 +100,12 @@ export function fetchReposFailure(err: Error): Action { // fetch repo -export function fetchRepo(namespace: string, name: string) { +export function fetchRepo(link: string, namespace: string, name: string) { + const repoUrl = link.endsWith("/") ? link : link + "/"; return function(dispatch: any) { dispatch(fetchRepoPending(namespace, name)); return apiClient - .get(`${REPOS_URL}/${namespace}/${name}`) + .get(`${repoUrl}${namespace}/${name}`) .then(response => response.json()) .then(repository => { dispatch(fetchRepoSuccess(repository)); @@ -154,11 +153,11 @@ export function fetchRepoFailure( // create repo -export function createRepo(repository: Repository, callback?: () => void) { +export function createRepo(link: string, repository: Repository, callback?: () => void) { return function(dispatch: any) { dispatch(createRepoPending()); return apiClient - .post(REPOS_URL, repository, CONTENT_TYPE) + .post(link, repository, CONTENT_TYPE) .then(() => { dispatch(createRepoSuccess()); if (callback) { diff --git a/scm-ui/src/repos/modules/repos.test.js b/scm-ui/src/repos/modules/repos.test.js index 204da73215..8dd78b7645 100644 --- a/scm-ui/src/repos/modules/repos.test.js +++ b/scm-ui/src/repos/modules/repos.test.js @@ -342,7 +342,7 @@ describe("repos fetch", () => { ]; const store = mockStore({}); - return store.dispatch(fetchRepo("slarti", "fjords")).then(() => { + return store.dispatch(fetchRepo(URL, "slarti", "fjords")).then(() => { expect(store.getActions()).toEqual(expectedActions); }); }); @@ -353,7 +353,7 @@ describe("repos fetch", () => { }); const store = mockStore({}); - return store.dispatch(fetchRepo("slarti", "fjords")).then(() => { + return store.dispatch(fetchRepo(URL, "slarti", "fjords")).then(() => { const actions = store.getActions(); expect(actions[0].type).toEqual(FETCH_REPO_PENDING); expect(actions[1].type).toEqual(FETCH_REPO_FAILURE); @@ -379,7 +379,7 @@ describe("repos fetch", () => { ]; const store = mockStore({}); - return store.dispatch(createRepo(slartiFjords)).then(() => { + return store.dispatch(createRepo(URL, slartiFjords)).then(() => { expect(store.getActions()).toEqual(expectedActions); }); }); @@ -396,7 +396,7 @@ describe("repos fetch", () => { }; const store = mockStore({}); - return store.dispatch(createRepo(slartiFjords, callback)).then(() => { + return store.dispatch(createRepo(URL, slartiFjords, callback)).then(() => { expect(callMe).toBe("yeah"); }); }); @@ -407,7 +407,7 @@ describe("repos fetch", () => { }); const store = mockStore({}); - return store.dispatch(createRepo(slartiFjords)).then(() => { + return store.dispatch(createRepo(URL, slartiFjords)).then(() => { const actions = store.getActions(); expect(actions[0].type).toEqual(CREATE_REPO_PENDING); expect(actions[1].type).toEqual(CREATE_REPO_FAILURE);