okfn-brasil / jarbas

🎩 API for information and suspicions about reimbursements by Brazilian congresspeople
https://jarbas.serenata.ai/
296 stars 61 forks source link

Keep user selected ordering in the dashboard #278

Closed cuducos closed 6 years ago

cuducos commented 6 years ago

What is the purpose of this Pull Request?

In Jarbas Dashboard users could click in the table headers to try to sort the results by value, date, etc…

Unfortunately this user selected ordering was being overridden by the search vector rank.

Fortunately this PR fixes this bug ; )

What was done to achieve this purpose?

Before calling the .order_by('-rank') into the Django QuerySet Jarbas will check if is there any previous ordering in place.

How to test if it really works?

  1. Run Jarbas from this branch
  2. Access the dashboard (the path is /dashboard)
  3. Search for some text using the search bar
  4. Try to filter by some clickable column headers — hopefully it'll work ; )

Who can help reviewing it? @anaschwendler

anaschwendler commented 6 years ago

I really didn't noticed that, but now let's test this PR:

  1. Clone the repository:

    $ git clone git@github.com:datasciencebr/jarbas.git
  2. Open the repo folder:

    $ cd jarbas
  3. Checkout to @cuducos branch:

    $ git checkout -b cuducos-fix-ordering origin/cuducos-fix-ordering
  4. Update the branch:

    $ git merge master
  5. Copy the .env file:

    $ cp contrib/.env.sample env
  6. Build and start services:

    $ docker-compose up -d
  7. Create the database and apply the migrations:

    $ docker-compose run --rm django python manage.py migrate
    $ docker-compose run --rm django python manage.py searchvector
  8. Seeding it with sample data:

$ docker-compose run --rm django python manage.py reimbursements /mnt/data/reimbursements_sample.xz
$ docker-compose run --rm django python manage.py companies /mnt/data/companies_sample.xz
$ docker-compose run --rm django python manage.py suspicions /mnt/data/suspicions_sample.xz
$ docker-compose run --rm django python manage.py tweets
  1. Access localhost:8000/dashboard:

8.1. Search for some text using the search bar (papel): image

8.2. Try to filter by some clickable column headers (papel e ano 2009): image

I think that's it, it is working combined! 🎉 Thanks @cuducos !