Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to restart jobs upon comment submission #5971

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

b10n1k
Copy link
Contributor

@b10n1k b10n1k commented Oct 2, 2024

  • Renamed addComments to bulkJobsAction to handle both commenting and restarting jobs.
  • Added button-specific actions using form.clickedButton.
  • Updated fetchWithCSRF logic to dynamically determine request URLs based on the button clicked.
  • Introduced separate success and error messages for restarting and commenting actions.
  • Updated HTML to include "Restart and Comment" and "Comment" buttons with individual data URLs.
  • Adjusted modal to allow submission of comments or restarts through the correct action handlers.

These updates enhance the user experience by allowing users to either comment on jobs, or perform restart with a comment simultaneously from the overview page. Comments always add to the original job of the overview page. By integrating this functionality we provide a workflow for users managing multiple jobs on the overview page.

https://progress.opensuse.org/issues/166559

@b10n1k
Copy link
Contributor Author

b10n1k commented Oct 2, 2024

overview_modal
overview_modal_submitted

@okurz
Copy link
Member

okurz commented Oct 2, 2024

please describe the relation to

Copy link
Member

@okurz okurz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. please describe the relation to
  1. Add option to restart jobs upon comment submission #5946 (comment)
  2. The icon on /tests/overview should be changed. I was thinking of
<span class="fa-stack fa-2x">
    <i class="fa fa-comment" aria-hidden="true"></i>
    <i class="fa fa-undo" aria-hidden="true"></i>
  </span>

which probably needs CSS adaptations to work

@b10n1k b10n1k force-pushed the batch_restart_with_comment branch 2 times, most recently from 7d7f709 to e886fd5 Compare October 3, 2024 12:12
Copy link

codecov bot commented Oct 3, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.75%. Comparing base (a94bc42) to head (e886fd5).
Report is 12 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5971      +/-   ##
==========================================
- Coverage   98.75%   98.75%   -0.01%     
==========================================
  Files         396      396              
  Lines       38983    38983              
==========================================
- Hits        38499    38496       -3     
- Misses        484      487       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@okurz okurz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. please describe the relation to
  1. Add option to restart jobs upon comment submission #5946 (comment)
  2. The icon on /tests/overview should be changed. I was thinking of
<span class="fa-stack fa-2x">
    <i class="fa fa-comment" aria-hidden="true"></i>
    <i class="fa fa-undo" aria-hidden="true"></i>
  </span>

which probably needs CSS adaptations to work
4. inline comments

assets/javascripts/overview.js Outdated Show resolved Hide resolved
t/ui/10-tests_overview.t Outdated Show resolved Hide resolved
templates/webapi/test/overview.html.ep Outdated Show resolved Hide resolved
- Renamed `addComments` to `bulkJobsAction` to handle both commenting and
restarting jobs.
- Added button-specific actions using `form.clickedButton`.
- Updated `fetchWithCSRF` logic to dynamically determine request URLs based on
the button clicked.
- Introduced separate success and error messages for restarting and commenting
actions.
- Updated HTML to include "Restart and Comment" and "Comment" buttons with
individual data URLs.
- Adjusted modal to allow submission of comments or restarts through the
correct action handlers.

These updates enhance the user experience by allowing users to either comment
on jobs, or perform restart with a comment simultaneously from the
overview page. Comments always add to the original job of the overview
page. By integrating this functionality we provide a workflow for
users managing multiple jobs on the overview page.

https://progress.opensuse.org/issues/166559

Signed-off-by: Ioannis Bonatakis <[email protected]>
@b10n1k
Copy link
Contributor Author

b10n1k commented Oct 3, 2024

fa-comment

I will take a look on 3 tmr

done();
});

