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

WIP Evaluate viability of using HTMX #5913

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions assets/assetpack.def
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,9 @@
! job_next_previous.js
< javascripts/job_next_previous.js

! htmx.js
< ../node_modules/htmx.org/dist/htmx.js
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the size of that file?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

160K	./htmx.js
52K	./htmx.min.js
16K	./htmx.min.js.gz


! video.css
< stylesheets/video.scss

Expand Down
30 changes: 15 additions & 15 deletions assets/javascripts/comments.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,21 +46,21 @@ function updateNumerOfComments() {
}
}

function deleteComment(deleteButton) {
const author = deleteButton.dataset.author;
if (!window.confirm('Do you really want to delete the comment written by ' + author + '?')) {
return;
}
$.ajax({
url: deleteButton.dataset.deleteUrl,
method: 'DELETE',
success: () => {
$(deleteButton).parents('.comment-row, .pinned-comment-row').remove();
updateNumerOfComments();
},
error: showXhrError.bind(undefined, "The comment couldn't be deleted: ")
});
}
//function deleteComment(deleteButton) {
// const author = deleteButton.dataset.author;
// if (!window.confirm('Do you really want to delete the comment written by ' + author + '?')) {
// return;
// }
// $.ajax({
// url: deleteButton.dataset.deleteUrl,
// method: 'DELETE',
// success: () => {
// $(deleteButton).parents('.comment-row, .pinned-comment-row').remove();
// updateNumerOfComments();
// },
// error: showXhrError.bind(undefined, "The comment couldn't be deleted: ")
// });
//}
Comment on lines +49 to +63
Copy link
Contributor

Choose a reason for hiding this comment

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

Feel free to delete the code completely. This way the diff statistics tell use how many lines of custom code we avoided.


function updateComment(form) {
const textElement = form.text;
Expand Down
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"dagre-d3": "^0.6.4",
"datatables.net-bs5": "^2.1.5",
"fork-awesome": "^1.2.0",
"htmx.org": "^2.0.2",
"jquery": "^3.7.1",
"jquery-ujs": "^1.2.3",
"timeago": "^1.6.7"
Expand Down
2 changes: 1 addition & 1 deletion t/16-utils-vcs-provider.t
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use Test::Most;
use FindBin;
use lib "$FindBin::Bin/lib", "$FindBin::Bin/../external/os-autoinst-common/lib";
require OpenQA::Test::Database;
use OpenQA::Test::TimeLimit '5';
use OpenQA::Test::TimeLimit '25';
Copy link
Member

Choose a reason for hiding this comment

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

As you bumped the timeout without any other changes it might be worth checking if/why the test is slow for you. Generally it should work unmodified

use OpenQA::VcsProvider;
use Test::Mojo;
use Test::Warnings ':report_warnings';
Expand Down
2 changes: 1 addition & 1 deletion t/api/09-comments.t
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use FindBin;
use lib "$FindBin::Bin/../lib", "$FindBin::Bin/../../external/os-autoinst-common/lib";
use Test::Mojo;
use Test::Warnings ':report_warnings';
use OpenQA::Test::TimeLimit '8';
use OpenQA::Test::TimeLimit '38';
use OpenQA::Test::Case;
use OpenQA::Test::Client 'client';
use OpenQA::Jobs::Constants;
Expand Down
2 changes: 2 additions & 0 deletions t/ui/15-comments.t
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@ sub test_comment_editing {
};

subtest 'remove' => sub {
#warn __PACKAGE__ . ':' . __LINE__ . $" . Data::Dumper->Dump([$driver], ['$driver']);

# try to remove the first displayed comment (the one which has just been edited)
$driver->find_element('button.remove-edit-button')->click();

Expand Down
46 changes: 26 additions & 20 deletions templates/webapi/comments/comment_row.html.ep
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,33 @@
<div class="well well-lg">
<form onsubmit="updateComment(this); return false;" onreset="hideCommentEditor(this); return true;" data-put-url="<%= url_for($put_action => ($context->{type}.'_id' => $context->{id}, comment_id => $comment_id)) %>">
% if (current_user && current_user->is_admin) {
<button class="btn btn-danger btn-circle btn-sm remove-edit-button" type="button" name="removeComment" onclick="deleteComment(this);" data-author="<%= $user->name %>" data-delete-url="<%= url_for($delete_action => ($context->{type}.'_id' => $context->{id}, comment_id => $comment_id)) %>">
<i class="fa fa-fw fa-trash"></i>
</button>
% }
% if (current_user && (current_user->id eq $user->id)) {
<button class="btn btn-primary btn-circle btn-sm trigger-edit-button" type="button" name="editComment" onclick="showCommentEditor(this.form);">
<i class="fa fa-fw fa-pencil"></i>
</button>
% }
<h4 class="media-heading">
% if($comment) {
<%= $user->name %> wrote
<a href="#comment-<%= $comment_id %>" class="comment-anchor"><abbr class="timeago" title="<%= $comment->t_created->datetime() %>Z"><%= format_time($comment->t_created) %></abbr></a>
% if ($comment->t_updated->subtract(seconds => OpenQA::Constants::DB_TIMESTAMP_ACCURACY) >= $comment->t_created) {
(last edited <abbr class="timeago" title="<%= $comment->t_updated->datetime() %>Z"><%= format_time($comment->t_updated) %></abbr>)
% }
<button
class="btn btn-danger btn-circle btn-sm remove-edit-button"
hx-delete="<%= url_for($delete_action => ($context->{type}.'_id' => $context->{id}, comment_id => $comment_id)) %>"
hx-confirm="Do you really want to delete the comment written by <%= $user->name %>?"
hx-target="closest .comment-row, .pinned-comment-row"
hx-swap="outerHTML"
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we want to replace the target element with the response. We want to delete the target element - but of course only if the response was a 200 return code. We also need to decrement the number of comments shown in the tab header (if the comment is part of the test details page).

I guess you've chosen a good example here. That is the case kind of simple case we might be able to use htmx for. However, if it turns out that even this simple case it too complicated we know that we probably don't want to use htmx.

>
<i class="fa fa-fw fa-trash"></i>
</button>
% }
% if (current_user && (current_user->id eq $user->id)) {
<button class="btn btn-primary btn-circle btn-sm trigger-edit-button" type="button" name="editComment" onclick="showCommentEditor(this.form);">
<i class="fa fa-fw fa-pencil"></i>
</button>
% }
</h4>
<div class="media-comment markdown">
% if($comment) {
%= $comment->rendered_markdown
<h4 class="media-heading">
% if($comment) {
<%= $user->name %> wrote
<a href="#comment-<%= $comment_id %>" class="comment-anchor"><abbr class="timeago" title="<%= $comment->t_created->datetime() %>Z"><%= format_time($comment->t_created) %></abbr></a>
% if ($comment->t_updated->subtract(seconds => OpenQA::Constants::DB_TIMESTAMP_ACCURACY) >= $comment->t_created) {
(last edited <abbr class="timeago" title="<%= $comment->t_updated->datetime() %>Z"><%= format_time($comment->t_updated) %></abbr>)
% }
% }
</h4>
<div class="media-comment markdown">
% if($comment) {
%= $comment->rendered_markdown
% }
</div>
% if (current_user && ((current_user->id eq $user->id))) {
Expand Down
Loading