diff --git a/packages/jaeger-ui/src/components/App/Page.tsx b/packages/jaeger-ui/src/components/App/Page.tsx index 810bcabc61..bc6d10220b 100644 --- a/packages/jaeger-ui/src/components/App/Page.tsx +++ b/packages/jaeger-ui/src/components/App/Page.tsx @@ -17,63 +17,39 @@ import { Layout } from 'antd'; import cx from 'classnames'; import Helmet from 'react-helmet'; import { connect } from 'react-redux'; - import TopNav from './TopNav'; -import { ReduxState } from '../../types'; -import { EmbeddedState } from '../../types/embedded'; import { trackPageView } from '../../utils/tracking'; - import './Page.css'; import withRouteProps from '../../utils/withRouteProps'; -type TProps = { - children: React.ReactNode; - embedded: EmbeddedState; - pathname: string; - search: string; -}; - const { Header, Content } = Layout; -// export for tests -export class PageImpl extends React.Component { - componentDidMount() { - const { pathname, search } = this.props; +const Page = ({ children, embedded, pathname, search }) => { + React.useEffect(() => { trackPageView(pathname, search); - } - - componentDidUpdate(prevProps: Readonly) { - const { pathname, search } = prevProps; - const { pathname: nextPathname, search: nextSearch } = this.props; - if (pathname !== nextPathname || search !== nextSearch) { - trackPageView(nextPathname, nextSearch); - } - } - - render() { - const { embedded } = this.props; - const contentCls = cx({ 'Page--content': true, 'Page--content--no-embedded': !embedded }); - return ( -
- - - {!embedded && ( -
- -
- )} - {this.props.children} -
-
- ); - } -} + }, [pathname, search]); + + const contentCls = cx({ 'Page--content': true, 'Page--content--no-embedded': !embedded }); + + return ( +
+ + + {!embedded && ( +
+ +
+ )} + {children} +
+
+ ); +}; -// export for tests -export function mapStateToProps(state: ReduxState) { +const mapStateToProps = (state) => { const { embedded } = state; const { pathname, search } = state.router.location; return { embedded, pathname, search }; -} +}; -export default connect(mapStateToProps)(withRouteProps(PageImpl)); +export default connect(mapStateToProps)(withRouteProps(Page));