mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-09 23:15:43 +01:00
use repository instead of namespace and name
This commit is contained in:
@@ -5,7 +5,6 @@ import { withRouter } from "react-router-dom";
|
||||
import type { Changeset, Repository } from "@scm-manager/ui-types";
|
||||
import {
|
||||
fetchChangesetIfNeeded,
|
||||
fetchChangesetReset,
|
||||
getChangeset,
|
||||
getFetchChangesetFailure,
|
||||
isFetchChangesetPending
|
||||
@@ -52,7 +51,7 @@ class ChangesetView extends React.Component<Props> {
|
||||
|
||||
if (!changeset || loading) return <Loading />;
|
||||
|
||||
return <ChangesetDetails changeset={changeset} repository={repository}/>;
|
||||
return <ChangesetDetails changeset={changeset} repository={repository} />;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,9 +72,6 @@ const mapDispatchToProps = dispatch => {
|
||||
id: string
|
||||
) => {
|
||||
dispatch(fetchChangesetIfNeeded(namespace, repoName, id));
|
||||
},
|
||||
resetForm: (namespace: string, repoName: string, id: string) => {
|
||||
dispatch(fetchChangesetReset(namespace, repoName, id));
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
@@ -9,7 +9,7 @@ import { apiClient } from "@scm-manager/ui-components";
|
||||
import { isPending } from "../../modules/pending";
|
||||
import { getFailure } from "../../modules/failure";
|
||||
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";
|
||||
|
||||
export const FETCH_CHANGESETS = "scm/repos/FETCH_CHANGESETS";
|
||||
@@ -33,80 +33,73 @@ const REPO_URL = "repositories";
|
||||
//********added for detailed view of changesets
|
||||
|
||||
export function fetchChangesetIfNeeded(
|
||||
namespace: string,
|
||||
repoName: string,
|
||||
repository: Repository,
|
||||
id: string
|
||||
) {
|
||||
return (dispatch: any, getState: any) => {
|
||||
if (shouldFetchChangeset(getState(), namespace, repoName, id)) {
|
||||
return dispatch(fetchChangeset(namespace, repoName, id));
|
||||
if (shouldFetchChangeset(getState(), repository, id)) {
|
||||
return dispatch(fetchChangeset(repository, id));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export function fetchChangeset(
|
||||
namespace: string,
|
||||
repoName: string,
|
||||
repository: Repository,
|
||||
id: string
|
||||
) {
|
||||
return function(dispatch: any) {
|
||||
dispatch(fetchChangesetPending(namespace, repoName, id));
|
||||
dispatch(fetchChangesetPending(repository, id));
|
||||
return apiClient
|
||||
.get(REPO_URL + `/${namespace}/${repoName}/changesets/${id}`)
|
||||
.get(REPO_URL + `/${repository.namespace}/${repository.name}/changesets/${id}`)
|
||||
.then(response => response.json())
|
||||
.then(data =>
|
||||
dispatch(fetchChangesetSuccess(data, namespace, repoName, id))
|
||||
dispatch(fetchChangesetSuccess(data, repository, id))
|
||||
)
|
||||
.catch(err => {
|
||||
dispatch(fetchChangesetFailure(namespace, repoName, id, err));
|
||||
dispatch(fetchChangesetFailure(repository, id, err));
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
export function fetchChangesetPending(
|
||||
namespace: string,
|
||||
repoName: string,
|
||||
repository: Repository,
|
||||
id: string
|
||||
): Action {
|
||||
return {
|
||||
type: FETCH_CHANGESET_PENDING,
|
||||
payload: {
|
||||
namespace,
|
||||
repoName,
|
||||
repository,
|
||||
id
|
||||
},
|
||||
itemId: createItemId(namespace, repoName, id)
|
||||
itemId: createItemId(repository.namespace, repository.name, id)
|
||||
};
|
||||
}
|
||||
|
||||
export function fetchChangesetSuccess(
|
||||
changeset: any,
|
||||
namespace: string,
|
||||
repoName: string,
|
||||
repository: Repository,
|
||||
id: string
|
||||
): Action {
|
||||
return {
|
||||
type: FETCH_CHANGESET_SUCCESS,
|
||||
payload: { changeset, namespace, repoName, id },
|
||||
itemId: createItemId(namespace, repoName, id)
|
||||
payload: { changeset, repository, id },
|
||||
itemId: createItemId(repository.namespace, repository.name, id)
|
||||
};
|
||||
}
|
||||
|
||||
function fetchChangesetFailure(
|
||||
namespace: string,
|
||||
repoName: string,
|
||||
repository: Repository,
|
||||
id: string,
|
||||
error: Error
|
||||
): Action {
|
||||
return {
|
||||
type: FETCH_CHANGESET_FAILURE,
|
||||
payload: {
|
||||
namespace,
|
||||
repoName,
|
||||
repository,
|
||||
id,
|
||||
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
|
||||
case FETCH_CHANGESET_SUCCESS:
|
||||
const _key = createItemId(
|
||||
action.payload.namespace,
|
||||
action.payload.repoName
|
||||
action.payload.repository.namespace,
|
||||
action.payload.repository.name
|
||||
);
|
||||
let _oldChangesets = { [_key]: {} };
|
||||
if (state[_key] !== undefined) {
|
||||
@@ -353,12 +346,11 @@ export function getChangesets(
|
||||
//********added for detailed view of changesets
|
||||
export function getChangeset(
|
||||
state: Object,
|
||||
namespace: string,
|
||||
name: string,
|
||||
repository: Repository,
|
||||
id: string,
|
||||
branch?: string
|
||||
) {
|
||||
const key = createItemId(namespace, name, branch);
|
||||
const key = createItemId(repository.namespace, repository.name, branch);
|
||||
const changesets =
|
||||
state.changesets && state.changesets.byKey && state.changesets.byKey[key]
|
||||
? state.changesets.byKey[key].byId
|
||||
@@ -371,11 +363,10 @@ export function getChangeset(
|
||||
|
||||
export function shouldFetchChangeset(
|
||||
state: Object,
|
||||
namespace: string,
|
||||
repoName: string,
|
||||
repository: Repository,
|
||||
id: string
|
||||
) {
|
||||
if (getChangeset(state, namespace, repoName, id)) {
|
||||
if (getChangeset(state, repository, id)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@@ -383,20 +374,18 @@ export function shouldFetchChangeset(
|
||||
|
||||
export function isFetchChangesetPending(
|
||||
state: Object,
|
||||
namespace: string,
|
||||
name: string,
|
||||
repository: Repository,
|
||||
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(
|
||||
state: Object,
|
||||
namespace: string,
|
||||
name: string,
|
||||
repository: Repository,
|
||||
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
|
||||
|
||||
|
||||
@@ -31,6 +31,12 @@ import {
|
||||
import reducer from "./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("fetching of changesets", () => {
|
||||
@@ -55,8 +61,10 @@ describe("changesets", () => {
|
||||
type: FETCH_CHANGESET_PENDING,
|
||||
payload: {
|
||||
id: changesetId,
|
||||
namespace: "foo",
|
||||
repoName: "bar"
|
||||
repository: {
|
||||
name: "bar",
|
||||
namespace: "foo"
|
||||
}
|
||||
},
|
||||
itemId: "foo/bar/" + changesetId
|
||||
},
|
||||
@@ -65,8 +73,10 @@ describe("changesets", () => {
|
||||
payload: {
|
||||
changeset: {},
|
||||
id: changesetId,
|
||||
namespace: "foo",
|
||||
repoName: "bar"
|
||||
repository: {
|
||||
name: "bar",
|
||||
namespace: "foo"
|
||||
}
|
||||
},
|
||||
itemId: "foo/bar/" + changesetId
|
||||
}
|
||||
@@ -74,7 +84,7 @@ describe("changesets", () => {
|
||||
|
||||
const store = mockStore({});
|
||||
return store
|
||||
.dispatch(fetchChangeset("foo", "bar", changesetId))
|
||||
.dispatch(fetchChangeset(repository, changesetId))
|
||||
.then(() => {
|
||||
expect(store.getActions()).toEqual(expectedActions);
|
||||
});
|
||||
@@ -88,8 +98,10 @@ describe("changesets", () => {
|
||||
type: FETCH_CHANGESET_PENDING,
|
||||
payload: {
|
||||
id: changesetId,
|
||||
namespace: "foo",
|
||||
repoName: "bar"
|
||||
repository: {
|
||||
name: "bar",
|
||||
namespace: "foo"
|
||||
}
|
||||
},
|
||||
itemId: "foo/bar/" + changesetId
|
||||
}
|
||||
@@ -97,7 +109,7 @@ describe("changesets", () => {
|
||||
|
||||
const store = mockStore({});
|
||||
return store
|
||||
.dispatch(fetchChangeset("foo", "bar", changesetId))
|
||||
.dispatch(fetchChangeset(repository, changesetId))
|
||||
.then(() => {
|
||||
expect(store.getActions()[0]).toEqual(expectedActions[0]);
|
||||
expect(store.getActions()[1].type).toEqual(FETCH_CHANGESET_FAILURE);
|
||||
@@ -126,8 +138,10 @@ describe("changesets", () => {
|
||||
type: FETCH_CHANGESET_PENDING,
|
||||
payload: {
|
||||
id: "id3",
|
||||
namespace: "foo",
|
||||
repoName: "bar"
|
||||
repository: {
|
||||
name: "bar",
|
||||
namespace: "foo"
|
||||
}
|
||||
},
|
||||
itemId: "foo/bar/" + "id3"
|
||||
},
|
||||
@@ -136,8 +150,10 @@ describe("changesets", () => {
|
||||
payload: {
|
||||
changeset: {},
|
||||
id: "id3",
|
||||
namespace: "foo",
|
||||
repoName: "bar"
|
||||
repository: {
|
||||
name: "bar",
|
||||
namespace: "foo"
|
||||
}
|
||||
},
|
||||
itemId: "foo/bar/" + "id3"
|
||||
}
|
||||
@@ -145,7 +161,7 @@ describe("changesets", () => {
|
||||
|
||||
const store = mockStore({});
|
||||
return store
|
||||
.dispatch(fetchChangesetIfNeeded("foo", "bar", "id3"))
|
||||
.dispatch(fetchChangesetIfNeeded(repository, "id3"))
|
||||
.then(() => {
|
||||
expect(store.getActions()).toEqual(expectedActions);
|
||||
});
|
||||
@@ -171,7 +187,7 @@ describe("changesets", () => {
|
||||
|
||||
const store = mockStore(state);
|
||||
return expect(
|
||||
store.dispatch(fetchChangesetIfNeeded("foo", "bar", "id1"))
|
||||
store.dispatch(fetchChangesetIfNeeded(repository, "id1"))
|
||||
).toEqual(undefined);
|
||||
});
|
||||
|
||||
@@ -431,7 +447,7 @@ describe("changesets", () => {
|
||||
entries: ["id2"]
|
||||
}
|
||||
},
|
||||
fetchChangesetSuccess(responseBodySingleChangeset, "foo", "bar", "id3")
|
||||
fetchChangesetSuccess(responseBodySingleChangeset, repository, "id3")
|
||||
);
|
||||
expect(newState).toBeDefined();
|
||||
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" });
|
||||
});
|
||||
|
||||
@@ -489,7 +505,7 @@ describe("changesets", () => {
|
||||
}
|
||||
}
|
||||
};
|
||||
const result = getChangeset(state, "foo", "bar", "id3");
|
||||
const result = getChangeset(state, repository, "id3");
|
||||
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);
|
||||
});
|
||||
|
||||
@@ -523,7 +539,7 @@ describe("changesets", () => {
|
||||
}
|
||||
}
|
||||
};
|
||||
const result = shouldFetchChangeset(state, "foo", "bar", "id2");
|
||||
const result = shouldFetchChangeset(state, repository, "id2");
|
||||
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", () => {
|
||||
expect(isFetchChangesetPending({}, "foo", "bar", "id1")).toEqual(false);
|
||||
expect(isFetchChangesetPending({}, repository, "id1")).toEqual(false);
|
||||
});
|
||||
|
||||
it("should return error if fetching changeset failed", () => {
|
||||
@@ -548,13 +564,11 @@ describe("changesets", () => {
|
||||
}
|
||||
};
|
||||
|
||||
expect(getFetchChangesetFailure(state, "foo", "bar", "id1")).toEqual(
|
||||
error
|
||||
);
|
||||
expect(getFetchChangesetFailure(state, repository, "id1")).toEqual(error);
|
||||
});
|
||||
|
||||
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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user