Skip to content

Commit

Permalink
HARMONY-1892: Change what links are shown for job status change actio…
Browse files Browse the repository at this point in the history
…ns to be union instead of intersection
  • Loading branch information
vinnyinverso committed Nov 13, 2024
1 parent 7711d23 commit 39a3205
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<tr id="job-{{jobID}}" class='job-table-row'>
<tr id="job-{{jobID}}" class='job-table-row' data-status="{{status}}">
<td>{{{jobSelectBox}}}</td>
<th scope="row"><a href="workflow-ui/{{jobID}}{{jobLinkQuery}}">{{jobID}}</a></th>
<td>{{service_name}}</td>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,10 @@ class JobsStatusChangeLinks extends StatusChangeLinks {
event.preventDefault();
const link = event.target;
const jobIDs = jobsTable.getJobIds();
const postfix = jobIDs.length > 1 ? 's' : '';
const actionableJobIDs = this.getActionableJobIDs(jobIDs, link);
const postfix = actionableJobIDs.length > 1 ? 's' : '';
// eslint-disable-next-line no-alert, no-restricted-globals
if (!confirm(`Are you sure you want to ${(link.textContent || link.innerText).trim()} ${jobIDs.length} job${postfix}?`)) {
if (!confirm(`Are you sure you want to ${(link.textContent || link.innerText).trim()} ${actionableJobIDs.length} job${postfix}?`)) {
return;
}
toasts.showUpper('Changing job state...');
Expand All @@ -57,10 +58,10 @@ class JobsStatusChangeLinks extends StatusChangeLinks {
Accept: 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify({ jobIDs }),
body: JSON.stringify({ jobIDs: actionableJobIDs }),
});
const data = await res.json();
const isAre = jobIDs.length > 1 ? 'are' : 'is';
const isAre = actionableJobIDs.length > 1 ? 'are' : 'is';
if (res.status === 200) {
toasts.showUpper(`The selected job${postfix} ${isAre} now ${data.status}.`);
} else if (data.description) {
Expand All @@ -73,6 +74,25 @@ class JobsStatusChangeLinks extends StatusChangeLinks {
);
}

/**
* Filter the job IDs to only those jobs that can be operated on by the action
* represented by the link's href attribute.
* @param {string[]} jobIDs - the job IDs to filter
* @param {EventTarget} link - the link whose href will be used as the filter
* @returns filtered list of job IDs
*/
getActionableJobIDs(jobIDs, link) {
const actionableJobIDs = [];
for (const jobID of jobIDs) {
const links = this.fetchLinksForStatuses([jobsTable.getJobStatus(jobID)]);
const jobHasTargetLink = links.some((linkForStatus) => link.getAttribute('href') === linkForStatus.href);
if (jobHasTargetLink) {
actionableJobIDs.push(jobID);
}
}
return actionableJobIDs;
}

/**
* Get job state change links (pause, resume, etc.) depending on jobs' statuses.
* @param {string[]} statuses - fetch links relevant to these job statuses
Expand All @@ -83,25 +103,17 @@ class JobsStatusChangeLinks extends StatusChangeLinks {
const hasRunningWithErrors = statuses.indexOf('running_with_errors') > -1;
const hasPreviewing = statuses.indexOf('previewing') > -1;
const hasPaused = statuses.indexOf('paused') > -1;
const hasCompleteWithErrors = statuses.indexOf('complete_with_errors') > -1;
const hasCanceled = statuses.indexOf('canceled') > -1;
const hasFailed = statuses.indexOf('failed') > -1;
const hasSuccessful = statuses.indexOf('successful') > -1;
const hasTerminalStatus = hasCompleteWithErrors || hasCanceled || hasFailed || hasSuccessful;
if (hasTerminalStatus) {
return [];
}
const hasActionableStatus = hasRunning || hasRunningWithErrors || hasPreviewing || hasPaused;
if (hasActionableStatus) {
const hasActiveStatus = hasRunning || hasRunningWithErrors || hasPreviewing;
if (hasActiveStatus || hasPaused) {
links.push(cancelLink);
}
if (!hasPaused && hasActionableStatus) {
if (hasActiveStatus) {
links.push(pauseLink);
}
if (hasPaused && !hasRunning && !hasRunningWithErrors && !hasPreviewing) {
if (hasPaused) {
links.push(resumeLink);
}
if (hasPreviewing && !hasRunning && !hasRunningWithErrors && !hasPaused) {
if (hasPreviewing) {
links.push(skipPreviewLink);
}
return links;
Expand Down
9 changes: 9 additions & 0 deletions services/harmony/public/js/workflow-ui/jobs/jobs-table.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,15 @@ const jobsTable = {
getJobIds() {
return jobIDs;
},

/**
* Gets the status of the specified job.
* @param {string} jobID - the job to retrieve status for
* @returns the job status string
*/
getJobStatus(jobID) {
return document.querySelector(`#job-${jobID}`).getAttribute('data-status');
},
};

export default jobsTable;

0 comments on commit 39a3205

Please sign in to comment.