Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 23 additions & 47 deletions packages/jaeger-ui/src/components/App/Page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<TProps> {
componentDidMount() {
const { pathname, search } = this.props;
const Page = ({ children, embedded, pathname, search }) => {
React.useEffect(() => {
trackPageView(pathname, search);
}

componentDidUpdate(prevProps: Readonly<TProps>) {
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 (
<div>
<Helmet title="Jaeger UI" />
<Layout>
{!embedded && (
<Header className="Page--topNav">
<TopNav />
</Header>
)}
<Content className={contentCls}>{this.props.children}</Content>
</Layout>
</div>
);
}
}
}, [pathname, search]);

const contentCls = cx({ 'Page--content': true, 'Page--content--no-embedded': !embedded });

return (
<div>
<Helmet title="Jaeger UI" />
<Layout>
{!embedded && (
<Header className="Page--topNav">
<TopNav />
</Header>
)}
<Content className={contentCls}>{children}</Content>
</Layout>
</div>
);
};

// 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));
Loading