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

Feature: Improve reports ui #7032

Merged

Conversation

ThisIsMissEm
Copy link
Contributor

After playing with the improved reports UI from #7000, I still wasn't happy with it. I've since redesigned the form for adding report notes, and added the "ActionLog" history (in a rough form) so we can see all the actions taken in relation to a specific report.

Note: I wasn't sure on the right way to implement fetching the ActionLog, so went with a relation, but now I think a Finder method would be better, as it needs to pull from the Report, the statuses of the report and the reported user; Though I'm not sure on the best way to implement this.

Here's what the page now looks like:

localhost_3000_admin_reports_2 2

@ThisIsMissEm
Copy link
Contributor Author

I really want to try to get the additional ActionLog items that are relevant into the report, but I'm not sure how to do this. Open to suggestions.

@nightpool
Copy link
Member

nightpool commented Apr 3, 2018 via email

@ThisIsMissEm
Copy link
Contributor Author

@nightpool oh, I agree, but I've absolutely no idea how to do that in rails. Not to mention that it's not the full action log for now, which I'm struggling to build.

@Gargron
Copy link
Member

Gargron commented Apr 3, 2018

I'm liking this a lot. 👍

}

Admin::ActionLog.from(sql)
end
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This probably isn't ideal or perfect, so I'm open to suggestions here @nightpool @Gargron

@ThisIsMissEm
Copy link
Contributor Author

Okay, I've added a limit on the report history to be only actions within the timeframe of the report (report.created_at..report.updated_at) and ensure that adding notes updates the report.

).unscope(:order)

query = "((#{report_log.to_sql}) UNION ALL (#{target_account_log.to_sql}) UNION ALL (#{statuses_log.to_sql})) as admin_action_logs"
sql = Admin::ActionLog.connection.unprepared_statement(query)
Copy link
Member

Choose a reason for hiding this comment

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

It seems that this method takes a block argument, i.e. unprepared_statement { query }, but I am not totally sure why unprepared_statement is needed in here?

Copy link
Member

Choose a reason for hiding this comment

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

We may want to just use https://github.com/brianhempel/active_record_union to do this the clean way

@ThisIsMissEm
Copy link
Contributor Author

ThisIsMissEm commented Apr 4, 2018 via email

@Gargron
Copy link
Member

Gargron commented Apr 6, 2018

Here is a fix for the UNION stuff that works for me:

diff --git a/app/models/report.rb b/app/models/report.rb
index e1bfa99..5b90c7b 100644
--- a/app/models/report.rb
+++ b/app/models/report.rb
@@ -61,27 +61,28 @@ class Report < ApplicationRecord
   end
 
   def history
-    report_log = Admin::ActionLog.where(
-      target_type: 'Report',
-      target_id: id,
-      created_at: created_at..updated_at
-    ).unscope(:order)
-
-    target_account_log = Admin::ActionLog.where(
-      target_type: 'Account',
-      target_id: target_account_id,
-      created_at: created_at..updated_at
-    ).unscope(:order)
-
-    statuses_log = Admin::ActionLog.where(
-      target_type: 'Status',
-      target_id: status_ids,
-      created_at: created_at..updated_at
-    ).unscope(:order)
-
-    query = "((#{report_log.to_sql}) UNION ALL (#{target_account_log.to_sql}) UNION ALL (#{statuses_log.to_sql})) as admin_action_logs"
-    sql = Admin::ActionLog.connection.unprepared_statement(query)
-
-    Admin::ActionLog.from(sql)
+    time_range = created_at..updated_at
+
+    sql = [
+      Admin::ActionLog.where(
+        target_type: 'Report',
+        target_id: id,
+        created_at: time_range
+      ).unscope(:order),
+
+      Admin::ActionLog.where(
+        target_type: 'Account',
+        target_id: target_account_id,
+        created_at: time_range
+      ).unscope(:order),
+
+      Admin::ActionLog.where(
+        target_type: 'Status',
+        target_id: status_ids,
+        created_at: time_range
+      ).unscope(:order),
+    ].map { |query| "(#{query.to_sql})" }.join(' UNION ALL ')
+
+    Admin::ActionLog.from("(#{sql}) AS admin_action_logs")
   end
 end

