Skip to content

Commit ee3971f

Browse files
yaooqinnLuciferYang
authored andcommitted
[SPARK-51542][UI] Add a scroll-button for addressing top and bottom
### What changes were proposed in this pull request? This PR adds buttons for addressing the top and bottom of every page ### Why are the changes needed? This is a UI UX improvement. Currently, most of our pages cannot be shown on a single screen and the nav bar on top of them is not fixed to the screen, a.k.a, it disappears when we scroll down. This button meets the need for quickly locating the nav bar and/or something else on our UI. ### Does this PR introduce _any_ user-facing change? yes, an UI only change ### How was this patch tested? A new jest test for js added ![image](https://github.com/user-attachments/assets/26b1f24e-3ced-4992-8523-e1dddd4ec1b6) ### Was this patch authored or co-authored using generative AI tooling? no Closes apache#50305 from yaooqinn/SPARK-51542. Authored-by: Kent Yao <[email protected]> Signed-off-by: yangjie01 <[email protected]>
1 parent 2eafed5 commit ee3971f

File tree

4 files changed

+136
-0
lines changed

4 files changed

+136
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
19+
export { addScrollButton };
20+
21+
function createBtn(top = true) {
22+
const button = document.createElement('div');
23+
button.classList.add('scroll-btn-half');
24+
const className = top ? 'scroll-btn-top' : 'scroll-btn-bottom';
25+
button.classList.add(className);
26+
button.addEventListener('click', function () {
27+
window.scrollTo({
28+
top: top ? 0 : document.body.scrollHeight,
29+
behavior: 'smooth' });
30+
})
31+
return button;
32+
}
33+
34+
function addScrollButton() {
35+
const containerClass = 'scroll-btn-container';
36+
if (document.querySelector(`.${containerClass}`)) {
37+
return;
38+
}
39+
const container = document.createElement('div');
40+
container.className = containerClass;
41+
container.appendChild(createBtn());
42+
container.appendChild(createBtn(false));
43+
document.body.appendChild(container);
44+
}
45+
46+
document.addEventListener('DOMContentLoaded', function () {
47+
addScrollButton();
48+
});

core/src/main/resources/org/apache/spark/ui/static/webui.css

+52
Original file line numberDiff line numberDiff line change
@@ -446,3 +446,55 @@ a.downloadbutton {
446446
#active-executors-table th:first-child {
447447
border-left: 1px solid #dddddd;
448448
}
449+
450+
.scroll-btn-container {
451+
position: fixed;
452+
bottom: 20px;
453+
right: 20px;
454+
width: 48px;
455+
height: 80px;
456+
border-radius: 8px;
457+
background-color: rgba(0, 136, 204, 0.5);;
458+
display: flex;
459+
flex-direction: column;
460+
overflow: hidden;
461+
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
462+
}
463+
464+
.scroll-btn-half {
465+
flex: 1;
466+
display: flex;
467+
justify-content: center;
468+
align-items: center;
469+
cursor: pointer;
470+
transition: background-color 0.3s ease;
471+
position: relative;
472+
}
473+
474+
.scroll-btn-half:hover {
475+
background-color: rgba(0, 136, 204, 1);
476+
}
477+
478+
.scroll-btn-top::before {
479+
content: '';
480+
width: 0;
481+
height: 0;
482+
border-left: 10px solid transparent;
483+
border-right: 10px solid transparent;
484+
border-bottom: 15px solid white;
485+
position: absolute;
486+
top: 50%;
487+
transform: translateY(-50%);
488+
}
489+
490+
.scroll-btn-bottom::before {
491+
content: '';
492+
width: 0;
493+
height: 0;
494+
border-left: 10px solid transparent;
495+
border-right: 10px solid transparent;
496+
border-top: 15px solid white;
497+
position: absolute;
498+
bottom: 50%;
499+
transform: translateY(50%);
500+
}

core/src/main/scala/org/apache/spark/ui/UIUtils.scala

+1
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ private[spark] object UIUtils extends Logging {
222222
<script src={prependBaseUri(request, "/static/timeline-view.js")}></script>
223223
<script src={prependBaseUri(request, "/static/log-view.js")}></script>
224224
<script src={prependBaseUri(request, "/static/webui.js")}></script>
225+
<script src={prependBaseUri(request, "/static/scroll-button.js")} type="module"></script>
225226
<script>setUIRoot('{UIUtils.uiRoot(request)}')</script>
226227
}
227228

ui-test/tests/scroll-button.test.js

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
19+
import '../../core/src/main/resources/org/apache/spark/ui/static/jquery-3.5.1.min.js';
20+
import { addScrollButton } from '../../core/src/main/resources/org/apache/spark/ui/static/scroll-button.js';
21+
22+
/* global $ */
23+
24+
/**
25+
* @jest-environment jsdom
26+
*
27+
* eslint-disable no-unused-vars
28+
*/
29+
test('addScrollButton', function () {
30+
addScrollButton();
31+
expect($('.scroll-btn-container').length).toBe(1);
32+
expect($('.scroll-btn-half').length).toBe(2);
33+
expect($('.scroll-btn-top').length).toBe(1);
34+
expect($('.scroll-btn-bottom').length).toBe(1);
35+
});

0 commit comments

Comments
 (0)