Skip to content

Commit

Permalink
refactor UNSAFE_componentWillReceiveProps to use componentDidUpdate
Browse files Browse the repository at this point in the history
Migrating these componentWillRecieveProps calls to componentDidUpdate in line with recommendations provided at https://reactjs.org/docs/react-component.html#unsafe_componentwillreceiveprops, stating "If you need to perform a side effect (for example, data fetching or an animation) in response to a change in props, use componentDidUpdate"

Signed-off-by: Tim Klever <Tim.V.Klever@aexp.com>
  • Loading branch information
tklever committed Aug 12, 2020
1 parent fe67712 commit 943a525
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 27 deletions.
7 changes: 3 additions & 4 deletions packages/jaeger-ui/src/components/App/Page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,9 @@ export class PageImpl extends React.Component<TProps> {
trackPageView(pathname, search);
}

// eslint-disable-next-line camelcase
UNSAFE_componentWillReceiveProps(nextProps: TProps) {
const { pathname, search } = this.props;
const { pathname: nextPathname, search: nextSearch } = nextProps;
componentDidUpdate(prevProps: Readonly<TProps>) {
const { pathname, search } = prevProps;
const { pathname: nextPathname, search: nextSearch } = this.props;
if (pathname !== nextPathname || search !== nextSearch) {
trackPageView(nextPathname, nextSearch);
}
Expand Down
5 changes: 2 additions & 3 deletions packages/jaeger-ui/src/components/DeepDependencies/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,8 @@ export class DeepDependencyGraphPageImpl extends React.PureComponent<TProps, TSt
}
}

// eslint-disable-next-line camelcase
UNSAFE_componentWillReceiveProps(nextProps: TProps) {
DeepDependencyGraphPageImpl.fetchModelIfStale(nextProps);
componentDidUpdate() {
DeepDependencyGraphPageImpl.fetchModelIfStale(this.props);
}

clearOperation = () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,9 @@ export default class TimelineViewingLayer extends React.PureComponent<TimelineVi
this._root = undefined;
}

// eslint-disable-next-line camelcase
UNSAFE_componentWillReceiveProps(nextProps: TimelineViewingLayerProps) {
componentDidUpdate(prevProps: Readonly<TimelineViewingLayerProps>) {
const { boundsInvalidator } = this.props;
if (boundsInvalidator !== nextProps.boundsInvalidator) {
if (prevProps.boundsInvalidator !== boundsInvalidator) {
this._draggerReframe.resetBounds();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,24 +179,29 @@ export class VirtualizedTraceViewImpl extends React.Component<VirtualizedTraceVi
return false;
}

// eslint-disable-next-line camelcase
UNSAFE_componentWillUpdate(nextProps: VirtualizedTraceViewProps) {
const { childrenHiddenIDs, detailStates, registerAccessors, trace, currentViewRangeTime } = this.props;
componentDidUpdate(prevProps: Readonly<VirtualizedTraceViewProps>) {
const { childrenHiddenIDs, detailStates, registerAccessors, trace, currentViewRangeTime } = prevProps;
const {
shouldScrollToFirstUiFindMatch,
clearShouldScrollToFirstUiFindMatch,
scrollToFirstVisibleSpan,
currentViewRangeTime: nextViewRangeTime,
childrenHiddenIDs: nextHiddenIDs,
detailStates: nextDetailStates,
registerAccessors: nextRegisterAccessors,
setTrace,
trace: nextTrace,
uiFind,
} = nextProps;
} = this.props;

if (trace !== nextTrace) {
setTrace(nextTrace, uiFind);
}

if (trace !== nextTrace || childrenHiddenIDs !== nextHiddenIDs || detailStates !== nextDetailStates) {
this.rowStates = nextTrace ? generateRowStates(nextTrace.spans, nextHiddenIDs, nextDetailStates) : [];
}

if (currentViewRangeTime !== nextViewRangeTime) {
this.clippingCssClasses = getCssClasses(nextViewRangeTime);
const [zoomStart, zoomEnd] = nextViewRangeTime;
Expand All @@ -207,17 +212,11 @@ export class VirtualizedTraceViewImpl extends React.Component<VirtualizedTraceVi
viewEnd: zoomEnd,
});
}

if (this.listView && registerAccessors !== nextRegisterAccessors) {
nextRegisterAccessors(this.getAccessors());
}
}

componentDidUpdate() {
const {
shouldScrollToFirstUiFindMatch,
clearShouldScrollToFirstUiFindMatch,
scrollToFirstVisibleSpan,
} = this.props;
if (shouldScrollToFirstUiFindMatch) {
scrollToFirstVisibleSpan();
clearShouldScrollToFirstUiFindMatch();
Expand Down
9 changes: 3 additions & 6 deletions packages/jaeger-ui/src/components/TracePage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -182,14 +182,11 @@ export class TracePageImpl extends React.PureComponent<TProps, TState> {
mergeShortcuts(shortcutCallbacks);
}

// eslint-disable-next-line camelcase
UNSAFE_componentWillReceiveProps(nextProps: TProps) {
const { trace } = nextProps;
this._scrollManager.setTrace(trace && trace.data);
}

componentDidUpdate({ id: prevID }: TProps) {
const { id, trace } = this.props;

this._scrollManager.setTrace(trace && trace.data);

this.setHeaderHeight(this._headerElm);
if (!trace) {
this.ensureTraceFetched();
Expand Down

0 comments on commit 943a525

Please sign in to comment.