forked from apache/beam
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add cancel button to Prism UI (apache#30811)
* Add cancel button to Prism UI * Modify TODO fmt
- Loading branch information
1 parent
6f6bbe1
commit c44b454
Showing
3 changed files
with
110 additions
and
1 deletion.
There are no files selected for viewing
97 changes: 97 additions & 0 deletions
97
sdks/go/pkg/beam/runners/prism/internal/web/assets/job-action.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters