]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-9177 Show a warning when accessing a removed file
authorGrégoire Aubert <gregoire.aubert@sonarsource.com>
Fri, 5 May 2017 09:17:22 +0000 (11:17 +0200)
committerGrégoire Aubert <gregoire.aubert@sonarsource.com>
Tue, 9 May 2017 09:15:45 +0000 (11:15 +0200)
server/sonar-web/src/main/js/components/SourceViewer/SourceViewerBase.js
sonar-core/src/main/resources/org/sonar/l10n/core.properties

index 28ba8f032d9e173080f66432dfce8e7cc6c66343..0ffb62eec717a83ee22987f0b734270b97ff84ba 100644 (file)
@@ -98,6 +98,7 @@ type State = {
   openIssuesByLine: { [number]: boolean },
   selectedIssue?: string,
   sources?: Array<SourceLine>,
+  sourceRemoved: boolean,
   symbolsByLine: { [number]: Array<string> }
 };
 
@@ -144,6 +145,7 @@ export default class SourceViewerBase extends React.PureComponent {
       openIssuesByLine: {},
       selectedIssue: props.selectedIssue,
       selectedIssueLocation: null,
+      sourceRemoved: false,
       symbolsByLine: {}
     };
   }
@@ -224,6 +226,7 @@ export default class SourceViewerBase extends React.PureComponent {
               loading: false,
               hasSourcesAfter: sources.length > LINES,
               sources: this.computeCoverageStatus(finalSources),
+              sourceRemoved: false,
               symbolsByLine: symbolsByLine(sources.slice(0, LINES))
             },
             () => {
@@ -248,6 +251,8 @@ export default class SourceViewerBase extends React.PureComponent {
       if (this.mounted) {
         if (response.status === 403) {
           this.setState({ component, loading: false, notAccessible: true });
+        } else if (response.status === 404) {
+          this.setState({ component, loading: false, sourceRemoved: true });
         }
       }
     };
@@ -307,9 +312,9 @@ export default class SourceViewerBase extends React.PureComponent {
       const onFailLoadSources = ({ response }) => {
         // TODO handle other statuses
         if (this.mounted) {
-          if (response.status === 403) {
+          if ([403, 404].includes(response.status)) {
             reject(response);
-          } else if (response.status === 404) {
+          } else {
             resolve([]);
           }
         }
@@ -570,7 +575,7 @@ export default class SourceViewerBase extends React.PureComponent {
   }
 
   render() {
-    const { component, loading } = this.state;
+    const { component, loading, sources, notAccessible, sourceRemoved } = this.state;
 
     if (loading) {
       return null;
@@ -592,14 +597,20 @@ export default class SourceViewerBase extends React.PureComponent {
       'source-duplications-expanded': this.state.displayDuplications
     });
 
+    const displaySources = !notAccessible && !sourceRemoved;
+
     return (
       <div className={className} ref={node => (this.node = node)}>
         <SourceViewerHeader component={this.state.component} showMeasures={this.showMeasures} />
-        {this.state.notAccessible &&
+        {notAccessible &&
           <div className="alert alert-warning spacer-top">
             {translate('code_viewer.no_source_code_displayed_due_to_security')}
           </div>}
-        {this.state.sources != null && this.renderCode(this.state.sources)}
+        {sourceRemoved &&
+          <div className="alert alert-warning spacer-top">
+            {translate('code_viewer.no_source_code_displayed_due_to_source_removed')}
+          </div>}
+        {displaySources && sources != null && this.renderCode(sources)}
       </div>
     );
   }
index d1e6ff744cf3e7559070c81883f0b55ee695cb6a..7671a1d216da3aa5852fa60a0bd1c2ecfcbd39d6 100644 (file)
@@ -1149,6 +1149,7 @@ coverage_viewer.x_covered_conditions={0} conditions are covered by tests
 #------------------------------------------------------------------------------
 code_viewer.no_info_displayed_due_to_security=Due to security settings, no information can be displayed.
 code_viewer.no_source_code_displayed_due_to_security=Due to security settings, no source code can be displayed.
+code_viewer.no_source_code_displayed_due_to_source_removed=The file was removed, no source code can be displayed.
 
 
 #------------------------------------------------------------------------------