mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-12 08:25:44 +01:00
Fixed bug causing multiple requests for changesets
Fixed bug related to displaying errors additionally: implemented i18n
This commit is contained in:
@@ -1,5 +1,10 @@
|
||||
import {FAILURE_SUFFIX, PENDING_SUFFIX, SUCCESS_SUFFIX} from "../../modules/types";
|
||||
import {apiClient} from "@scm-manager/ui-components";
|
||||
// @flow
|
||||
import {
|
||||
FAILURE_SUFFIX,
|
||||
PENDING_SUFFIX,
|
||||
SUCCESS_SUFFIX
|
||||
} from "../../modules/types";
|
||||
import { apiClient } from "@scm-manager/ui-components";
|
||||
|
||||
export const FETCH_BRANCHES = "scm/repos/FETCH_BRANCHES";
|
||||
export const FETCH_BRANCHES_PENDING = `${FETCH_BRANCHES}_${PENDING_SUFFIX}`;
|
||||
@@ -9,64 +14,81 @@ export const FETCH_BRANCHES_FAILURE = `${FETCH_BRANCHES}_${FAILURE_SUFFIX}`;
|
||||
const REPO_URL = "repositories";
|
||||
|
||||
// Fetching branches
|
||||
export function fetchBranchesByNamespaceAndName(namespace: string, name: string) {
|
||||
return function (dispatch: any) {
|
||||
export function fetchBranchesByNamespaceAndName(
|
||||
namespace: string,
|
||||
name: string
|
||||
) {
|
||||
return function(dispatch: any) {
|
||||
dispatch(fetchBranchesPending(namespace, name));
|
||||
return apiClient.get(REPO_URL + "/" + namespace + "/" + name + "/branches")
|
||||
return apiClient
|
||||
.get(REPO_URL + "/" + namespace + "/" + name + "/branches")
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
dispatch(fetchBranchesSuccess(data, namespace, name))
|
||||
dispatch(fetchBranchesSuccess(data, namespace, name));
|
||||
})
|
||||
.catch(cause => {
|
||||
dispatch(fetchBranchesFailure(namespace, name, cause))
|
||||
})
|
||||
}
|
||||
.catch(error => {
|
||||
dispatch(fetchBranchesFailure(namespace, name, error));
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
// Action creators
|
||||
export function fetchBranchesPending(namespace: string, name: string) {
|
||||
return {
|
||||
type: FETCH_BRANCHES_PENDING,
|
||||
payload: {namespace, name},
|
||||
payload: { namespace, name },
|
||||
itemId: namespace + "/" + name
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export function fetchBranchesSuccess(data: string, namespace: string, name: string) {
|
||||
export function fetchBranchesSuccess(
|
||||
data: string,
|
||||
namespace: string,
|
||||
name: string
|
||||
) {
|
||||
return {
|
||||
type: FETCH_BRANCHES_SUCCESS,
|
||||
payload: {data, namespace, name},
|
||||
payload: { data, namespace, name },
|
||||
itemId: namespace + "/" + name
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export function fetchBranchesFailure(namespace: string, name: string, error: Error) {
|
||||
export function fetchBranchesFailure(
|
||||
namespace: string,
|
||||
name: string,
|
||||
error: Error
|
||||
) {
|
||||
return {
|
||||
type: FETCH_BRANCHES_FAILURE,
|
||||
payload: {error, namespace, name},
|
||||
payload: { error, namespace, name },
|
||||
itemId: namespace + "/" + name
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// Reducers
|
||||
|
||||
export default function reducer(state: Object = {}, action: Action = {type: "UNKNOWN"}): Object {
|
||||
export default function reducer(
|
||||
state: Object = {},
|
||||
action: Action = { type: "UNKNOWN" }
|
||||
): Object {
|
||||
switch (action.type) {
|
||||
case FETCH_BRANCHES_SUCCESS:
|
||||
const key = action.payload.namespace + "/" + action.payload.name;
|
||||
let oldBranchesByNames = {[key]: {}};
|
||||
let oldBranchesByNames = { [key]: {} };
|
||||
if (state[key] !== undefined) {
|
||||
oldBranchesByNames[key] = state[key]
|
||||
oldBranchesByNames[key] = state[key];
|
||||
}
|
||||
return {
|
||||
[key]: {
|
||||
byNames: extractBranchesByNames(action.payload.data, oldBranchesByNames[key].byNames)
|
||||
byNames: extractBranchesByNames(
|
||||
action.payload.data,
|
||||
oldBranchesByNames[key].byNames
|
||||
)
|
||||
}
|
||||
};
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function extractBranchesByNames(data: any, oldBranchesByNames: any): Branch[] {
|
||||
@@ -78,14 +100,18 @@ function extractBranchesByNames(data: any, oldBranchesByNames: any): Branch[] {
|
||||
}
|
||||
|
||||
for (let name in oldBranchesByNames) {
|
||||
branchesByNames[name] = oldBranchesByNames[name]
|
||||
branchesByNames[name] = oldBranchesByNames[name];
|
||||
}
|
||||
return branchesByNames;
|
||||
}
|
||||
|
||||
// Selectors
|
||||
|
||||
export function getBranchesForNamespaceAndNameFromState(namespace: string, name: string, state: Object) {
|
||||
export function getBranchesForNamespaceAndNameFromState(
|
||||
namespace: string,
|
||||
name: string,
|
||||
state: Object
|
||||
) {
|
||||
const key = namespace + "/" + name;
|
||||
if (!state.branches[key]) {
|
||||
return null;
|
||||
|
||||
@@ -140,8 +140,8 @@ function fetchChangesetsFailure(
|
||||
payload: {
|
||||
namespace,
|
||||
name,
|
||||
branch,
|
||||
error
|
||||
error,
|
||||
branch
|
||||
},
|
||||
itemId: createItemId(namespace, name, branch)
|
||||
};
|
||||
|
||||
@@ -127,7 +127,7 @@ describe("changesets", () => {
|
||||
});
|
||||
|
||||
it("should fetch changesets by page", () => {
|
||||
fetchMock.getOnce(DEFAULT_BRANCH_URL + "?page=5", "{}");
|
||||
fetchMock.getOnce(DEFAULT_BRANCH_URL + "?page=4", "{}");
|
||||
|
||||
const expectedActions = [
|
||||
{
|
||||
@@ -149,7 +149,7 @@ describe("changesets", () => {
|
||||
});
|
||||
|
||||
it("should fetch changesets by branch and page", () => {
|
||||
fetchMock.getOnce(SPECIFIC_BRANCH_URL + "?page=5", "{}");
|
||||
fetchMock.getOnce(SPECIFIC_BRANCH_URL + "?page=4", "{}");
|
||||
|
||||
const expectedActions = [
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user