aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-web/src/main/js/store
diff options
context:
space:
mode:
authorStas Vilchik <stas-vilchik@users.noreply.github.com>2017-03-02 13:18:27 +0100
committerGitHub <noreply@github.com>2017-03-02 13:18:27 +0100
commitce9f0892fc3d15638c4eaa4054ed06f3d7e5fc19 (patch)
tree0dd0d0633c514ef51071b03516d5eca5b23d64f2 /server/sonar-web/src/main/js/store
parent0a547ba79c4affb9b6ff0b669ee4a5e87ef16479 (diff)
downloadsonarqube-ce9f0892fc3d15638c4eaa4054ed06f3d7e5fc19.tar.gz
sonarqube-ce9f0892fc3d15638c4eaa4054ed06f3d7e5fc19.zip
refactor source viewer (#1705)
Diffstat (limited to 'server/sonar-web/src/main/js/store')
-rw-r--r--server/sonar-web/src/main/js/store/favorites/duck.js37
-rw-r--r--server/sonar-web/src/main/js/store/issues/duck.js52
-rw-r--r--server/sonar-web/src/main/js/store/rootReducer.js6
3 files changed, 89 insertions, 6 deletions
diff --git a/server/sonar-web/src/main/js/store/favorites/duck.js b/server/sonar-web/src/main/js/store/favorites/duck.js
index c97f715edbd..ceeb119abfa 100644
--- a/server/sonar-web/src/main/js/store/favorites/duck.js
+++ b/server/sonar-web/src/main/js/store/favorites/duck.js
@@ -17,32 +17,58 @@
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
+// @flow
import uniq from 'lodash/uniq';
import without from 'lodash/without';
+type Favorite = { key: string };
+
+type ReceiveFavoritesAction = {
+ type: 'RECEIVE_FAVORITES',
+ favorites: Array<Favorite>,
+ notFavorites: Array<Favorite>
+};
+
+type AddFavoriteAction = {
+ type: 'ADD_FAVORITE',
+ componentKey: string
+};
+
+type RemoveFavoriteAction = {
+ type: 'REMOVE_FAVORITE',
+ componentKey: string
+};
+
+type Action = ReceiveFavoritesAction | AddFavoriteAction | RemoveFavoriteAction;
+
+type State = Array<string>;
+
export const actions = {
RECEIVE_FAVORITES: 'RECEIVE_FAVORITES',
ADD_FAVORITE: 'ADD_FAVORITE',
REMOVE_FAVORITE: 'REMOVE_FAVORITE'
};
-export const receiveFavorites = (favorites, notFavorites = []) => ({
+export const receiveFavorites = (
+ favorites: Array<Favorite>,
+ notFavorites: Array<Favorite> = []
+): ReceiveFavoritesAction => ({
type: actions.RECEIVE_FAVORITES,
favorites,
notFavorites
});
-export const addFavorite = componentKey => ({
+export const addFavorite = (componentKey: string): AddFavoriteAction => ({
type: actions.ADD_FAVORITE,
componentKey
});
-export const removeFavorite = componentKey => ({
+export const removeFavorite = (componentKey: string): RemoveFavoriteAction => ({
type: actions.REMOVE_FAVORITE,
componentKey
});
-export default (state = [], action = {}) => {
+export default (state: State = [], action: Action): State => {
if (action.type === actions.RECEIVE_FAVORITES) {
const toAdd = action.favorites.map(f => f.key);
const toRemove = action.notFavorites.map(f => f.key);
@@ -60,7 +86,6 @@ export default (state = [], action = {}) => {
return state;
};
-export const isFavorite = (state, componentKey) => (
+export const isFavorite = (state: State, componentKey: string) => (
state.includes(componentKey)
);
-
diff --git a/server/sonar-web/src/main/js/store/issues/duck.js b/server/sonar-web/src/main/js/store/issues/duck.js
new file mode 100644
index 00000000000..1126bcfd57f
--- /dev/null
+++ b/server/sonar-web/src/main/js/store/issues/duck.js
@@ -0,0 +1,52 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+// @flow
+import keyBy from 'lodash/keyBy';
+
+type Issue = { key: string };
+
+type ReceiveIssuesAction = {
+ type: 'RECEIVE_ISSUES',
+ issues: Array<Issue>
+};
+
+type Action = ReceiveIssuesAction;
+
+type State = { [key: string]: Issue };
+
+export const receiveIssues = (issues: Array<Issue>): ReceiveIssuesAction => ({
+ type: 'RECEIVE_ISSUES',
+ issues
+});
+
+const reducer = (state: State = {}, action: Action) => {
+ switch (action.type) {
+ case 'RECEIVE_ISSUES':
+ return { ...state, ...keyBy(action.issues, 'key') };
+ default:
+ return state;
+ }
+};
+
+export default reducer;
+
+export const getIssueByKey = (state: State, key: string): ?Issue => (
+ state[key]
+);
diff --git a/server/sonar-web/src/main/js/store/rootReducer.js b/server/sonar-web/src/main/js/store/rootReducer.js
index aee309845c2..1b8539f84eb 100644
--- a/server/sonar-web/src/main/js/store/rootReducer.js
+++ b/server/sonar-web/src/main/js/store/rootReducer.js
@@ -22,6 +22,7 @@ import appState from './appState/duck';
import components, * as fromComponents from './components/reducer';
import users, * as fromUsers from './users/reducer';
import favorites, * as fromFavorites from './favorites/duck';
+import issues, * as fromIssues from './issues/duck';
import languages, * as fromLanguages from './languages/reducer';
import measures, * as fromMeasures from './measures/reducer';
import notifications, * as fromNotifications from './notifications/duck';
@@ -40,6 +41,7 @@ export default combineReducers({
components,
globalMessages,
favorites,
+ issues,
languages,
measures,
notifications,
@@ -80,6 +82,10 @@ export const isFavorite = (state, componentKey) => (
fromFavorites.isFavorite(state.favorites, componentKey)
);
+export const getIssueByKey = (state, key) => (
+ fromIssues.getIssueByKey(state.issues, key)
+);
+
export const getComponentMeasure = (state, componentKey, metricKey) => (
fromMeasures.getComponentMeasure(state.measures, componentKey, metricKey)
);