You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@beam.apache.org by jr...@apache.org on 2024/04/02 20:21:49 UTC
(beam) branch master updated: Add cancel button to Prism UI (#30811)
This is an automated email from the ASF dual-hosted git repository.
jrmccluskey pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/beam.git
The following commit(s) were added to refs/heads/master by this push:
new c44b4542627 Add cancel button to Prism UI (#30811)
c44b4542627 is described below
commit c44b45426274024d9b29683a0753706fcb9e7632
Author: Damon <da...@users.noreply.github.com>
AuthorDate: Tue Apr 2 13:21:42 2024 -0700
Add cancel button to Prism UI (#30811)
* Add cancel button to Prism UI
* Modify TODO fmt
---
.../prism/internal/web/assets/job-action.js | 97 ++++++++++++++++++++++
.../runners/prism/internal/web/assets/style.css | 8 +-
.../runners/prism/internal/web/jobdetails.html | 6 ++
3 files changed, 110 insertions(+), 1 deletion(-)
diff --git a/sdks/go/pkg/beam/runners/prism/internal/web/assets/job-action.js b/sdks/go/pkg/beam/runners/prism/internal/web/assets/job-action.js
new file mode 100644
index 00000000000..999fd22bbf8
--- /dev/null
+++ b/sdks/go/pkg/beam/runners/prism/internal/web/assets/job-action.js
@@ -0,0 +1,97 @@
+/**
+ Licensed 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.
+ */
+
+/** Element class for job action container. */
+const JOB_ACTION = '.job-action'
+
+/** Element class for cancel button. */
+const CANCEL = '.cancel'
+
+/** Element class assigned to RUNNING Job state. */
+const RUNNING = 'RUNNING'
+
+/**
+ * Client for Job Management.
+ *
+ * Invokes backend for various Job Management tasks.
+ */
+const jobManager = {
+
+ /**
+ * Cancel a Job.
+ * Invokes backend handler to request a Job cancellation state.
+ * @param jobId
+ * TODO(https://github.com/apache/beam/issues/29669) Send request to backend service.
+ */
+ cancel: function(jobId) {
+ console.debug(`cancel button for Job: ${jobId} clicked`)
+ }
+}
+
+/**
+ * Encapsulates UI state such as enabling/disabling elements and querying various elements and their properties.
+ */
+const uiStateProvider = {
+
+ /**
+ * Queries the DOM for the Job Action container.
+ * Logs an error if not found.
+ * @returns {Element}
+ */
+ get jobAction() {
+ let element = document.querySelector(JOB_ACTION)
+ if (element === null) {
+ console.error(`no element found at ${JOB_ACTION}`)
+ }
+ return element
+ },
+
+ /**
+ * Queries Job Action container DOM for the cancel button.
+ * Logs an error if not found.
+ * @returns {Element}
+ */
+ get cancelButton() {
+ let element = this.jobAction.querySelector(CANCEL)
+ if (element === null) {
+ console.error(`no element found at ${CANCEL} within ${this.jobAction}`)
+ }
+ return element
+ },
+
+ /**
+ * Initializes the uiStateManager.
+ * Called from the window's load event.
+ */
+ init() {
+ this.cancelButton.disabled = this.isStateRunning === false
+ },
+
+ /**
+ * Queries whether the Job Action container contains the RUNNING class name.
+ * @returns {boolean}
+ */
+ get isStateRunning() {
+ return this.jobAction.classList.contains(RUNNING)
+ }
+}
+
+/**
+ * Attaches an event listener to the window for 'load' events.
+ */
+window.addEventListener("load", function(){
+ console.debug(JOB_ACTION, uiStateProvider.jobAction)
+ console.debug(CANCEL, uiStateProvider.cancelButton)
+ uiStateProvider.init()
+})
diff --git a/sdks/go/pkg/beam/runners/prism/internal/web/assets/style.css b/sdks/go/pkg/beam/runners/prism/internal/web/assets/style.css
index d252dc020e6..48cc7acecb3 100644
--- a/sdks/go/pkg/beam/runners/prism/internal/web/assets/style.css
+++ b/sdks/go/pkg/beam/runners/prism/internal/web/assets/style.css
@@ -205,4 +205,10 @@ footer {
display: inline-block;
margin-bottom: 10px;
}
-}
\ No newline at end of file
+}
+
+/* Make Job action related buttons more visible. */
+.job-action button {
+ border-radius: 5px;
+ padding: 5px;
+}
diff --git a/sdks/go/pkg/beam/runners/prism/internal/web/jobdetails.html b/sdks/go/pkg/beam/runners/prism/internal/web/jobdetails.html
index cfe82c15147..ff87f677e2d 100644
--- a/sdks/go/pkg/beam/runners/prism/internal/web/jobdetails.html
+++ b/sdks/go/pkg/beam/runners/prism/internal/web/jobdetails.html
@@ -18,6 +18,7 @@ limitations under the License. See accompanying LICENSE file.
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>{{.JobID}} - {{ .JobName }} - Job Details - Beam Prism</title>
<link rel="stylesheet" href="/assets/style.css" />
+ <script src="/assets/job-action.js"></script>
{{/*
<meta http-equiv="refresh" content="10"> refresh page every 10 seconds */}}
</head>
@@ -27,6 +28,11 @@ limitations under the License. See accompanying LICENSE file.
<header>
<a class="logo" href="/">Job Details - Beam Prism</a>
<div>{{.JobID}} - {{ .JobName }}</div>
+ <div class="job-action {{.State}}">
+ <button class="cancel"
+ onclick="if (jobManager !== null) { jobManager.cancel('{{.JobID}}') }"
+ >Cancel</button>
+ </div>
<div>{{.State}}</div>
</header>
<section class="container">