diff options
author | Stas Vilchik <stas-vilchik@users.noreply.github.com> | 2017-03-02 13:18:27 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-03-02 13:18:27 +0100 |
commit | ce9f0892fc3d15638c4eaa4054ed06f3d7e5fc19 (patch) | |
tree | 0dd0d0633c514ef51071b03516d5eca5b23d64f2 /server/sonar-web/src/main/js/apps/component | |
parent | 0a547ba79c4affb9b6ff0b669ee4a5e87ef16479 (diff) | |
download | sonarqube-ce9f0892fc3d15638c4eaa4054ed06f3d7e5fc19.tar.gz sonarqube-ce9f0892fc3d15638c4eaa4054ed06f3d7e5fc19.zip |
refactor source viewer (#1705)
Diffstat (limited to 'server/sonar-web/src/main/js/apps/component')
-rw-r--r-- | server/sonar-web/src/main/js/apps/component/components/App.js | 45 |
1 files changed, 28 insertions, 17 deletions
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 ( <div className="page"> - <SourceViewer component={{ id: this.state.component.id }} line={line}/> + <SourceViewer + aroundLine={finalLine} + component={id} + highlightedLine={finalLine} + onLoaded={this.scrollToLine}/> </div> ); } |