]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-16300 Fix activity graph options availability
authorPhilippe Perrin <philippe.perrin@sonarsource.com>
Fri, 29 Apr 2022 10:23:37 +0000 (12:23 +0200)
committersonartech <sonartech@sonarsource.com>
Fri, 29 Apr 2022 20:03:19 +0000 (20:03 +0000)
server/sonar-web/src/main/js/apps/projectActivity/components/ProjectActivityGraphs.tsx
server/sonar-web/src/main/js/apps/projectActivity/components/__tests__/__snapshots__/ProjectActivityGraphs-test.tsx.snap

index 2ac68912d7c965b5fdd904105eed99aa47c4d416..57b70d18ebeb0b4cce4d15154e76ce4dc3b276c9 100644 (file)
@@ -142,14 +142,16 @@ export default class ProjectActivityGraphs extends React.PureComponent<Props, St
       .map(graph => graph[0].type);
   };
 
-  updateSelectedMetrics = (selectedMetrics: string[]) => {
-    saveActivityGraph(
-      PROJECT_ACTIVITY_GRAPH,
-      this.props.project,
-      GraphType.custom,
-      selectedMetrics
-    );
-    this.props.updateQuery({ customMetrics: selectedMetrics });
+  addCustomMetric = (metric: string) => {
+    const customMetrics = [...this.props.query.customMetrics, metric];
+    saveActivityGraph(PROJECT_ACTIVITY_GRAPH, this.props.project, GraphType.custom, customMetrics);
+    this.props.updateQuery({ customMetrics });
+  };
+
+  removeCustomMetric = (removedMetric: string) => {
+    const customMetrics = this.props.query.customMetrics.filter(metric => metric !== removedMetric);
+    saveActivityGraph(PROJECT_ACTIVITY_GRAPH, this.props.project, GraphType.custom, customMetrics);
+    this.props.updateQuery({ customMetrics });
   };
 
   updateGraph = (graph: GraphType) => {
@@ -193,10 +195,12 @@ export default class ProjectActivityGraphs extends React.PureComponent<Props, St
     return (
       <div className="project-activity-layout-page-main-inner boxed-group boxed-group-inner">
         <GraphsHeader
+          addCustomMetric={this.addCustomMetric}
           className="big-spacer-bottom"
           graph={query.graph}
           metrics={metrics}
           metricsTypeFilter={this.getMetricsTypeFilter()}
+          removeCustomMetric={this.removeCustomMetric}
           selectedMetrics={this.props.query.customMetrics}
           updateGraph={this.updateGraph}
         />
@@ -209,6 +213,7 @@ export default class ProjectActivityGraphs extends React.PureComponent<Props, St
           leakPeriodDate={leakPeriodDate}
           loading={loading}
           measuresHistory={this.props.measuresHistory}
+          removeCustomMetric={this.removeCustomMetric}
           selectedDate={this.props.query.selectedDate}
           series={series}
           updateGraphZoom={this.updateGraphZoom}
index cbc6c857b88da145f89b2f92e37377b6d11dd059..b817fd80c5ebb2b904d7ed8a79e096abce0ff57b 100644 (file)
@@ -5,6 +5,7 @@ exports[`should render correctly the graph and legends 1`] = `
   className="project-activity-layout-page-main-inner boxed-group boxed-group-inner"
 >
   <GraphsHeader
+    addCustomMetric={[Function]}
     className="big-spacer-bottom"
     graph="issues"
     metrics={
@@ -17,6 +18,7 @@ exports[`should render correctly the graph and legends 1`] = `
         },
       ]
     }
+    removeCustomMetric={[Function]}
     selectedMetrics={Array []}
     updateGraph={[Function]}
   />
@@ -106,6 +108,7 @@ exports[`should render correctly the graph and legends 1`] = `
         },
       ]
     }
+    removeCustomMetric={[Function]}
     series={
       Array [
         Object {