You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

EmbedDocsPopup.tsx 4.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2021 SonarSource SA
  4. * mailto:info AT sonarsource DOT com
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 3 of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public License
  17. * along with this program; if not, write to the Free Software Foundation,
  18. * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  19. */
  20. import * as React from 'react';
  21. import { Link } from 'react-router';
  22. import { DropdownOverlay } from 'sonar-ui-common/components/controls/Dropdown';
  23. import { translate } from 'sonar-ui-common/helpers/l10n';
  24. import { getBaseUrl } from 'sonar-ui-common/helpers/urls';
  25. import { isSonarCloud } from '../../../helpers/system';
  26. import ProductNewsMenuItem from './ProductNewsMenuItem';
  27. import { SuggestionsContext } from './SuggestionsContext';
  28. interface Props {
  29. onClose: () => void;
  30. }
  31. export default class EmbedDocsPopup extends React.PureComponent<Props> {
  32. renderTitle(text: string) {
  33. return <li className="menu-header">{text}</li>;
  34. }
  35. renderSuggestions = ({ suggestions }: { suggestions: T.SuggestionLink[] }) => {
  36. if (suggestions.length === 0) {
  37. return null;
  38. }
  39. return (
  40. <>
  41. {this.renderTitle(translate('embed_docs.suggestion'))}
  42. {suggestions.map((suggestion, index) => (
  43. <li key={index}>
  44. <Link onClick={this.props.onClose} target="_blank" to={suggestion.link}>
  45. {suggestion.text}
  46. </Link>
  47. </li>
  48. ))}
  49. <li className="divider" />
  50. </>
  51. );
  52. };
  53. renderIconLink(link: string, icon: string, text: string) {
  54. return (
  55. <a href={link} rel="noopener noreferrer" target="_blank">
  56. <img
  57. alt={text}
  58. className="spacer-right"
  59. height="18"
  60. src={`${getBaseUrl()}/images/${icon}`}
  61. width="18"
  62. />
  63. {text}
  64. </a>
  65. );
  66. }
  67. renderSonarCloudLinks() {
  68. return (
  69. <>
  70. <li className="divider" />
  71. <li>
  72. <a
  73. href="https://community.sonarsource.com/c/help/sc"
  74. rel="noopener noreferrer"
  75. target="_blank">
  76. {translate('embed_docs.get_help')}
  77. </a>
  78. </li>
  79. <li className="divider" />
  80. {this.renderTitle(translate('embed_docs.stay_connected'))}
  81. <li>
  82. {this.renderIconLink(
  83. 'https://twitter.com/sonarcloud',
  84. 'embed-doc/twitter-icon.svg',
  85. 'Twitter'
  86. )}
  87. </li>
  88. <li>
  89. {this.renderIconLink(
  90. 'https://blog.sonarsource.com/product/SonarCloud',
  91. 'sonarcloud-square-logo.svg',
  92. translate('embed_docs.blog')
  93. )}
  94. </li>
  95. <li>
  96. <ProductNewsMenuItem tag="SonarCloud" />
  97. </li>
  98. </>
  99. );
  100. }
  101. renderSonarQubeLinks() {
  102. return (
  103. <>
  104. <li className="divider" />
  105. <li>
  106. <a href="https://community.sonarsource.com/" rel="noopener noreferrer" target="_blank">
  107. {translate('embed_docs.get_help')}
  108. </a>
  109. </li>
  110. <li className="divider" />
  111. {this.renderTitle(translate('embed_docs.stay_connected'))}
  112. <li>
  113. {this.renderIconLink(
  114. 'https://www.sonarqube.org/whats-new/?referrer=sonarqube',
  115. 'embed-doc/sq-icon.svg',
  116. translate('embed_docs.news')
  117. )}
  118. </li>
  119. <li>
  120. {this.renderIconLink(
  121. 'https://twitter.com/SonarQube',
  122. 'embed-doc/twitter-icon.svg',
  123. 'Twitter'
  124. )}
  125. </li>
  126. </>
  127. );
  128. }
  129. render() {
  130. return (
  131. <DropdownOverlay>
  132. <ul className="menu abs-width-240">
  133. <SuggestionsContext.Consumer>{this.renderSuggestions}</SuggestionsContext.Consumer>
  134. <li>
  135. <Link onClick={this.props.onClose} target="_blank" to="/documentation">
  136. {translate('embed_docs.documentation')}
  137. </Link>
  138. </li>
  139. <li>
  140. <Link onClick={this.props.onClose} to="/web_api">
  141. {translate('api_documentation.page')}
  142. </Link>
  143. </li>
  144. {isSonarCloud() ? this.renderSonarCloudLinks() : this.renderSonarQubeLinks()}
  145. </ul>
  146. </DropdownOverlay>
  147. );
  148. }
  149. }