]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-17295 Fixing scroll issue when searching for saml related properties
authorRevanshu Paliwal <revanshu.paliwal@sonarsource.com>
Mon, 19 Sep 2022 10:24:46 +0000 (12:24 +0200)
committersonartech <sonartech@sonarsource.com>
Wed, 21 Sep 2022 20:03:35 +0000 (20:03 +0000)
server/sonar-web/src/main/js/apps/settings/components/authentication/SamlAuthentication.tsx

index 05a8a9b44bfffc7180c2addad7f5e5861d754ff7..e0ccf340bfa68bffbce02e0c388a5e4f8da4b4b2 100644 (file)
@@ -87,19 +87,31 @@ class SamlAuthentication extends React.PureComponent<
   componentDidMount() {
     const { definitions } = this.props;
     const keys = definitions.map(definition => definition.key).join(',');
+    // Added setTimeout to make sure the component gets updated before scrolling
+    setTimeout(() => {
+      if (location.hash) {
+        this.scrollToSearchedField();
+      }
+    });
     this.loadSettingValues(keys);
   }
 
   componentDidUpdate(prevProps: SamlAuthenticationProps) {
     const { location } = this.props;
-    if (this.formFieldRef.current && prevProps.location.hash !== location.hash) {
+    if (prevProps.location.hash !== location.hash) {
+      this.scrollToSearchedField();
+    }
+  }
+
+  scrollToSearchedField = () => {
+    if (this.formFieldRef.current) {
       this.formFieldRef.current.scrollIntoView({
         behavior: 'smooth',
         block: 'center',
         inline: 'nearest'
       });
     }
-  }
+  };
 
   onFieldChange = (id: string, value: string | boolean) => {
     const { settingValue, dirtyFields } = this.state;