diff options
author | Wouter Admiraal <wouter.admiraal@sonarsource.com> | 2019-08-09 10:23:50 +0200 |
---|---|---|
committer | SonarTech <sonartech@sonarsource.com> | 2019-10-28 20:21:09 +0100 |
commit | 24963a443c4459d03baab2b583e3690250d056aa (patch) | |
tree | 57a09116dd92d3990d15ecdae502a17a52b97e7d /server/sonar-web/src/main/js/apps | |
parent | 5394a58739dd14d397ae5594cb92b408b29ccc58 (diff) | |
download | sonarqube-24963a443c4459d03baab2b583e3690250d056aa.tar.gz sonarqube-24963a443c4459d03baab2b583e3690250d056aa.zip |
Improve Edition handling
Diffstat (limited to 'server/sonar-web/src/main/js/apps')
13 files changed, 37 insertions, 94 deletions
diff --git a/server/sonar-web/src/main/js/apps/marketplace/App.tsx b/server/sonar-web/src/main/js/apps/marketplace/App.tsx index a21f283ed69..b1cda108aba 100644 --- a/server/sonar-web/src/main/js/apps/marketplace/App.tsx +++ b/server/sonar-web/src/main/js/apps/marketplace/App.tsx @@ -31,6 +31,7 @@ import { } from '../../api/plugins'; import Suggestions from '../../app/components/embed-docs-modal/Suggestions'; import { Location, Router, withRouter } from '../../components/hoc/withRouter'; +import { EditionKey } from '../../types/editions'; import EditionBoxes from './EditionBoxes'; import Footer from './Footer'; import Header from './Header'; @@ -40,7 +41,7 @@ import './style.css'; import { filterPlugins, parseQuery, Query, serializeQuery } from './utils'; export interface Props { - currentEdition?: T.EditionKey; + currentEdition?: EditionKey; fetchPendingPlugins: () => void; pendingPlugins: PluginPendingResult; location: Location; diff --git a/server/sonar-web/src/main/js/apps/marketplace/AppContainer.tsx b/server/sonar-web/src/main/js/apps/marketplace/AppContainer.tsx index bf9d761eed9..607190d272c 100644 --- a/server/sonar-web/src/main/js/apps/marketplace/AppContainer.tsx +++ b/server/sonar-web/src/main/js/apps/marketplace/AppContainer.tsx @@ -21,6 +21,7 @@ import * as React from 'react'; import { connect } from 'react-redux'; import AdminContext from '../../app/components/AdminContext'; import { getAppState, getGlobalSettingValue, Store } from '../../store/rootReducer'; +import { EditionKey } from '../../types/editions'; import App from './App'; interface OwnProps { @@ -28,7 +29,7 @@ interface OwnProps { } interface StateToProps { - currentEdition?: T.EditionKey; + currentEdition?: EditionKey; standaloneMode?: boolean; updateCenterActive: boolean; } @@ -36,7 +37,7 @@ interface StateToProps { const mapStateToProps = (state: Store) => { const updateCenterActive = getGlobalSettingValue(state, 'sonar.updatecenter.activate'); return { - currentEdition: getAppState(state).edition, + currentEdition: getAppState(state).edition as EditionKey, // TODO: Fix once AppState is no longer ambiant. standaloneMode: getAppState(state).standalone, updateCenterActive: Boolean(updateCenterActive && updateCenterActive.value === 'true') }; diff --git a/server/sonar-web/src/main/js/apps/marketplace/EditionBoxes.tsx b/server/sonar-web/src/main/js/apps/marketplace/EditionBoxes.tsx index 0f0cf9c21a7..246ca057648 100644 --- a/server/sonar-web/src/main/js/apps/marketplace/EditionBoxes.tsx +++ b/server/sonar-web/src/main/js/apps/marketplace/EditionBoxes.tsx @@ -19,11 +19,12 @@ */ import * as React from 'react'; import { getMarketplaceNavigation } from '../../api/nav'; +import { getAllEditionsAbove } from '../../helpers/editions'; +import { EditionKey } from '../../types/editions'; import EditionBox from './components/EditionBox'; -import { EDITIONS } from './utils'; export interface Props { - currentEdition?: T.EditionKey; + currentEdition?: EditionKey; } interface State { @@ -58,8 +59,7 @@ export default class EditionBoxes extends React.PureComponent<Props, State> { render() { const { currentEdition } = this.props; const { serverId, ncloc } = this.state; - const currentEditionIdx = EDITIONS.findIndex(edition => edition.key === currentEdition); - const visibleEditions = EDITIONS.slice(currentEditionIdx + 1); + const visibleEditions = getAllEditionsAbove(currentEdition); if (visibleEditions.length <= 0) { return null; diff --git a/server/sonar-web/src/main/js/apps/marketplace/Header.tsx b/server/sonar-web/src/main/js/apps/marketplace/Header.tsx index 5eb40c31d9d..a457c29f0ff 100644 --- a/server/sonar-web/src/main/js/apps/marketplace/Header.tsx +++ b/server/sonar-web/src/main/js/apps/marketplace/Header.tsx @@ -19,9 +19,10 @@ */ import * as React from 'react'; import { translate } from 'sonar-ui-common/helpers/l10n'; +import { EditionKey } from '../../types/editions'; interface Props { - currentEdition?: T.EditionKey; + currentEdition?: EditionKey; } export default function Header({ currentEdition }: Props) { diff --git a/server/sonar-web/src/main/js/apps/marketplace/__tests__/EditionBoxes-test.tsx b/server/sonar-web/src/main/js/apps/marketplace/__tests__/EditionBoxes-test.tsx index 5a3091c8670..f85440002e0 100644 --- a/server/sonar-web/src/main/js/apps/marketplace/__tests__/EditionBoxes-test.tsx +++ b/server/sonar-web/src/main/js/apps/marketplace/__tests__/EditionBoxes-test.tsx @@ -19,8 +19,8 @@ */ import { shallow } from 'enzyme'; import * as React from 'react'; +import { EditionKey } from '../../../types/editions'; import EditionBoxes from '../EditionBoxes'; -import { EditionKey } from '../utils'; it('should display the available edition boxes correctly', () => { expect(getWrapper()).toMatchSnapshot(); diff --git a/server/sonar-web/src/main/js/apps/marketplace/__tests__/Header-test.tsx b/server/sonar-web/src/main/js/apps/marketplace/__tests__/Header-test.tsx index 9c2a9700454..b1c39d09913 100644 --- a/server/sonar-web/src/main/js/apps/marketplace/__tests__/Header-test.tsx +++ b/server/sonar-web/src/main/js/apps/marketplace/__tests__/Header-test.tsx @@ -19,8 +19,8 @@ */ import { shallow } from 'enzyme'; import * as React from 'react'; +import { EditionKey } from '../../../types/editions'; import Header from '../Header'; -import { EditionKey } from '../utils'; it('should render with installed editions', () => { expect(shallow(<Header currentEdition={EditionKey.community} />)).toMatchSnapshot(); diff --git a/server/sonar-web/src/main/js/apps/marketplace/__tests__/__snapshots__/EditionBoxes-test.tsx.snap b/server/sonar-web/src/main/js/apps/marketplace/__tests__/__snapshots__/EditionBoxes-test.tsx.snap index 251e57d80e2..7ed8b99d9f6 100644 --- a/server/sonar-web/src/main/js/apps/marketplace/__tests__/__snapshots__/EditionBoxes-test.tsx.snap +++ b/server/sonar-web/src/main/js/apps/marketplace/__tests__/__snapshots__/EditionBoxes-test.tsx.snap @@ -8,7 +8,7 @@ exports[`should display the available edition boxes correctly 1`] = ` currentEdition="community" edition={ Object { - "downloadUrl": "https://binaries.sonarsource.com/CommercialDistribution/editions/developer-edition-7.0.0.717.zip", + "downloadProperty": "downloadDeveloperUrl", "homeUrl": "https://redirect.sonarsource.com/editions/developer.html", "key": "developer", "name": "Developer Edition", @@ -20,7 +20,7 @@ exports[`should display the available edition boxes correctly 1`] = ` currentEdition="community" edition={ Object { - "downloadUrl": "https://binaries.sonarsource.com/CommercialDistribution/editions/enterprise-edition-7.0.0.717.zip", + "downloadProperty": "downloadEnterpriseUrl", "homeUrl": "https://redirect.sonarsource.com/editions/enterprise.html", "key": "enterprise", "name": "Enterprise Edition", @@ -32,7 +32,7 @@ exports[`should display the available edition boxes correctly 1`] = ` currentEdition="community" edition={ Object { - "downloadUrl": "https://binaries.sonarsource.com/CommercialDistribution/editions/datacenter-edition-7.0.0.717.zip", + "downloadProperty": "downloadDatacenterUrl", "homeUrl": "https://redirect.sonarsource.com/editions/datacenter.html", "key": "datacenter", "name": "Data Center Edition", @@ -51,7 +51,7 @@ exports[`should display the datacenter edition box only 1`] = ` currentEdition="enterprise" edition={ Object { - "downloadUrl": "https://binaries.sonarsource.com/CommercialDistribution/editions/datacenter-edition-7.0.0.717.zip", + "downloadProperty": "downloadDatacenterUrl", "homeUrl": "https://redirect.sonarsource.com/editions/datacenter.html", "key": "datacenter", "name": "Data Center Edition", @@ -70,7 +70,7 @@ exports[`should display the enterprise and datacenter edition boxes 1`] = ` currentEdition="developer" edition={ Object { - "downloadUrl": "https://binaries.sonarsource.com/CommercialDistribution/editions/enterprise-edition-7.0.0.717.zip", + "downloadProperty": "downloadEnterpriseUrl", "homeUrl": "https://redirect.sonarsource.com/editions/enterprise.html", "key": "enterprise", "name": "Enterprise Edition", @@ -82,7 +82,7 @@ exports[`should display the enterprise and datacenter edition boxes 1`] = ` currentEdition="developer" edition={ Object { - "downloadUrl": "https://binaries.sonarsource.com/CommercialDistribution/editions/datacenter-edition-7.0.0.717.zip", + "downloadProperty": "downloadDatacenterUrl", "homeUrl": "https://redirect.sonarsource.com/editions/datacenter.html", "key": "datacenter", "name": "Data Center Edition", diff --git a/server/sonar-web/src/main/js/apps/marketplace/components/EditionBox.tsx b/server/sonar-web/src/main/js/apps/marketplace/components/EditionBox.tsx index a4cd935eca9..9efb90bb83c 100644 --- a/server/sonar-web/src/main/js/apps/marketplace/components/EditionBox.tsx +++ b/server/sonar-web/src/main/js/apps/marketplace/components/EditionBox.tsx @@ -23,12 +23,13 @@ import tooltipEE from 'Docs/tooltips/editions/enterprise.md'; import * as React from 'react'; import { lazyLoad } from 'sonar-ui-common/components/lazyLoad'; import { translate } from 'sonar-ui-common/helpers/l10n'; -import { Edition, getEditionUrl } from '../utils'; +import { getEditionUrl } from '../../../helpers/editions'; +import { Edition, EditionKey } from '../../../types/editions'; const DocMarkdownBlock = lazyLoad(() => import('../../../components/docs/DocMarkdownBlock')); interface Props { - currentEdition?: T.EditionKey; + currentEdition?: EditionKey; edition: Edition; ncloc?: number; serverId?: string; diff --git a/server/sonar-web/src/main/js/apps/marketplace/components/__tests__/EditionBox-test.tsx b/server/sonar-web/src/main/js/apps/marketplace/components/__tests__/EditionBox-test.tsx index a774f10d0be..c562e5d0cd6 100644 --- a/server/sonar-web/src/main/js/apps/marketplace/components/__tests__/EditionBox-test.tsx +++ b/server/sonar-web/src/main/js/apps/marketplace/components/__tests__/EditionBox-test.tsx @@ -19,22 +19,16 @@ */ import { shallow } from 'enzyme'; import * as React from 'react'; -import { EditionKey } from '../../utils'; +import { getEdition } from '../../../../helpers/editions'; +import { EditionKey } from '../../../../types/editions'; import EditionBox from '../EditionBox'; -const DEFAULT_EDITION = { - key: EditionKey.developer, - name: 'Developer', - downloadUrl: 'download_url', - homeUrl: 'more_url' -}; - it('should display the edition', () => { expect( shallow( <EditionBox currentEdition={EditionKey.community} - edition={DEFAULT_EDITION} + edition={getEdition(EditionKey.developer)} ncloc={1000} serverId="serverId" /> diff --git a/server/sonar-web/src/main/js/apps/marketplace/components/__tests__/__snapshots__/EditionBox-test.tsx.snap b/server/sonar-web/src/main/js/apps/marketplace/components/__tests__/__snapshots__/EditionBox-test.tsx.snap index a047f84b3b4..5d63a4a3ec2 100644 --- a/server/sonar-web/src/main/js/apps/marketplace/components/__tests__/__snapshots__/EditionBox-test.tsx.snap +++ b/server/sonar-web/src/main/js/apps/marketplace/components/__tests__/__snapshots__/EditionBox-test.tsx.snap @@ -9,7 +9,7 @@ exports[`should display the edition 1`] = ` className="marketplace-edition-action spacer-top" > <a - href="more_url?ncloc=1000&serverId=serverId&sourceEdition=community" + href="https://redirect.sonarsource.com/editions/developer.html?ncloc=1000&serverId=serverId&sourceEdition=community" rel="noopener noreferrer" target="_blank" > diff --git a/server/sonar-web/src/main/js/apps/marketplace/utils.ts b/server/sonar-web/src/main/js/apps/marketplace/utils.ts index f1f2f939fa2..325b0889787 100644 --- a/server/sonar-web/src/main/js/apps/marketplace/utils.ts +++ b/server/sonar-web/src/main/js/apps/marketplace/utils.ts @@ -18,71 +18,14 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ import { memoize } from 'lodash'; -import { stringify } from 'querystring'; import { cleanQuery, parseAsString, serializeString } from 'sonar-ui-common/helpers/query'; -import { omitNil } from 'sonar-ui-common/helpers/request'; import { Plugin, PluginAvailable, PluginInstalled, PluginPending } from '../../api/plugins'; -export enum EditionKey { - community = 'community', - developer = 'developer', - enterprise = 'enterprise', - datacenter = 'datacenter' -} - -export interface Edition { - downloadUrl?: string; - homeUrl: string; - key: EditionKey; - name: string; -} - export interface Query { filter: string; search?: string; } -export const EDITIONS: Edition[] = [ - { - key: EditionKey.community, - name: 'Community Edition', - homeUrl: 'https://redirect.sonarsource.com/editions/community.html' - }, - { - key: EditionKey.developer, - name: 'Developer Edition', - homeUrl: 'https://redirect.sonarsource.com/editions/developer.html', - downloadUrl: - 'https://binaries.sonarsource.com/CommercialDistribution/editions/developer-edition-7.0.0.717.zip' - }, - { - key: EditionKey.enterprise, - name: 'Enterprise Edition', - homeUrl: 'https://redirect.sonarsource.com/editions/enterprise.html', - downloadUrl: - 'https://binaries.sonarsource.com/CommercialDistribution/editions/enterprise-edition-7.0.0.717.zip' - }, - { - key: EditionKey.datacenter, - name: 'Data Center Edition', - homeUrl: 'https://redirect.sonarsource.com/editions/datacenter.html', - downloadUrl: - 'https://binaries.sonarsource.com/CommercialDistribution/editions/datacenter-edition-7.0.0.717.zip' - } -]; - -export function getEditionUrl( - edition: Edition, - data: { serverId?: string; ncloc?: number; sourceEdition?: T.EditionKey } -) { - let url = edition.homeUrl; - const query = stringify(omitNil(data)); - if (query) { - url += '?' + query; - } - return url; -} - const EXCLUDED_PLUGINS = ['license']; export function filterPlugins(plugins: Plugin[], search?: string): Plugin[] { if (!search) { diff --git a/server/sonar-web/src/main/js/apps/system/__tests__/utils-test.ts b/server/sonar-web/src/main/js/apps/system/__tests__/utils-test.ts index b90fab875f1..f760288d215 100644 --- a/server/sonar-web/src/main/js/apps/system/__tests__/utils-test.ts +++ b/server/sonar-web/src/main/js/apps/system/__tests__/utils-test.ts @@ -19,6 +19,7 @@ */ /* eslint-disable sonarjs/no-duplicate-string */ import { mockClusterSysInfo, mockStandaloneSysInfo } from '../../../helpers/testMocks'; +import { SystemUpgrade } from '../../../types/system'; import * as u from '../utils'; describe('parseQuery', () => { @@ -80,7 +81,7 @@ describe('sortUpgrades', () => { { version: '5.10' }, { version: '5.1' }, { version: '5.4' } - ] as T.SystemUpgrade[]) + ] as SystemUpgrade[]) ).toEqual([{ version: '5.10' }, { version: '5.4.2' }, { version: '5.4' }, { version: '5.1' }]); expect( u.sortUpgrades([ @@ -88,7 +89,7 @@ describe('sortUpgrades', () => { { version: '5.1.2' }, { version: '6.0' }, { version: '6.9' } - ] as T.SystemUpgrade[]) + ] as SystemUpgrade[]) ).toEqual([{ version: '6.9' }, { version: '6.0' }, { version: '5.10' }, { version: '5.1.2' }]); }); }); @@ -101,7 +102,7 @@ describe('groupUpgrades', () => { { version: '5.4.2' }, { version: '5.4' }, { version: '5.1' } - ] as T.SystemUpgrade[]) + ] as SystemUpgrade[]) ).toEqual([ [{ version: '5.10' }, { version: '5.4.2' }, { version: '5.4' }, { version: '5.1' }] ]); @@ -112,7 +113,7 @@ describe('groupUpgrades', () => { { version: '6.0' }, { version: '5.10' }, { version: '5.4.2' } - ] as T.SystemUpgrade[]) + ] as SystemUpgrade[]) ).toEqual([ [{ version: '6.9' }, { version: '6.7' }, { version: '6.0' }], [{ version: '5.10' }, { version: '5.4.2' }] diff --git a/server/sonar-web/src/main/js/apps/system/utils.ts b/server/sonar-web/src/main/js/apps/system/utils.ts index 9b75c19d451..2df36614aae 100644 --- a/server/sonar-web/src/main/js/apps/system/utils.ts +++ b/server/sonar-web/src/main/js/apps/system/utils.ts @@ -25,6 +25,7 @@ import { parseAsString, serializeStringArray } from 'sonar-ui-common/helpers/query'; +import { SystemUpgrade } from '../../types/system'; export interface Query { expandedCards: string[]; @@ -230,15 +231,15 @@ export const serializeQuery = memoize( }) ); -export function sortUpgrades(upgrades: T.SystemUpgrade[]): T.SystemUpgrade[] { +export function sortUpgrades(upgrades: SystemUpgrade[]): SystemUpgrade[] { return sortBy(upgrades, [ - (upgrade: T.SystemUpgrade) => -Number(upgrade.version.split('.')[0]), - (upgrade: T.SystemUpgrade) => -Number(upgrade.version.split('.')[1] || 0), - (upgrade: T.SystemUpgrade) => -Number(upgrade.version.split('.')[2] || 0) + (upgrade: SystemUpgrade) => -Number(upgrade.version.split('.')[0]), + (upgrade: SystemUpgrade) => -Number(upgrade.version.split('.')[1] || 0), + (upgrade: SystemUpgrade) => -Number(upgrade.version.split('.')[2] || 0) ]); } -export function groupUpgrades(upgrades: T.SystemUpgrade[]): T.SystemUpgrade[][] { +export function groupUpgrades(upgrades: SystemUpgrade[]): SystemUpgrade[][] { const groupedVersions = groupBy(upgrades, upgrade => upgrade.version.split('.')[0]); const sortedMajor = sortBy(Object.keys(groupedVersions), key => -Number(key)); return sortedMajor.map(key => groupedVersions[key]); |