]> source.dussan.org Git - sonarqube.git/commitdiff
PoC Add Open in IDE link in issue poc/kirill+dam/open-issue-in-ide
authorKirill Knize <kirill.knize@sonarsource.com>
Tue, 25 Aug 2020 13:30:16 +0000 (15:30 +0200)
committerKirill Knize <kirill.knize@sonarsource.com>
Wed, 26 Aug 2020 13:52:01 +0000 (15:52 +0200)
server/sonar-web/src/main/js/components/issue/components/IssueActionsBar.tsx
server/sonar-web/src/main/js/components/issue/components/IssueOpenInIde.tsx [new file with mode: 0644]

index 0d06292141791fe06d5cdd910a8fa6b00191ddf1..6ed338182f5319774d950136e14944bc78dbf9ff 100644 (file)
@@ -27,6 +27,7 @@ import IssueSeverity from './IssueSeverity';
 import IssueTags from './IssueTags';
 import IssueTransition from './IssueTransition';
 import IssueType from './IssueType';
+import IssueOpenInIde from "./IssueOpenInIde";
 
 interface Props {
   issue: T.Issue;
@@ -84,6 +85,33 @@ export default class IssueActionsBar extends React.PureComponent<Props, State> {
     }
   };
 
+  openInIde = (issue: T.Issue) => {
+    console.log(issue);
+    async function postData(url = '') {
+      // Default options are marked with *
+      const response = await fetch(url, {
+        method: 'GET', // *GET, POST, PUT, DELETE, etc.
+        mode: 'cors', // no-cors, *cors, same-origin
+        cache: 'no-cache', // *default, no-cache, reload, force-cache, only-if-cached
+        credentials: 'same-origin', // include, *same-origin, omit
+        headers: {
+          'Content-Type': 'application/json',
+          'Access-Control-Allow-Origin': 'http://localhost:9000 http://135.181.88.65:9000'
+          // 'Content-Type': 'application/x-www-form-urlencoded',
+        },
+        redirect: 'follow', // manual, *follow, error
+        referrerPolicy: 'no-referrer', // no-referrer, *no-referrer-when-downgrade, origin, origin-when-cross-origin, same-origin, strict-origin, strict-origin-when-cross-origin, unsafe-url
+        body: null// body data type must match "Content-Type" header
+      });
+      return response.json(); // parses JSON response into native JavaScript objects
+    }
+    postData(`http://localhost:63333?projectName=${issue.projectName}&fileName=${issue.componentLongName}&lineNumber=${issue.line}`)
+    .then(data => {
+      console.log(data); // JSON data parsed by `data.json()` call
+    });
+  }
+    
+
   render() {
     const { issue } = this.props;
     const canAssign = issue.actions.includes('assign');
@@ -152,6 +180,7 @@ export default class IssueActionsBar extends React.PureComponent<Props, State> {
               toggleComment={this.toggleComment}
             />
           )}
+          <IssueOpenInIde openIssueInIde={() => this.openInIde(issue)}/>
         </ul>
         <ul className="list-inline">
           <li className="issue-meta js-issue-tags">
diff --git a/server/sonar-web/src/main/js/components/issue/components/IssueOpenInIde.tsx b/server/sonar-web/src/main/js/components/issue/components/IssueOpenInIde.tsx
new file mode 100644 (file)
index 0000000..4ea8050
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+import * as React from 'react';
+import { ButtonLink } from 'sonar-ui-common/components/controls/buttons';
+
+
+interface Props {
+    openIssueInIde:() => void
+}
+
+export default class IssueOpenInIde extends React.PureComponent<Props> {
+
+    render() {
+        return (
+            <li className="issue-meta dropdown">
+                <ButtonLink className="issue-action js-issue-comment"
+                            onClick={this.props.openIssueInIde}>
+                    <span className="issue-meta-label">Open in IDE</span>
+                </ButtonLink>
+            </li>
+        );
+    }
+}