From d5fbab940ffbdc45df0c5a078a340caaf9fea956 Mon Sep 17 00:00:00 2001 From: Stas Vilchik Date: Thu, 20 Sep 2018 11:44:42 +0200 Subject: [PATCH] rewrite about app in ts --- .../js/apps/about/{actions.js => actions.ts} | 4 +- .../components/{AboutApp.js => AboutApp.tsx} | 86 +++++++------------ .../{AboutCleanCode.js => AboutCleanCode.tsx} | 2 +- .../{AboutLanguages.js => AboutLanguages.tsx} | 5 +- ...AboutLeakPeriod.js => AboutLeakPeriod.tsx} | 2 +- .../{AboutProjects.js => AboutProjects.tsx} | 20 ++--- ...tQualityGates.js => AboutQualityGates.tsx} | 2 +- ...tQualityModel.js => AboutQualityModel.tsx} | 2 +- .../{AboutScanners.js => AboutScanners.tsx} | 5 +- .../{AboutStandards.js => AboutStandards.tsx} | 20 ++--- ...EntryIssueTypes.js => EntryIssueTypes.tsx} | 26 +++--- .../main/js/apps/about/components/ReadMore.js | 38 -------- .../js/apps/about/components/ReadMore.tsx | 35 ++++++++ .../store/values/{actions.js => actions.ts} | 21 ++--- 14 files changed, 114 insertions(+), 154 deletions(-) rename server/sonar-web/src/main/js/apps/about/{actions.js => actions.ts} (87%) rename server/sonar-web/src/main/js/apps/about/components/{AboutApp.js => AboutApp.tsx} (81%) rename server/sonar-web/src/main/js/apps/about/components/{AboutCleanCode.js => AboutCleanCode.tsx} (97%) rename server/sonar-web/src/main/js/apps/about/components/{AboutLanguages.js => AboutLanguages.tsx} (96%) rename server/sonar-web/src/main/js/apps/about/components/{AboutLeakPeriod.js => AboutLeakPeriod.tsx} (97%) rename server/sonar-web/src/main/js/apps/about/components/{AboutProjects.js => AboutProjects.tsx} (84%) rename server/sonar-web/src/main/js/apps/about/components/{AboutQualityGates.js => AboutQualityGates.tsx} (97%) rename server/sonar-web/src/main/js/apps/about/components/{AboutQualityModel.js => AboutQualityModel.tsx} (98%) rename server/sonar-web/src/main/js/apps/about/components/{AboutScanners.js => AboutScanners.tsx} (93%) rename server/sonar-web/src/main/js/apps/about/components/{AboutStandards.js => AboutStandards.tsx} (90%) rename server/sonar-web/src/main/js/apps/about/components/{EntryIssueTypes.js => EntryIssueTypes.tsx} (91%) delete mode 100644 server/sonar-web/src/main/js/apps/about/components/ReadMore.js create mode 100644 server/sonar-web/src/main/js/apps/about/components/ReadMore.tsx rename server/sonar-web/src/main/js/apps/settings/store/values/{actions.js => actions.ts} (69%) diff --git a/server/sonar-web/src/main/js/apps/about/actions.js b/server/sonar-web/src/main/js/apps/about/actions.ts similarity index 87% rename from server/sonar-web/src/main/js/apps/about/actions.js rename to server/sonar-web/src/main/js/apps/about/actions.ts index a60d730c30a..515d95128db 100644 --- a/server/sonar-web/src/main/js/apps/about/actions.js +++ b/server/sonar-web/src/main/js/apps/about/actions.ts @@ -17,10 +17,12 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ +import { Dispatch } from 'redux'; import { getValues } from '../../api/settings'; import { receiveValues } from '../settings/store/values/actions'; +import { Store } from '../../store/rootReducer'; -export const fetchAboutPageSettings = () => dispatch => { +export const fetchAboutPageSettings = () => (dispatch: Dispatch) => { const keys = ['sonar.lf.aboutText']; return getValues({ keys: keys.join() }).then(values => { diff --git a/server/sonar-web/src/main/js/apps/about/components/AboutApp.js b/server/sonar-web/src/main/js/apps/about/components/AboutApp.tsx similarity index 81% rename from server/sonar-web/src/main/js/apps/about/components/AboutApp.js rename to server/sonar-web/src/main/js/apps/about/components/AboutApp.tsx index 941db10c50b..40737d5408e 100644 --- a/server/sonar-web/src/main/js/apps/about/components/AboutApp.js +++ b/server/sonar-web/src/main/js/apps/about/components/AboutApp.tsx @@ -17,11 +17,11 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -// @flow -import React from 'react'; +import * as React from 'react'; import { connect } from 'react-redux'; import { keyBy } from 'lodash'; import { Link } from 'react-router'; +import { Location } from 'history'; import AboutProjects from './AboutProjects'; import EntryIssueTypes from './EntryIssueTypes'; import AboutLanguages from './AboutLanguages'; @@ -34,63 +34,49 @@ import AboutScanners from './AboutScanners'; import { searchProjects } from '../../../api/components'; import { getFacet } from '../../../api/issues'; import GlobalContainer from '../../../app/components/GlobalContainer'; -import { getAppState, getCurrentUser, getGlobalSettingValue } from '../../../store/rootReducer'; +import { + getAppState, + getCurrentUser, + getGlobalSettingValue, + Store +} from '../../../store/rootReducer'; import { translate } from '../../../helpers/l10n'; import { fetchAboutPageSettings } from '../actions'; -import { isSonarCloud } from '../../../helpers/system'; -import { IssueType } from '../../../app/types'; +import { IssueType, AppState, CurrentUser } from '../../../app/types'; import '../styles.css'; -/*:: -type State = { - loading: boolean, - projectsCount: number, - issueTypes?: { - [key: string]: ?{ - count: number - } - } -}; -*/ - -class AboutApp extends React.PureComponent { - /*:: mounted: boolean; */ - - /*:: props: { - appState: { - defaultOrganization: string, - organizationsEnabled: boolean - }, - currentUser: { isLoggedIn: boolean }, - customText?: string, - fetchAboutPageSettings: () => Promise<*>, - location: { pathname: string } - }; -*/ +interface Props { + appState: Pick; + currentUser: CurrentUser; + customText?: { value: string }; + fetchAboutPageSettings: () => Promise; + location: Location; +} + +interface State { + issueTypes?: { [key: string]: { count: number } }; + loading: boolean; + projectsCount: number; +} + +class AboutApp extends React.PureComponent { + mounted = false; - state /*: State */ = { + state: State = { loading: true, projectsCount: 0 }; componentDidMount() { this.mounted = true; - if (isSonarCloud()) { - window.location = 'https://about.sonarcloud.io'; - } else { - this.loadData(); - // $FlowFixMe - document.body.classList.add('white-page'); - // $FlowFixMe - document.documentElement.classList.add('white-page'); - } + this.loadData(); + document.body.classList.add('white-page'); + document.documentElement.classList.add('white-page'); } componentWillUnmount() { this.mounted = false; - // $FlowFixMe document.body.classList.remove('white-page'); - // $FlowFixMe document.documentElement.classList.remove('white-page'); } @@ -112,11 +98,7 @@ class AboutApp extends React.PureComponent { if (this.mounted) { const [projectsCount, issues] = responses; const issueTypes = keyBy(issues.facet, 'val'); - this.setState({ - projectsCount, - issueTypes, - loading: false - }); + this.setState({ projectsCount, issueTypes, loading: false }); } }, () => { @@ -131,10 +113,6 @@ class AboutApp extends React.PureComponent { const { customText } = this.props; const { loading, issueTypes, projectsCount } = this.state; - if (isSonarCloud()) { - return null; - } - let bugs; let vulnerabilities; let codeSmells; @@ -213,13 +191,13 @@ class AboutApp extends React.PureComponent { } } -const mapStateToProps = state => ({ +const mapStateToProps = (state: Store) => ({ appState: getAppState(state), currentUser: getCurrentUser(state), customText: getGlobalSettingValue(state, 'sonar.lf.aboutText') }); -const mapDispatchToProps = { fetchAboutPageSettings }; +const mapDispatchToProps = { fetchAboutPageSettings } as any; export default connect( mapStateToProps, diff --git a/server/sonar-web/src/main/js/apps/about/components/AboutCleanCode.js b/server/sonar-web/src/main/js/apps/about/components/AboutCleanCode.tsx similarity index 97% rename from server/sonar-web/src/main/js/apps/about/components/AboutCleanCode.js rename to server/sonar-web/src/main/js/apps/about/components/AboutCleanCode.tsx index c98cd4e9d07..29ad172144b 100644 --- a/server/sonar-web/src/main/js/apps/about/components/AboutCleanCode.js +++ b/server/sonar-web/src/main/js/apps/about/components/AboutCleanCode.tsx @@ -17,7 +17,7 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -import React from 'react'; +import * as React from 'react'; import ReadMore from './ReadMore'; import { translate } from '../../../helpers/l10n'; diff --git a/server/sonar-web/src/main/js/apps/about/components/AboutLanguages.js b/server/sonar-web/src/main/js/apps/about/components/AboutLanguages.tsx similarity index 96% rename from server/sonar-web/src/main/js/apps/about/components/AboutLanguages.js rename to server/sonar-web/src/main/js/apps/about/components/AboutLanguages.tsx index 1fecd6de905..d770ba01b18 100644 --- a/server/sonar-web/src/main/js/apps/about/components/AboutLanguages.js +++ b/server/sonar-web/src/main/js/apps/about/components/AboutLanguages.tsx @@ -17,8 +17,7 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -// @flow -import React from 'react'; +import * as React from 'react'; import { translate } from '../../../helpers/l10n'; const languages = [ @@ -56,7 +55,7 @@ export default function AboutLanguages() {
    {languages.slice(0, half).map((language, index) => (
  • - {languages[index].name} + {language.name}
    {index + half < languages.length && ( {languages[index + half].name} diff --git a/server/sonar-web/src/main/js/apps/about/components/AboutLeakPeriod.js b/server/sonar-web/src/main/js/apps/about/components/AboutLeakPeriod.tsx similarity index 97% rename from server/sonar-web/src/main/js/apps/about/components/AboutLeakPeriod.js rename to server/sonar-web/src/main/js/apps/about/components/AboutLeakPeriod.tsx index 203a2855936..78c3aaa89c2 100644 --- a/server/sonar-web/src/main/js/apps/about/components/AboutLeakPeriod.js +++ b/server/sonar-web/src/main/js/apps/about/components/AboutLeakPeriod.tsx @@ -17,7 +17,7 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -import React from 'react'; +import * as React from 'react'; import ReadMore from './ReadMore'; import { translate } from '../../../helpers/l10n'; diff --git a/server/sonar-web/src/main/js/apps/about/components/AboutProjects.js b/server/sonar-web/src/main/js/apps/about/components/AboutProjects.tsx similarity index 84% rename from server/sonar-web/src/main/js/apps/about/components/AboutProjects.js rename to server/sonar-web/src/main/js/apps/about/components/AboutProjects.tsx index ded5a77736f..81e8065bda8 100644 --- a/server/sonar-web/src/main/js/apps/about/components/AboutProjects.js +++ b/server/sonar-web/src/main/js/apps/about/components/AboutProjects.tsx @@ -17,24 +17,22 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -//@flow -import React from 'react'; +import * as React from 'react'; import { Link } from 'react-router'; import { formatMeasure } from '../../../helpers/measures'; import { translate } from '../../../helpers/l10n'; -/*:: -type Props = { - count: number, - loading: boolean -}; -*/ +interface Props { + count: number; + loading: boolean; +} -export default function AboutProjects({ count, loading } /*: Props */) { +export default function AboutProjects({ count, loading }: Props) { return (
    - {loading && } - {!loading && ( + {loading ? ( + + ) : (
    diff --git a/server/sonar-web/src/main/js/apps/about/components/AboutQualityGates.js b/server/sonar-web/src/main/js/apps/about/components/AboutQualityGates.tsx similarity index 97% rename from server/sonar-web/src/main/js/apps/about/components/AboutQualityGates.js rename to server/sonar-web/src/main/js/apps/about/components/AboutQualityGates.tsx index 2af98417ba5..d89d581114c 100644 --- a/server/sonar-web/src/main/js/apps/about/components/AboutQualityGates.js +++ b/server/sonar-web/src/main/js/apps/about/components/AboutQualityGates.tsx @@ -17,7 +17,7 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -import React from 'react'; +import * as React from 'react'; import ReadMore from './ReadMore'; import { translate } from '../../../helpers/l10n'; diff --git a/server/sonar-web/src/main/js/apps/about/components/AboutQualityModel.js b/server/sonar-web/src/main/js/apps/about/components/AboutQualityModel.tsx similarity index 98% rename from server/sonar-web/src/main/js/apps/about/components/AboutQualityModel.js rename to server/sonar-web/src/main/js/apps/about/components/AboutQualityModel.tsx index a1fa080202d..322ae44abcc 100644 --- a/server/sonar-web/src/main/js/apps/about/components/AboutQualityModel.js +++ b/server/sonar-web/src/main/js/apps/about/components/AboutQualityModel.tsx @@ -17,7 +17,7 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -import React from 'react'; +import * as React from 'react'; import { translate } from '../../../helpers/l10n'; import BugIcon from '../../../components/icons-components/BugIcon'; import VulnerabilityIcon from '../../../components/icons-components/VulnerabilityIcon'; diff --git a/server/sonar-web/src/main/js/apps/about/components/AboutScanners.js b/server/sonar-web/src/main/js/apps/about/components/AboutScanners.tsx similarity index 93% rename from server/sonar-web/src/main/js/apps/about/components/AboutScanners.js rename to server/sonar-web/src/main/js/apps/about/components/AboutScanners.tsx index 42ad663a7ad..b6f500b669e 100644 --- a/server/sonar-web/src/main/js/apps/about/components/AboutScanners.js +++ b/server/sonar-web/src/main/js/apps/about/components/AboutScanners.tsx @@ -17,8 +17,9 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -import React from 'react'; +import * as React from 'react'; import { translate } from '../../../helpers/l10n'; +import { getBaseUrl } from '../../../helpers/urls'; const scanners = [ { @@ -59,7 +60,7 @@ export default function AboutScanners() { {translate('about_page.scanners', ))} diff --git a/server/sonar-web/src/main/js/apps/about/components/AboutStandards.js b/server/sonar-web/src/main/js/apps/about/components/AboutStandards.tsx similarity index 90% rename from server/sonar-web/src/main/js/apps/about/components/AboutStandards.js rename to server/sonar-web/src/main/js/apps/about/components/AboutStandards.tsx index b4624dc821e..07d58182fdb 100644 --- a/server/sonar-web/src/main/js/apps/about/components/AboutStandards.js +++ b/server/sonar-web/src/main/js/apps/about/components/AboutStandards.tsx @@ -17,12 +17,13 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -import React from 'react'; +import * as React from 'react'; import { Link } from 'react-router'; import ReadMore from './ReadMore'; import TagsIcon from '../../../components/icons-components/TagsIcon'; import { translate } from '../../../helpers/l10n'; import { getRulesUrl } from '../../../helpers/urls'; +import { AppState } from '../../../app/types'; const link = 'https://redirect.sonarsource.com/doc/rules.html'; @@ -30,19 +31,12 @@ const owaspTags = 'owasp-a1,owasp-a2,owasp-a3,owasp-a4,owasp-a5,owasp-a6,owasp-a7,owasp-a8,owasp-a9,owasp-a10'; const sans25Tags = 'sans-top25-porous,sans-top25-risky,sans-top25-insecure'; -/*:: -type Props = { - appState: { - defaultOrganization: string, - organizationsEnabled: boolean - } -}; -*/ +interface Props { + appState: Pick; +} -export default function AboutStandards(props /*: Props */) { - const organization = props.appState.organizationsEnabled - ? props.appState.defaultOrganization - : undefined; +export default function AboutStandards({ appState }: Props) { + const organization = appState.organizationsEnabled ? appState.defaultOrganization : undefined; return (
    diff --git a/server/sonar-web/src/main/js/apps/about/components/EntryIssueTypes.js b/server/sonar-web/src/main/js/apps/about/components/EntryIssueTypes.tsx similarity index 91% rename from server/sonar-web/src/main/js/apps/about/components/EntryIssueTypes.js rename to server/sonar-web/src/main/js/apps/about/components/EntryIssueTypes.tsx index b6584777311..5361e0ef438 100644 --- a/server/sonar-web/src/main/js/apps/about/components/EntryIssueTypes.js +++ b/server/sonar-web/src/main/js/apps/about/components/EntryIssueTypes.tsx @@ -17,8 +17,7 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -//@flow -import React from 'react'; +import * as React from 'react'; import { Link } from 'react-router'; import { formatMeasure } from '../../../helpers/measures'; import { translate } from '../../../helpers/l10n'; @@ -28,22 +27,19 @@ import VulnerabilityIcon from '../../../components/icons-components/Vulnerabilit import CodeSmellIcon from '../../../components/icons-components/CodeSmellIcon'; import { IssueType } from '../../../app/types'; -/*:: -type Props = { - bugs: ?number, - codeSmells: ?number, - loading: boolean, - vulnerabilities: ?number -}; -*/ +interface Props { + bugs?: number; + codeSmells?: number; + loading: boolean; + vulnerabilities?: number; +} -export default function EntryIssueTypes( - { bugs, codeSmells, loading, vulnerabilities } /*: Props */ -) { +export default function EntryIssueTypes({ bugs, codeSmells, loading, vulnerabilities }: Props) { return (
    - {loading && } - {!loading && ( + {loading ? ( + + ) : ( diff --git a/server/sonar-web/src/main/js/apps/about/components/ReadMore.js b/server/sonar-web/src/main/js/apps/about/components/ReadMore.js deleted file mode 100644 index 1024c4407ed..00000000000 --- a/server/sonar-web/src/main/js/apps/about/components/ReadMore.js +++ /dev/null @@ -1,38 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2018 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 React from 'react'; -import PropTypes from 'prop-types'; -import { translate } from '../../../helpers/l10n'; - -export default class ReadMore extends React.PureComponent { - static propTypes = { - link: PropTypes.string.isRequired - }; - - render() { - return ( - - ); - } -} diff --git a/server/sonar-web/src/main/js/apps/about/components/ReadMore.tsx b/server/sonar-web/src/main/js/apps/about/components/ReadMore.tsx new file mode 100644 index 00000000000..2abbff21e6b --- /dev/null +++ b/server/sonar-web/src/main/js/apps/about/components/ReadMore.tsx @@ -0,0 +1,35 @@ +/* + * SonarQube + * Copyright (C) 2009-2018 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 { translate } from '../../../helpers/l10n'; + +interface Props { + link: string; +} + +export default function ReadMore({ link }: Props) { + return ( + + ); +} diff --git a/server/sonar-web/src/main/js/apps/settings/store/values/actions.js b/server/sonar-web/src/main/js/apps/settings/store/values/actions.ts similarity index 69% rename from server/sonar-web/src/main/js/apps/settings/store/values/actions.js rename to server/sonar-web/src/main/js/apps/settings/store/values/actions.ts index 0da9d1b6bff..a7d6f8f30a8 100644 --- a/server/sonar-web/src/main/js/apps/settings/store/values/actions.js +++ b/server/sonar-web/src/main/js/apps/settings/store/values/actions.ts @@ -17,18 +17,13 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -// @flow -/*:: import type { SettingValue } from '../../types'; */ +interface SettingValue { + key: string; + value?: string; +} -export const RECEIVE_VALUES /*: string */ = 'RECEIVE_VALUES'; +export const RECEIVE_VALUES = 'RECEIVE_VALUES'; -/** - * Receive settings action creator - * @param {Array} settings - * @returns {Object} - */ -export const receiveValues = (settings /*: SettingValue[] */, componentKey /*: ?string */) => ({ - type: RECEIVE_VALUES, - settings, - componentKey -}); +export function receiveValues(settings: SettingValue[], componentKey?: string) { + return { type: RECEIVE_VALUES, settings, componentKey }; +} -- 2.39.5