diff options
author | Grégoire Aubert <gregoire.aubert@sonarsource.com> | 2017-08-04 13:36:55 +0200 |
---|---|---|
committer | Grégoire Aubert <gregoire.aubert@sonarsource.com> | 2017-08-14 11:44:44 +0200 |
commit | 0024569cab9918efb65fb83756c82373e48dfbd8 (patch) | |
tree | d4facafe144c878e411cb5c7a28ab2d1b6cf2099 /server/sonar-web | |
parent | 3d7ad29b570e76695fd4b53ba6d1ad127e5c92f3 (diff) | |
download | sonarqube-0024569cab9918efb65fb83756c82373e48dfbd8.tar.gz sonarqube-0024569cab9918efb65fb83756c82373e48dfbd8.zip |
SONAR-9608 Use api/components/app to get favorits informations in the measures page
Diffstat (limited to 'server/sonar-web')
3 files changed, 98 insertions, 6 deletions
diff --git a/server/sonar-web/src/main/js/apps/component-measures/components/MeasureContent.js b/server/sonar-web/src/main/js/apps/component-measures/components/MeasureContent.js index 1743010d1e7..a47e5f81739 100644 --- a/server/sonar-web/src/main/js/apps/component-measures/components/MeasureContent.js +++ b/server/sonar-web/src/main/js/apps/component-measures/components/MeasureContent.js @@ -21,8 +21,8 @@ import React from 'react'; import moment from 'moment'; import Breadcrumbs from './Breadcrumbs'; -import Favorite from '../../../components/controls/Favorite'; import FilesView from '../drilldown/FilesView'; +import MeasureFavoriteContainer from './MeasureFavoriteContainer'; import MeasureHeader from './MeasureHeader'; import MeasureViewSelect from './MeasureViewSelect'; import MetricNotFound from './MetricNotFound'; @@ -231,8 +231,7 @@ export default class MeasureContent extends React.PureComponent { /> {component.key !== rootComponent.key && isLoggedIn && - <Favorite - favorite={component.isFavorite === true} + <MeasureFavoriteContainer component={component.key} className="measure-favorite spacer-right" />} diff --git a/server/sonar-web/src/main/js/apps/component-measures/components/MeasureFavoriteContainer.js b/server/sonar-web/src/main/js/apps/component-measures/components/MeasureFavoriteContainer.js new file mode 100644 index 00000000000..62b3c228641 --- /dev/null +++ b/server/sonar-web/src/main/js/apps/component-measures/components/MeasureFavoriteContainer.js @@ -0,0 +1,94 @@ +/* + * SonarQube + * Copyright (C) 2009-2017 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 { connect } from 'react-redux'; +import FavoriteContainer from '../../../components/controls/FavoriteContainer'; +import { getComponentForSourceViewer } from '../../../api/components'; +import { receiveFavorites } from '../../../store/favorites/duck'; + +type FavComponent = { key: string, canMarkAsFavorite: boolean, fav: boolean }; + +type Props = { + className?: string, + component: string, + onReceiveComponent: (component: FavComponent) => void +}; + +type State = { component: ?FavComponent }; + +class MeasureFavoriteContainer extends React.PureComponent { + mounted: boolean; + props: Props; + state: State = { + component: null + }; + + componentDidMount() { + this.mounted = true; + this.fetchComponentFavorite(this.props); + } + + componentWillReceiveProps(nextProps: Props) { + if (nextProps.component !== this.props.component) { + this.fetchComponentFavorite(nextProps); + } + } + + componentWillUnmount() { + this.mounted = false; + } + + fetchComponentFavorite({ component, onReceiveComponent }: Props) { + getComponentForSourceViewer(component).then(component => { + this.setState({ component }); + onReceiveComponent(component); + }); + } + + render() { + const { component } = this.state; + if (component == null || !component.canMarkAsFavorite) { + return null; + } + return ( + <FavoriteContainer className={this.props.className} componentKey={this.props.component} /> + ); + } +} + +const mapStateToProps = null; + +const mapDispatchToProps = { + onReceiveComponent: (component: FavComponent) => dispatch => { + if (component.canMarkAsFavorite) { + const favorites = []; + const notFavorites = []; + if (component.fav) { + favorites.push({ key: component.key }); + } else { + notFavorites.push({ key: component.key }); + } + dispatch(receiveFavorites(favorites, notFavorites)); + } + } +}; + +export default connect(mapStateToProps, mapDispatchToProps)(MeasureFavoriteContainer); diff --git a/server/sonar-web/src/main/js/apps/component-measures/components/MeasureOverview.js b/server/sonar-web/src/main/js/apps/component-measures/components/MeasureOverview.js index cab6f21fc1a..4dd6eb92774 100644 --- a/server/sonar-web/src/main/js/apps/component-measures/components/MeasureOverview.js +++ b/server/sonar-web/src/main/js/apps/component-measures/components/MeasureOverview.js @@ -21,8 +21,8 @@ import React from 'react'; import Breadcrumbs from './Breadcrumbs'; import BubbleChart from '../drilldown/BubbleChart'; -import Favorite from '../../../components/controls/Favorite'; import LeakPeriodLegend from './LeakPeriodLegend'; +import MeasureFavoriteContainer from './MeasureFavoriteContainer'; import PageActions from './PageActions'; import SourceViewer from '../../../components/SourceViewer/SourceViewer'; import { getComponentLeaves } from '../../../api/components'; @@ -154,8 +154,7 @@ export default class MeasureOverview extends React.PureComponent { /> {component.key !== rootComponent.key && isLoggedIn && - <Favorite - favorite={component.isFavorite === true} + <MeasureFavoriteContainer component={component.key} className="measure-favorite spacer-right" />} |