if (actionBtn == 'restartAndCommentJobs') {
//const commenttUrl = document.getElementById('CommentJobsBtn').dataset.url;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't add disabled code as nobody but you will understand why this is not active. Better leave it out and keep in your local git repository, either in git stash or a temporary "WIP"-commit

See https://github.com/os-autoinst/os-autoinst-distri-opensuse/blob/master/CONTRIBUTING.md#coding-style for more details

fetchWithCSRF(reqUrl, {method: 'POST', body: new FormData(form)})
.then(response => {
if (!response.ok) throw `Server returned ${response.status}: ${response.statusText}`;
addFlash('info', 'The comments have been created on the previous jobs');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this looks like a new flash. But there is already a info text with the reload link. Isn't this redundant?

Copy link
Contributor

@Martchus Martchus Oct 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(@okurz as this was actually a comment in reply to your remark.) It looks like with this approach the JavaScript code will first do the restarting and after that do the commenting. So I guess it is acceptable to also show two flash messages for this. Of course it would be nicer if both were combined.

However, the way these actions are combined here in terms of error handling is probably generally very problematic anyway, see my other inline comment.

Note that I would have preferred a solution where this is combined by the API on the server rather than in JavaScript code. This way the feature could also be used via e.g. openqa-cli and we generally have less back-and-forth between the server and client. The commenting could also be atomic this way¹.

(With this approach here we can have the annoying "error case outcome" that all jobs have been restarted but the comment creation failed at some point in the middle. This leaves it in an inconsistent state that the user cannot really repair (except by redoing the commenting manually).)

@@ -42,7 +42,8 @@
<div class="card-body">
% my $allow_commenting = @$job_ids && current_user;
% if ($allow_commenting) {
<button type="button" class="btn btn-secondary btn-circle btn-sm trigger-edit-button" onclick="showAddCommentsDialog()" title="Add comments">
<button type="button" class="btn btn-secondary btn-circle btn-sm
trigger-edit-button" onclick="showAddCommentsDialog()" title="Add comments or restart Jobs">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I now realize that there is inconsistent phrasing "Add comments and/or restart [jJ]obs" or "Restart and/or comment jobs". I suggest a consistent phrasing "Restart or comment jobs". Mind the proper casing. I am using "comment" as a verb replacing "Add comments". Also I am using "or" here as inclusive or meaning that it's one of restarting, commenting, restarting && commenting. And please use consistent phrasing in all cases including the button labels and javascript functions.

const text = form.elements.text.value;
if (!text.length) {
return window.alert("The comment text mustn't be empty.");
}
const actionBtn = form.clickedButton.value;
let reqUrl = form.clickedButton.dataset.url || form.action;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, this should probably use ?? to make the intention of the fallback more clear:

Suggested change
let reqUrl = form.clickedButton.dataset.url || form.action;
let reqUrl = form.clickedButton.dataset.url ?? form.action;

<i class="fa fa-play-circle-o"></i> Restart and Comment <%= scalar @$job_ids %> jobs
</button>
<button type="submit" name="bulkAction" class="btn btn-info"
value="commentJobs" id="CommentJobsBtn"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please start IDs with lower case characters.

</button>
<button type="submit" name="bulkAction" class="btn btn-info"
value="commentJobs" id="CommentJobsBtn"
data-url="<%= url_for('apiv1_post_comments')->query(job_id=>$job_ids) %>"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could use formaction here instead of a generic data attribute. It might also make sense to turn the form's action attribute into a formaction attribute of the other button. This way both URLs are defined on the same level.

let infoTxt =
'The comments have been created. <a href="javascript: location.reload()">Reload</a> the page to show changes.';
let errTxt = 'The comments could not be added:';
if (actionBtn == 'restartAndCommentJobs') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please follow common best practices, e.g. preferring === over ==:

Suggested change
if (actionBtn == 'restartAndCommentJobs') {
if (actionBtn === 'restartAndCommentJobs') {

This concerns other occurrences as well.

const text = form.elements.text.value;
if (!text.length) {
return window.alert("The comment text mustn't be empty.");
}
const actionBtn = form.clickedButton.value;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

form.clickedButton might not be set if the form was submitted by other means than clicking one of the two buttons. The code has to handle that. Maybe it is good enough to simply return early.

@@ -301,17 +303,38 @@ function addComments(form) {
controls.style.display = 'inline';
window.addCommentsModal.hide();
};
fetchWithCSRF(form.action, {method: 'POST', body: new FormData(form)})

let infoTxt =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would avoid over-abbreviating variable names:

Suggested change
let infoTxt =
let infoText =


let infoTxt =
'The comments have been created. <a href="javascript: location.reload()">Reload</a> the page to show changes.';
let errTxt = 'The comments could not be added:';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let errTxt = 'The comments could not be added:';
let errorText = 'The comments could not be added:';

if (actionBtn == 'restartAndCommentJobs') {
//const commenttUrl = document.getElementById('CommentJobsBtn').dataset.url;
reqUrl = document.getElementById('CommentJobsBtn').dataset.url;
console.log('iob ' + reqUrl);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
console.log('iob ' + reqUrl);

fetchWithCSRF(reqUrl, {method: 'POST', body: new FormData(form)})
.then(response => {
if (!response.ok) throw `Server returned ${response.status}: ${response.statusText}`;
addFlash('info', 'The comments have been created on the previous jobs');
Copy link
Contributor

@Martchus Martchus Oct 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(@okurz as this was actually a comment in reply to your remark.) It looks like with this approach the JavaScript code will first do the restarting and after that do the commenting. So I guess it is acceptable to also show two flash messages for this. Of course it would be nicer if both were combined.

However, the way these actions are combined here in terms of error handling is probably generally very problematic anyway, see my other inline comment.

Note that I would have preferred a solution where this is combined by the API on the server rather than in JavaScript code. This way the feature could also be used via e.g. openqa-cli and we generally have less back-and-forth between the server and client. The commenting could also be atomic this way¹.

(With this approach here we can have the annoying "error case outcome" that all jobs have been restarted but the comment creation failed at some point in the middle. This leaves it in an inconsistent state that the user cannot really repair (except by redoing the commenting manually).)

'info',
'The comments have been created. <a href="javascript: location.reload()">Reload</a> the page to show changes.'
);
addFlash('info', infoTxt);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not good enough. In case of a 200 response not all jobs might have been restarted. In fact, no jobs might have been restarted at all.

When restarting jobs, you might get a 200 response like {"enforceable":1,"errors":["Job 4339 misses the following mandatory assets: iso\/foo.iso\nEnsure to provide mandatory assets and\/or force re-triggering if necessary."],"warnings",[],"result":[],"test_url":[]}. The code has to display those errors and allow the user to force the restart if possible. There can also be warnings which also need to be displayed.

I suggest you check how restarting is dealt with in other places of the UI (like the job details page) and see what code you can share.

The code should also read the set of jobs that actually was restarted from the response and then do the commenting only on those jobs (because the comment is likely something like "I am restarting these jobs because of …") so it probably makes no sense to write the comments when the restart didn't actually happen.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants