-
Notifications
You must be signed in to change notification settings - Fork 206
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
base: master
Are you sure you want to change the base?
Conversation
please describe the relation to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- please describe the relation to
- Add option to restart jobs upon comment submission #5946 (comment)
- 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
7d7f709
to
e886fd5
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- please describe the relation to
- Add option to restart jobs upon comment submission #5946 (comment)
- 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
- 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]>
e886fd5
to
b1590ed
Compare
I will take a look on 3 tmr |
done(); | ||
}); | ||
|
||
if (actionBtn == 'restartAndCommentJobs') { | ||
//const commenttUrl = document.getElementById('CommentJobsBtn').dataset.url; |
There was a problem hiding this comment.
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'); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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"> |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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:
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" |
There was a problem hiding this comment.
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) %>" |
There was a problem hiding this comment.
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') { |
There was a problem hiding this comment.
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 ==
:
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; |
There was a problem hiding this comment.
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 = |
There was a problem hiding this comment.
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:
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:'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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'); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
addComments
tobulkJobsAction
to handle both commenting and restarting jobs.form.clickedButton
.fetchWithCSRF
logic to dynamically determine request URLs based on the button clicked.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