From 72c602efb630c1d843cefdf185a54b20c313e13d Mon Sep 17 00:00:00 2001 From: Wouter Admiraal Date: Thu, 2 Jan 2020 15:20:29 +0100 Subject: [PATCH] SONAR-12886 Update LTS handling in static documentation --- server/sonar-docs/src/@types/types.d.ts | 1 + server/sonar-docs/src/components/Sidebar.tsx | 37 +- .../src/components/VersionSelect.tsx | 4 +- .../src/components/__tests__/Sidebar-test.tsx | 15 +- .../__tests__/VersionSelect-test.tsx | 61 ++ .../__snapshots__/Sidebar-test.tsx.snap | 565 +++++++++++++++++- .../__snapshots__/VersionSelect-test.tsx.snap | 109 ++++ server/sonar-docs/src/layouts/layout.css | 3 +- server/sonar-docs/static/DocsVersions.json | 2 +- server/sonar-docs/yarn.lock | 2 +- 10 files changed, 771 insertions(+), 28 deletions(-) create mode 100644 server/sonar-docs/src/components/__tests__/VersionSelect-test.tsx create mode 100644 server/sonar-docs/src/components/__tests__/__snapshots__/VersionSelect-test.tsx.snap diff --git a/server/sonar-docs/src/@types/types.d.ts b/server/sonar-docs/src/@types/types.d.ts index 289ad620c2a..4dffe9d5227 100644 --- a/server/sonar-docs/src/@types/types.d.ts +++ b/server/sonar-docs/src/@types/types.d.ts @@ -22,6 +22,7 @@ export type Dict = { [key: string]: T }; export interface DocVersion { current: boolean; + lts?: boolean; value: string; } diff --git a/server/sonar-docs/src/components/Sidebar.tsx b/server/sonar-docs/src/components/Sidebar.tsx index e49e89b8b4e..fa6ba53d796 100644 --- a/server/sonar-docs/src/components/Sidebar.tsx +++ b/server/sonar-docs/src/components/Sidebar.tsx @@ -17,24 +17,24 @@ * 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 { Link } from 'gatsby'; +import * as React from 'react'; import CategoryBlockLink from './CategoryBlockLink'; import ExternalLink from './ExternalLink'; -import PageLink from './PageLink'; -import Search from './Search'; -import SearchEntryResult from './SearchEntryResult'; -import VersionSelect from './VersionSelect'; import DownloadIcon from './icons/DownloadIcon'; import { getNavTree, + getOpenChainFromPath, isDocsNavigationBlock, isDocsNavigationExternalLink, - getOpenChainFromPath, testPathAgainstUrl } from './navTreeUtils'; +import PageLink from './PageLink'; +import Search from './Search'; +import SearchEntryResult from './SearchEntryResult'; +import VersionSelect from './VersionSelect'; +import { DocNavigationItem, DocVersion, SearchResult } from '../@types/types'; import { MarkdownRemark } from '../@types/graphql-types'; -import { SearchResult, DocVersion, DocNavigationItem } from '../@types/types'; interface Props { location: Location; @@ -169,10 +169,16 @@ export default class Sidebar extends React.PureComponent { render() { const { versions } = this.state; + const { version } = this.props; + const currentVersion = versions.find(v => v.current); + const ltsVersion = versions.find(v => Boolean(v.lts)); + const selectedVersionValue = - currentVersion && this.props.version === 'latest' ? currentVersion.value : this.props.version; + currentVersion && version === 'latest' ? currentVersion.value : version; const isOnCurrentVersion = !currentVersion || selectedVersionValue === currentVersion.value; + const isOnLTSVersion = ltsVersion && version === ltsVersion.value; + return (
@@ -180,7 +186,7 @@ export default class Sidebar extends React.PureComponent { Continuous Code Quality @@ -190,11 +196,10 @@ export default class Sidebar extends React.PureComponent { selectedVersionValue={selectedVersionValue} versions={versions} /> - {this.state.loaded && !isOnCurrentVersion && ( + {this.state.loaded && !isOnCurrentVersion && !isOnLTSVersion && (
- This is an archived version of the doc for{' '} - SonarQube version {this.props.version}. See Documentation for - current functionnality. + This is an archived version of the doc for SonarQube version {version}.{' '} + See Documentation for current functionnality.
)}
@@ -211,21 +216,21 @@ export default class Sidebar extends React.PureComponent { SonarQube - Community Community + Community Community - Twitter + Twitter - Product News + Product News Product News
diff --git a/server/sonar-docs/src/components/VersionSelect.tsx b/server/sonar-docs/src/components/VersionSelect.tsx index a7ea4465824..1723e998448 100644 --- a/server/sonar-docs/src/components/VersionSelect.tsx +++ b/server/sonar-docs/src/components/VersionSelect.tsx @@ -62,7 +62,9 @@ export default class VersionSelect extends React.PureComponent { return (
  • - {version.value} + + {version.value + (version.lts ? ' LTS' : '')} +
  • ); diff --git a/server/sonar-docs/src/components/__tests__/Sidebar-test.tsx b/server/sonar-docs/src/components/__tests__/Sidebar-test.tsx index a7d64ea8ba2..5545d472344 100644 --- a/server/sonar-docs/src/components/__tests__/Sidebar-test.tsx +++ b/server/sonar-docs/src/components/__tests__/Sidebar-test.tsx @@ -59,18 +59,23 @@ jest.mock('../navTreeUtils', () => { beforeEach(() => { (fetch as FetchMock).resetMocks(); (fetch as FetchMock).mockResponse(`[ - { "value": "2.0", "current": true }, + { "value": "3.0", "current": true }, + { "value": "2.0", "current": false, "lts": true }, { "value": "1.0", "current": false } ]`); }); -it('should render correctly', () => { +it('should render correctly', async () => { const wrapper = shallowRender(); - expect(wrapper).toMatchSnapshot(); + await new Promise(setImmediate); + + expect(wrapper).toMatchSnapshot('default'); + expect(wrapper.setProps({ version: '1.0' })).toMatchSnapshot('show warning'); + expect(wrapper.setProps({ version: '2.0' })).toMatchSnapshot('lts'); }); function shallowRender(props: Partial = {}) { - return shallow( + return shallow( = {}) { } } as MarkdownRemark ]} - version="2.0" + version="3.0" {...props} /> ); diff --git a/server/sonar-docs/src/components/__tests__/VersionSelect-test.tsx b/server/sonar-docs/src/components/__tests__/VersionSelect-test.tsx new file mode 100644 index 00000000000..411b5620609 --- /dev/null +++ b/server/sonar-docs/src/components/__tests__/VersionSelect-test.tsx @@ -0,0 +1,61 @@ +/* + * 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 OutsideClickHandler from '../OutsideClickHandler'; +import VersionSelect from '../VersionSelect'; + +it('should render correctly', () => { + expect(shallowRender()).toMatchSnapshot('default'); + + const wrapper = shallowRender(); + wrapper.setState({ open: true }); + expect(wrapper).toMatchSnapshot('open'); + + expect(shallowRender({ isOnCurrentVersion: true })).toMatchSnapshot('on current version'); +}); + +it('should handle open/closing the list', () => { + const wrapper = shallowRender(); + + wrapper.find('button').simulate('click'); + expect(wrapper.state().open).toBe(true); + wrapper.find('button').simulate('click'); + expect(wrapper.state().open).toBe(false); + + wrapper.setState({ open: true }); + wrapper.find(OutsideClickHandler).prop('onClickOutside')(); + expect(wrapper.state().open).toBe(false); +}); + +function shallowRender(props: Partial = {}) { + return shallow( + + ); +} diff --git a/server/sonar-docs/src/components/__tests__/__snapshots__/Sidebar-test.tsx.snap b/server/sonar-docs/src/components/__tests__/__snapshots__/Sidebar-test.tsx.snap index 3380f584f82..d7c45fad7d6 100644 --- a/server/sonar-docs/src/components/__tests__/__snapshots__/Sidebar-test.tsx.snap +++ b/server/sonar-docs/src/components/__tests__/__snapshots__/Sidebar-test.tsx.snap @@ -1,6 +1,6 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`should render correctly 1`] = ` +exports[`should render correctly: default 1`] = `
    @@ -13,15 +13,294 @@ exports[`should render correctly 1`] = ` Continuous Code Quality +
    +
    + + +
    + + +`; + +exports[`should render correctly: lts 1`] = ` +
    +
    + + Continuous Code Quality + +
    `; + +exports[`should render correctly: show warning 1`] = ` +
    +
    + + Continuous Code Quality + + +
    + This is an archived version of the doc for + + SonarQube version + 1.0 + + . + + + See Documentation + + for current functionnality. +
    +
    +
    + + +
    + +
    +`; diff --git a/server/sonar-docs/src/components/__tests__/__snapshots__/VersionSelect-test.tsx.snap b/server/sonar-docs/src/components/__tests__/__snapshots__/VersionSelect-test.tsx.snap new file mode 100644 index 00000000000..b91c29e7a44 --- /dev/null +++ b/server/sonar-docs/src/components/__tests__/__snapshots__/VersionSelect-test.tsx.snap @@ -0,0 +1,109 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`should render correctly: default 1`] = ` +
    + +
    +`; + +exports[`should render correctly: on current version 1`] = ` +
    + +
    +`; + +exports[`should render correctly: open 1`] = ` +
    + + + + +
    +`; diff --git a/server/sonar-docs/src/layouts/layout.css b/server/sonar-docs/src/layouts/layout.css index 8a8f25594c2..e15e9484cc7 100644 --- a/server/sonar-docs/src/layouts/layout.css +++ b/server/sonar-docs/src/layouts/layout.css @@ -485,8 +485,9 @@ a.search-result .note { font-size: 15px; margin: 0; padding: 4px 16px; - text-align: center; + text-align: left; transition: all 0.2s ease; + white-space: nowrap; } .version-select ul li:hover { diff --git a/server/sonar-docs/static/DocsVersions.json b/server/sonar-docs/static/DocsVersions.json index 19772b03b16..501eab58d1e 100644 --- a/server/sonar-docs/static/DocsVersions.json +++ b/server/sonar-docs/static/DocsVersions.json @@ -1,6 +1,6 @@ [ { "value": "7.3", "current": true }, { "value": "7.2", "current": false }, - { "value": "7.1", "current": false }, + { "value": "7.1", "current": false, "lts": true }, { "value": "7.0", "current": false } ] diff --git a/server/sonar-docs/yarn.lock b/server/sonar-docs/yarn.lock index 7862252cb08..cc8bdefa6ea 100644 --- a/server/sonar-docs/yarn.lock +++ b/server/sonar-docs/yarn.lock @@ -4826,7 +4826,7 @@ gatsby-plugin-page-creator@^2.0.11: parse-filepath "^1.0.1" slash "^1.0.0" -gatsby-plugin-polyfill-io@^1.1.0: +gatsby-plugin-polyfill-io@1.1.0: version "1.1.0" resolved "https://repox.jfrog.io/repox/api/npm/npm/gatsby-plugin-polyfill-io/-/gatsby-plugin-polyfill-io-1.1.0.tgz#61424c773ae123680e50b9a6692a4b939a1e6e13" integrity sha1-YUJMdzrhI2gOULmmaSpLk5oebhM= -- 2.39.5