diff options
author | Stas Vilchik <stas.vilchik@sonarsource.com> | 2017-08-14 15:15:26 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-08-14 15:15:26 +0200 |
commit | 90306cb436e4fadceda6c106adc407618674f0d0 (patch) | |
tree | 4884373f2827b3fb59adb4516aa63bc4c4b1ae47 /server/sonar-web/src/main/js/store | |
parent | ffff02cbed3e5f94bbf0c1718425d66e19ac3901 (diff) | |
download | sonarqube-90306cb436e4fadceda6c106adc407618674f0d0.tar.gz sonarqube-90306cb436e4fadceda6c106adc407618674f0d0.zip |
comment flow annotations (#2335)
Diffstat (limited to 'server/sonar-web/src/main/js/store')
10 files changed, 342 insertions, 190 deletions
diff --git a/server/sonar-web/src/main/js/store/appState/duck.js b/server/sonar-web/src/main/js/store/appState/duck.js index 3ddcf2f52cb..2358bb011fc 100644 --- a/server/sonar-web/src/main/js/store/appState/duck.js +++ b/server/sonar-web/src/main/js/store/appState/duck.js @@ -18,6 +18,7 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ // @flow +/*:: type AppState = { adminPages?: Array<*>, authenticationError: boolean, @@ -25,32 +26,44 @@ type AppState = { organizationsEnabled: boolean, qualifiers: ?Array<string> }; +*/ +/*:: type SetAppStateAction = { type: 'SET_APP_STATE', appState: AppState }; +*/ +/*:: type SetAdminPagesAction = { type: 'SET_ADMIN_PAGES', adminPages: Array<*> }; +*/ -export type Action = SetAppStateAction | SetAdminPagesAction; +/*:: +export type Action = SetAppStateAction | SetAdminPagesAction; */ -export const setAppState = (appState: AppState): SetAppStateAction => ({ - type: 'SET_APP_STATE', - appState -}); +export function setAppState(appState /*: AppState */) /*: SetAppStateAction */ { + return { + type: 'SET_APP_STATE', + appState + }; +} -export const setAdminPages = (adminPages: Array<*>): SetAdminPagesAction => ({ - type: 'SET_ADMIN_PAGES', - adminPages -}); +export function setAdminPages(adminPages /*: Array<*> */) /*: SetAdminPagesAction */ { + return { + type: 'SET_ADMIN_PAGES', + adminPages + }; +} -export const requireAuthorization = () => ({ - type: 'REQUIRE_AUTHORIZATION' -}); +export function requireAuthorization() { + return { + type: 'REQUIRE_AUTHORIZATION' + }; +} const defaultValue = { authenticationError: false, @@ -59,7 +72,7 @@ const defaultValue = { qualifiers: null }; -export default (state: AppState = defaultValue, action: Action) => { +export default function(state /*: AppState */ = defaultValue, action /*: Action */) { if (action.type === 'SET_APP_STATE') { return { ...state, ...action.appState }; } @@ -73,6 +86,8 @@ export default (state: AppState = defaultValue, action: Action) => { } return state; -}; +} -export const getRootQualifiers = (state: AppState) => state.qualifiers; +export function getRootQualifiers(state /*: AppState */) { + return state.qualifiers; +} 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 73abccaeef1..44bb1ff9b83 100644 --- a/server/sonar-web/src/main/js/store/favorites/duck.js +++ b/server/sonar-web/src/main/js/store/favorites/duck.js @@ -20,27 +20,39 @@ // @flow import { uniq, without } from 'lodash'; +/*:: 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', @@ -48,26 +60,32 @@ export const actions = { REMOVE_FAVORITE: 'REMOVE_FAVORITE' }; -export const receiveFavorites = ( - favorites: Array<Favorite>, - notFavorites: Array<Favorite> = [] -): ReceiveFavoritesAction => ({ - type: actions.RECEIVE_FAVORITES, - favorites, - notFavorites -}); +export function receiveFavorites( + favorites /*: Array<Favorite> */, + notFavorites /*: Array<Favorite> */ = [] +) /*: ReceiveFavoritesAction */ { + return { + type: actions.RECEIVE_FAVORITES, + favorites, + notFavorites + }; +} -export const addFavorite = (componentKey: string): AddFavoriteAction => ({ - type: actions.ADD_FAVORITE, - componentKey -}); +export function addFavorite(componentKey /*: string */) /*: AddFavoriteAction */ { + return { + type: actions.ADD_FAVORITE, + componentKey + }; +} -export const removeFavorite = (componentKey: string): RemoveFavoriteAction => ({ - type: actions.REMOVE_FAVORITE, - componentKey -}); +export function removeFavorite(componentKey /*: string */) /*: RemoveFavoriteAction */ { + return { + type: actions.REMOVE_FAVORITE, + componentKey + }; +} -export default (state: State = [], action: Action): State => { +export default function(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); @@ -83,6 +101,8 @@ export default (state: State = [], action: Action): State => { } return state; -}; +} -export const isFavorite = (state: State, componentKey: string) => state.includes(componentKey); +export function isFavorite(state /*: State */, componentKey /*: string */) { + return state.includes(componentKey); +} diff --git a/server/sonar-web/src/main/js/store/globalMessages/duck.js b/server/sonar-web/src/main/js/store/globalMessages/duck.js index b74b8efdfaa..57dd1060f54 100644 --- a/server/sonar-web/src/main/js/store/globalMessages/duck.js +++ b/server/sonar-web/src/main/js/store/globalMessages/duck.js @@ -20,17 +20,25 @@ // @flow import { uniqueId } from 'lodash'; +/*:: type Level = 'ERROR' | 'SUCCESS'; +*/ +/*:: type Message = { id: string, message: string, level: Level }; +*/ +/*:: export type State = Array<Message>; +*/ +/*:: type Action = Object; +*/ export const ERROR = 'ERROR'; export const SUCCESS = 'SUCCESS'; @@ -40,35 +48,51 @@ const ADD_GLOBAL_MESSAGE = 'ADD_GLOBAL_MESSAGE'; const CLOSE_GLOBAL_MESSAGE = 'CLOSE_GLOBAL_MESSAGE'; const CLOSE_ALL_GLOBAL_MESSAGES = 'CLOSE_ALL_GLOBAL_MESSAGES'; -const addGlobalMessageActionCreator = (id: string, message: string, level: Level) => ({ - type: ADD_GLOBAL_MESSAGE, - message, - level, - id -}); - -export const closeGlobalMessage = (id: string) => ({ - type: CLOSE_GLOBAL_MESSAGE, - id -}); - -export const closeAllGlobalMessages = (id: string) => ({ - type: CLOSE_ALL_GLOBAL_MESSAGES, - id -}); - -const addGlobalMessage = (message: string, level: Level) => (dispatch: Function) => { - const id = uniqueId('global-message-'); - dispatch(addGlobalMessageActionCreator(id, message, level)); - setTimeout(() => dispatch(closeGlobalMessage(id)), 5000); -}; - -export const addGlobalErrorMessage = (message: string) => addGlobalMessage(message, ERROR); - -export const addGlobalSuccessMessage = (message: string) => addGlobalMessage(message, SUCCESS); +function addGlobalMessageActionCreator( + id /*: string */, + message /*: string */, + level /*: Level */ +) { + return { + type: ADD_GLOBAL_MESSAGE, + message, + level, + id + }; +} + +export function closeGlobalMessage(id /*: string */) { + return { + type: CLOSE_GLOBAL_MESSAGE, + id + }; +} + +export function closeAllGlobalMessages(id /*: string */) { + return { + type: CLOSE_ALL_GLOBAL_MESSAGES, + id + }; +} + +function addGlobalMessage(message /*: string */, level /*: Level */) { + return function(dispatch /*: Function */) { + const id = uniqueId('global-message-'); + dispatch(addGlobalMessageActionCreator(id, message, level)); + setTimeout(() => dispatch(closeGlobalMessage(id)), 5000); + }; +} + +export function addGlobalErrorMessage(message /*: string */) { + return addGlobalMessage(message, ERROR); +} + +export function addGlobalSuccessMessage(message /*: string */) { + return addGlobalMessage(message, SUCCESS); +} /* Reducer */ -const globalMessages = (state: State = [], action: Action = {}) => { +export default function(state /*: State */ = [], action /*: Action */ = {}) { switch (action.type) { case ADD_GLOBAL_MESSAGE: return [ @@ -99,9 +123,9 @@ const globalMessages = (state: State = [], action: Action = {}) => { default: return state; } -}; - -export default globalMessages; +} /* Selectors */ -export const getGlobalMessages = (state: State) => state; +export function getGlobalMessages(state /*: State */) { + return state; +} diff --git a/server/sonar-web/src/main/js/store/metrics/actions.js b/server/sonar-web/src/main/js/store/metrics/actions.js index c144c2e1527..cf35d52eb29 100644 --- a/server/sonar-web/src/main/js/store/metrics/actions.js +++ b/server/sonar-web/src/main/js/store/metrics/actions.js @@ -18,8 +18,7 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ // @flow - -export type Metric = { +/*:: export type Metric = { custom?: boolean, decimalScale?: number, description?: string, @@ -30,11 +29,11 @@ export type Metric = { name: string, qualitative?: boolean, type: string -}; +}; */ export const RECEIVE_METRICS = 'RECEIVE_METRICS'; -export const receiveMetrics = (metrics: Array<Metric>) => ({ +export const receiveMetrics = (metrics /*: Array<Metric> */) => ({ type: RECEIVE_METRICS, metrics }); diff --git a/server/sonar-web/src/main/js/store/metrics/reducer.js b/server/sonar-web/src/main/js/store/metrics/reducer.js index edc8750186c..f1c4bf73c38 100644 --- a/server/sonar-web/src/main/js/store/metrics/reducer.js +++ b/server/sonar-web/src/main/js/store/metrics/reducer.js @@ -21,20 +21,22 @@ import { combineReducers } from 'redux'; import { keyBy } from 'lodash'; import { RECEIVE_METRICS } from './actions'; -import type { Metric } from './actions'; +/*:: import type { Metric } from './actions'; */ +/*:: type StateByKey = { [string]: Metric }; type StateKeys = Array<string>; type State = { byKey: StateByKey, keys: StateKeys }; +*/ -const byKey = (state: StateByKey = {}, action = {}) => { +const byKey = (state /*: StateByKey */ = {}, action = {}) => { if (action.type === RECEIVE_METRICS) { return keyBy(action.metrics, 'key'); } return state; }; -const keys = (state: StateKeys = [], action = {}) => { +const keys = (state /*: StateKeys */ = [], action = {}) => { if (action.type === RECEIVE_METRICS) { return action.metrics.map(f => f.key); } @@ -44,6 +46,6 @@ const keys = (state: StateKeys = [], action = {}) => { export default combineReducers({ byKey, keys }); -export const getMetrics = (state: State) => state.byKey; -export const getMetricByKey = (state: State, key: string) => state.byKey[key]; -export const getMetricsKey = (state: State) => state.keys; +export const getMetrics = (state /*: State */) => state.byKey; +export const getMetricByKey = (state /*: State */, key /*: string */) => state.byKey[key]; +export const getMetricsKey = (state /*: State */) => state.keys; diff --git a/server/sonar-web/src/main/js/store/notifications/duck.js b/server/sonar-web/src/main/js/store/notifications/duck.js index 1a3f554fbd5..11f695f63c5 100644 --- a/server/sonar-web/src/main/js/store/notifications/duck.js +++ b/server/sonar-web/src/main/js/store/notifications/duck.js @@ -21,6 +21,7 @@ import { combineReducers } from 'redux'; import { uniqBy, uniqWith } from 'lodash'; +/*:: export type Notification = { channel: string, type: string, @@ -28,21 +29,33 @@ export type Notification = { projectName?: string, organization?: string }; +*/ +/*:: export type NotificationsState = Array<Notification>; +*/ +/*:: export type ChannelsState = Array<string>; +*/ +/*:: export type TypesState = Array<string>; +*/ +/*:: type AddNotificationAction = { type: 'ADD_NOTIFICATION', notification: Notification }; +*/ +/*:: type RemoveNotificationAction = { type: 'REMOVE_NOTIFICATION', notification: Notification }; +*/ +/*:: type ReceiveNotificationsAction = { type: 'RECEIVE_NOTIFICATIONS', notifications: NotificationsState, @@ -50,52 +63,67 @@ type ReceiveNotificationsAction = { globalTypes: TypesState, perProjectTypes: TypesState }; +*/ +/*:: type Action = AddNotificationAction | RemoveNotificationAction | ReceiveNotificationsAction; - -export const addNotification = (notification: Notification): AddNotificationAction => ({ - type: 'ADD_NOTIFICATION', - notification -}); - -export const removeNotification = (notification: Notification): RemoveNotificationAction => ({ - type: 'REMOVE_NOTIFICATION', - notification -}); - -export const receiveNotifications = ( - notifications: NotificationsState, - channels: ChannelsState, - globalTypes: TypesState, - perProjectTypes: TypesState -): ReceiveNotificationsAction => ({ - type: 'RECEIVE_NOTIFICATIONS', - notifications, - channels, - globalTypes, - perProjectTypes -}); - -const onAddNotification = (state: NotificationsState, notification: Notification) => { - const isNotificationsEqual = (a: Notification, b: Notification) => - a.channel === b.channel && a.type === b.type && a.project === b.project; +*/ + +export function addNotification(notification /*: Notification */) /*: AddNotificationAction */ { + return { + type: 'ADD_NOTIFICATION', + notification + }; +} + +export function removeNotification( + notification /*: Notification */ +) /*: RemoveNotificationAction */ { + return { + type: 'REMOVE_NOTIFICATION', + notification + }; +} + +export function receiveNotifications( + notifications /*: NotificationsState */, + channels /*: ChannelsState */, + globalTypes /*: TypesState */, + perProjectTypes /*: TypesState */ +) /*: ReceiveNotificationsAction */ { + return { + type: 'RECEIVE_NOTIFICATIONS', + notifications, + channels, + globalTypes, + perProjectTypes + }; +} + +function onAddNotification(state /*: NotificationsState */, notification /*: Notification */) { + function isNotificationsEqual(a /*: Notification */, b /*: Notification */) { + return a.channel === b.channel && a.type === b.type && a.project === b.project; + } return uniqWith([...state, notification], isNotificationsEqual); -}; +} -const onRemoveNotification = (state: NotificationsState, notification: Notification) => { +function onRemoveNotification(state /*: NotificationsState */, notification /*: Notification */) { return state.filter( n => n.channel !== notification.channel || n.type !== notification.type || n.project !== notification.project ); -}; +} -const onReceiveNotifications = (state: NotificationsState, notifications: NotificationsState) => { +function onReceiveNotifications( + state /*: NotificationsState */, + notifications /*: NotificationsState */ +) { return [...notifications]; -}; +} -const notifications = (state: NotificationsState = [], action: Action) => { +function notifications(state /*: NotificationsState */ = [], action /*: Action */) { switch (action.type) { case 'ADD_NOTIFICATION': return onAddNotification(state, action.notification); @@ -106,45 +134,48 @@ const notifications = (state: NotificationsState = [], action: Action) => { default: return state; } -}; +} -const channels = (state: ChannelsState = [], action: Action) => { +function channels(state /*: ChannelsState */ = [], action /*: Action */) { if (action.type === 'RECEIVE_NOTIFICATIONS') { return action.channels; } else { return state; } -}; +} -const globalTypes = (state: TypesState = [], action: Action) => { +function globalTypes(state /*: TypesState */ = [], action /*: Action */) { if (action.type === 'RECEIVE_NOTIFICATIONS') { return action.globalTypes; } else { return state; } -}; +} -const perProjectTypes = (state: TypesState = [], action: Action) => { +function perProjectTypes(state /*: TypesState */ = [], action /*: Action */) { if (action.type === 'RECEIVE_NOTIFICATIONS') { return action.perProjectTypes; } else { return state; } -}; +} +/*:: type State = { notifications: NotificationsState, channels: ChannelsState, globalTypes: TypesState, perProjectTypes: TypesState }; +*/ export default combineReducers({ notifications, channels, globalTypes, perProjectTypes }); -export const getGlobal = (state: State): NotificationsState => - state.notifications.filter(n => !n.project); +export function getGlobal(state /*: State */) /*: NotificationsState */ { + return state.notifications.filter(n => !n.project); +} -export const getProjects = (state: State): Array<{ key: string, name: string }> => { +export function getProjects(state /*: State */) /*: Array<{ key: string, name: string }> */ { // $FlowFixMe const allProjects = state.notifications.filter(n => n.project != null).map(n => ({ key: n.project, @@ -153,13 +184,20 @@ export const getProjects = (state: State): Array<{ key: string, name: string }> })); return uniqBy(allProjects, project => project.key); -}; +} -export const getForProject = (state: State, project: string): NotificationsState => - state.notifications.filter(n => n.project === project); +export function getForProject(state /*: State */, project /*: string */) /*: NotificationsState */ { + return state.notifications.filter(n => n.project === project); +} -export const getChannels = (state: State): ChannelsState => state.channels; +export function getChannels(state /*: State */) /*: ChannelsState */ { + return state.channels; +} -export const getGlobalTypes = (state: State): TypesState => state.globalTypes; +export function getGlobalTypes(state /*: State */) /*: TypesState */ { + return state.globalTypes; +} -export const getPerProjectTypes = (state: State): TypesState => state.perProjectTypes; +export function getPerProjectTypes(state /*: State */) /*: TypesState */ { + return state.perProjectTypes; +} diff --git a/server/sonar-web/src/main/js/store/organizations/duck.js b/server/sonar-web/src/main/js/store/organizations/duck.js index 5c8ee446cf7..fa8af85260f 100644 --- a/server/sonar-web/src/main/js/store/organizations/duck.js +++ b/server/sonar-web/src/main/js/store/organizations/duck.js @@ -21,6 +21,7 @@ import { combineReducers } from 'redux'; import { omit, uniq, without } from 'lodash'; +/*:: export type Organization = { adminPages?: Array<{ key: string, name: string }>, avatar?: string, @@ -35,7 +36,9 @@ export type Organization = { projectVisibility: string, url?: string }; +*/ +/*:: export type OrgGroup = { id: string, default: boolean, @@ -43,114 +46,153 @@ export type OrgGroup = { membersCount: number, name: string }; +*/ +/*:: type ReceiveOrganizationsAction = { type: 'RECEIVE_ORGANIZATIONS', organizations: Array<Organization> }; +*/ +/*:: type ReceiveMyOrganizationsAction = { type: 'RECEIVE_MY_ORGANIZATIONS', organizations: Array<Organization> }; +*/ +/*:: type ReceiveOrganizationGroups = { type: 'RECEIVE_ORGANIZATION_GROUPS', key: string, groups: Array<OrgGroup> }; +*/ +/*:: type CreateOrganizationAction = { type: 'CREATE_ORGANIZATION', organization: Organization }; +*/ +/*:: type UpdateOrganizationAction = { type: 'UPDATE_ORGANIZATION', key: string, changes: {} }; +*/ +/*:: type DeleteOrganizationAction = { type: 'DELETE_ORGANIZATION', key: string }; +*/ +/*:: type Action = | ReceiveOrganizationsAction | ReceiveMyOrganizationsAction | ReceiveOrganizationGroups | CreateOrganizationAction | UpdateOrganizationAction - | DeleteOrganizationAction; + | DeleteOrganizationAction; */ +/*:: type ByKeyState = { [key: string]: Organization }; +*/ +/*:: type GroupsState = { [key: string]: Array<OrgGroup> }; +*/ +/*:: type MyState = Array<string>; +*/ +/*:: type State = { byKey: ByKeyState, my: MyState, groups: GroupsState }; +*/ -export const receiveOrganizations = ( - organizations: Array<Organization> -): ReceiveOrganizationsAction => ({ - type: 'RECEIVE_ORGANIZATIONS', - organizations -}); +export function receiveOrganizations( + organizations /*: Array<Organization> */ +) /*: ReceiveOrganizationsAction */ { + return { + type: 'RECEIVE_ORGANIZATIONS', + organizations + }; +} -export const receiveMyOrganizations = ( - organizations: Array<Organization> -): ReceiveMyOrganizationsAction => ({ - type: 'RECEIVE_MY_ORGANIZATIONS', - organizations -}); +export function receiveMyOrganizations( + organizations /*: Array<Organization> */ +) /*: ReceiveMyOrganizationsAction */ { + return { + type: 'RECEIVE_MY_ORGANIZATIONS', + organizations + }; +} -export const receiveOrganizationGroups = ( - key: string, - groups: Array<OrgGroup> -): receiveOrganizationGroups => ({ - type: 'RECEIVE_ORGANIZATION_GROUPS', - key, - groups -}); +export function receiveOrganizationGroups( + key /*: string */, + groups /*: Array<OrgGroup> */ +) /*: receiveOrganizationGroups */ { + return { + type: 'RECEIVE_ORGANIZATION_GROUPS', + key, + groups + }; +} -export const createOrganization = (organization: Organization): CreateOrganizationAction => ({ - type: 'CREATE_ORGANIZATION', - organization -}); +export function createOrganization( + organization /*: Organization */ +) /*: CreateOrganizationAction */ { + return { + type: 'CREATE_ORGANIZATION', + organization + }; +} -export const updateOrganization = (key: string, changes: {}): UpdateOrganizationAction => ({ - type: 'UPDATE_ORGANIZATION', - key, - changes -}); +export function updateOrganization( + key /*: string */, + changes /*: {} */ +) /*: UpdateOrganizationAction */ { + return { + type: 'UPDATE_ORGANIZATION', + key, + changes + }; +} -export const deleteOrganization = (key: string): DeleteOrganizationAction => ({ - type: 'DELETE_ORGANIZATION', - key -}); +export function deleteOrganization(key /*: string */) /*: DeleteOrganizationAction */ { + return { + type: 'DELETE_ORGANIZATION', + key + }; +} -const onReceiveOrganizations = ( - state: ByKeyState, - action: ReceiveOrganizationsAction | ReceiveMyOrganizationsAction -): ByKeyState => { +function onReceiveOrganizations( + state /*: ByKeyState */, + action /*: ReceiveOrganizationsAction | ReceiveMyOrganizationsAction */ +) /*: ByKeyState */ { const nextState = { ...state }; action.organizations.forEach(organization => { nextState[organization.key] = { ...state[organization.key], ...organization }; }); return nextState; -}; +} -const byKey = (state: ByKeyState = {}, action: Action) => { +function byKey(state /*: ByKeyState */ = {}, action /*: Action */) { switch (action.type) { case 'RECEIVE_ORGANIZATIONS': case 'RECEIVE_MY_ORGANIZATIONS': @@ -171,9 +213,9 @@ const byKey = (state: ByKeyState = {}, action: Action) => { default: return state; } -}; +} -const my = (state: MyState = [], action: Action) => { +function my(state /*: MyState */ = [], action /*: Action */) { switch (action.type) { case 'RECEIVE_MY_ORGANIZATIONS': return uniq([...state, ...action.organizations.map(o => o.key)]); @@ -184,26 +226,34 @@ const my = (state: MyState = [], action: Action) => { default: return state; } -}; +} -const groups = (state: GroupsState = {}, action: Action) => { +function groups(state /*: GroupsState */ = {}, action /*: Action */) { switch (action.type) { case 'RECEIVE_ORGANIZATION_GROUPS': return { ...state, [action.key]: action.groups }; default: return state; } -}; +} export default combineReducers({ byKey, my, groups }); -export const getOrganizationByKey = (state: State, key: string): Organization => state.byKey[key]; +export function getOrganizationByKey(state /*: State */, key /*: string */) /*: Organization */ { + return state.byKey[key]; +} -export const getOrganizationGroupsByKey = (state: State, key: string): Array<OrgGroup> => - state.groups[key] || []; +export function getOrganizationGroupsByKey( + state /*: State */, + key /*: string */ +) /*: Array<OrgGroup> */ { + return state.groups[key] || []; +} -export const getMyOrganizations = (state: State): Array<Organization> => - state.my.map(key => getOrganizationByKey(state, key)); +export function getMyOrganizations(state /*: State */) /*: Array<Organization> */ { + return state.my.map(key => getOrganizationByKey(state, key)); +} -export const areThereCustomOrganizations = (state: State): boolean => - Object.keys(state.byKey).length > 1; +export function areThereCustomOrganizations(state /*: State */) /*: boolean */ { + return Object.keys(state.byKey).length > 1; +} diff --git a/server/sonar-web/src/main/js/store/organizations/utils.js b/server/sonar-web/src/main/js/store/organizations/utils.js index a17f80f47cf..f98e88e2085 100644 --- a/server/sonar-web/src/main/js/store/organizations/utils.js +++ b/server/sonar-web/src/main/js/store/organizations/utils.js @@ -24,14 +24,14 @@ import { areThereCustomOrganizations as customOrganizations } from '../rootReducer'; -export const getOrganization = (key: string) => { +export function getOrganization(key /*: string */) { const store = getStore(); const state = store.getState(); return getOrganizationByKey(state, key); -}; +} -export const areThereCustomOrganizations = () => { +export function areThereCustomOrganizations() { const store = getStore(); const state = store.getState(); return customOrganizations(state); -}; +} diff --git a/server/sonar-web/src/main/js/store/organizationsMembers/actions.js b/server/sonar-web/src/main/js/store/organizationsMembers/actions.js index abb41e71624..3698ed4c66f 100644 --- a/server/sonar-web/src/main/js/store/organizationsMembers/actions.js +++ b/server/sonar-web/src/main/js/store/organizationsMembers/actions.js @@ -18,6 +18,7 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ //@flow +/*:: export type Member = { login: string, name: string, @@ -25,13 +26,16 @@ export type Member = { email?: string, groupCount?: number }; +*/ +/*:: type MembersState = { paging?: number, total?: number, loading?: boolean, query?: string | null }; +*/ export const actions = { UPDATE_STATE: 'organizations/UPDATE_STATE', @@ -42,9 +46,9 @@ export const actions = { }; export const receiveMembers = ( - organizationKey: string, - members: Array<Member>, - stateChanges: MembersState + organizationKey /*: string */, + members /*: Array<Member> */, + stateChanges /*: MembersState */ ) => ({ type: actions.RECEIVE_MEMBERS, organization: organizationKey, @@ -53,9 +57,9 @@ export const receiveMembers = ( }); export const receiveMoreMembers = ( - organizationKey: string, - members: Array<Member>, - stateChanges: MembersState + organizationKey /*: string */, + members /*: Array<Member> */, + stateChanges /*: MembersState */ ) => ({ type: actions.RECEIVE_MORE_MEMBERS, organization: organizationKey, @@ -63,19 +67,19 @@ export const receiveMoreMembers = ( stateChanges }); -export const addMember = (organizationKey: string, member: Member) => ({ +export const addMember = (organizationKey /*: string */, member /*: Member */) => ({ type: actions.ADD_MEMBER, organization: organizationKey, member }); -export const removeMember = (organizationKey: string, member: Member) => ({ +export const removeMember = (organizationKey /*: string */, member /*: Member */) => ({ type: actions.REMOVE_MEMBER, organization: organizationKey, member }); -export const updateState = (organizationKey: string, stateChanges: MembersState) => ({ +export const updateState = (organizationKey /*: string */, stateChanges /*: MembersState */) => ({ type: actions.UPDATE_STATE, organization: organizationKey, stateChanges diff --git a/server/sonar-web/src/main/js/store/rootActions.js b/server/sonar-web/src/main/js/store/rootActions.js index b4558241c65..1ec61770048 100644 --- a/server/sonar-web/src/main/js/store/rootActions.js +++ b/server/sonar-web/src/main/js/store/rootActions.js @@ -45,7 +45,7 @@ export const fetchMetrics = () => dispatch => { return getMetrics().then(metrics => dispatch(receiveMetrics(metrics)), onFail(dispatch)); }; -export const fetchOrganizations = (organizations?: Array<string>) => dispatch => +export const fetchOrganizations = (organizations /*: Array<string> | void */) => dispatch => getOrganizations(organizations).then( r => dispatch(receiveOrganizations(r.organizations)), onFail(dispatch) |