-
Notifications
You must be signed in to change notification settings - Fork 579
Feat/migrate page ,index and TraceIdSearch to functional component #2673
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ import { Layout } from 'antd'; | |
import cx from 'classnames'; | ||
import Helmet from 'react-helmet'; | ||
import { connect } from 'react-redux'; | ||
import { useEffect } from 'react'; | ||
|
||
import TopNav from './TopNav'; | ||
import { ReduxState } from '../../types'; | ||
|
@@ -36,38 +37,27 @@ type TProps = { | |
const { Header, Content } = Layout; | ||
|
||
// export for tests | ||
export class PageImpl extends React.Component<TProps> { | ||
componentDidMount() { | ||
const { pathname, search } = this.props; | ||
export const PageImpl: React.FC<TProps> = ({ children, embedded, pathname, search }) => { | ||
useEffect(() => { | ||
trackPageView(pathname, search); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. previously this was called conditionally. What happens now?
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @yurishkuro The conditional check |
||
} | ||
}, [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); | ||
} | ||
} | ||
const contentCls = cx({ 'Page--content': true, 'Page--content--no-embedded': !embedded }); | ||
|
||
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> | ||
); | ||
} | ||
} | ||
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) { | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -12,7 +12,7 @@ | |||||
// See the License for the specific language governing permissions and | ||||||
// limitations under the License. | ||||||
|
||||||
import React, { Component } from 'react'; | ||||||
import React from 'react'; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The import React, { useEffect } from 'react'; This will resolve the undefined reference to
Suggested change
Spotted by Diamond |
||||||
import { Provider } from 'react-redux'; | ||||||
import { Route, Redirect, Switch, Router } from 'react-router-dom'; | ||||||
|
||||||
|
@@ -77,62 +77,60 @@ const jaegerTheme = { | |||||
}, | ||||||
}; | ||||||
|
||||||
export default class JaegerUIApp extends Component { | ||||||
constructor(props) { | ||||||
super(props); | ||||||
JaegerAPI.apiRoot = DEFAULT_API_ROOT; | ||||||
processScripts(); | ||||||
} | ||||||
// Initialize API and process scripts | ||||||
JaegerAPI.apiRoot = DEFAULT_API_ROOT; | ||||||
processScripts(); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why is this ok to call this function unconditionally on importing index.jsx? Isn't there some lifecycle thing in functional components when it can be called? Is there an official recommendation for functions like this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i thought this is just a configuration step,which we can call at module level,but the |
||||||
|
||||||
render() { | ||||||
return ( | ||||||
<ConfigProvider theme={jaegerTheme}> | ||||||
<Provider store={store}> | ||||||
<HistoryProvider history={history}> | ||||||
<Router history={history}> | ||||||
<Page> | ||||||
<Switch> | ||||||
<Route path={searchPath}> | ||||||
<SearchTracePage /> | ||||||
</Route> | ||||||
<Route path={traceDiffPath}> | ||||||
<TraceDiff /> | ||||||
</Route> | ||||||
<Route path={tracePath}> | ||||||
<TracePage /> | ||||||
</Route> | ||||||
<Route path={dependenciesPath}> | ||||||
<DependencyGraph /> | ||||||
</Route> | ||||||
<Route path={deepDependenciesPath}> | ||||||
<DeepDependencies /> | ||||||
</Route> | ||||||
<Route path={qualityMetricsPath}> | ||||||
<QualityMetrics /> | ||||||
</Route> | ||||||
<Route path={monitorATMPath}> | ||||||
<MonitorATMPage /> | ||||||
</Route> | ||||||
const JaegerUIApp = () => { | ||||||
return ( | ||||||
<ConfigProvider theme={jaegerTheme}> | ||||||
<Provider store={store}> | ||||||
<HistoryProvider history={history}> | ||||||
<Router history={history}> | ||||||
<Page> | ||||||
<Switch> | ||||||
<Route path={searchPath}> | ||||||
<SearchTracePage /> | ||||||
</Route> | ||||||
<Route path={traceDiffPath}> | ||||||
<TraceDiff /> | ||||||
</Route> | ||||||
<Route path={tracePath}> | ||||||
<TracePage /> | ||||||
</Route> | ||||||
<Route path={dependenciesPath}> | ||||||
<DependencyGraph /> | ||||||
</Route> | ||||||
<Route path={deepDependenciesPath}> | ||||||
<DeepDependencies /> | ||||||
</Route> | ||||||
<Route path={qualityMetricsPath}> | ||||||
<QualityMetrics /> | ||||||
</Route> | ||||||
<Route path={monitorATMPath}> | ||||||
<MonitorATMPage /> | ||||||
</Route> | ||||||
|
||||||
<Route exact path="/"> | ||||||
<Redirect to={searchPath} /> | ||||||
</Route> | ||||||
<Route exact path={prefixUrl()}> | ||||||
<Redirect to={searchPath} /> | ||||||
</Route> | ||||||
<Route exact path={prefixUrl('/')}> | ||||||
<Redirect to={searchPath} /> | ||||||
</Route> | ||||||
<Route exact path="/"> | ||||||
<Redirect to={searchPath} /> | ||||||
</Route> | ||||||
<Route exact path={prefixUrl()}> | ||||||
<Redirect to={searchPath} /> | ||||||
</Route> | ||||||
<Route exact path={prefixUrl('/')}> | ||||||
<Redirect to={searchPath} /> | ||||||
</Route> | ||||||
|
||||||
<Route> | ||||||
<NotFound /> | ||||||
</Route> | ||||||
</Switch> | ||||||
</Page> | ||||||
</Router> | ||||||
</HistoryProvider> | ||||||
</Provider> | ||||||
</ConfigProvider> | ||||||
); | ||||||
} | ||||||
} | ||||||
<Route> | ||||||
<NotFound /> | ||||||
</Route> | ||||||
</Switch> | ||||||
</Page> | ||||||
</Router> | ||||||
</HistoryProvider> | ||||||
</Provider> | ||||||
</ConfigProvider> | ||||||
); | ||||||
}; | ||||||
|
||||||
export default JaegerUIApp; |
Uh oh!
There was an error while loading. Please reload this page.