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 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2024 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 { ItemDivider, ItemHeader, ItemLink, OpenNewTabIcon } from 'design-system';
  21. import * as React from 'react';
  22. import { translate } from '../../helpers/l10n';
  23. import { getBaseUrl } from '../../helpers/system';
  24. import { SuggestionLink } from '../../types/types';
  25. import { DocItemLink } from './DocItemLink';
  26. import { SuggestionsContext } from './SuggestionsContext';
  27. function IconLink({
  28. icon = 'embed-doc/sq-icon.svg',
  29. link,
  30. text,
  31. }: {
  32. icon?: string;
  33. link: string;
  34. text: string;
  35. }) {
  36. return (
  37. <ItemLink to={link}>
  38. <img
  39. alt={text}
  40. aria-hidden
  41. className="spacer-right"
  42. height="18"
  43. src={`${getBaseUrl()}/images/${icon}`}
  44. width="18"
  45. />
  46. {text}
  47. </ItemLink>
  48. );
  49. }
  50. function Suggestions({
  51. firstItemRef,
  52. suggestions,
  53. }: {
  54. firstItemRef: React.RefObject<HTMLAnchorElement>;
  55. suggestions: SuggestionLink[];
  56. }) {
  57. return (
  58. <>
  59. <ItemHeader id="suggestion">{translate('docs.suggestion')}</ItemHeader>
  60. {suggestions.map((suggestion, i) => (
  61. <DocItemLink
  62. innerRef={i === 0 ? firstItemRef : undefined}
  63. key={suggestion.link}
  64. to={suggestion.link}
  65. >
  66. {suggestion.text}
  67. </DocItemLink>
  68. ))}
  69. <ItemDivider />
  70. </>
  71. );
  72. }
  73. export function EmbedDocsPopup() {
  74. const firstItemRef = React.useRef<HTMLAnchorElement>(null);
  75. const { suggestions } = React.useContext(SuggestionsContext);
  76. React.useEffect(() => {
  77. firstItemRef.current?.focus();
  78. }, []);
  79. return (
  80. <>
  81. {suggestions.length !== 0 && (
  82. <Suggestions firstItemRef={firstItemRef} suggestions={suggestions} />
  83. )}
  84. <DocItemLink innerRef={suggestions.length === 0 ? firstItemRef : undefined} to="/">
  85. {translate('docs.documentation')}
  86. </DocItemLink>
  87. <ItemLink to="/web_api">{translate('api_documentation.page')}</ItemLink>
  88. <ItemLink to="/web_api_v2">{translate('api_documentation.page.v2')}</ItemLink>
  89. <ItemDivider />
  90. <ItemLink to="https://community.sonarsource.com/">
  91. <OpenNewTabIcon />
  92. {translate('docs.get_help')}
  93. </ItemLink>
  94. <ItemDivider />
  95. <ItemHeader id="stay_connected">{translate('docs.stay_connected')}</ItemHeader>
  96. <IconLink
  97. link="https://www.sonarsource.com/products/sonarqube/whats-new/?referrer=sonarqube"
  98. text={translate('docs.news')}
  99. />
  100. <IconLink
  101. link="https://www.sonarsource.com/products/sonarqube/roadmap/?referrer=sonarqube"
  102. text={translate('docs.roadmap')}
  103. />
  104. <IconLink
  105. icon="embed-doc/x-icon-black.svg"
  106. link="https://twitter.com/SonarQube"
  107. text="X @SonarQube"
  108. />
  109. </>
  110. );
  111. }