From e377ee8c0a152016507ca97d42ed52a170d9d7ed Mon Sep 17 00:00:00 2001 From: Mathieu Suen Date: Mon, 25 Apr 2022 10:41:31 +0200 Subject: [PATCH] SONAR-16297 Replace React legacy lifecycle methods in the global Search --- .../sonar-web/src/main/js/app/components/search/Search.tsx | 5 +---- .../src/main/js/app/components/search/SearchResult.tsx | 6 +++--- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/server/sonar-web/src/main/js/app/components/search/Search.tsx b/server/sonar-web/src/main/js/app/components/search/Search.tsx index 9d3c30f43ff..4ddad49b88e 100644 --- a/server/sonar-web/src/main/js/app/components/search/Search.tsx +++ b/server/sonar-web/src/main/js/app/components/search/Search.tsx @@ -84,10 +84,6 @@ export class Search extends React.PureComponent { }); } - componentWillUpdate() { - this.nodes = {}; - } - componentDidUpdate(_prevProps: WithRouterProps, prevState: State) { if (prevState.selected !== this.state.selected) { this.scrollToSelected(); @@ -171,6 +167,7 @@ export class Search extends React.PureComponent { if (this.mounted && this.state.query === query) { const results: Results = {}; const more: More = {}; + this.nodes = {}; response.results.forEach(group => { results[group.q] = group.items.map(item => ({ ...item, qualifier: group.q })); more[group.q] = group.more; diff --git a/server/sonar-web/src/main/js/app/components/search/SearchResult.tsx b/server/sonar-web/src/main/js/app/components/search/SearchResult.tsx index 6856767f4c5..a34ee40cfd3 100644 --- a/server/sonar-web/src/main/js/app/components/search/SearchResult.tsx +++ b/server/sonar-web/src/main/js/app/components/search/SearchResult.tsx @@ -53,10 +53,10 @@ export default class SearchResult extends React.PureComponent { } } - componentWillReceiveProps(nextProps: Props) { - if (!this.props.selected && nextProps.selected) { + componentDidUpdate(prevProps: Props) { + if (!prevProps.selected && this.props.selected) { this.scheduleTooltip(); - } else if (this.props.selected && !nextProps.selected) { + } else if (prevProps.selected && !this.props.selected) { this.unscheduleTooltip(); this.setState({ tooltipVisible: false }); } -- 2.39.5