--- /dev/null
+/*
+ * 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
+
+export type Metric = {
+ custom?: boolean,
+ decimalScale?: number,
+ description?: string,
+ direction?: number,
+ domain?: string,
+ hidden?: boolean,
+ key: string,
+ name: string,
+ qualitative?: boolean,
+ type: string
+};
+
+export type Metrics = Array<Metric>;
+
+export const RECEIVE_METRICS = 'RECEIVE_METRICS';
+
+export const receiveMetrics = (metrics: Metrics) => ({
+ type: RECEIVE_METRICS,
+ metrics
+});
--- /dev/null
+/*
+ * 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 { combineReducers } from 'redux';
+import { keyBy } from 'lodash';
+import { RECEIVE_METRICS } 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 = {}) => {
+ if (action.type === RECEIVE_METRICS) {
+ return keyBy(action.metrics, 'key');
+ }
+ return state;
+};
+
+const keys = (state: StateKeys = [], action = {}) => {
+ if (action.type === RECEIVE_METRICS) {
+ return action.metrics.map(f => f.key);
+ }
+
+ return state;
+};
+
+export default combineReducers({ byKey, keys });
+
+export const getMetrics = (state: State) => state.keys;
+
+export const getMetricByKey = (state: State, key: string) => state.byKey[key];
import { getComponentData } from '../api/components';
import * as auth from '../api/auth';
import { getOrganizations } from '../api/organizations';
+import { getMetrics } from '../api/metrics';
import { receiveLanguages } from './languages/actions';
import { receiveComponents } from './components/actions';
+import { receiveMetrics } from './metrics/actions';
import { addGlobalErrorMessage } from './globalMessages/duck';
import { parseError } from '../apps/code/utils';
import { setAppState } from './appState/duck';
return getLanguages().then(languages => dispatch(receiveLanguages(languages)), onFail(dispatch));
};
+export const fetchMetrics = () => dispatch => {
+ return getMetrics().then(metrics => dispatch(receiveMetrics(metrics)), onFail(dispatch));
+};
+
export const fetchOrganizations = (organizations?: Array<string>) => dispatch =>
getOrganizations(organizations).then(
r => dispatch(receiveOrganizations(r.organizations)),
import favorites, * as fromFavorites from './favorites/duck';
import languages, * as fromLanguages from './languages/reducer';
import measures, * as fromMeasures from './measures/reducer';
+import metrics, * as fromMetrics from './metrics/reducer';
import notifications, * as fromNotifications from './notifications/duck';
import organizations, * as fromOrganizations from './organizations/duck';
import organizationsMembers, * as fromOrganizationsMembers from './organizationsMembers/reducer';
favorites,
languages,
measures,
+ metrics,
notifications,
organizations,
organizationsMembers,
export const getComponentMeasures = (state, componentKey) =>
fromMeasures.getComponentMeasures(state.measures, componentKey);
+export const getMetrics = state => fromMetrics.getMetrics(state.metrics);
+
+export const getMetricByKey = (state, key) => fromMetrics.getMetricByKey(state.metrics, key);
+
export const getGlobalNotifications = state => fromNotifications.getGlobal(state.notifications);
export const getProjectsWithNotifications = state =>