mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-16 02:06:18 +01:00
Added possibility to fetch changesets by branches
This commit is contained in:
@@ -50,4 +50,45 @@ export function fetchBranchesFailure(namespace: string, name: string, error: Err
|
||||
|
||||
// Reducers
|
||||
|
||||
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]: {}};
|
||||
if (state[key] !== undefined) {
|
||||
oldBranchesByNames[key] = state[key]
|
||||
}
|
||||
return {
|
||||
[key]: {
|
||||
byNames: extractBranchesByNames(action.payload.data, oldBranchesByNames[key].byNames)
|
||||
}
|
||||
};
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function extractBranchesByNames(data: any, oldBranchesByNames: any): Branch[] {
|
||||
const branches = data._embedded.branches;
|
||||
const branchesByNames = {};
|
||||
|
||||
for (let branch of branches) {
|
||||
branchesByNames[branch.name] = branch;
|
||||
}
|
||||
|
||||
for (let name in oldBranchesByNames) {
|
||||
branchesByNames[name] = oldBranchesByNames[name]
|
||||
}
|
||||
return branchesByNames;
|
||||
}
|
||||
|
||||
// Selectors
|
||||
|
||||
export function getBranchesForNamespaceAndNameFromState(namespace: string, name: string, state: Object) {
|
||||
const key = namespace + "/" + name;
|
||||
if (!state.branches[key]) {
|
||||
return null;
|
||||
}
|
||||
return Object.values(state.branches[key].byNames);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user