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

Instantly display the 'You reported the X' message #15299

Merged
merged 1 commit into from
Dec 4, 2023
Merged
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
22 changes: 22 additions & 0 deletions src/api/app/assets/javascripts/webui/report.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,28 @@ function hideReportButton(element) {
$(element).addClass('d-none');
}

/* exported showYouReportedMessage */
function showYouReportedMessage(reportLinkId, reportableType, reportableId, message) {
switch(reportableType) {
case 'Comment':
// Comments differ depending on where they are, so this is why we have two ways. If an element isn't found, nothing will happen...
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I won't say this is great. As I wrote in the PR description, given how the comments are rendered, I decided to do it this way.

// For comments on a project/package - In the comment, insert the 'You reported the comment' message after 'User X wrote (...)'
$('#comment-' + reportableId + '-user').after(message);
// For comments on a request - In the comment, insert the 'You reported the comment' message before the comment body
$('#comment-' + reportableId + '-body').prepend(message);
break;
case 'Project':
case 'Package':
// The 'You reported the project/package' is displayed in the side links of the project/package
$('ul.side_links').append(message);
break;
case 'User':
// The 'You reported the user' message is displayed after the (now) hidden 'Report' link
$(reportLinkId).after(message);
break;
}
}

$(document).ready(function(){
$('#report-category').on('change', '.form-check-input', function(e) {
$('#report-reason textarea').attr('required', (e.target.value !== 'other' ? null : true));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
= link_to request_changes_path(number: action.bs_request, request_action_id: action, anchor: comment.diff_ref) do
= render(DiffSubjectComponent.new(state: diff['state'], old_filename: diff.dig('old', 'name'), new_filename: diff.dig('new', 'name')))
= render(DiffComponent.new(diff: diff.dig('diff', '_content'), range:))
.comment-bubble-content
.comment-bubble-content{ id: "comment-#{comment.id}-body" }
= render ReportsNoticeComponent.new(reportable: comment, user: User.session)
= helpers.render_as_markdown(comment)

Expand Down
12 changes: 6 additions & 6 deletions src/api/app/controllers/webui/reports_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
after_action :verify_authorized

def create
user = User.session!
report = user.submitted_reports.new(report_params)
authorize report
@user = User.session!
@report = @user.submitted_reports.new(report_params)
authorize @report

Check warning on line 8 in src/api/app/controllers/webui/reports_controller.rb

View check run for this annotation

Codecov / codecov/patch

src/api/app/controllers/webui/reports_controller.rb#L6-L8

Added lines #L6 - L8 were not covered by tests

@link_id = params[:link_id]

if report.save
flash[:success] = "#{report.reportable_type} reported successfully"
if @report.save
flash[:success] = "#{@report.reportable_type} reported successfully"

Check warning on line 13 in src/api/app/controllers/webui/reports_controller.rb

View check run for this annotation

Codecov / codecov/patch

src/api/app/controllers/webui/reports_controller.rb#L12-L13

Added lines #L12 - L13 were not covered by tests
else
flash[:error] = report.errors.full_messages.to_sentence
flash[:error] = @report.errors.full_messages.to_sentence

Check warning on line 15 in src/api/app/controllers/webui/reports_controller.rb

View check run for this annotation

Codecov / codecov/patch

src/api/app/controllers/webui/reports_controller.rb#L15

Added line #L15 was not covered by tests
end

respond_to do |format|
Expand Down
2 changes: 1 addition & 1 deletion src/api/app/views/webui/comment/_content.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
.flex-shrink-0
= image_tag_for(comment.user, size: 35, custom_class: 'me-3 d-none d-sm-block')
.comment.flex-grow-1.text-break
.mb-3
.mb-3{ id: "comment-#{comment.id}-user" }
= link_to(comment.user, user_path(comment.user))
wrote
= link_to("#comment-#{comment.id}", title: I18n.l(comment.created_at.utc), name: "comment-#{comment.id}") do
Expand Down
2 changes: 1 addition & 1 deletion src/api/app/views/webui/package/_side_links.html.haml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
%ul.list-unstyled
%ul.side_links.list-unstyled
- if failures.positive?
= render partial: 'webui/package/side_links/show_failures', locals: { failures: failures, package_name: package.name, project: project }

Expand Down
2 changes: 1 addition & 1 deletion src/api/app/views/webui/project/_side_links.html.haml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
%ul.list-unstyled
%ul.side_links.list-unstyled
- if project.is_maintenance?
= render partial: 'webui/project/side_links/maintenance_project', locals: { open_maintenance_incidents: open_maintenance_incidents,
project: project,
Expand Down
3 changes: 3 additions & 0 deletions src/api/app/views/webui/reports/create.js.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@ $('#report-modal').modal('hide');
$('#flash').html("<%= escape_javascript(render(partial: 'layouts/webui/flash'))%>")

hideReportButton("#<%= @link_id %>");
showYouReportedMessage("#<%= @link_id %>", "<%= @report.reportable_type %>",
"<%= @report.reportable_id %>",
"<%= escape_javascript(render ReportsNoticeComponent.new(reportable: @report.reportable, user: @user)) %>");
collectReportModalsAndSetValues();

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

Loading