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 () {
this.renderSourceViewer();
}
- componentWillUnmount() {
+ componentWillUnmount () {
this.destroySourceViewer();
}
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>;
}
}
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
{selected && (
<div className="measure-details-viewer">
- <SourceViewer component={selected}/>
+ <SourceViewer component={selected} period={sourceViewerPeriod}/>
</div>
)}
</div>
}
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;
return <Spinner/>;
}
+ const sourceViewerPeriod = metric.key.indexOf('new_') === 0 && !!leakPeriod ? leakPeriod : null;
+
return (
<div className="measure-details-tree">
<MeasureDrilldownComponents
{selected && (
<div className="measure-details-viewer">
- <SourceViewer component={selected}/>
+ <SourceViewer component={selected} period={sourceViewerPeriod}/>
</div>
)}
</div>