aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-web/src/main/js/store
diff options
context:
space:
mode:
authorStas Vilchik <stas.vilchik@sonarsource.com>2018-03-02 16:24:37 +0100
committerGitHub <noreply@github.com>2018-03-02 16:24:37 +0100
commit299cebedac5ef4a6a17dd18782c2b1a2a79f08d5 (patch)
tree357d7b0ebe5fe686b9f2ea35507a2fb58bce12a0 /server/sonar-web/src/main/js/store
parent2d98999918574c56056c21f9c4791476d644a041 (diff)
downloadsonarqube-299cebedac5ef4a6a17dd18782c2b1a2a79f08d5.tar.gz
sonarqube-299cebedac5ef4a6a17dd18782c2b1a2a79f08d5.zip
rewrite remaining popups in react (#3109)
* extract baseFontFamily * rewrite favorites store in ts * add new types and change existing ones * rewrite SourceViewer helpers in ts * rewrite SourceViewer in ts and its popups in react * drop popups * fix iterating over nodelist * fix quality flaws
Diffstat (limited to 'server/sonar-web/src/main/js/store')
-rw-r--r--server/sonar-web/src/main/js/store/favorites/duck.ts (renamed from server/sonar-web/src/main/js/store/favorites/duck.js)87
1 files changed, 30 insertions, 57 deletions
diff --git a/server/sonar-web/src/main/js/store/favorites/duck.js b/server/sonar-web/src/main/js/store/favorites/duck.ts
index 3015e256953..710151e4eb2 100644
--- a/server/sonar-web/src/main/js/store/favorites/duck.js
+++ b/server/sonar-web/src/main/js/store/favorites/duck.ts
@@ -17,92 +17,65 @@
* 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, without } from 'lodash';
-/*::
-type Favorite = { key: string };
-*/
+interface Favorite {
+ key: string;
+}
-/*::
-type ReceiveFavoritesAction = {
- type: 'RECEIVE_FAVORITES',
- favorites: Array<Favorite>,
- notFavorites: Array<Favorite>
-};
-*/
+interface ReceiveFavoritesAction {
+ type: 'RECEIVE_FAVORITES';
+ favorites: Array<Favorite>;
+ notFavorites: Array<Favorite>;
+}
-/*::
-type AddFavoriteAction = {
- type: 'ADD_FAVORITE',
- componentKey: string
-};
-*/
+interface AddFavoriteAction {
+ type: 'ADD_FAVORITE';
+ componentKey: string;
+}
-/*::
-type RemoveFavoriteAction = {
- type: 'REMOVE_FAVORITE',
- componentKey: string
-};
-*/
+interface 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'
-};
+type State = string[];
export function receiveFavorites(
- favorites /*: Array<Favorite> */,
- notFavorites /*: Array<Favorite> */ = []
-) /*: ReceiveFavoritesAction */ {
- return {
- type: actions.RECEIVE_FAVORITES,
- favorites,
- notFavorites
- };
+ favorites: Favorite[],
+ notFavorites: Favorite[] = []
+): ReceiveFavoritesAction {
+ return { type: 'RECEIVE_FAVORITES', favorites, notFavorites };
}
-export function addFavorite(componentKey /*: string */) /*: AddFavoriteAction */ {
- return {
- type: actions.ADD_FAVORITE,
- componentKey
- };
+export function addFavorite(componentKey: string): AddFavoriteAction {
+ return { type: 'ADD_FAVORITE', componentKey };
}
-export function removeFavorite(componentKey /*: string */) /*: RemoveFavoriteAction */ {
- return {
- type: actions.REMOVE_FAVORITE,
- componentKey
- };
+export function removeFavorite(componentKey: string): RemoveFavoriteAction {
+ return { type: 'REMOVE_FAVORITE', componentKey };
}
-export default function(state /*: State */ = [], action /*: Action */) /*: State */ {
- if (action.type === actions.RECEIVE_FAVORITES) {
+export default function(state: State = [], action: Action): State {
+ if (action.type === 'RECEIVE_FAVORITES') {
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) {
+ if (action.type === 'ADD_FAVORITE') {
return uniq([...state, action.componentKey]);
}
- if (action.type === actions.REMOVE_FAVORITE) {
+ if (action.type === 'REMOVE_FAVORITE') {
return without(state, action.componentKey);
}
return state;
}
-export function isFavorite(state /*: State */, componentKey /*: string */) {
+export function isFavorite(state: State, componentKey: string) {
return state.includes(componentKey);
}