From: Grégoire Aubert Date: Tue, 17 Oct 2017 12:41:51 +0000 (+0200) Subject: SONAR-9944 Update editions json format and use url from global settings X-Git-Tag: 6.7-RC1~95 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=3979c1713989085fa72b7d355ed544197de5b283;p=sonarqube.git SONAR-9944 Update editions json format and use url from global settings --- diff --git a/server/sonar-web/src/main/js/api/marketplace.ts b/server/sonar-web/src/main/js/api/marketplace.ts index 17ef7d367a3..4cff1587d94 100644 --- a/server/sonar-web/src/main/js/api/marketplace.ts +++ b/server/sonar-web/src/main/js/api/marketplace.ts @@ -21,6 +21,7 @@ import { checkStatus, corsRequest, getJSON, parseJSON, postJSON } from '../helpe import throwGlobalError from '../app/utils/throwGlobalError'; export interface Edition { + key: string; name: string; desc: string; more_link: string; @@ -28,8 +29,8 @@ export interface Edition { download_link: string; } -export interface Editions { - [key: string]: Edition; +export interface EditionsPerVersion { + [version: string]: Edition[]; } export interface EditionStatus { @@ -47,10 +48,7 @@ export function getEditionStatus(): Promise { return getJSON('/api/editions/status').catch(throwGlobalError); } -export function getEditionsList(): Promise { - // TODO Replace with real url - const url = - 'https://gist.githubusercontent.com/gregaubert/e34535494f8a94bec7cbc4d750ae7d06/raw/ba8670a28d4bc6fbac18f92e450ec42029cc5dcb/editions.json'; +export function getEditionsList(url: string): Promise { return corsRequest(url) .submit() .then(checkStatus) 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 6ee3d1bce8f..18fc8adaaee 100644 --- a/server/sonar-web/src/main/js/apps/marketplace/App.tsx +++ b/server/sonar-web/src/main/js/apps/marketplace/App.tsx @@ -42,7 +42,9 @@ import { filterPlugins, parseQuery, Query, serializeQuery } from './utils'; export interface Props { editionStatus?: EditionStatus; + editionsUrl: string; location: { pathname: string; query: RawQuery }; + sonarqubeVersion: string; updateCenterActive: boolean; } @@ -167,6 +169,8 @@ export default class App extends React.PureComponent {
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 418219fd22a..64794ebbda2 100644 --- a/server/sonar-web/src/main/js/apps/marketplace/AppContainer.tsx +++ b/server/sonar-web/src/main/js/apps/marketplace/AppContainer.tsx @@ -24,6 +24,8 @@ import './style.css'; const mapStateToProps = (state: any) => ({ editionStatus: getAppState(state).editionStatus, + editionsUrl: (getGlobalSettingValue(state, 'sonar.editions.jsonUrl') || {}).value, + sonarqubeVersion: getAppState(state).version, updateCenterActive: (getGlobalSettingValue(state, 'sonar.updatecenter.activate') || {}).value }); 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 64290f13e9e..58ffe846c63 100644 --- a/server/sonar-web/src/main/js/apps/marketplace/EditionBoxes.tsx +++ b/server/sonar-web/src/main/js/apps/marketplace/EditionBoxes.tsx @@ -21,16 +21,19 @@ import * as React from 'react'; import { FormattedMessage } from 'react-intl'; import EditionBox from './components/EditionBox'; import LicenseEditionForm from './components/LicenseEditionForm'; -import { Edition, Editions, EditionStatus, getEditionsList } from '../../api/marketplace'; +import { Edition, EditionStatus, getEditionsList } from '../../api/marketplace'; +import { getEditionsForVersion } from './utils'; import { translate } from '../../helpers/l10n'; export interface Props { editionStatus?: EditionStatus; + editionsUrl: string; + sonarqubeVersion: string; updateCenterActive: boolean; } interface State { - editions: Editions; + editions?: Edition[]; editionsError: boolean; loading: boolean; installEdition?: Edition; @@ -38,7 +41,7 @@ interface State { export default class EditionBoxes extends React.PureComponent { mounted: boolean; - state: State = { editions: {}, editionsError: false, loading: true }; + state: State = { editionsError: false, loading: true }; componentDidMount() { this.mounted = true; @@ -51,12 +54,12 @@ export default class EditionBoxes extends React.PureComponent { fetchEditions = () => { this.setState({ loading: true }); - getEditionsList().then( - editions => { + getEditionsList(this.props.editionsUrl).then( + editionsPerVersion => { if (this.mounted) { this.setState({ loading: false, - editions, + editions: getEditionsForVersion(editionsPerVersion, this.props.sonarqubeVersion), editionsError: false }); } @@ -73,13 +76,13 @@ export default class EditionBoxes extends React.PureComponent { handleCloseLicenseForm = () => this.setState({ installEdition: undefined }); render() { - const { editions, loading, installEdition } = this.state; + const { editions, editionsError, loading, installEdition } = this.state; if (loading) { - return null; + return ; } return (
- {this.state.editionsError ? ( + {!editions || editionsError ? ( { /> ) : ( - Object.keys(editions).map(key => ( + editions.map(edition => ( )) 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 ca32326f225..c3525b0e304 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 @@ -28,22 +28,24 @@ const DEFAULT_STATUS: EditionStatus = { installationStatus: 'NONE' }; -const DEFAULT_EDITIONS = { - foo: { +const DEFAULT_EDITIONS = [ + { + key: 'foo', name: 'Foo', desc: 'Foo desc', download_link: 'download_url', more_link: 'more_url', request_license_link: 'license_url' }, - bar: { + { + key: 'bar', name: 'Bar', desc: 'Bar desc', download_link: 'download_url', more_link: 'more_url', request_license_link: 'license_url' } -}; +]; it('should display the edition boxes', () => { const wrapper = getWrapper(); @@ -67,12 +69,18 @@ it('should open the license form', () => { editions: DEFAULT_EDITIONS, loading: false }); - (wrapper.instance() as EditionBoxes).handleOpenLicenseForm(DEFAULT_EDITIONS.foo); + (wrapper.instance() as EditionBoxes).handleOpenLicenseForm(DEFAULT_EDITIONS[0]); expect(wrapper.find('LicenseEditionForm').exists()).toBeTruthy(); }); function getWrapper(props = {}) { return shallow( - + ); } 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 cfc6695810a..f6b1475c0e6 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 @@ -25,7 +25,11 @@ exports[`should display an error message 1`] = `
`; -exports[`should display the edition boxes 1`] = `null`; +exports[`should display the edition boxes 1`] = ` + +`; exports[`should display the edition boxes 2`] = `
void; } @@ -33,9 +32,9 @@ export default class EditionBox extends React.PureComponent { handleInstall = () => this.props.onInstall(this.props.edition); render() { - const { edition, editionKey, editionStatus } = this.props; - const isInstalled = editionStatus && editionStatus.currentEditionKey === editionKey; - const isInstalling = editionStatus && editionStatus.nextEditionKey === editionKey; + const { edition, editionStatus } = this.props; + const isInstalled = editionStatus && editionStatus.currentEditionKey === edition.key; + const isInstalling = editionStatus && editionStatus.nextEditionKey === edition.key; const installInProgress = editionStatus && editionStatus.installationStatus === 'AUTOMATIC_IN_PROGRESS'; return ( 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 e0faa1bc3a3..2b89b1bc1e2 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 @@ -29,6 +29,7 @@ const DEFAULT_STATUS: EditionStatus = { }; const DEFAULT_EDITION: Edition = { + key: 'foo', name: 'Foo', desc: 'Foo desc', download_link: 'download_url', @@ -92,7 +93,6 @@ function getWrapper(props = {}) { return shallow( ; const DEFAULT_EDITION = { + key: 'foo', name: 'Foo', desc: 'Foo desc', download_link: 'download_url', diff --git a/server/sonar-web/src/main/js/apps/marketplace/components/__tests__/LicenseEditionSet-test.tsx b/server/sonar-web/src/main/js/apps/marketplace/components/__tests__/LicenseEditionSet-test.tsx index 49c97b43027..3e1d45ac3e0 100644 --- a/server/sonar-web/src/main/js/apps/marketplace/components/__tests__/LicenseEditionSet-test.tsx +++ b/server/sonar-web/src/main/js/apps/marketplace/components/__tests__/LicenseEditionSet-test.tsx @@ -39,6 +39,7 @@ const getLicensePreview = require('../../../../api/marketplace').getLicensePrevi >; const DEFAULT_EDITION = { + key: 'foo', name: 'Foo', desc: 'Foo desc', download_link: 'download_url', diff --git a/server/sonar-web/src/main/js/apps/marketplace/components/__tests__/__snapshots__/LicenseEditionForm-test.tsx.snap b/server/sonar-web/src/main/js/apps/marketplace/components/__tests__/__snapshots__/LicenseEditionForm-test.tsx.snap index 492f821f630..e6dde0fb6ed 100644 --- a/server/sonar-web/src/main/js/apps/marketplace/components/__tests__/__snapshots__/LicenseEditionForm-test.tsx.snap +++ b/server/sonar-web/src/main/js/apps/marketplace/components/__tests__/__snapshots__/LicenseEditionForm-test.tsx.snap @@ -45,6 +45,7 @@ exports[`should display correctly 1`] = ` Object { "desc": "Foo desc", "download_link": "download_url", + "key": "foo", "more_link": "more_url", "name": "Foo", "request_license_link": "license_url", 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 780fafb3af8..f4c8eea8d92 100644 --- a/server/sonar-web/src/main/js/apps/marketplace/utils.ts +++ b/server/sonar-web/src/main/js/apps/marketplace/utils.ts @@ -19,6 +19,7 @@ */ import { memoize } from 'lodash'; import { Plugin, PluginAvailable, PluginInstalled, PluginPending } from '../../api/plugins'; +import { Edition, EditionsPerVersion } from '../../api/marketplace'; import { cleanQuery, parseAsString, RawQuery, serializeString } from '../../helpers/query'; export interface Query { @@ -51,6 +52,19 @@ export function filterPlugins(plugins: Plugin[], search: string): Plugin[] { }); } +export function getEditionsForVersion( + editions: EditionsPerVersion, + version: string +): Edition[] | undefined { + const matchResult = version.match(/\d+\.\d+/); + if (matchResult) { + if (editions[matchResult[0]]) { + return editions[matchResult[0]]; + } + } + return undefined; +} + export const parseQuery = memoize((urlQuery: RawQuery): Query => ({ filter: parseAsString(urlQuery['filter']) || DEFAULT_FILTER, search: parseAsString(urlQuery['search'])