mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-18 03:01:05 +01:00
updates current namespace strategy after configuration has changed
This commit is contained in:
@@ -5,6 +5,7 @@ import type { Action, NamespaceStrategies } from "@scm-manager/ui-types";
|
||||
import { apiClient } from "@scm-manager/ui-components";
|
||||
import { isPending } from "../../modules/pending";
|
||||
import { getFailure } from "../../modules/failure";
|
||||
import { MODIFY_CONFIG_SUCCESS } from "./config";
|
||||
|
||||
export const FETCH_NAMESPACESTRATEGIES_TYPES =
|
||||
"scm/config/FETCH_NAMESPACESTRATEGIES_TYPES";
|
||||
@@ -22,7 +23,10 @@ export function fetchNamespaceStrategiesIfNeeded() {
|
||||
return function(dispatch: any, getState: () => Object) {
|
||||
const state = getState();
|
||||
if (shouldFetchNamespaceStrategies(state)) {
|
||||
return fetchNamespaceStrategies(dispatch, state.indexResources.links.namespaceStrategies.href);
|
||||
return fetchNamespaceStrategies(
|
||||
dispatch,
|
||||
state.indexResources.links.namespaceStrategies.href
|
||||
);
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -75,14 +79,20 @@ export function fetchNamespaceStrategiesFailure(error: Error): Action {
|
||||
// reducers
|
||||
|
||||
export default function reducer(
|
||||
state: NamespaceStrategies = {},
|
||||
state: Object = {},
|
||||
action: Action = { type: "UNKNOWN" }
|
||||
): NamespaceStrategies {
|
||||
): Object {
|
||||
if (
|
||||
action.type === FETCH_NAMESPACESTRATEGIES_TYPES_SUCCESS &&
|
||||
action.payload
|
||||
) {
|
||||
return action.payload;
|
||||
} else if (action.type === MODIFY_CONFIG_SUCCESS && action.payload) {
|
||||
const config = action.payload;
|
||||
return {
|
||||
...state,
|
||||
current: config.defaultNamespaceStrategy
|
||||
};
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
@@ -15,14 +15,15 @@ import {
|
||||
isFetchNamespaceStrategiesPending,
|
||||
getFetchNamespaceStrategiesFailure
|
||||
} from "./namespaceStrategies";
|
||||
import { MODIFY_CONFIG_SUCCESS } from "./config";
|
||||
|
||||
const strategies = {
|
||||
current: "sonia.scm.repository.UsernameNamespaceStrategy",
|
||||
current: "UsernameNamespaceStrategy",
|
||||
available: [
|
||||
"sonia.scm.repository.UsernameNamespaceStrategy",
|
||||
"sonia.scm.repository.CustomNamespaceStrategy",
|
||||
"sonia.scm.repository.CurrentYearNamespaceStrategy",
|
||||
"sonia.scm.repository.RepositoryTypeNamespaceStrategy"
|
||||
"UsernameNamespaceStrategy",
|
||||
"CustomNamespaceStrategy",
|
||||
"CurrentYearNamespaceStrategy",
|
||||
"RepositoryTypeNamespaceStrategy"
|
||||
],
|
||||
_links: {
|
||||
self: {
|
||||
@@ -135,14 +136,25 @@ describe("namespace strategies fetch", () => {
|
||||
|
||||
describe("namespace strategies reducer", () => {
|
||||
it("should return unmodified state on unknown action", () => {
|
||||
const state = [];
|
||||
const state = {};
|
||||
expect(reducer(state)).toBe(state);
|
||||
});
|
||||
|
||||
it("should store the strategies on success", () => {
|
||||
const newState = reducer([], fetchNamespaceStrategiesSuccess(strategies));
|
||||
const newState = reducer({}, fetchNamespaceStrategiesSuccess(strategies));
|
||||
expect(newState).toBe(strategies);
|
||||
});
|
||||
|
||||
it("should clear store if config was modified", () => {
|
||||
const modifyConfigAction = {
|
||||
type: MODIFY_CONFIG_SUCCESS,
|
||||
payload: {
|
||||
defaultNamespaceStrategy: "CustomNamespaceStrategy"
|
||||
}
|
||||
};
|
||||
const newState = reducer(strategies, modifyConfigAction);
|
||||
expect(newState.current).toEqual("CustomNamespaceStrategy");
|
||||
});
|
||||
});
|
||||
|
||||
describe("namespace strategy selectors", () => {
|
||||
|
||||
Reference in New Issue
Block a user