import { getMetrics } from '../../../api/metrics';
import * as api from '../../../api/projectActivity';
import * as actions from '../actions';
-import { getGraph, saveGraph } from '../../../helpers/storage';
+import { getCustomGraph, getGraph } from '../../../helpers/storage';
import {
customMetricsChanged,
getHistoryMetrics,
+ isCustomGraph,
parseQuery,
serializeQuery,
serializeUrlQuery
};
if (this.shouldRedirect()) {
+ const newQuery = { ...this.state.query, graph: getGraph() };
+ if (isCustomGraph(newQuery.graph)) {
+ newQuery.customMetrics = getCustomGraph();
+ }
this.props.router.replace({
pathname: props.location.pathname,
- query: serializeUrlQuery({ ...this.state.query, graph: getGraph() })
+ query: serializeUrlQuery(newQuery)
});
}
}
...this.state.query,
...newQuery
});
- saveGraph(query.graph);
this.props.router.push({
pathname: this.props.location.pathname,
query: {
import ProjectActivityGraphsHeader from './ProjectActivityGraphsHeader';
import GraphsZoom from './GraphsZoom';
import GraphsHistory from './GraphsHistory';
+import { getCustomGraph, saveCustomGraph, saveGraph } from '../../../helpers/storage';
import {
datesQueryChanged,
+ isCustomGraph,
generateSeries,
getDisplayedHistoryMetrics,
historyQueryChanged
}
};
- addCustomMetric = (metric: string) =>
- this.props.updateQuery({ customMetrics: [...this.props.query.customMetrics, metric] });
+ addCustomMetric = (metric: string) => {
+ const customMetrics = [...this.props.query.customMetrics, metric];
+ saveCustomGraph(customMetrics);
+ this.props.updateQuery({ customMetrics });
+ };
- removeCustomMetric = (removedMetric: string) =>
- this.props.updateQuery({
- customMetrics: this.props.query.customMetrics.filter(metric => metric !== removedMetric)
- });
+ removeCustomMetric = (removedMetric: string) => {
+ const customMetrics = this.props.query.customMetrics.filter(metric => metric !== removedMetric);
+ saveCustomGraph(customMetrics);
+ this.props.updateQuery({ customMetrics });
+ };
- updateGraph = (graph: string) => this.props.updateQuery({ graph });
+ updateGraph = (graph: string) => {
+ saveGraph(graph);
+ if (isCustomGraph(graph) && this.props.query.customMetrics.length <= 0) {
+ this.props.updateQuery({ graph, customMetrics: getCustomGraph() });
+ } else {
+ this.props.updateQuery({ graph, customMetrics: [] });
+ }
+ };
updateGraphZoom = (graphStartDate: ?Date, graphEndDate: ?Date) => {
if (graphEndDate != null && graphStartDate != null) {
const PROJECTS_SORT = 'sonarqube.projects.sort';
const PROJECT_ACTIVITY_GRAPH = 'sonarqube.project_activity.graph';
+const PROJECT_ACTIVITY_GRAPH_CUSTOM = 'sonarqube.project_activity.graph.custom';
const save = (key: string, value: ?string) => {
try {
export const saveSort = (sort: ?string) => save(PROJECTS_SORT, sort);
export const getSort = () => window.localStorage.getItem(PROJECTS_SORT);
+export const saveCustomGraph = (metrics: ?Array<string>) =>
+ save(PROJECT_ACTIVITY_GRAPH_CUSTOM, metrics ? metrics.join(',') : '');
+export const getCustomGraph = (): Array<string> =>
+ (window.localStorage.getItem(PROJECT_ACTIVITY_GRAPH_CUSTOM) || '').split(',');
+
export const saveGraph = (graph: ?string) => save(PROJECT_ACTIVITY_GRAPH, graph);
-export const getGraph = () => window.localStorage.getItem(PROJECT_ACTIVITY_GRAPH) || 'overview';
+export const getGraph = (): string =>
+ window.localStorage.getItem(PROJECT_ACTIVITY_GRAPH) || 'overview';