]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-8451 fix favorites
authorStas Vilchik <vilchiks@gmail.com>
Mon, 9 Jan 2017 13:52:12 +0000 (14:52 +0100)
committerStas Vilchik <vilchiks@gmail.com>
Mon, 9 Jan 2017 13:52:12 +0000 (14:52 +0100)
server/sonar-web/src/main/js/apps/projects/store/actions.js
server/sonar-web/src/main/js/store/favorites/duck.js

index 5a6f5affdec93fcb960b82974fa5d4ebfe6d581e..7e3e0f0800dfed7ad814f843b695c14def5a2e20 100644 (file)
@@ -88,9 +88,10 @@ const fetchProjectMeasures = projects => dispatch => {
 };
 
 const handleFavorites = (dispatch, projects) => {
-  const favorites = projects.filter(project => project.isFavorite);
-  if (favorites.length) {
-    dispatch(receiveFavorites(favorites));
+  const toAdd = projects.filter(project => project.isFavorite);
+  const toRemove = projects.filter(project => project.isFavorite === false);
+  if (toAdd.length || toRemove.length) {
+    dispatch(receiveFavorites(toAdd, toRemove));
   }
 };
 
index 7c6d4b5201256a334fbe47eaecbaa72ce482658a..f4e8b935a8c3d47d09566a19a653b1cd7b1adfd6 100644 (file)
@@ -26,9 +26,10 @@ export const actions = {
   REMOVE_FAVORITE: 'REMOVE_FAVORITE'
 };
 
-export const receiveFavorites = favorites => ({
+export const receiveFavorites = (favorites, notFavorites = []) => ({
   type: actions.RECEIVE_FAVORITES,
-  favorites
+  favorites,
+  notFavorites
 });
 
 export const addFavorite = componentKey => ({
@@ -43,7 +44,9 @@ export const removeFavorite = componentKey => ({
 
 export default (state = [], action = {}) => {
   if (action.type === actions.RECEIVE_FAVORITES) {
-    return uniq([...state, ...action.favorites.map(f => f.key)]);
+    const toAdd = action.favorites.map(f => f.key);
+    const toRemove = action.notFavorites.map(f => f.key);
+    return without(uniq([...state, ...toAdd]), ...toRemove);
   }
 
   if (action.type === actions.ADD_FAVORITE) {