]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-16297 Replace React legacy lifecycle methods in the global Search
authorMathieu Suen <mathieu.suen@sonarsource.com>
Mon, 25 Apr 2022 08:41:31 +0000 (10:41 +0200)
committersonartech <sonartech@sonarsource.com>
Mon, 25 Apr 2022 20:02:45 +0000 (20:02 +0000)
server/sonar-web/src/main/js/app/components/search/Search.tsx
server/sonar-web/src/main/js/app/components/search/SearchResult.tsx

index 9d3c30f43ffee11ee77bf9bfe5ddecba85750f32..4ddad49b88e4b73218d61296ee356aad9cb0254c 100644 (file)
@@ -84,10 +84,6 @@ export class Search extends React.PureComponent<WithRouterProps, State> {
     });
   }
 
-  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<WithRouterProps, State> {
         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;
index 6856767f4c54ece9296c846bc7f5d4c1cb474ac4..a34ee40cfd3d0e44f38665b8cae0e37890d3c439 100644 (file)
@@ -53,10 +53,10 @@ export default class SearchResult extends React.PureComponent<Props, State> {
     }
   }
 
-  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 });
     }