aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-web/src/main/js/apps/settings/store
diff options
context:
space:
mode:
authorGrégoire Aubert <gregoire.aubert@sonarsource.com>2017-08-24 09:23:21 +0200
committerGrégoire Aubert <gregoire.aubert@sonarsource.com>2017-08-25 16:01:06 +0200
commit7d034a6d0d9991c251757eb9ab72bd37ac97b6ab (patch)
tree170ba041b744a95f4bc0377fa27dbb15a8567c6c /server/sonar-web/src/main/js/apps/settings/store
parentf56a05f14fe4b0685bce7a8750c929641ebf0b78 (diff)
downloadsonarqube-7d034a6d0d9991c251757eb9ab72bd37ac97b6ab.tar.gz
sonarqube-7d034a6d0d9991c251757eb9ab72bd37ac97b6ab.zip
SONAR-9747 Make components and global settings independant from each others in the ui
Diffstat (limited to 'server/sonar-web/src/main/js/apps/settings/store')
-rw-r--r--server/sonar-web/src/main/js/apps/settings/store/actions.js8
-rw-r--r--server/sonar-web/src/main/js/apps/settings/store/rootReducer.js17
-rw-r--r--server/sonar-web/src/main/js/apps/settings/store/values/actions.js5
-rw-r--r--server/sonar-web/src/main/js/apps/settings/store/values/reducer.js35
4 files changed, 49 insertions, 16 deletions
diff --git a/server/sonar-web/src/main/js/apps/settings/store/actions.js b/server/sonar-web/src/main/js/apps/settings/store/actions.js
index fab49983ff7..cbdd7eb63ba 100644
--- a/server/sonar-web/src/main/js/apps/settings/store/actions.js
+++ b/server/sonar-web/src/main/js/apps/settings/store/actions.js
@@ -43,7 +43,7 @@ export const fetchSettings = componentKey => dispatch => {
return getValues(keys, componentKey);
})
.then(settings => {
- dispatch(receiveValues(settings));
+ dispatch(receiveValues(settings, componentKey));
dispatch(closeAllGlobalMessages());
})
.catch(e => parseError(e).then(message => dispatch(addGlobalErrorMessage(message))));
@@ -65,7 +65,7 @@ export const saveValue = (key, componentKey) => (dispatch, getState) => {
return setSettingValue(definition, value, componentKey)
.then(() => getValues(key, componentKey))
.then(values => {
- dispatch(receiveValues(values));
+ dispatch(receiveValues(values, componentKey));
dispatch(cancelChange(key));
dispatch(passValidation(key));
dispatch(stopLoading(key));
@@ -84,9 +84,9 @@ export const resetValue = (key, componentKey) => dispatch => {
.then(() => getValues(key, componentKey))
.then(values => {
if (values.length > 0) {
- dispatch(receiveValues(values));
+ dispatch(receiveValues(values, componentKey));
} else {
- dispatch(receiveValues([{ key }]));
+ dispatch(receiveValues([{ key }], componentKey));
}
dispatch(passValidation(key));
dispatch(stopLoading(key));
diff --git a/server/sonar-web/src/main/js/apps/settings/store/rootReducer.js b/server/sonar-web/src/main/js/apps/settings/store/rootReducer.js
index d483892a9aa..0f22d81cf13 100644
--- a/server/sonar-web/src/main/js/apps/settings/store/rootReducer.js
+++ b/server/sonar-web/src/main/js/apps/settings/store/rootReducer.js
@@ -24,8 +24,9 @@ import values, * as fromValues from './values/reducer';
import settingsPage, * as fromSettingsPage from './settingsPage/reducer';
import licenses, * as fromLicenses from './licenses/reducer';
import globalMessages, * as fromGlobalMessages from '../../../store/globalMessages/duck';
-/*:: import type { State as GlobalMessagesState } from '../../../store/globalMessages/duck'; */
import encryptionPage from './encryptionPage/reducer';
+/*:: import type { State as GlobalMessagesState } from '../../../store/globalMessages/duck'; */
+/*:: import type { State as ValuesState } from './values/reducer'; */
/*::
type State = {
@@ -34,7 +35,7 @@ type State = {
globalMessages: GlobalMessagesState,
licenses: {},
settingsPage: {},
- values: {}
+ values: ValuesState
};
*/
@@ -58,12 +59,16 @@ export const getAllCategories = (state /*: State */) =>
export const getDefaultCategory = (state /*: State */) =>
fromDefinitions.getDefaultCategory(state.definitions);
-export const getValue = (state /*: State */, key /*: string */) =>
- fromValues.getValue(state.values, key);
+export const getValue = (state /*: State */, key /*: string */, componentKey /*: ?string */) =>
+ fromValues.getValue(state.values, key, componentKey);
-export const getSettingsForCategory = (state /*: State */, category /*: string */) =>
+export const getSettingsForCategory = (
+ state /*: State */,
+ category /*: string */,
+ componentKey /*: ?string */
+) =>
fromDefinitions.getDefinitionsForCategory(state.definitions, category).map(definition => ({
- ...getValue(state, definition.key),
+ ...getValue(state, definition.key, componentKey),
definition
}));
diff --git a/server/sonar-web/src/main/js/apps/settings/store/values/actions.js b/server/sonar-web/src/main/js/apps/settings/store/values/actions.js
index e9087a0b6d5..8ccc1d5ec1e 100644
--- a/server/sonar-web/src/main/js/apps/settings/store/values/actions.js
+++ b/server/sonar-web/src/main/js/apps/settings/store/values/actions.js
@@ -27,7 +27,8 @@ export const RECEIVE_VALUES /*: string */ = 'RECEIVE_VALUES';
* @param {Array} settings
* @returns {Object}
*/
-export const receiveValues = (settings /*: SettingValue[] */) => ({
+export const receiveValues = (settings /*: SettingValue[] */, componentKey /*: ?string */) => ({
type: RECEIVE_VALUES,
- settings
+ settings,
+ componentKey
});
diff --git a/server/sonar-web/src/main/js/apps/settings/store/values/reducer.js b/server/sonar-web/src/main/js/apps/settings/store/values/reducer.js
index d8e42984fd7..e08ace6f2bb 100644
--- a/server/sonar-web/src/main/js/apps/settings/store/values/reducer.js
+++ b/server/sonar-web/src/main/js/apps/settings/store/values/reducer.js
@@ -18,14 +18,35 @@
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
// @flow
+import { combineReducers } from 'redux';
import { keyBy } from 'lodash';
import { RECEIVE_VALUES } from './actions';
/*::
-type State = { [key: string]: {} };
+type SettingsState = { [key: string]: {} };
+type ComponentsState = { [key: string]: SettingsState };
+export type State = { components: ComponentsState, global: SettingsState };
*/
-const reducer = (state /*: State */ = {}, action /*: Object */) => {
+const componentsSettings = (state /*: ComponentsState */ = {}, action /*: Object */) => {
+ if (!action.componentKey) {
+ return state;
+ }
+
+ const key = action.componentKey;
+ if (action.type === RECEIVE_VALUES) {
+ const settingsByKey = keyBy(action.settings, 'key');
+ return { ...state, [key]: { ...(state[key] || {}), ...settingsByKey } };
+ }
+
+ return state;
+};
+
+const globalSettings = (state /*: SettingsState */ = {}, action /*: Object */) => {
+ if (action.componentKey) {
+ return state;
+ }
+
if (action.type === RECEIVE_VALUES) {
const settingsByKey = keyBy(action.settings, 'key');
return { ...state, ...settingsByKey };
@@ -42,6 +63,12 @@ const reducer = (state /*: State */ = {}, action /*: Object */) => {
return state;
};
-export default reducer;
+export default combineReducers({ components: componentsSettings, global: globalSettings });
-export const getValue = (state /*: State */, key /*: string */) => state[key];
+export const getValue = (state /*: State */, key /*: string */, componentKey /*: ?string */) => {
+ let settings = state.global;
+ if (componentKey) {
+ settings = state.components[componentKey];
+ }
+ return settings && settings[key];
+};