mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-17 10:41:06 +01:00
Restructured changeset module
This commit is contained in:
@@ -39,21 +39,18 @@ export function fetchChangesetsByNamespaceNameAndBranch(namespace: string, name:
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function fetchChangesetsPending(namespace: string, name: string, branch?: string): Action {
|
export function fetchChangesetsPending(namespace: string, name: string, branch?: string): Action {
|
||||||
|
const itemId = createItemId(namespace, name, branch);
|
||||||
return {
|
return {
|
||||||
type: FETCH_CHANGESETS_PENDING,
|
type: FETCH_CHANGESETS_PENDING,
|
||||||
payload: {
|
payload: itemId,
|
||||||
namespace,
|
itemId
|
||||||
name,
|
|
||||||
branch
|
|
||||||
},
|
|
||||||
itemId: createItemId(namespace, name, branch)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function fetchChangesetsSuccess(collection: any, namespace: string, name: string, branch?: string): Action {
|
export function fetchChangesetsSuccess(changesets: any, namespace: string, name: string, branch?: string): Action {
|
||||||
return {
|
return {
|
||||||
type: FETCH_CHANGESETS_SUCCESS,
|
type: FETCH_CHANGESETS_SUCCESS,
|
||||||
payload: {collection, namespace, name, branch},
|
payload: changesets,
|
||||||
itemId: createItemId(namespace, name, branch)
|
itemId: createItemId(namespace, name, branch)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -83,13 +80,12 @@ function createItemId(namespace: string, name: string, branch?: string): string
|
|||||||
export default function reducer(state: any = {}, action: Action = {type: "UNKNOWN"}): Object {
|
export default function reducer(state: any = {}, action: Action = {type: "UNKNOWN"}): Object {
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
case FETCH_CHANGESETS_SUCCESS:
|
case FETCH_CHANGESETS_SUCCESS:
|
||||||
const {namespace, name, branch} = action.payload;
|
const key = action.itemId
|
||||||
const key = createItemId(namespace, name, branch);
|
|
||||||
let oldChangesets = {[key]: {}};
|
let oldChangesets = {[key]: {}};
|
||||||
if (state[key] !== undefined) {
|
if (state[key] !== undefined) {
|
||||||
oldChangesets[key] = state[key]
|
oldChangesets[key] = state[key]
|
||||||
}
|
}
|
||||||
return {...state, [key]: {byId: extractChangesetsByIds(action.payload.collection, oldChangesets[key].byId)}};
|
return {...state, [key]: {byId: extractChangesetsByIds(action.payload, oldChangesets[key].byId)}};
|
||||||
default:
|
default:
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ import {
|
|||||||
} from "./changesets";
|
} from "./changesets";
|
||||||
import reducer from "./changesets";
|
import reducer from "./changesets";
|
||||||
|
|
||||||
const collection = {};
|
const changesets = {};
|
||||||
|
|
||||||
describe("changesets", () => {
|
describe("changesets", () => {
|
||||||
describe("fetching of changesets", () => {
|
describe("fetching of changesets", () => {
|
||||||
@@ -35,12 +35,12 @@ describe("changesets", () => {
|
|||||||
|
|
||||||
const expectedActions = [
|
const expectedActions = [
|
||||||
{
|
{
|
||||||
type: FETCH_CHANGESETS_PENDING, payload: {namespace: "foo", name: "bar"},
|
type: FETCH_CHANGESETS_PENDING, payload: "foo/bar",
|
||||||
itemId: "foo/bar"
|
itemId: "foo/bar"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
type: FETCH_CHANGESETS_SUCCESS,
|
type: FETCH_CHANGESETS_SUCCESS,
|
||||||
payload: {collection, namespace: "foo", name: "bar"},
|
payload: changesets,
|
||||||
itemId: "foo/bar"
|
itemId: "foo/bar"
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
@@ -52,17 +52,18 @@ describe("changesets", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("should fetch changesets for specific branch", () => {
|
it("should fetch changesets for specific branch", () => {
|
||||||
|
const itemId = "foo/bar/specific";
|
||||||
fetchMock.getOnce(SPECIFIC_BRANCH_URL, "{}");
|
fetchMock.getOnce(SPECIFIC_BRANCH_URL, "{}");
|
||||||
|
|
||||||
const expectedActions = [
|
const expectedActions = [
|
||||||
{
|
{
|
||||||
type: FETCH_CHANGESETS_PENDING, payload: {namespace: "foo", name: "bar", branch: "specific"},
|
type: FETCH_CHANGESETS_PENDING, payload: itemId,
|
||||||
itemId: "foo/bar/specific"
|
itemId
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
type: FETCH_CHANGESETS_SUCCESS,
|
type: FETCH_CHANGESETS_SUCCESS,
|
||||||
payload: {collection, namespace: "foo", name: "bar", branch: "specific"},
|
payload: changesets,
|
||||||
itemId: "foo/bar/specific"
|
itemId
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
@@ -73,17 +74,13 @@ describe("changesets", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("should fail fetching changesets on error", () => {
|
it("should fail fetching changesets on error", () => {
|
||||||
|
const itemId = "foo/bar";
|
||||||
fetchMock.getOnce(DEFAULT_BRANCH_URL, 500);
|
fetchMock.getOnce(DEFAULT_BRANCH_URL, 500);
|
||||||
|
|
||||||
const expectedActions = [
|
const expectedActions = [
|
||||||
{
|
{
|
||||||
type: FETCH_CHANGESETS_PENDING, payload: {namespace: "foo", name: "bar"},
|
type: FETCH_CHANGESETS_PENDING, payload: itemId,
|
||||||
itemId: "foo/bar"
|
itemId
|
||||||
},
|
|
||||||
{
|
|
||||||
type: FETCH_CHANGESETS_SUCCESS,
|
|
||||||
payload: {collection, namespace: "foo", name: "bar"},
|
|
||||||
itemId: "foo/bar"
|
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
@@ -96,17 +93,13 @@ describe("changesets", () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it("should fail fetching changesets for specific branch on error", () => {
|
it("should fail fetching changesets for specific branch on error", () => {
|
||||||
|
const itemId = "foo/bar/specific";
|
||||||
fetchMock.getOnce(SPECIFIC_BRANCH_URL, 500);
|
fetchMock.getOnce(SPECIFIC_BRANCH_URL, 500);
|
||||||
|
|
||||||
const expectedActions = [
|
const expectedActions = [
|
||||||
{
|
{
|
||||||
type: FETCH_CHANGESETS_PENDING, payload: {namespace: "foo", name: "bar", branch: "specific"},
|
type: FETCH_CHANGESETS_PENDING, payload: itemId,
|
||||||
itemId: "foo/bar/specific"
|
itemId
|
||||||
},
|
|
||||||
{
|
|
||||||
type: FETCH_CHANGESETS_SUCCESS,
|
|
||||||
payload: {collection, namespace: "foo", name: "bar", branch: "specific"},
|
|
||||||
itemId: "foo/bar/specific"
|
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user