LuciferYang commented on code in PR #50305:
URL: https://github.com/apache/spark/pull/50305#discussion_r2001229805


##########
core/src/main/resources/org/apache/spark/ui/static/scroll-button.js:
##########
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* global $ */
+
+export { addScrollButton };
+
+function addScrollButton() {
+  const container = $('<div></div>', {
+    'class': 'scroll-btn-container'
+  });
+
+  const topBtn = $('<div></div>', {
+    'class': 'scroll-btn-half scroll-btn-top'
+  }).click(function () {
+    $('html, body').animate({scrollTop: 0}, 'slow');

Review Comment:
   I prefer using window.scrollTo with behavior: smooth instead of jQuery 
animate to reduce repaint overhead."



##########
core/src/main/scala/org/apache/spark/ui/UIUtils.scala:
##########
@@ -222,6 +222,7 @@ private[spark] object UIUtils extends Logging {
     <script src={prependBaseUri(request, "/static/timeline-view.js")}></script>
     <script src={prependBaseUri(request, "/static/log-view.js")}></script>
     <script src={prependBaseUri(request, "/static/webui.js")}></script>
+    <script src={prependBaseUri(request, "/static/scroll-button.js")} 
type="module"></script>
     <script>setUIRoot('{UIUtils.uiRoot(request)}')</script>

Review Comment:
   
![image](https://github.com/user-attachments/assets/ba655740-f029-4543-bfe4-3c57a9b8cc76)
   
   Interesting. this `</script>` is red..
   
   



##########
core/src/main/resources/org/apache/spark/ui/static/scroll-button.js:
##########
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* global $ */
+
+export { addScrollButton };
+
+function addScrollButton() {
+  const container = $('<div></div>', {
+    'class': 'scroll-btn-container'
+  });
+
+  const topBtn = $('<div></div>', {
+    'class': 'scroll-btn-half scroll-btn-top'
+  }).click(function () {
+    $('html, body').animate({scrollTop: 0}, 'slow');
+  });
+
+  const bottomBtn = $('<div></div>', {

Review Comment:
   Perhaps we can define some functions to improve code reusability, like 
   ```
   function scrollToTop() {
     window.scrollTo({ top: 0, behavior: 'smooth' });
   }
   
   function scrollToBottom() {
     window.scrollTo({ top: document.documentElement.scrollHeight, behavior: 
'smooth' });
   }
   
   function createScrollBtn(className, handler) {
     return $('<div>', { class: `${config.btnClass} ${className}` })
       .on('click', function(e) {
         handler();
         $(this).addClass(config.activeClass)
                .delay(300)
                .queue(() => $(this).removeClass(config.activeClass).dequeue());
       });
   }
   ```
   
   then 
   
   ```
   const topBtn = createScrollBtn(config.topBtnClass, scrollToTop);
    const bottomBtn = createScrollBtn(config.bottomBtnClass, scrollToBottom);
   ```
   
   



##########
core/src/main/resources/org/apache/spark/ui/static/scroll-button.js:
##########
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* global $ */
+
+export { addScrollButton };

Review Comment:
   It's best to define a `config` to manage style classes, like 
   
   ```
   const config = {
     containerClass: 'scroll-btn-container',
     btnClass: 'scroll-btn-half',
     topBtnClass: 'scroll-btn-top',
     bottomBtnClass: 'scroll-btn-bottom',
     activeClass: 'active'
   };
   ```



##########
core/src/main/resources/org/apache/spark/ui/static/scroll-button.js:
##########
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* global $ */
+
+export { addScrollButton };
+
+function addScrollButton() {

Review Comment:
   can add a container existence check to avoid duplicate injections, like 
   
   ```
   if ($(`.${config.containerClass}`).length) return;
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to