From d030db77d634090dddc1345ea16b0b2cb0aa3ba2 Mon Sep 17 00:00:00 2001 From: Stas Vilchik Date: Wed, 19 Apr 2017 08:51:45 +0200 Subject: improve react usage (#1936) * remove React.createClass * remove react-addons-shallow-compare * convert to functional components * replace Component with PureComponent * remove react-router-redux * declare function components consistently * fix quality flaws * fix typo * declare children prop consistently * pass location to ComponentNavMenu --- .../js/apps/projects/components/AllProjects.js | 2 +- .../src/main/js/apps/projects/components/App.js | 2 +- .../js/apps/projects/components/EmptyInstance.js | 14 +++---- .../apps/projects/components/NoFavoriteProjects.js | 26 ++++++------- .../main/js/apps/projects/components/PageHeader.js | 44 +++++++++++----------- .../projects/components/ProjectCardLanguages.js | 2 +- .../apps/projects/components/ProjectsListFooter.js | 2 +- .../main/js/apps/projects/filters/FilterHeader.js | 2 +- .../apps/projects/filters/MaintainabilityFilter.js | 6 +-- .../js/apps/projects/filters/ReliabilityFilter.js | 6 +-- .../apps/projects/filters/SearchFilterContainer.js | 2 +- .../js/apps/projects/filters/SecurityFilter.js | 6 +-- 12 files changed, 51 insertions(+), 63 deletions(-) (limited to 'server/sonar-web/src/main/js/apps/projects') diff --git a/server/sonar-web/src/main/js/apps/projects/components/AllProjects.js b/server/sonar-web/src/main/js/apps/projects/components/AllProjects.js index c62d9e8c612..92ddc79dde0 100644 --- a/server/sonar-web/src/main/js/apps/projects/components/AllProjects.js +++ b/server/sonar-web/src/main/js/apps/projects/components/AllProjects.js @@ -31,7 +31,7 @@ import PageSide from '../../../components/layout/PageSide'; import PageFilters from '../../../components/layout/PageFilters'; import '../styles.css'; -export default class AllProjects extends React.Component { +export default class AllProjects extends React.PureComponent { static propTypes = { isFavorite: React.PropTypes.bool.isRequired, location: React.PropTypes.object.isRequired, diff --git a/server/sonar-web/src/main/js/apps/projects/components/App.js b/server/sonar-web/src/main/js/apps/projects/components/App.js index 69c18380bb3..8897f1e6f36 100644 --- a/server/sonar-web/src/main/js/apps/projects/components/App.js +++ b/server/sonar-web/src/main/js/apps/projects/components/App.js @@ -21,7 +21,7 @@ import React from 'react'; import Helmet from 'react-helmet'; import { translate } from '../../../helpers/l10n'; -export default class App extends React.Component { +export default class App extends React.PureComponent { componentDidMount() { document.querySelector('html').classList.add('dashboard-page'); } diff --git a/server/sonar-web/src/main/js/apps/projects/components/EmptyInstance.js b/server/sonar-web/src/main/js/apps/projects/components/EmptyInstance.js index 8b4156532ab..1eb2241cfb1 100644 --- a/server/sonar-web/src/main/js/apps/projects/components/EmptyInstance.js +++ b/server/sonar-web/src/main/js/apps/projects/components/EmptyInstance.js @@ -20,12 +20,10 @@ import React from 'react'; import { translate } from '../../../helpers/l10n'; -export default class EmptyInstance extends React.Component { - render() { - return ( -
-

{translate('projects.no_projects.empty_instance')}

-
- ); - } +export default function EmptyInstance() { + return ( +
+

{translate('projects.no_projects.empty_instance')}

+
+ ); } diff --git a/server/sonar-web/src/main/js/apps/projects/components/NoFavoriteProjects.js b/server/sonar-web/src/main/js/apps/projects/components/NoFavoriteProjects.js index 43709aecbe3..f69fbebc834 100644 --- a/server/sonar-web/src/main/js/apps/projects/components/NoFavoriteProjects.js +++ b/server/sonar-web/src/main/js/apps/projects/components/NoFavoriteProjects.js @@ -21,18 +21,16 @@ import React from 'react'; import { Link } from 'react-router'; import { translate } from '../../../helpers/l10n'; -export default class NoFavoriteProjects extends React.Component { - render() { - return ( -
-

{translate('projects.no_favorite_projects')}

-

{translate('projects.no_favorite_projects.engagement')}

-

- - {translate('projects.explore_projects')} - -

-
- ); - } +export default function NoFavoriteProjects() { + return ( +
+

{translate('projects.no_favorite_projects')}

+

{translate('projects.no_favorite_projects.engagement')}

+

+ + {translate('projects.explore_projects')} + +

+
+ ); } diff --git a/server/sonar-web/src/main/js/apps/projects/components/PageHeader.js b/server/sonar-web/src/main/js/apps/projects/components/PageHeader.js index ee2cb6cf6d0..61a9bba24ab 100644 --- a/server/sonar-web/src/main/js/apps/projects/components/PageHeader.js +++ b/server/sonar-web/src/main/js/apps/projects/components/PageHeader.js @@ -22,30 +22,28 @@ import React from 'react'; import ViewSelect from './ViewSelect'; import { translate } from '../../../helpers/l10n'; -export default class PageHeader extends React.Component { - props: { - loading: boolean, - onViewChange: (string) => void, - total?: number, - view: string - }; +type Props = { + loading: boolean, + onViewChange: (string) => void, + total?: number, + view: string +}; - render() { - return ( -
- +export default function PageHeader(props: Props) { + return ( +
+ -
- {!!this.props.loading && } +
+ {!!props.loading && } - {this.props.total != null && - - {this.props.total} - {' '} - {translate('projects._projects')} - } -
-
- ); - } + {props.total != null && + + {props.total} + {' '} + {translate('projects._projects')} + } + +
+ ); } diff --git a/server/sonar-web/src/main/js/apps/projects/components/ProjectCardLanguages.js b/server/sonar-web/src/main/js/apps/projects/components/ProjectCardLanguages.js index 172d228f0d8..e4d4c283521 100644 --- a/server/sonar-web/src/main/js/apps/projects/components/ProjectCardLanguages.js +++ b/server/sonar-web/src/main/js/apps/projects/components/ProjectCardLanguages.js @@ -24,7 +24,7 @@ import Tooltip from '../../../components/controls/Tooltip'; import { getLanguages } from '../../../store/rootReducer'; import { translate } from '../../../helpers/l10n'; -class ProjectCardLanguages extends React.Component { +class ProjectCardLanguages extends React.PureComponent { getLanguageName(key) { if (key === '') { return translate('unknown'); diff --git a/server/sonar-web/src/main/js/apps/projects/components/ProjectsListFooter.js b/server/sonar-web/src/main/js/apps/projects/components/ProjectsListFooter.js index 745b6683372..3a1f5d4c1fe 100644 --- a/server/sonar-web/src/main/js/apps/projects/components/ProjectsListFooter.js +++ b/server/sonar-web/src/main/js/apps/projects/components/ProjectsListFooter.js @@ -20,7 +20,7 @@ import React from 'react'; import ListFooter from '../../../components/controls/ListFooter'; -export default class ProjectsListFooter extends React.Component { +export default class ProjectsListFooter extends React.PureComponent { static propTypes = { total: React.PropTypes.number.isRequired }; diff --git a/server/sonar-web/src/main/js/apps/projects/filters/FilterHeader.js b/server/sonar-web/src/main/js/apps/projects/filters/FilterHeader.js index 7ac7113d587..11d9d790662 100644 --- a/server/sonar-web/src/main/js/apps/projects/filters/FilterHeader.js +++ b/server/sonar-web/src/main/js/apps/projects/filters/FilterHeader.js @@ -22,7 +22,7 @@ import React from 'react'; type Props = { name: string, - children?: {} + children?: React.Element<*> }; export default class FilterHeader extends React.PureComponent { diff --git a/server/sonar-web/src/main/js/apps/projects/filters/MaintainabilityFilter.js b/server/sonar-web/src/main/js/apps/projects/filters/MaintainabilityFilter.js index 2f8c422dac4..a02a5f70c57 100644 --- a/server/sonar-web/src/main/js/apps/projects/filters/MaintainabilityFilter.js +++ b/server/sonar-web/src/main/js/apps/projects/filters/MaintainabilityFilter.js @@ -20,8 +20,6 @@ import React from 'react'; import IssuesFilter from './IssuesFilter'; -export default class MaintainabilityFilter extends React.Component { - render() { - return ; - } +export default function MaintainabilityFilter(props) { + return ; } diff --git a/server/sonar-web/src/main/js/apps/projects/filters/ReliabilityFilter.js b/server/sonar-web/src/main/js/apps/projects/filters/ReliabilityFilter.js index da1372a2a86..07852afe335 100644 --- a/server/sonar-web/src/main/js/apps/projects/filters/ReliabilityFilter.js +++ b/server/sonar-web/src/main/js/apps/projects/filters/ReliabilityFilter.js @@ -20,8 +20,6 @@ import React from 'react'; import IssuesFilter from './IssuesFilter'; -export default class ReliabilityFilter extends React.Component { - render() { - return ; - } +export default function ReliabilityFilter(props) { + return ; } diff --git a/server/sonar-web/src/main/js/apps/projects/filters/SearchFilterContainer.js b/server/sonar-web/src/main/js/apps/projects/filters/SearchFilterContainer.js index b70d403a499..ec6bad4c55d 100644 --- a/server/sonar-web/src/main/js/apps/projects/filters/SearchFilterContainer.js +++ b/server/sonar-web/src/main/js/apps/projects/filters/SearchFilterContainer.js @@ -31,7 +31,7 @@ type Props = { organization?: {} }; -class SearchFilterContainer extends React.Component { +class SearchFilterContainer extends React.PureComponent { handleSearch: (userQuery?: string) => void; props: Props; diff --git a/server/sonar-web/src/main/js/apps/projects/filters/SecurityFilter.js b/server/sonar-web/src/main/js/apps/projects/filters/SecurityFilter.js index 22eac70799c..9f7fa7aa997 100644 --- a/server/sonar-web/src/main/js/apps/projects/filters/SecurityFilter.js +++ b/server/sonar-web/src/main/js/apps/projects/filters/SecurityFilter.js @@ -20,8 +20,6 @@ import React from 'react'; import IssuesFilter from './IssuesFilter'; -export default class SecurityFilter extends React.Component { - render() { - return ; - } +export default function SecurityFilter(props) { + return ; } -- cgit v1.2.3