discourse/app/controllers/admin
Tarek Khalil f8480ed911
FEATURE: Exposing a way to add a generic report filter (#6816)
* FEATURE: Exposing a way to add a generic report filter

## Why do we need this change?

Part of the work discussed [here](https://meta.discourse.org/t/gain-understanding-of-file-uploads-usage/104994), and implemented a first spike [here](https://github.com/discourse/discourse/pull/6809), I am trying to expose a single generic filter selector per report.

## How does this work?

We basically expose a simple, single generic filter that is computed and displayed based on backend values passed into the report.

This would be a simple contract between the frontend and the backend.

**Backend changes:** we simply need to return a list of dropdown / select options, and enable the report's newly introduced `custom_filtering` property.

For example, for our [Top Uploads](https://github.com/discourse/discourse/pull/6809/files#diff-3f97cbb8726f3310e0b0c386dbe89e22R1423) report, it can look like this on the backend:

```ruby
report.custom_filtering = true
report.custom_filter_options = [{ id: "any", name: "Any" }, { id: "jpg", name: "JPEG" } ]
```

In our javascript report HTTP call, it will look like:

```js
{
  "custom_filtering": true,
  "custom_filter_options": [
    {
      "id": "any",
      "name": "Any"
    },
    {
      "id": "jpg",
      "name": "JPG"
    }
  ]
}
```

**Frontend changes:** We introduced a generic `filter` param and a `combo-box` which hooks up into the existing framework for fetching a report.

This works alright, with the limitation of being a single custom filter per report. If we wanted to add, for an instance a `filesize filter`, this will not work for us. _I went through with this approach because it is hard to predict and build abstractions for requirements or problems we don't have yet, or might not have._

## How does it look like?

![a1ktg1odde](https://user-images.githubusercontent.com/45508821/50485875-f17edb80-09ee-11e9-92dd-1454ab041fbb.gif)

## More on the bigger picture

The major concern here I have is the solution I introduced might serve the `think small` version of the reporting work, but I don't think it serves the `think big`, I will try to shed some light into why.

Within the current design, It is hard to maintain QueryParams for dynamically generated params (based on the idea of introducing more than one custom filter per report).

To allow ourselves to have more than one generic filter, we will need to:

a. Use the Route's model to retrieve the report's payload (we are now dependent on changes of the QueryParams via computed properties)
b. After retrieving the payload, we can use the `setupController` to define our dynamic QueryParams based on the custom filters definitions we received from the backend
c. Load a custom filter specific Ember component based on the definitions we received from the backend
2019-03-15 12:15:38 +00:00
..
admin_controller.rb Refactor requires login logic, reduce duplicate code 2018-02-01 15:17:59 +11:00
api_controller.rb Fix all the errors to get our tests green on Rails 5.1. 2017-09-25 13:48:58 +08:00
backups_controller.rb FIX: Outgoing emails were not disabled after restoring backup 2019-02-25 16:07:24 +01:00
badges_controller.rb Make rubocop happy again. 2018-06-07 13:28:18 +08:00
color_schemes_controller.rb Fix all the errors to get our tests green on Rails 5.1. 2017-09-25 13:48:58 +08:00
dashboard_controller.rb FEATURE: Improve backup stats on admin dashboard 2018-12-17 11:35:11 +01:00
dashboard_next_controller.rb UX: Adding reports dashboard tab, new layout, report descriptions (#6790) 2018-12-19 14:44:43 +01:00
email_controller.rb FIX: Return 400 when username params is invalid. 2019-01-30 16:06:55 +08:00
email_templates_controller.rb FIX: Failed to save email template with pluralized subject 2019-03-06 16:51:04 +01:00
embeddable_hosts_controller.rb Make rubocop happy again. 2018-06-07 13:28:18 +08:00
embedding_controller.rb Make rubocop happy again. 2018-06-07 13:28:18 +08:00
emojis_controller.rb FIX: use hijack for emoji uploads 2017-12-18 10:31:19 +11:00
flagged_topics_controller.rb Add front end service for staff controls 2017-09-25 12:25:14 -04:00
flags_controller.rb FIX: When disagreeing with a flag that silenced a user, unsilence them 2019-02-08 08:50:50 -05:00
groups_controller.rb FIX: Incorrect query when removing a group owner. 2018-05-07 13:57:00 +08:00
impersonate_controller.rb FIX: Do not check for suspicious login when impersonating. (#6534) 2018-11-12 15:34:12 +01:00
moderation_history_controller.rb FEATURE: show post approvals in Moderation History (#6643) 2018-11-22 10:22:23 +08:00
permalinks_controller.rb Fix all the errors to get our tests green on Rails 5.1. 2017-09-25 13:48:58 +08:00
plugins_controller.rb Rename display_plugins -> visible_plugins. 2018-05-09 07:52:45 +08:00
reports_controller.rb FEATURE: Exposing a way to add a generic report filter (#6816) 2019-03-15 12:15:38 +00:00
screened_emails_controller.rb FEATURE: admins can clear screend emails if needed 2014-06-02 16:53:00 +10:00
screened_ip_addresses_controller.rb FIX: Do not show an empty modal when an IP address is allowed or blocked. (#6265) 2018-08-20 17:37:30 +02:00
screened_urls_controller.rb Should have put order on the screened urls results 2013-11-04 16:31:31 -05:00
search_logs_controller.rb fix the build 2018-01-17 12:57:33 +05:30
site_settings_controller.rb FIX: Properly support defaults for upload site settings. 2019-03-13 16:36:57 +08:00
site_texts_controller.rb FIX: Text content search warning if more than 50 results 2019-03-11 12:56:15 -04:00
staff_action_logs_controller.rb Add rubocop to our build. (#5004) 2017-07-28 10:20:09 +09:00
themes_controller.rb PERF: Remove final N+1 from theme admin page 2019-03-05 12:10:53 +00:00
user_fields_controller.rb Make rubocop happy again. 2018-06-07 13:28:18 +08:00
users_controller.rb FIX: removes legacy browsers-refresh button (#7028) 2019-02-19 16:38:21 +01:00
versions_controller.rb Don't blow up if Redis switches to READONLY 2015-04-24 14:37:16 -04:00
watched_words_controller.rb Add rubocop to our build. (#5004) 2017-07-28 10:20:09 +09:00
web_hooks_controller.rb FEATURE: Filter topic and post web hook events by tags (#6726) 2018-12-05 14:44:06 +05:30