Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Page.tsx #2270

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
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));