From cbd59575a5e66f5d4421bf5625c454db526fc584 Mon Sep 17 00:00:00 2001 From: Grégoire Aubert Date: Fri, 21 Jul 2017 13:32:19 +0200 Subject: Correctly display Issues graph as default if no custom metrics are selected. --- .../apps/projectActivity/components/ProjectActivityAppContainer.js | 7 +++++-- server/sonar-web/src/main/js/helpers/storage.js | 6 ++++-- 2 files changed, 9 insertions(+), 4 deletions(-) (limited to 'server/sonar-web/src') diff --git a/server/sonar-web/src/main/js/apps/projectActivity/components/ProjectActivityAppContainer.js b/server/sonar-web/src/main/js/apps/projectActivity/components/ProjectActivityAppContainer.js index 01a3a09af36..d5ea86bad0c 100644 --- a/server/sonar-web/src/main/js/apps/projectActivity/components/ProjectActivityAppContainer.js +++ b/server/sonar-web/src/main/js/apps/projectActivity/components/ProjectActivityAppContainer.js @@ -273,9 +273,12 @@ class ProjectActivityAppContainer extends React.PureComponent { key => key !== 'id' && locationQuery[key] !== '' ); - // if there is no filter, but there are saved preferences in the localStorage const graph = getGraph(); - return !filtered && graph != null && graph !== DEFAULT_GRAPH; + const emptyCustomGraph = isCustomGraph(graph) && getCustomGraph().length <= 0; + + // if there is no filter, but there are saved preferences in the localStorage + // also don't redirect to custom if there is no metrics selected for it + return !filtered && graph != null && graph !== DEFAULT_GRAPH && !emptyCustomGraph; } }; diff --git a/server/sonar-web/src/main/js/helpers/storage.js b/server/sonar-web/src/main/js/helpers/storage.js index 977f184443e..763aa3d64b1 100644 --- a/server/sonar-web/src/main/js/helpers/storage.js +++ b/server/sonar-web/src/main/js/helpers/storage.js @@ -66,8 +66,10 @@ export const getSort = () => window.localStorage.getItem(PROJECTS_SORT); export const saveCustomGraph = (metrics: ?Array) => save(PROJECT_ACTIVITY_GRAPH_CUSTOM, metrics ? metrics.join(',') : ''); -export const getCustomGraph = (): Array => - (window.localStorage.getItem(PROJECT_ACTIVITY_GRAPH_CUSTOM) || '').split(','); +export const getCustomGraph = (): Array => { + const customGraphs = window.localStorage.getItem(PROJECT_ACTIVITY_GRAPH_CUSTOM); + return customGraphs ? customGraphs.split(',') : []; +}; export const saveGraph = (graph: ?string) => save(PROJECT_ACTIVITY_GRAPH, graph); export const getGraph = (): string => -- cgit v1.2.3