@ThisIsMissEm
Copy link
Contributor Author

@Gargron this is now ready for review again, the 1 issue to fix from code climate isn't an issue, because we know what we're doing™

@Gargron Gargron merged commit d9b62e3 into mastodon:master Apr 10, 2018
mayaeh added a commit to mayaeh/mastodon that referenced this pull request Apr 11, 2018
ykzts pushed a commit that referenced this pull request Apr 13, 2018
* Update Japanese translations.

* Update Japanese translations.

* Update Japanese translations.

* Update Japanese translations.

* Add Japanese translations for #6984, #7040, #7072.
Update Japanese translations for privacy policy.

* Add Japanese translations for #7032, #7074, #7089.

* Proofreading Japanese translations for privacy policy.
@ThisIsMissEm ThisIsMissEm deleted the feature/improve-reports-ui branch April 13, 2018 22:02
Gargron pushed a commit that referenced this pull request May 21, 2018
* i18n: (zh-CN) #7532

* i18n: (zh-CN) #6984

* i18n: (zh-CN) #7391, #7507

* i18n: (zh-CN) #6998

* i18n: (zh-CN) #7074

* i18n: (zh-CN) #7000, #7032, #7131 (#7032, #7040)

* i18n: (zh-CN) #7130, #7188

* i18n: (zh-CN) #6486

* i18n: (zh-CN) #6292

* i18n: (zh-CN) #7347

* i18n: (zh-CN) #6661

* i18n: (zh-CN) #6425

* i18n: (zh-CN) #6597

* i18n: (zh-CN) #6695

* i18n: (zh-CN) #6325

* i18n: (zh-CN) #6460, #7375

* i18n: (zh-CN) #6872

* i18n: (zh-CN) #6818

* i18n: (zh-CN) #7452

* i18n: (zh-CN) #7176

* i18n: (zh-CN) #6460

* i18n: (zh-CN) #7213

* i18n: (zh-CN) #7376

* i18n: (zh-CN) #6556

* i18n: (zh-CN) #6645

* i18n: (zh-CN) #6448

* i18n: (zh-CN) #5303

* i18n: (zh-CN) #7445

* i18n: (zh-CN) Normalization and improvements

* i18n: (zh-CN) #7391

* i18n: (zh-CN) #6627

* i18n: (zh-CN) #6956, #7546

* i18n: (zh-CN) #6636

* i18n: (zh-CN) #6610, #6875

* i18n: (zh-CN) #6887

* i18n: (zh-CN) #4514

* i18n: (zh-CN) #6628

* i18n: (zh-CN) #6771

* i18n: (zh-CN) #6772

* i18n: (zh-CN) #7178

* i18n: (zh-CN) #7521

* i18n: (zh-CN) #6570

* i18n: (zh-CN) #6593

* i18n: (zh-CN) #6423

* i18n: (zh-CN) #6157

* i18n: (zh-CN) #7089

* i18n: (zh-CN) #6733

* i18n: (zh-CN) #7072

* i18n: (zh-CN) #6520

* i18n: (zh-CN) Improvment

* i18n: (zh-CN) #6631
chendo pushed a commit to assemblyfour/switter that referenced this pull request May 28, 2018
* Further improvements to Reports UI

- Clean up notes display
- Clean up add new note form
- Simplify controller
- Allow reopening a report with a note
- Show created at date for reports
- Fix report details table formatting

* Show history of report using Admin::ActionLog beneath the report

* Fix incorrect log message when reopening a report

* Implement fetching of all ActionLog items that could be related to the report

* Ensure adding a report_note updates the report's updated_at

* Limit Report History to actions that happened between the report being created and the report being resolved

* Fix linting issues

* Improve report history builder

Thanks @Gargron for the improvements
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.

None yet

3 participants