use repository instead of namespace and name

This commit is contained in:
Maren Süwer
2018-10-09 11:32:56 +02:00
parent 8c1ec57548
commit 5cb5bc9bd7
3 changed files with 68 additions and 69 deletions

View File

@@ -5,7 +5,6 @@ import { withRouter } from "react-router-dom";
import type { Changeset, Repository } from "@scm-manager/ui-types"; import type { Changeset, Repository } from "@scm-manager/ui-types";
import { import {
fetchChangesetIfNeeded, fetchChangesetIfNeeded,
fetchChangesetReset,
getChangeset, getChangeset,
getFetchChangesetFailure, getFetchChangesetFailure,
isFetchChangesetPending isFetchChangesetPending
@@ -73,9 +72,6 @@ const mapDispatchToProps = dispatch => {
id: string id: string
) => { ) => {
dispatch(fetchChangesetIfNeeded(namespace, repoName, id)); dispatch(fetchChangesetIfNeeded(namespace, repoName, id));
},
resetForm: (namespace: string, repoName: string, id: string) => {
dispatch(fetchChangesetReset(namespace, repoName, id));
} }
}; };
}; };

View File

@@ -9,7 +9,7 @@ import { apiClient } from "@scm-manager/ui-components";
import { isPending } from "../../modules/pending"; import { isPending } from "../../modules/pending";
import { getFailure } from "../../modules/failure"; import { getFailure } from "../../modules/failure";
import { combineReducers } from "redux"; import { combineReducers } from "redux";
import type { Action, PagedCollection } from "@scm-manager/ui-types"; import type { Action, PagedCollection, Repository } from "@scm-manager/ui-types";
import * as types from "../../modules/types"; import * as types from "../../modules/types";
export const FETCH_CHANGESETS = "scm/repos/FETCH_CHANGESETS"; export const FETCH_CHANGESETS = "scm/repos/FETCH_CHANGESETS";
@@ -33,80 +33,73 @@ const REPO_URL = "repositories";
//********added for detailed view of changesets //********added for detailed view of changesets
export function fetchChangesetIfNeeded( export function fetchChangesetIfNeeded(
namespace: string, repository: Repository,
repoName: string,
id: string id: string
) { ) {
return (dispatch: any, getState: any) => { return (dispatch: any, getState: any) => {
if (shouldFetchChangeset(getState(), namespace, repoName, id)) { if (shouldFetchChangeset(getState(), repository, id)) {
return dispatch(fetchChangeset(namespace, repoName, id)); return dispatch(fetchChangeset(repository, id));
} }
}; };
} }
export function fetchChangeset( export function fetchChangeset(
namespace: string, repository: Repository,
repoName: string,
id: string id: string
) { ) {
return function(dispatch: any) { return function(dispatch: any) {
dispatch(fetchChangesetPending(namespace, repoName, id)); dispatch(fetchChangesetPending(repository, id));
return apiClient return apiClient
.get(REPO_URL + `/${namespace}/${repoName}/changesets/${id}`) .get(REPO_URL + `/${repository.namespace}/${repository.name}/changesets/${id}`)
.then(response => response.json()) .then(response => response.json())
.then(data => .then(data =>
dispatch(fetchChangesetSuccess(data, namespace, repoName, id)) dispatch(fetchChangesetSuccess(data, repository, id))
) )
.catch(err => { .catch(err => {
dispatch(fetchChangesetFailure(namespace, repoName, id, err)); dispatch(fetchChangesetFailure(repository, id, err));
}); });
}; };
} }
export function fetchChangesetPending( export function fetchChangesetPending(
namespace: string, repository: Repository,
repoName: string,
id: string id: string
): Action { ): Action {
return { return {
type: FETCH_CHANGESET_PENDING, type: FETCH_CHANGESET_PENDING,
payload: { payload: {
namespace, repository,
repoName,
id id
}, },
itemId: createItemId(namespace, repoName, id) itemId: createItemId(repository.namespace, repository.name, id)
}; };
} }
export function fetchChangesetSuccess( export function fetchChangesetSuccess(
changeset: any, changeset: any,
namespace: string, repository: Repository,
repoName: string,
id: string id: string
): Action { ): Action {
return { return {
type: FETCH_CHANGESET_SUCCESS, type: FETCH_CHANGESET_SUCCESS,
payload: { changeset, namespace, repoName, id }, payload: { changeset, repository, id },
itemId: createItemId(namespace, repoName, id) itemId: createItemId(repository.namespace, repository.name, id)
}; };
} }
function fetchChangesetFailure( function fetchChangesetFailure(
namespace: string, repository: Repository,
repoName: string,
id: string, id: string,
error: Error error: Error
): Action { ): Action {
return { return {
type: FETCH_CHANGESET_FAILURE, type: FETCH_CHANGESET_FAILURE,
payload: { payload: {
namespace, repository,
repoName,
id, id,
error error
}, },
itemId: createItemId(namespace, repoName, id) itemId: createItemId(repository.namespace, repository.name, id)
}; };
} }
@@ -234,8 +227,8 @@ function byKeyReducer(
//********added for detailed view of changesets //********added for detailed view of changesets
case FETCH_CHANGESET_SUCCESS: case FETCH_CHANGESET_SUCCESS:
const _key = createItemId( const _key = createItemId(
action.payload.namespace, action.payload.repository.namespace,
action.payload.repoName action.payload.repository.name
); );
let _oldChangesets = { [_key]: {} }; let _oldChangesets = { [_key]: {} };
if (state[_key] !== undefined) { if (state[_key] !== undefined) {
@@ -353,12 +346,11 @@ export function getChangesets(
//********added for detailed view of changesets //********added for detailed view of changesets
export function getChangeset( export function getChangeset(
state: Object, state: Object,
namespace: string, repository: Repository,
name: string,
id: string, id: string,
branch?: string branch?: string
) { ) {
const key = createItemId(namespace, name, branch); const key = createItemId(repository.namespace, repository.name, branch);
const changesets = const changesets =
state.changesets && state.changesets.byKey && state.changesets.byKey[key] state.changesets && state.changesets.byKey && state.changesets.byKey[key]
? state.changesets.byKey[key].byId ? state.changesets.byKey[key].byId
@@ -371,11 +363,10 @@ export function getChangeset(
export function shouldFetchChangeset( export function shouldFetchChangeset(
state: Object, state: Object,
namespace: string, repository: Repository,
repoName: string,
id: string id: string
) { ) {
if (getChangeset(state, namespace, repoName, id)) { if (getChangeset(state, repository, id)) {
return false; return false;
} }
return true; return true;
@@ -383,20 +374,18 @@ export function shouldFetchChangeset(
export function isFetchChangesetPending( export function isFetchChangesetPending(
state: Object, state: Object,
namespace: string, repository: Repository,
name: string,
id: string id: string
) { ) {
return isPending(state, FETCH_CHANGESET, createItemId(namespace, name, id)); return isPending(state, FETCH_CHANGESET, createItemId(repository.namespace, repository.name, id));
} }
export function getFetchChangesetFailure( export function getFetchChangesetFailure(
state: Object, state: Object,
namespace: string, repository: Repository,
name: string,
id: string id: string
) { ) {
return getFailure(state, FETCH_CHANGESET, createItemId(namespace, name, id)); return getFailure(state, FETCH_CHANGESET, createItemId(repository.namespace, repository.name, id));
} }
//********end of added for detailed view of changesets //********end of added for detailed view of changesets

View File

@@ -31,6 +31,12 @@ import {
import reducer from "./changesets"; import reducer from "./changesets";
const changesets = {}; const changesets = {};
//********added for detailed view of changesets
const repository = {
namespace: "foo",
name: "bar"
};
//********end of added for detailed view of changesets
describe("changesets", () => { describe("changesets", () => {
describe("fetching of changesets", () => { describe("fetching of changesets", () => {
@@ -55,8 +61,10 @@ describe("changesets", () => {
type: FETCH_CHANGESET_PENDING, type: FETCH_CHANGESET_PENDING,
payload: { payload: {
id: changesetId, id: changesetId,
namespace: "foo", repository: {
repoName: "bar" name: "bar",
namespace: "foo"
}
}, },
itemId: "foo/bar/" + changesetId itemId: "foo/bar/" + changesetId
}, },
@@ -65,8 +73,10 @@ describe("changesets", () => {
payload: { payload: {
changeset: {}, changeset: {},
id: changesetId, id: changesetId,
namespace: "foo", repository: {
repoName: "bar" name: "bar",
namespace: "foo"
}
}, },
itemId: "foo/bar/" + changesetId itemId: "foo/bar/" + changesetId
} }
@@ -74,7 +84,7 @@ describe("changesets", () => {
const store = mockStore({}); const store = mockStore({});
return store return store
.dispatch(fetchChangeset("foo", "bar", changesetId)) .dispatch(fetchChangeset(repository, changesetId))
.then(() => { .then(() => {
expect(store.getActions()).toEqual(expectedActions); expect(store.getActions()).toEqual(expectedActions);
}); });
@@ -88,8 +98,10 @@ describe("changesets", () => {
type: FETCH_CHANGESET_PENDING, type: FETCH_CHANGESET_PENDING,
payload: { payload: {
id: changesetId, id: changesetId,
namespace: "foo", repository: {
repoName: "bar" name: "bar",
namespace: "foo"
}
}, },
itemId: "foo/bar/" + changesetId itemId: "foo/bar/" + changesetId
} }
@@ -97,7 +109,7 @@ describe("changesets", () => {
const store = mockStore({}); const store = mockStore({});
return store return store
.dispatch(fetchChangeset("foo", "bar", changesetId)) .dispatch(fetchChangeset(repository, changesetId))
.then(() => { .then(() => {
expect(store.getActions()[0]).toEqual(expectedActions[0]); expect(store.getActions()[0]).toEqual(expectedActions[0]);
expect(store.getActions()[1].type).toEqual(FETCH_CHANGESET_FAILURE); expect(store.getActions()[1].type).toEqual(FETCH_CHANGESET_FAILURE);
@@ -126,8 +138,10 @@ describe("changesets", () => {
type: FETCH_CHANGESET_PENDING, type: FETCH_CHANGESET_PENDING,
payload: { payload: {
id: "id3", id: "id3",
namespace: "foo", repository: {
repoName: "bar" name: "bar",
namespace: "foo"
}
}, },
itemId: "foo/bar/" + "id3" itemId: "foo/bar/" + "id3"
}, },
@@ -136,8 +150,10 @@ describe("changesets", () => {
payload: { payload: {
changeset: {}, changeset: {},
id: "id3", id: "id3",
namespace: "foo", repository: {
repoName: "bar" name: "bar",
namespace: "foo"
}
}, },
itemId: "foo/bar/" + "id3" itemId: "foo/bar/" + "id3"
} }
@@ -145,7 +161,7 @@ describe("changesets", () => {
const store = mockStore({}); const store = mockStore({});
return store return store
.dispatch(fetchChangesetIfNeeded("foo", "bar", "id3")) .dispatch(fetchChangesetIfNeeded(repository, "id3"))
.then(() => { .then(() => {
expect(store.getActions()).toEqual(expectedActions); expect(store.getActions()).toEqual(expectedActions);
}); });
@@ -171,7 +187,7 @@ describe("changesets", () => {
const store = mockStore(state); const store = mockStore(state);
return expect( return expect(
store.dispatch(fetchChangesetIfNeeded("foo", "bar", "id1")) store.dispatch(fetchChangesetIfNeeded(repository, "id1"))
).toEqual(undefined); ).toEqual(undefined);
}); });
@@ -431,7 +447,7 @@ describe("changesets", () => {
entries: ["id2"] entries: ["id2"]
} }
}, },
fetchChangesetSuccess(responseBodySingleChangeset, "foo", "bar", "id3") fetchChangesetSuccess(responseBodySingleChangeset, repository, "id3")
); );
expect(newState).toBeDefined(); expect(newState).toBeDefined();
expect(newState.byKey["foo/bar"].byId["id3"].description).toEqual( expect(newState.byKey["foo/bar"].byId["id3"].description).toEqual(
@@ -472,7 +488,7 @@ describe("changesets", () => {
} }
} }
}; };
const result = getChangeset(state, "foo", "bar", "id1"); const result = getChangeset(state, repository, "id1");
expect(result).toEqual({ id: "id1" }); expect(result).toEqual({ id: "id1" });
}); });
@@ -489,7 +505,7 @@ describe("changesets", () => {
} }
} }
}; };
const result = getChangeset(state, "foo", "bar", "id3"); const result = getChangeset(state, repository, "id3");
expect(result).toEqual(null); expect(result).toEqual(null);
}); });
@@ -506,7 +522,7 @@ describe("changesets", () => {
} }
} }
}; };
const result = shouldFetchChangeset(state, "foo", "bar", "id3"); const result = shouldFetchChangeset(state, repository, "id3");
expect(result).toEqual(true); expect(result).toEqual(true);
}); });
@@ -523,7 +539,7 @@ describe("changesets", () => {
} }
} }
}; };
const result = shouldFetchChangeset(state, "foo", "bar", "id2"); const result = shouldFetchChangeset(state, repository, "id2");
expect(result).toEqual(false); expect(result).toEqual(false);
}); });
@@ -534,11 +550,11 @@ describe("changesets", () => {
} }
}; };
expect(isFetchChangesetPending(state, "foo", "bar", "id1")).toBeTruthy(); expect(isFetchChangesetPending(state, repository, "id1")).toBeTruthy();
}); });
it("should return false, when fetching changeset is not pending", () => { it("should return false, when fetching changeset is not pending", () => {
expect(isFetchChangesetPending({}, "foo", "bar", "id1")).toEqual(false); expect(isFetchChangesetPending({}, repository, "id1")).toEqual(false);
}); });
it("should return error if fetching changeset failed", () => { it("should return error if fetching changeset failed", () => {
@@ -548,13 +564,11 @@ describe("changesets", () => {
} }
}; };
expect(getFetchChangesetFailure(state, "foo", "bar", "id1")).toEqual( expect(getFetchChangesetFailure(state, repository, "id1")).toEqual(error);
error
);
}); });
it("should return false if fetching changeset did not fail", () => { it("should return false if fetching changeset did not fail", () => {
expect(getFetchChangesetFailure({}, "foo", "bar", "id1")).toBeUndefined(); expect(getFetchChangesetFailure({}, repository, "id1")).toBeUndefined();
}); });
//********end of added for detailed view of changesets //********end of added for detailed view of changesets