From ce80f2115245688992a727beeecd46ac43dca703 Mon Sep 17 00:00:00 2001 From: Stas Vilchik Date: Thu, 6 Dec 2018 15:53:55 +0100 Subject: remove some usages of legacy react context --- .../main/js/apps/web-api/components/WebApiApp.tsx | 28 +++++++--------------- 1 file changed, 8 insertions(+), 20 deletions(-) (limited to 'server/sonar-web/src/main/js/apps/web-api') diff --git a/server/sonar-web/src/main/js/apps/web-api/components/WebApiApp.tsx b/server/sonar-web/src/main/js/apps/web-api/components/WebApiApp.tsx index 77630d3f8a4..437b2b78fbd 100644 --- a/server/sonar-web/src/main/js/apps/web-api/components/WebApiApp.tsx +++ b/server/sonar-web/src/main/js/apps/web-api/components/WebApiApp.tsx @@ -18,9 +18,8 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ import * as React from 'react'; -import * as PropTypes from 'prop-types'; import Helmet from 'react-helmet'; -import { Link } from 'react-router'; +import { Link, withRouter, WithRouterProps } from 'react-router'; import Menu from './Menu'; import Search from './Search'; import Domain from './Domain'; @@ -30,29 +29,17 @@ import { getActionKey, isDomainPathActive, Query, serializeQuery, parseQuery } f import { scrollToElement } from '../../../helpers/scrolling'; import { translate } from '../../../helpers/l10n'; import Suggestions from '../../../app/components/embed-docs-modal/Suggestions'; -import { RawQuery } from '../../../helpers/query'; import '../styles/web-api.css'; -interface Props { - location: { pathname: string; query: RawQuery }; - params: { splat?: string }; -} +type Props = WithRouterProps; interface State { domains: DomainType[]; } -export default class WebApiApp extends React.PureComponent { +class WebApiApp extends React.PureComponent { mounted = false; - - static contextTypes = { - router: PropTypes.object.isRequired - }; - - constructor(props: Props) { - super(props); - this.state = { domains: [] }; - } + state: State = { domains: [] }; componentDidMount() { this.mounted = true; @@ -99,7 +86,7 @@ export default class WebApiApp extends React.PureComponent { updateQuery = (newQuery: Partial) => { const query = serializeQuery({ ...parseQuery(this.props.location.query), ...newQuery }); - this.context.router.push({ pathname: this.props.location.pathname, query }); + this.props.router.push({ pathname: this.props.location.pathname, query }); }; toggleInternalInitially() { @@ -127,14 +114,13 @@ export default class WebApiApp extends React.PureComponent { handleToggleInternal = () => { const splat = this.props.params.splat || ''; - const { router } = this.context; const { domains } = this.state; const domain = domains.find(domain => isDomainPathActive(domain.path, splat)); const query = parseQuery(this.props.location.query); const internal = !query.internal; if (domain && domain.internal && !internal) { - router.push({ + this.props.router.push({ pathname: '/web_api', query: { ...serializeQuery(query), internal: false } }); @@ -194,3 +180,5 @@ export default class WebApiApp extends React.PureComponent { ); } } + +export default withRouter(WebApiApp); -- cgit v1.2.3