diff options
author | Grégoire Aubert <gregoire.aubert@sonarsource.com> | 2018-01-16 13:49:10 +0100 |
---|---|---|
committer | Grégoire Aubert <gregoire.aubert@sonarsource.com> | 2018-01-25 15:16:50 +0100 |
commit | 49391d2eff65209068acc31e41393b9617fb2458 (patch) | |
tree | 705191348ecc0cbc2db933f3c20ec8edad26c688 /server/sonar-web/src/main/js/apps | |
parent | e85902788fd722f1c17d214d8be15eea5cf276e0 (diff) | |
download | sonarqube-49391d2eff65209068acc31e41393b9617fb2458.tar.gz sonarqube-49391d2eff65209068acc31e41393b9617fb2458.zip |
Migrate App to tsx and clean up measures related types
Diffstat (limited to 'server/sonar-web/src/main/js/apps')
4 files changed, 2 insertions, 166 deletions
diff --git a/server/sonar-web/src/main/js/apps/code/types.ts b/server/sonar-web/src/main/js/apps/code/types.ts index 0c7040622e8..3a226f8127d 100644 --- a/server/sonar-web/src/main/js/apps/code/types.ts +++ b/server/sonar-web/src/main/js/apps/code/types.ts @@ -17,16 +17,8 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -interface Measure { - metric: string; - value: string; - periods?: Period[]; -} -interface Period { - index: number; - value: string; -} +import { Measure } from '../../helpers/measures'; export interface Component extends Breadcrumb { measures?: Measure[]; diff --git a/server/sonar-web/src/main/js/apps/overview/components/App.js b/server/sonar-web/src/main/js/apps/overview/components/App.js deleted file mode 100644 index 2d4067baa60..00000000000 --- a/server/sonar-web/src/main/js/apps/overview/components/App.js +++ /dev/null @@ -1,104 +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. - */ -// @flow -import React from 'react'; -import PropTypes from 'prop-types'; -import OverviewApp from './OverviewApp'; -import EmptyOverview from './EmptyOverview'; -import { getBranchName, isShortLivingBranch } from '../../../helpers/branches'; -import { getProjectBranchUrl, getCodeUrl } from '../../../helpers/urls'; - -/*:: -type Props = { - branch?: { name: string }, - component: { - analysisDate?: string, - breadcrumbs: Array<{ key: string }>, - id: string, - key: string, - qualifier: string, - tags: Array<string>, - organization?: string - }, - isInProgress?: bool, - isPending?: bool, - onComponentChange: {} => void, - router: Object -}; -*/ - -export default class App extends React.PureComponent { - /*:: props: Props; */ - /*:: state: Object; */ - - static contextTypes = { - router: PropTypes.object - }; - - componentDidMount() { - const { branch, component } = this.props; - - if (this.isPortfolio()) { - this.context.router.replace({ - pathname: '/portfolio', - query: { id: component.key } - }); - } else if (this.isFile()) { - this.context.router.replace( - getCodeUrl(component.breadcrumbs[0].key, getBranchName(branch), component.key) - ); - } else if (isShortLivingBranch(branch)) { - this.context.router.replace(getProjectBranchUrl(component.key, branch)); - } - } - - isPortfolio() { - return ['VW', 'SVW'].includes(this.props.component.qualifier); - } - - isFile() { - return ['FIL', 'UTS'].includes(this.props.component.qualifier); - } - - render() { - const { branch, component } = this.props; - - if (this.isPortfolio() || this.isFile() || isShortLivingBranch(branch)) { - return null; - } - - if (!component.analysisDate) { - return ( - <EmptyOverview - component={component.key} - showWarning={!this.props.isPending && !this.props.isInProgress} - /> - ); - } - - return ( - <OverviewApp - branch={branch} - component={component} - onComponentChange={this.props.onComponentChange} - /> - ); - } -} diff --git a/server/sonar-web/src/main/js/apps/overview/components/__tests__/App-test.js b/server/sonar-web/src/main/js/apps/overview/components/__tests__/App-test.js deleted file mode 100644 index 09c4aea0151..00000000000 --- a/server/sonar-web/src/main/js/apps/overview/components/__tests__/App-test.js +++ /dev/null @@ -1,51 +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 { mount, shallow } from 'enzyme'; -import App from '../App'; -import OverviewApp from '../OverviewApp'; -import EmptyOverview from '../EmptyOverview'; - -it('should render OverviewApp', () => { - const component = { key: 'foo', analysisDate: '2016-01-01' }; - const output = shallow(<App component={component} />); - expect(output.type()).toBe(OverviewApp); -}); - -it('should render EmptyOverview', () => { - const component = { key: 'foo' }; - const output = shallow(<App component={component} />); - expect(output.type()).toBe(EmptyOverview); -}); - -it('redirects on Code page for files', () => { - const branch = { isMain: false, name: 'b' }; - const component = { - breadcrumbs: [{ key: 'project' }, { key: 'foo' }], - key: 'foo', - qualifier: 'FIL' - }; - const replace = jest.fn(); - mount(<App branch={branch} component={component} />, { context: { router: { replace } } }); - expect(replace).toBeCalledWith({ - pathname: '/code', - query: { branch: 'b', id: 'project', selected: 'foo' } - }); -}); diff --git a/server/sonar-web/src/main/js/apps/portfolio/components/Summary.tsx b/server/sonar-web/src/main/js/apps/portfolio/components/Summary.tsx index a19cd99b2a4..3279b530d70 100644 --- a/server/sonar-web/src/main/js/apps/portfolio/components/Summary.tsx +++ b/server/sonar-web/src/main/js/apps/portfolio/components/Summary.tsx @@ -30,8 +30,7 @@ interface Props { } export default function Summary({ component, measures }: Props) { - const projects = measures['projects']; - const ncloc = measures['ncloc']; + const { projects, ncloc } = measures; const nclocDistribution = measures['ncloc_language_distribution']; return ( |