From ce9f0892fc3d15638c4eaa4054ed06f3d7e5fc19 Mon Sep 17 00:00:00 2001 From: Stas Vilchik Date: Thu, 2 Mar 2017 13:18:27 +0100 Subject: refactor source viewer (#1705) --- .../src/main/js/apps/component/components/App.js | 45 ++++++++++++++-------- 1 file changed, 28 insertions(+), 17 deletions(-) (limited to 'server/sonar-web/src/main/js/apps/component') diff --git a/server/sonar-web/src/main/js/apps/component/components/App.js b/server/sonar-web/src/main/js/apps/component/components/App.js index d889e4df77f..041625d8243 100644 --- a/server/sonar-web/src/main/js/apps/component/components/App.js +++ b/server/sonar-web/src/main/js/apps/component/components/App.js @@ -19,32 +19,43 @@ */ // @flow import React from 'react'; -import SourceViewer from '../../../components/source-viewer/SourceViewer'; -import { getComponentNavigation } from '../../../api/nav'; +import SourceViewer from '../../../components/SourceViewer/StandaloneSourceViewer'; export default class App extends React.Component { - static propTypes = { - location: React.PropTypes.object.isRequired - }; - - state = {}; - - componentDidMount () { - getComponentNavigation(this.props.location.query.id).then(component => ( - this.setState({ component }) - )); + props: { + location: { + query: { + id: string, + line?: string + } + } } - render () { - if (!this.state.component) { - return null; + scrollToLine = () => { + const { line } = this.props.location.query; + if (line) { + const row = document.querySelector(`.source-line[data-line-number="${line}"]`); + if (row) { + const rect = row.getBoundingClientRect(); + const topOffset = window.innerHeight / 2 - 60; + const goal = rect.top - topOffset; + window.scrollTo(0, goal); + } } + }; - const { line } = this.props.location.query; + render () { + const { id, line } = this.props.location.query; + + const finalLine = line != null ? Number(line) : null; return (
- +
); } -- cgit v1.2.3