From 37a3a7ac753b6f8133b80bc3b8ab20cd7068d402 Mon Sep 17 00:00:00 2001 From: Philippe Perrin Date: Wed, 2 Sep 2020 16:59:05 +0200 Subject: [PATCH] SONAR-13643 Remove the version history of a language analyzer from its documentation page --- server/sonar-docs/README.md | 25 +- server/sonar-docs/package.json | 3 + .../src/@types/hast-util-select.d.ts | 27 + .../UpdateCenterMetaDataInjector.tsx | 132 -- .../UpdateCenterMetaDataInjector-test.tsx | 55 - ...UpdateCenterMetaDataInjector-test.tsx.snap | 39 - server/sonar-docs/src/layouts/index.tsx | 2 - .../src/pages/analysis/languages/abap.md | 3 - .../src/pages/analysis/languages/apex.md | 3 - .../src/pages/analysis/languages/cfamily.md | 3 - .../src/pages/analysis/languages/cobol.md | 3 - .../src/pages/analysis/languages/csharp.md | 3 - .../src/pages/analysis/languages/css.md | 3 - .../src/pages/analysis/languages/flex.md | 3 - .../src/pages/analysis/languages/go.md | 3 - .../src/pages/analysis/languages/html.md | 3 - .../src/pages/analysis/languages/java.md | 3 - .../pages/analysis/languages/javascript.md | 3 - .../src/pages/analysis/languages/kotlin.md | 3 - .../src/pages/analysis/languages/php.md | 3 - .../src/pages/analysis/languages/pli.md | 3 - .../src/pages/analysis/languages/plsql.md | 3 - .../src/pages/analysis/languages/python.md | 3 - .../src/pages/analysis/languages/rpg.md | 3 - .../src/pages/analysis/languages/ruby.md | 3 - .../src/pages/analysis/languages/scala.md | 3 - .../src/pages/analysis/languages/swift.md | 3 - .../src/pages/analysis/languages/tsql.md | 3 - .../src/pages/analysis/languages/vb6.md | 3 - .../src/pages/analysis/languages/vbnet.md | 3 - .../src/pages/analysis/languages/xml.md | 3 - .../analysis/scan/sonarscanner-for-ant.md | 3 - .../scan/sonarscanner-for-azure-devops.md | 3 - .../analysis/scan/sonarscanner-for-gradle.md | 3 - .../analysis/scan/sonarscanner-for-jenkins.md | 3 - .../analysis/scan/sonarscanner-for-maven.md | 3 - .../analysis/scan/sonarscanner-for-msbuild.md | 3 - .../src/pages/analysis/scan/sonarscanner.md | 3 - server/sonar-docs/src/templates/page.tsx | 181 ++- server/sonar-docs/src/types/hast.ts | 31 + server/sonar-docs/yarn.lock | 1121 +++++++++++------ 41 files changed, 914 insertions(+), 795 deletions(-) create mode 100644 server/sonar-docs/src/@types/hast-util-select.d.ts delete mode 100644 server/sonar-docs/src/components/UpdateCenterMetaDataInjector.tsx delete mode 100644 server/sonar-docs/src/components/__tests__/UpdateCenterMetaDataInjector-test.tsx delete mode 100644 server/sonar-docs/src/components/__tests__/__snapshots__/UpdateCenterMetaDataInjector-test.tsx.snap create mode 100644 server/sonar-docs/src/types/hast.ts diff --git a/server/sonar-docs/README.md b/server/sonar-docs/README.md index f0f21aff683..acd52390717 100644 --- a/server/sonar-docs/README.md +++ b/server/sonar-docs/README.md @@ -301,34 +301,17 @@ Note that an iframe is **not** a self-closing tag. This means that the following ``` -#### Dynamic Plugin/Scanner Version Info +#### Dynamic Scanner Version Info -You can dynamically include a plugin/scanner version block to any page, using the following special tag: - -For static documentation, use: - -```html - -``` - -For embedded documentation, use: -```html - -``` - -For example, for Sonar Java, use: +You can dynamically include a scanner version block to any page, using the following special tag: ```html - -or - + ``` -For gradle's scanner, use: +For example, for gradle's scanner, use: ```html - -or ``` diff --git a/server/sonar-docs/package.json b/server/sonar-docs/package.json index d504b6cfcd9..ba428774ddc 100644 --- a/server/sonar-docs/package.json +++ b/server/sonar-docs/package.json @@ -15,12 +15,14 @@ "gatsby-remark-custom-blocks": "2.1.27", "gatsby-source-filesystem": "2.1.57", "gatsby-transformer-remark": "2.6.59", + "hast-util-select": "4.0.0", "lodash": "4.17.15", "lunr": "2.3.8", "react": "16.13.0", "react-dom": "16.13.0", "react-helmet": "5.2.1", "react-typography": "0.16.19", + "rehype-react": "6.1.0", "sonar-ui-common": "1.0.22", "typography": "0.16.19" }, @@ -33,6 +35,7 @@ "@types/react": "16.8.23", "@types/react-dom": "16.8.4", "@types/react-helmet": "5.0.15", + "@types/rehype-react": "4.0.0", "@typescript-eslint/parser": "2.6.0", "babel-jest": "25.1.0", "enzyme": "3.11.0", diff --git a/server/sonar-docs/src/@types/hast-util-select.d.ts b/server/sonar-docs/src/@types/hast-util-select.d.ts new file mode 100644 index 00000000000..bc2fb4dde79 --- /dev/null +++ b/server/sonar-docs/src/@types/hast-util-select.d.ts @@ -0,0 +1,27 @@ +/* + * 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 { HtmlAST, HtmlASTNode } from '../types/hast'; + +declare module 'hast-util-select' { + export function matches(selector: string, ode: HtmlASTNode): boolean; + export function selectAll(selector: string, tree: HtmlAST): HtmlASTNode[]; + export function select(selector: string, tree: HtmlAST): HtmlASTNode; +} diff --git a/server/sonar-docs/src/components/UpdateCenterMetaDataInjector.tsx b/server/sonar-docs/src/components/UpdateCenterMetaDataInjector.tsx deleted file mode 100644 index 2593983a4f7..00000000000 --- a/server/sonar-docs/src/components/UpdateCenterMetaDataInjector.tsx +++ /dev/null @@ -1,132 +0,0 @@ -/* - * 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 { createPortal } from 'react-dom'; -import MetaData from 'sonar-ui-common/components/ui/update-center/MetaData'; -import { Dict } from '../@types/types'; - -interface Props { - location: Pick; -} - -interface State { - wrappers: Dict; -} - -export default class UpdateCenterMetaDataInjector extends React.Component { - state: State = { - wrappers: {} - }; - - componentDidMount() { - this.searchForMetaData(); - } - - componentDidUpdate({ location }: Props) { - if (location.pathname !== this.props.location.pathname) { - this.clearMetaData(); - this.searchForMetaData(); - } - } - - componentWillUnmount() { - this.clearMetaData(); - } - - clearMetaData = () => { - const { wrappers } = this.state; - - Object.keys(wrappers).forEach(key => { - const node = wrappers[key]; - const { parentNode } = node; - if (parentNode) { - parentNode.removeChild(node); - } - - delete wrappers[key]; - }); - - this.setState({ wrappers: {} }); - }; - - searchForMetaData = () => { - const pageContainer = document.querySelector('.page-container'); - - if (!pageContainer) { - return; - } - - // The following uses an older syntax for createNodeIterator() in order - // to support IE11 - // - IE doesn't support the new { acceptNode: (node: Node) => number } - // format for the 3rd parameter, and instead expects to get it passed - // the function directly. Modern browsers support both paradigms as a - // fallback, so we fallback to the old one. - // - IE11 requires the 4th argument. - // @ts-ignore: tsc requires an additional comment at the function call. - const iterator = document.createNodeIterator( - pageContainer, - NodeFilter.SHOW_COMMENT, - // @ts-ignore: IE11 doesn't support the { acceptNode: () => number } format. - (_: Node) => NodeFilter.FILTER_ACCEPT, - // @ts-ignore: IE11 requires the 4th argument. - false - ); - - const wrappers: Dict = {}; - let node = iterator.nextNode(); - - while (node) { - if (node.nodeValue && node.parentNode && /update_center\s*:/.test(node.nodeValue)) { - let [, key] = node.nodeValue.split(':'); - key = key.trim(); - - const wrapper = document.createElement('div'); - wrappers[key] = wrapper; - node.parentNode.insertBefore(wrapper, node); - } - - node = iterator.nextNode(); - } - - this.setState({ wrappers }); - }; - - render() { - const { wrappers } = this.state; - const keys = Object.keys(wrappers); - - if (keys.length === 0) { - return null; - } - - return ( -
- {keys.map(key => { - if (wrappers[key]) { - return createPortal(, wrappers[key]); - } else { - return null; - } - })} -
- ); - } -} diff --git a/server/sonar-docs/src/components/__tests__/UpdateCenterMetaDataInjector-test.tsx b/server/sonar-docs/src/components/__tests__/UpdateCenterMetaDataInjector-test.tsx deleted file mode 100644 index b12ea7e0e74..00000000000 --- a/server/sonar-docs/src/components/__tests__/UpdateCenterMetaDataInjector-test.tsx +++ /dev/null @@ -1,55 +0,0 @@ -/* - * 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 { shallow } from 'enzyme'; -import * as React from 'react'; -import UpdateCenterMetaDataInjector from '../UpdateCenterMetaDataInjector'; - -it('should render correctly', () => { - (global as any).document.body.innerHTML = ` -
-

