From a57b5dd4d8ba48dd55a80111f1c6db54cb36c63d Mon Sep 17 00:00:00 2001 From: Philippe Perrin Date: Thu, 15 Jul 2021 15:55:30 +0200 Subject: SONAR-14617 Embed the sonar-ui-common library --- .../components/ui/update-center/MetaData.css | 102 ++++++++++++++++ .../components/ui/update-center/MetaData.tsx | 123 +++++++++++++++++++ .../ui/update-center/MetaDataVersion.tsx | 99 +++++++++++++++ .../ui/update-center/MetaDataVersions.tsx | 85 +++++++++++++ .../ui/update-center/__tests__/MetaData-test.tsx | 87 ++++++++++++++ .../__tests__/MetaDataVersion-test.tsx | 46 +++++++ .../__tests__/MetaDataVersions-test.tsx | 52 ++++++++ .../__tests__/__snapshots__/MetaData-test.tsx.snap | 133 +++++++++++++++++++++ .../__snapshots__/MetaDataVersion-test.tsx.snap | 113 +++++++++++++++++ .../__snapshots__/MetaDataVersions-test.tsx.snap | 28 +++++ .../update-center/mocks/update-center-metadata.ts | 58 +++++++++ .../ui/update-center/update-center-metadata.ts | 49 ++++++++ 12 files changed, 975 insertions(+) create mode 100644 server/sonar-ui-common/components/ui/update-center/MetaData.css create mode 100644 server/sonar-ui-common/components/ui/update-center/MetaData.tsx create mode 100644 server/sonar-ui-common/components/ui/update-center/MetaDataVersion.tsx create mode 100644 server/sonar-ui-common/components/ui/update-center/MetaDataVersions.tsx create mode 100644 server/sonar-ui-common/components/ui/update-center/__tests__/MetaData-test.tsx create mode 100644 server/sonar-ui-common/components/ui/update-center/__tests__/MetaDataVersion-test.tsx create mode 100644 server/sonar-ui-common/components/ui/update-center/__tests__/MetaDataVersions-test.tsx create mode 100644 server/sonar-ui-common/components/ui/update-center/__tests__/__snapshots__/MetaData-test.tsx.snap create mode 100644 server/sonar-ui-common/components/ui/update-center/__tests__/__snapshots__/MetaDataVersion-test.tsx.snap create mode 100644 server/sonar-ui-common/components/ui/update-center/__tests__/__snapshots__/MetaDataVersions-test.tsx.snap create mode 100644 server/sonar-ui-common/components/ui/update-center/mocks/update-center-metadata.ts create mode 100644 server/sonar-ui-common/components/ui/update-center/update-center-metadata.ts (limited to 'server/sonar-ui-common/components/ui/update-center') diff --git a/server/sonar-ui-common/components/ui/update-center/MetaData.css b/server/sonar-ui-common/components/ui/update-center/MetaData.css new file mode 100644 index 00000000000..582d6633757 --- /dev/null +++ b/server/sonar-ui-common/components/ui/update-center/MetaData.css @@ -0,0 +1,102 @@ +/* + * Sonar UI Common + * Copyright (C) 2019-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. + */ + +.update-center-meta-data { + margin: 16px 0; + padding: 16px 16px 8px 16px; + background: #f9f9fb; + border: 1px solid #e6e6e6; + border-radius: 3px; +} + +.update-center-meta-data a svg { + margin-right: 8px; +} + +.update-center-meta-data-header { + border-bottom: 1px solid #cfd3d7; + padding-bottom: 16px; +} + +.update-center-meta-data-header, +.update-center-meta-data-version-release-info, +.update-center-meta-data-version-links { + display: flex; +} + +.update-center-meta-data-header > * + *, +.update-center-meta-data-version-release-info > * + * { + margin-left: 16px; +} + +.update-center-meta-data-header > * + * { + padding-left: 16px; + border-left: 1px solid #cfd3d7; +} + +.update-center-meta-data-versions { + margin-top: 16px; +} + +.update-center-meta-data-versions-show-more { + font-size: 14px; + float: right; + color: #51575a; + border-color: #7b8184; + border-width: 0 0 1px 0; + padding-left: 0; + padding-right: 0; + background: transparent; + cursor: pointer; +} + +.update-center-meta-data-versions-show-more:hover { + color: #2d3032; + border-color: #2d3032; +} + +.update-center-meta-data-version { + margin-bottom: 16px; +} + +.update-center-meta-data-version + .update-center-meta-data-version { + padding-top: 8px; + border-top: 1px dashed #cfd3d7; +} + +.update-center-meta-data-version-version { + font-weight: bold; + font-size: 18px; +} + +.update-center-meta-data-version-release-info { + margin-top: 8px; + font-style: italic; +} + +.update-center-meta-data-version-release-description { + margin-top: 8px; +} + +.update-center-meta-data-version-download > a, +.update-center-meta-data-version-release-notes > a { + display: inline-block; + margin: 8px 16px 0 0; +} diff --git a/server/sonar-ui-common/components/ui/update-center/MetaData.tsx b/server/sonar-ui-common/components/ui/update-center/MetaData.tsx new file mode 100644 index 00000000000..568a7fba454 --- /dev/null +++ b/server/sonar-ui-common/components/ui/update-center/MetaData.tsx @@ -0,0 +1,123 @@ +/* + * Sonar UI Common + * Copyright (C) 2019-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 './MetaData.css'; +import MetaDataVersions from './MetaDataVersions'; +import { MetaDataInformation } from './update-center-metadata'; +import { isSuccessStatus } from '../../../helpers/request'; + +interface Props { + updateCenterKey?: string; +} + +interface State { + data?: MetaDataInformation; +} + +export default class MetaData extends React.Component { + mounted = false; + state: State = {}; + + componentDidMount() { + this.mounted = true; + this.fetchData(); + } + + componentDidUpdate(prevProps: Props) { + if (prevProps.updateCenterKey !== this.props.updateCenterKey) { + this.fetchData(); + } + } + + componentWillUnmount() { + this.mounted = false; + } + + fetchData() { + const { updateCenterKey } = this.props; + + if (updateCenterKey) { + window + .fetch(`https://update.sonarsource.org/${updateCenterKey}.json`) + .then((response: Response) => { + if (isSuccessStatus(response.status)) { + return response.json(); + } else { + return Promise.reject(response); + } + }) + .then((data) => { + if (this.mounted) { + this.setState({ data }); + } + }) + .catch(() => { + if (this.mounted) { + this.setState({ data: undefined }); + } + }); + } else { + this.setState({ data: undefined }); + } + } + + render() { + const { data } = this.state; + + if (!data) { + return null; + } + + const { isSonarSourceCommercial, issueTrackerURL, license, organization, versions } = data; + + let vendor; + if (organization) { + vendor = organization.name; + if (organization.url) { + vendor = ( + + {vendor} + + ); + } + } + + return ( +
+
+ {vendor && By {vendor}} + {license && {license}} + {issueTrackerURL && ( + + + Issue Tracker + + + )} + {isSonarSourceCommercial && ( + Supported by SonarSource + )} +
+ {versions && versions.length > 0 && } +
+ ); + } +} diff --git a/server/sonar-ui-common/components/ui/update-center/MetaDataVersion.tsx b/server/sonar-ui-common/components/ui/update-center/MetaDataVersion.tsx new file mode 100644 index 00000000000..f9f2155179e --- /dev/null +++ b/server/sonar-ui-common/components/ui/update-center/MetaDataVersion.tsx @@ -0,0 +1,99 @@ +/* + * Sonar UI Common + * Copyright (C) 2019-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 classNames from 'classnames'; +import * as React from 'react'; +import { AdvancedDownloadUrl, MetaDataVersionInformation } from './update-center-metadata'; + +export interface MetaDataVersionProps { + versionInformation: MetaDataVersionInformation; +} + +export default function MetaDataVersion(props: MetaDataVersionProps) { + const { + versionInformation: { + archived, + changeLogUrl, + compatibility, + date, + description, + downloadURL, + version, + }, + } = props; + + const fallbackLabel = 'Download'; + + const advancedDownloadUrls = isAdvancedDownloadUrlArray(downloadURL) + ? downloadURL.map((url) => ({ ...url, label: url.label || fallbackLabel })) + : [{ label: fallbackLabel, url: downloadURL }]; + + return ( +
+
{version}
+ +
+ {date && } + + {compatibility && ( + {compatibility} + )} +
+ + {description && ( +
{description}
+ )} + + {(advancedDownloadUrls.length > 0 || changeLogUrl) && ( +
+ {advancedDownloadUrls.length > 0 && + advancedDownloadUrls.map( + (advancedDownloadUrl, i) => + advancedDownloadUrl.url && ( + // eslint-disable-next-line react/no-array-index-key + + + {advancedDownloadUrl.label} + + + ) + )} + + {changeLogUrl && ( + + + Release notes + + + )} +
+ )} +
+ ); +} + +function isAdvancedDownloadUrlArray( + downloadUrl: string | AdvancedDownloadUrl[] | undefined +): downloadUrl is AdvancedDownloadUrl[] { + return !!downloadUrl && typeof downloadUrl !== 'string'; +} diff --git a/server/sonar-ui-common/components/ui/update-center/MetaDataVersions.tsx b/server/sonar-ui-common/components/ui/update-center/MetaDataVersions.tsx new file mode 100644 index 00000000000..59e3a2cf41b --- /dev/null +++ b/server/sonar-ui-common/components/ui/update-center/MetaDataVersions.tsx @@ -0,0 +1,85 @@ +/* + * Sonar UI Common + * Copyright (C) 2019-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 MetaDataVersion from './MetaDataVersion'; +import { MetaDataVersionInformation } from './update-center-metadata'; + +interface Props { + versions: MetaDataVersionInformation[]; +} + +interface State { + collapsed: boolean; +} + +export default class MetaDataVersions extends React.Component { + state: State = { + collapsed: true, + }; + + componentDidUpdate(prevProps: Props) { + if (prevProps.versions !== this.props.versions) { + this.setState({ collapsed: true }); + } + } + + handleClick = (event: React.SyntheticEvent) => { + event.preventDefault(); + event.currentTarget.blur(); + this.setState(({ collapsed }) => ({ collapsed: !collapsed })); + }; + + render() { + const { versions } = this.props; + const { collapsed } = this.state; + + const archivedVersions = versions.filter((version) => version.archived); + const currentVersions = versions.filter((version) => !version.archived); + + return ( +
+ {archivedVersions.length > 0 && ( + + )} + + {currentVersions.map((versionInformation) => ( + + ))} + + {!collapsed && + archivedVersions.map((archivedVersionInformation) => ( + + ))} +
+ ); + } +} diff --git a/server/sonar-ui-common/components/ui/update-center/__tests__/MetaData-test.tsx b/server/sonar-ui-common/components/ui/update-center/__tests__/MetaData-test.tsx new file mode 100644 index 00000000000..574abcb130f --- /dev/null +++ b/server/sonar-ui-common/components/ui/update-center/__tests__/MetaData-test.tsx @@ -0,0 +1,87 @@ +/* + * Sonar UI Common + * Copyright (C) 2019-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 { waitAndUpdate } from '../../../../helpers/testUtils'; +import MetaData from '../MetaData'; +import { mockMetaDataInformation } from '../mocks/update-center-metadata'; +import { MetaDataInformation } from '../update-center-metadata'; +import { HttpStatus } from '../../../../helpers/request'; + +beforeAll(() => { + window.fetch = jest.fn(); +}); + +beforeEach(() => { + jest.resetAllMocks(); +}); + +it('should render correctly', async () => { + const metaDataInfo = mockMetaDataInformation(); + mockFetchReturnValue(metaDataInfo); + + const wrapper = shallowRender(); + await waitAndUpdate(wrapper); + expect(wrapper).toMatchSnapshot(); +}); + +it('should render correctly with organization', async () => { + const metaDataInfo = mockMetaDataInformation({ + organization: { name: 'test-org', url: 'test-org-url' }, + }); + mockFetchReturnValue(metaDataInfo); + + const wrapper = shallowRender(); + await waitAndUpdate(wrapper); + expect(wrapper).toMatchSnapshot(); +}); + +it('should not render anything if call for metadata fails', async () => { + const metaDataInfo = mockMetaDataInformation(); + mockFetchReturnValue(metaDataInfo, HttpStatus.NotFound); + + const wrapper = shallowRender(); + await waitAndUpdate(wrapper); + expect(wrapper.type()).toBeNull(); +}); + +it('should fetch metadata again if the update center key if modified', async () => { + const metaDataInfo = mockMetaDataInformation(); + mockFetchReturnValue(metaDataInfo); + + const wrapper = shallowRender(); + await waitAndUpdate(wrapper); + + expect(window.fetch).toHaveBeenCalledTimes(1); + + mockFetchReturnValue(metaDataInfo); + wrapper.setProps({ updateCenterKey: 'abap' }); + + expect(window.fetch).toHaveBeenCalledTimes(2); +}); + +function shallowRender(props?: Partial) { + return shallow(); +} + +function mockFetchReturnValue(metaDataInfo: MetaDataInformation, status = HttpStatus.Ok) { + (window.fetch as jest.Mock).mockResolvedValueOnce({ status, json: () => metaDataInfo }); +} diff --git a/server/sonar-ui-common/components/ui/update-center/__tests__/MetaDataVersion-test.tsx b/server/sonar-ui-common/components/ui/update-center/__tests__/MetaDataVersion-test.tsx new file mode 100644 index 00000000000..eb21373830c --- /dev/null +++ b/server/sonar-ui-common/components/ui/update-center/__tests__/MetaDataVersion-test.tsx @@ -0,0 +1,46 @@ +/* + * Sonar UI Common + * Copyright (C) 2019-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 MetaDataVersion, { MetaDataVersionProps } from '../MetaDataVersion'; +import { mockMetaDataVersionInformation } from '../mocks/update-center-metadata'; + +it('should render correctly', () => { + expect(shallowRender()).toMatchSnapshot(); + expect( + shallowRender({ + versionInformation: mockMetaDataVersionInformation({ + downloadURL: [{ label: 'macos 64 bits', url: '' }], + }), + }) + ).toMatchSnapshot('with advanced downloadUrl'); + expect( + shallowRender({ + versionInformation: { version: '2.0' }, + }) + ).toMatchSnapshot('with very few info'); +}); + +function shallowRender(props?: Partial) { + return shallow( + + ); +} diff --git a/server/sonar-ui-common/components/ui/update-center/__tests__/MetaDataVersions-test.tsx b/server/sonar-ui-common/components/ui/update-center/__tests__/MetaDataVersions-test.tsx new file mode 100644 index 00000000000..5a4fc20d4f1 --- /dev/null +++ b/server/sonar-ui-common/components/ui/update-center/__tests__/MetaDataVersions-test.tsx @@ -0,0 +1,52 @@ +/* + * Sonar UI Common + * Copyright (C) 2019-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 { click } from '../../../../helpers/testUtils'; +import MetaDataVersion from '../MetaDataVersion'; +import MetaDataVersions from '../MetaDataVersions'; +import { mockMetaDataVersionInformation } from '../mocks/update-center-metadata'; + +it('should render correctly', () => { + const wrapper = shallowRender(); + expect(wrapper).toMatchSnapshot(); +}); + +it('should properly handle show more / show less', () => { + const wrapper = shallowRender(); + expect(wrapper.find(MetaDataVersion).length).toBe(1); + + click(wrapper.find('.update-center-meta-data-versions-show-more')); + expect(wrapper.find(MetaDataVersion).length).toBe(3); +}); + +function shallowRender(props?: Partial) { + return shallow( + + ); +} diff --git a/server/sonar-ui-common/components/ui/update-center/__tests__/__snapshots__/MetaData-test.tsx.snap b/server/sonar-ui-common/components/ui/update-center/__tests__/__snapshots__/MetaData-test.tsx.snap new file mode 100644 index 00000000000..89e8d74a6d1 --- /dev/null +++ b/server/sonar-ui-common/components/ui/update-center/__tests__/__snapshots__/MetaData-test.tsx.snap @@ -0,0 +1,133 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`should render correctly 1`] = ` +
+
+ + By + + SonarSource + + + + SonarSource + + + + Issue Tracker + + + + Supported by SonarSource + +
+ +
+`; + +exports[`should render correctly with organization 1`] = ` +
+
+ + By + + test-org + + + + SonarSource + + + + Issue Tracker + + + + Supported by SonarSource + +
+ +
+`; diff --git a/server/sonar-ui-common/components/ui/update-center/__tests__/__snapshots__/MetaDataVersion-test.tsx.snap b/server/sonar-ui-common/components/ui/update-center/__tests__/__snapshots__/MetaDataVersion-test.tsx.snap new file mode 100644 index 00000000000..7fd964fe2ab --- /dev/null +++ b/server/sonar-ui-common/components/ui/update-center/__tests__/__snapshots__/MetaDataVersion-test.tsx.snap @@ -0,0 +1,113 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`should render correctly 1`] = ` +
+
+ 5.13 +
+
+ + + 6.7 + +
+ +
+`; + +exports[`should render correctly: with advanced downloadUrl 1`] = ` +
+
+ 5.13 +
+
+ + + 6.7 + +
+ +
+`; + +exports[`should render correctly: with very few info 1`] = ` +
+
+ 2.0 +
+
+
+
+`; diff --git a/server/sonar-ui-common/components/ui/update-center/__tests__/__snapshots__/MetaDataVersions-test.tsx.snap b/server/sonar-ui-common/components/ui/update-center/__tests__/__snapshots__/MetaDataVersions-test.tsx.snap new file mode 100644 index 00000000000..109fe964473 --- /dev/null +++ b/server/sonar-ui-common/components/ui/update-center/__tests__/__snapshots__/MetaDataVersions-test.tsx.snap @@ -0,0 +1,28 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`should render correctly 1`] = ` +
+ + +
+`; diff --git a/server/sonar-ui-common/components/ui/update-center/mocks/update-center-metadata.ts b/server/sonar-ui-common/components/ui/update-center/mocks/update-center-metadata.ts new file mode 100644 index 00000000000..0da8569994f --- /dev/null +++ b/server/sonar-ui-common/components/ui/update-center/mocks/update-center-metadata.ts @@ -0,0 +1,58 @@ +/* + * Sonar UI Common + * Copyright (C) 2019-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 { MetaDataInformation, MetaDataVersionInformation } from '../update-center-metadata'; + +export function mockMetaDataVersionInformation( + overrides?: Partial +): MetaDataVersionInformation { + return { + version: '5.13', + date: '2019-05-31', + compatibility: '6.7', + archived: false, + downloadURL: 'https://example.com/sonar-java-plugin-5.13.0.18197.jar', + changeLogUrl: 'https://example.com/sonar-java-plugin/release', + ...overrides, + }; +} + +export function mockMetaDataInformation( + overrides?: Partial +): MetaDataInformation { + return { + name: 'SonarJava', + key: 'java', + isSonarSourceCommercial: true, + organization: { + name: 'SonarSource', + url: 'http://www.sonarsource.com/', + }, + category: 'Languages', + license: 'SonarSource', + issueTrackerURL: 'https://jira.sonarsource.com/browse/SONARJAVA', + sourcesURL: 'https://github.com/SonarSource/sonar-java', + versions: [ + mockMetaDataVersionInformation({ version: '2.0' }), + mockMetaDataVersionInformation({ version: '1.0', archived: true }), + ], + ...overrides, + }; +} diff --git a/server/sonar-ui-common/components/ui/update-center/update-center-metadata.ts b/server/sonar-ui-common/components/ui/update-center/update-center-metadata.ts new file mode 100644 index 00000000000..00e1d969b40 --- /dev/null +++ b/server/sonar-ui-common/components/ui/update-center/update-center-metadata.ts @@ -0,0 +1,49 @@ +/* + * Sonar UI Common + * Copyright (C) 2019-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. + */ + +export interface MetaDataInformation { + category?: string; + isSonarSourceCommercial?: boolean; + issueTrackerURL?: string; + key?: string; + license?: string; + name: string; + organization?: { + name: string; + url?: string; + }; + sourcesURL?: string; + versions?: MetaDataVersionInformation[]; +} + +export interface MetaDataVersionInformation { + archived?: boolean; + changeLogUrl?: string; + compatibility?: string; + date?: string; + description?: string; + downloadURL?: string | AdvancedDownloadUrl[]; + version: string; +} + +export interface AdvancedDownloadUrl { + label?: string; + url: string; +} -- cgit v1.2.3