diff options
author | Stas Vilchik <stas.vilchik@sonarsource.com> | 2018-09-20 11:44:42 +0200 |
---|---|---|
committer | SonarTech <sonartech@sonarsource.com> | 2018-09-21 20:20:55 +0200 |
commit | d5fbab940ffbdc45df0c5a078a340caaf9fea956 (patch) | |
tree | 81006b1bdd9eb9dd301a55caa220c2710e327cc1 /server/sonar-web/src | |
parent | fbf80ad4a51f1c3c267c0267345a14881bfc614f (diff) | |
download | sonarqube-d5fbab940ffbdc45df0c5a078a340caaf9fea956.tar.gz sonarqube-d5fbab940ffbdc45df0c5a078a340caaf9fea956.zip |
rewrite about app in ts
Diffstat (limited to 'server/sonar-web/src')
-rw-r--r-- | server/sonar-web/src/main/js/apps/about/actions.ts (renamed from server/sonar-web/src/main/js/apps/about/actions.js) | 4 | ||||
-rw-r--r-- | server/sonar-web/src/main/js/apps/about/components/AboutApp.tsx (renamed from server/sonar-web/src/main/js/apps/about/components/AboutApp.js) | 86 | ||||
-rw-r--r-- | server/sonar-web/src/main/js/apps/about/components/AboutCleanCode.tsx (renamed from server/sonar-web/src/main/js/apps/about/components/AboutCleanCode.js) | 2 | ||||
-rw-r--r-- | server/sonar-web/src/main/js/apps/about/components/AboutLanguages.tsx (renamed from server/sonar-web/src/main/js/apps/about/components/AboutLanguages.js) | 5 | ||||
-rw-r--r-- | server/sonar-web/src/main/js/apps/about/components/AboutLeakPeriod.tsx (renamed from server/sonar-web/src/main/js/apps/about/components/AboutLeakPeriod.js) | 2 | ||||
-rw-r--r-- | server/sonar-web/src/main/js/apps/about/components/AboutProjects.tsx (renamed from server/sonar-web/src/main/js/apps/about/components/AboutProjects.js) | 20 | ||||
-rw-r--r-- | server/sonar-web/src/main/js/apps/about/components/AboutQualityGates.tsx (renamed from server/sonar-web/src/main/js/apps/about/components/AboutQualityGates.js) | 2 | ||||
-rw-r--r-- | server/sonar-web/src/main/js/apps/about/components/AboutQualityModel.tsx (renamed from server/sonar-web/src/main/js/apps/about/components/AboutQualityModel.js) | 2 | ||||
-rw-r--r-- | server/sonar-web/src/main/js/apps/about/components/AboutScanners.tsx (renamed from server/sonar-web/src/main/js/apps/about/components/AboutScanners.js) | 5 | ||||
-rw-r--r-- | server/sonar-web/src/main/js/apps/about/components/AboutStandards.tsx (renamed from server/sonar-web/src/main/js/apps/about/components/AboutStandards.js) | 20 | ||||
-rw-r--r-- | server/sonar-web/src/main/js/apps/about/components/EntryIssueTypes.tsx (renamed from server/sonar-web/src/main/js/apps/about/components/EntryIssueTypes.js) | 26 | ||||
-rw-r--r-- | server/sonar-web/src/main/js/apps/about/components/ReadMore.js | 38 | ||||
-rw-r--r-- | server/sonar-web/src/main/js/apps/about/components/ReadMore.tsx | 35 | ||||
-rw-r--r-- | server/sonar-web/src/main/js/apps/settings/store/values/actions.ts (renamed from server/sonar-web/src/main/js/apps/settings/store/values/actions.js) | 21 |
14 files changed, 114 insertions, 154 deletions
diff --git a/server/sonar-web/src/main/js/apps/about/actions.js b/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<Store>) => { 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 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<AppState, 'defaultOrganization' | 'organizationsEnabled'>; + currentUser: CurrentUser; + customText?: { value: string }; + fetchAboutPageSettings: () => Promise<void>; + location: Location; +} + +interface State { + issueTypes?: { [key: string]: { count: number } }; + loading: boolean; + projectsCount: number; +} + +class AboutApp extends React.PureComponent<Props, State> { + 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 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 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() { <ul className="about-page-languages"> {languages.slice(0, half).map((language, index) => ( <li key={index}> - <a href={languages[index].url}>{languages[index].name}</a> + <a href={language.url}>{language.name}</a> <br /> {index + half < languages.length && ( <a href={languages[index + half].url}>{languages[index + half].name}</a> 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 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 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 ( <div className="about-page-projects"> - {loading && <i className="spinner" />} - {!loading && ( + {loading ? ( + <i className="spinner" /> + ) : ( <div> <div> <Link className="about-page-projects-link" to="/projects"> 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 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 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 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() { <img alt={translate('about_page.scanners', scanner.key)} height={60} - src={`${window.baseUrl}/images/scanner-logos/${scanner.key}.svg`} + src={`${getBaseUrl()}/images/scanner-logos/${scanner.key}.svg`} /> </a> ))} 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 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<AppState, 'defaultOrganization' | 'organizationsEnabled'>; +} -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 ( <div className="boxed-group"> 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 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 ( <div className="about-page-projects"> - {loading && <i className="spinner" />} - {!loading && ( + {loading ? ( + <i className="spinner" /> + ) : ( <table className="about-page-issue-types"> <tbody> <tr> 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 ( - <div className="big-spacer-top"> - <a className="about-page-link-more" href={this.props.link} target="_blank"> - <span>{translate('about_page.read_more')}</span> - </a> - </div> - ); - } -} 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 ( + <div className="big-spacer-top"> + <a className="about-page-link-more" href={link} rel="noopener noreferrer" target="_blank"> + <span>{translate('about_page.read_more')}</span> + </a> + </div> + ); +} 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 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 }; +} |