diff options
Diffstat (limited to 'server/sonar-web/src/main')
3 files changed, 77 insertions, 18 deletions
diff --git a/server/sonar-web/src/main/js/apps/issues/components/App.js b/server/sonar-web/src/main/js/apps/issues/components/App.js index a6745fa2add..8d71be0d1ff 100644 --- a/server/sonar-web/src/main/js/apps/issues/components/App.js +++ b/server/sonar-web/src/main/js/apps/issues/components/App.js @@ -426,18 +426,32 @@ export default class App extends React.PureComponent { }); }; - fetchIssuesForComponent = (): Promise<Array<Issue>> => { + fetchIssuesForComponent = ( + component: string, + from: number, + to: number + ): Promise<Array<Issue>> => { const { issues, openIssue, paging } = this.state; + /* eslint-disable no-console */ + console.log(`loadin issues from line ${from} to line ${to}`); + if (!openIssue || !paging) { return Promise.reject(); } const isSameComponent = (issue: Issue): boolean => issue.component === openIssue.component; - const done = (issues: Array<Issue>, paging: Paging): boolean => - paging.total <= paging.pageIndex * paging.pageSize || - issues[issues.length - 1].component !== openIssue.component; + const done = (issues: Array<Issue>, paging: Paging): boolean => { + if (paging.total <= paging.pageIndex * paging.pageSize) { + return true; + } + const lastIssue = issues[issues.length - 1]; + if (lastIssue.component !== openIssue.component) { + return true; + } + return lastIssue.line != null && lastIssue.line > to; + }; if (done(issues, paging)) { return Promise.resolve(issues.filter(isSameComponent)); diff --git a/server/sonar-web/src/main/js/apps/issues/components/IssuesSourceViewer.js b/server/sonar-web/src/main/js/apps/issues/components/IssuesSourceViewer.js index 947be331377..062d8530e6d 100644 --- a/server/sonar-web/src/main/js/apps/issues/components/IssuesSourceViewer.js +++ b/server/sonar-web/src/main/js/apps/issues/components/IssuesSourceViewer.js @@ -24,7 +24,7 @@ import { scrollToElement } from '../../../helpers/scrolling'; import type { Issue } from '../../../components/issue/types'; type Props = {| - loadIssues: () => Promise<*>, + loadIssues: (string, number, number) => Promise<*>, onIssueChange: Issue => void, onIssueSelect: string => void, onLocationSelect: number => void, diff --git a/server/sonar-web/src/main/js/components/SourceViewer/SourceViewerBase.js b/server/sonar-web/src/main/js/components/SourceViewer/SourceViewerBase.js index 8f29e6a59c7..085c889bbb5 100644 --- a/server/sonar-web/src/main/js/components/SourceViewer/SourceViewerBase.js +++ b/server/sonar-web/src/main/js/components/SourceViewer/SourceViewerBase.js @@ -168,6 +168,16 @@ export default class SourceViewerBase extends React.PureComponent { this.isLineOutsideOfRange(this.props.aroundLine) ) { this.fetchSources(); + } else { + const { selectedIssue } = this.props; + const { issues } = this.state; + if ( + selectedIssue != null && + issues != null && + issues.find(issue => issue.key === selectedIssue) == null + ) { + this.reloadIssues(); + } } } @@ -273,6 +283,25 @@ export default class SourceViewerBase extends React.PureComponent { }); } + reloadIssues() { + if (!this.state.sources) { + return; + } + const firstSourceLine = this.state.sources[0]; + const lastSourceLine = this.state.sources[this.state.sources.length - 1]; + this.props + .loadIssues(this.props.component, firstSourceLine.line, lastSourceLine.line) + .then(issues => { + if (this.mounted) { + this.setState({ + issues, + issuesByLine: issuesByLine(issues), + issueLocationsByLine: locationsByLine(issues) + }); + } + }); + } + loadSources() { return new Promise((resolve, reject) => { const onFailLoadSources = ({ response }) => { @@ -312,12 +341,17 @@ export default class SourceViewerBase extends React.PureComponent { this.props.loadSources(this.props.component, from, firstSourceLine.line - 1).then(sources => { this.props.loadIssues(this.props.component, from, firstSourceLine.line - 1).then(issues => { if (this.mounted) { - this.setState(prevState => ({ - issues: uniqBy([...issues, ...prevState.issues], issue => issue.key), - loadingSourcesBefore: false, - sources: [...this.computeCoverageStatus(sources), ...prevState.sources], - symbolsByLine: { ...prevState.symbolsByLine, ...symbolsByLine(sources) } - })); + this.setState(prevState => { + const nextIssues = uniqBy([...issues, ...prevState.issues], issue => issue.key); + return { + issues: nextIssues, + issuesByLine: issuesByLine(nextIssues), + issueLocationsByLine: locationsByLine(nextIssues), + loadingSourcesBefore: false, + sources: [...this.computeCoverageStatus(sources), ...prevState.sources], + symbolsByLine: { ...prevState.symbolsByLine, ...symbolsByLine(sources) } + }; + }); } }); }); @@ -335,13 +369,24 @@ export default class SourceViewerBase extends React.PureComponent { this.props.loadSources(this.props.component, fromLine, toLine).then(sources => { this.props.loadIssues(this.props.component, fromLine, toLine).then(issues => { if (this.mounted) { - this.setState(prevState => ({ - issues: uniqBy([...prevState.issues, ...issues], issue => issue.key), - hasSourcesAfter: sources.length > LINES, - loadingSourcesAfter: false, - sources: [...prevState.sources, ...this.computeCoverageStatus(sources.slice(0, LINES))], - symbolsByLine: { ...prevState.symbolsByLine, ...symbolsByLine(sources.slice(0, LINES)) } - })); + this.setState(prevState => { + const nextIssues = uniqBy([...prevState.issues, ...issues], issue => issue.key); + return { + issues: nextIssues, + issuesByLine: issuesByLine(nextIssues), + issueLocationsByLine: locationsByLine(nextIssues), + hasSourcesAfter: sources.length > LINES, + loadingSourcesAfter: false, + sources: [ + ...prevState.sources, + ...this.computeCoverageStatus(sources.slice(0, LINES)) + ], + symbolsByLine: { + ...prevState.symbolsByLine, + ...symbolsByLine(sources.slice(0, LINES)) + } + }; + }); } }); }); |