]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-7402 highlight new code in source viewer
authorStas Vilchik <vilchiks@gmail.com>
Thu, 10 Mar 2016 13:18:52 +0000 (14:18 +0100)
committerStas Vilchik <vilchiks@gmail.com>
Thu, 10 Mar 2016 13:27:17 +0000 (14:27 +0100)
server/sonar-web/src/main/js/apps/code/components/SourceViewer.js
server/sonar-web/src/main/js/apps/component-measures/components/MeasureDetails.js
server/sonar-web/src/main/js/apps/component-measures/components/MeasureDrilldownList.js
server/sonar-web/src/main/js/apps/component-measures/components/MeasureDrilldownTree.js

index ddedbf2617d6f41cf98db7ec6425c7598026d23c..0f0431a9e3dc283ee0a9c1c05097b13d2f550375 100644 (file)
@@ -20,7 +20,7 @@
 import React, { Component } from 'react';
 
 import BaseSourceViewer from '../../../components/source-viewer/main';
-
+import { getPeriodDate, getPeriodLabel } from '../../../helpers/periods';
 
 export default class SourceViewer extends Component {
   componentDidMount () {
@@ -39,7 +39,7 @@ export default class SourceViewer extends Component {
     this.renderSourceViewer();
   }
 
-  componentWillUnmount() {
+  componentWillUnmount () {
     this.destroySourceViewer();
   }
 
@@ -47,12 +47,24 @@ export default class SourceViewer extends Component {
     this.sourceViewer = new BaseSourceViewer();
     this.sourceViewer.render().$el.appendTo(this.refs.container);
     this.sourceViewer.open(this.props.component.id);
+    this.sourceViewer.on('loaded', this.handleLoad.bind(this));
   }
 
   destroySourceViewer () {
     this.sourceViewer.destroy();
   }
 
+  handleLoad () {
+    const { period } = this.props;
+
+    if (period) {
+      const periodDate = getPeriodDate(period);
+      const periodLabel = getPeriodLabel(period);
+      console.log(periodDate, periodLabel);
+      this.sourceViewer.filterLinesByDate(periodDate, periodLabel);
+    }
+  }
+
   render () {
     return <div ref="container" className="code-source-viewer"></div>;
   }
index 2bdc9143f20775823a258212a6b64f29db38d3d8..e4e738870edddd2f14503f47ea2e3b2f71ca352c 100644 (file)
@@ -133,6 +133,7 @@ export default class MeasureDetails extends React.Component {
               <MeasureDrilldown
                   metric={metric}
                   tab={tab}
+                  leakPeriod={leakPeriod}
                   leakPeriodDate={leakPeriodDate}>
                 {this.props.children}
               </MeasureDrilldown>
index 78872e291a77701b264cbe8ecb4323174d3f0daf..d0f68256d3c28575a0e3421a3f6fd15034fb5bb0 100644 (file)
@@ -89,13 +89,15 @@ export default class MeasureDrilldownList extends React.Component {
   }
 
   render () {
-    const { metric, store } = this.props;
+    const { metric, store, leakPeriod } = this.props;
     const { components, selected, fetching } = store.list;
 
     if (fetching) {
       return <Spinner/>;
     }
 
+    const sourceViewerPeriod = metric.key.indexOf('new_') === 0 && !!leakPeriod ? leakPeriod : null;
+
     return (
         <div className="measure-details-plain-list">
           <MeasureDrilldownComponents
@@ -106,7 +108,7 @@ export default class MeasureDrilldownList extends React.Component {
 
           {selected && (
               <div className="measure-details-viewer">
-                <SourceViewer component={selected}/>
+                <SourceViewer component={selected} period={sourceViewerPeriod}/>
               </div>
           )}
         </div>
index 0f925cc2f4203d78977c4da2a52141ff1398e995..f6da317ad5bda5fee9540c109cf653efaf135510 100644 (file)
@@ -97,7 +97,7 @@ export default class MeasureDrilldownTree extends React.Component {
   }
 
   render () {
-    const { metric, store } = this.props;
+    const { metric, store, leakPeriod } = this.props;
     const { components, selected, breadcrumbs, fetching } = store.tree;
     const parent = breadcrumbs.length > 1 ? breadcrumbs[breadcrumbs.length - 2] : null;
 
@@ -105,6 +105,8 @@ export default class MeasureDrilldownTree extends React.Component {
       return <Spinner/>;
     }
 
+    const sourceViewerPeriod = metric.key.indexOf('new_') === 0 && !!leakPeriod ? leakPeriod : null;
+
     return (
         <div className="measure-details-tree">
           <MeasureDrilldownComponents
@@ -116,7 +118,7 @@ export default class MeasureDrilldownTree extends React.Component {
 
           {selected && (
               <div className="measure-details-viewer">
-                <SourceViewer component={selected}/>
+                <SourceViewer component={selected} period={sourceViewerPeriod}/>
               </div>
           )}
         </div>