Lorem ipsum

- -

Dolor sit amet

- -

Foo Bar

- -
-`; - - const wrapper = shallowRender(); - expect(wrapper).toMatchSnapshot(); - - (global as any).document.body.innerHTML = ` -
-

Lorem ipsum

- -

Foo Bar

-
-`; - - wrapper.setProps({ location: { pathname: 'foo2' } }); - expect(wrapper).toMatchSnapshot(); -}); - -function shallowRender(props: Partial = {}) { - return shallow( - - ); -} diff --git a/server/sonar-docs/src/components/__tests__/__snapshots__/UpdateCenterMetaDataInjector-test.tsx.snap b/server/sonar-docs/src/components/__tests__/__snapshots__/UpdateCenterMetaDataInjector-test.tsx.snap deleted file mode 100644 index 7682b8ca34b..00000000000 --- a/server/sonar-docs/src/components/__tests__/__snapshots__/UpdateCenterMetaDataInjector-test.tsx.snap +++ /dev/null @@ -1,39 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`should render correctly 1`] = ` -
- } - > - - - } - > - - - } - > - - -
-`; - -exports[`should render correctly 2`] = ` -
- } - > - - -
-`; diff --git a/server/sonar-docs/src/layouts/index.tsx b/server/sonar-docs/src/layouts/index.tsx index 5d1ef762124..48172b4b592 100644 --- a/server/sonar-docs/src/layouts/index.tsx +++ b/server/sonar-docs/src/layouts/index.tsx @@ -24,7 +24,6 @@ import Footer from '../components/Footer'; import HeaderListProvider from '../components/HeaderListProvider'; import HeadingsLink from '../components/HeadingsLink'; import Sidebar from '../components/Sidebar'; -import UpdateCenterMetaDataInjector from '../components/UpdateCenterMetaDataInjector'; import './layout.css'; const version = process.env.GATSBY_DOCS_VERSION || '1.0'; @@ -95,7 +94,6 @@ export default function Layout({ children, location }: Props) {
{children}