WildAid / o-fish-web

Web application for the Officer's Fishery Information Sharing Hub (O-FISH). The web app allows agencies to gain insights from the aggregated information gathered during a routine vessel inspection (submitted via the web app).
Apache License 2.0
31 stars 41 forks source link

Filter should include violations #137

Closed o-fish-wildaid closed 3 years ago

o-fish-wildaid commented 4 years ago

The filtering on the Vessels and Crew and Boardings pages should include a filter for violation. The search term should search the violationCode and violationDescription arrays.

akhilkh2000 commented 4 years ago

Can you give me more details about this issue as Im a beginner and would love to contribute

Sheeri commented 4 years ago

Hello @akhilkh2000 - The current "Vessels" page has a "Filter" button (top right), that when clicked, has a few options to filter on: Screen Shot 2020-08-31 at 10 20 36 AM

Right now the filters are: Risk (select Red, Amber, Green) Boarding Information (select Date, Time, Location) Vessel Information (select Permit Number, Nationality)

We would like to add a filter for Violation, which should bring up a text field. The text that is added in the field, should be searched for in the violationCode and violationDescription arrays in the wildaid.MenuData collection.

This is similar to how Boarding Information-> Location works - if you click the "Location" checkbox on the screen above, you get the word "Location" with a box next to it - click the box, and you get this:

Screen Shot 2020-08-31 at 10 23 28 AM

That is what it should be for choosing a "Violation" filter. When the user types text in and clicks "Search", the arrays are searched and the results returned to the app.

evayde commented 3 years ago

Hey @Sheeri I would like to take this issue

Sheeri commented 3 years ago

Hello @evayde, thanks for offering to work on this! I have assigned it to you.

evayde commented 3 years ago

Thank you for assigning this to me @Sheeri I have some questions after I further investigated this issue.

  1. How are violationDescriptions and violationCodes glued to realm? e.g. I have the following Descriptions and Codes in my MenuData:
    
    violationCodes: Array(5)
    0: "Fish and Game code 7850(a)"
    1: "Fish and Game code 7145(a)"
    2: "T-14 29.85(a)(7)"
    3: "T-14 189(a)"
    4: "T-14 27.80(a)(2)"

violationDescriptions: Array(5) 0: "No commercial license" 1: "Fishing without a license" 2: "Take/Possess undersize Dungeness crab" 3: "Take in violation of Federal Regulations" 4: "Use barbed hooks for Salmon"



But one entry looks like this:
![image](https://user-images.githubusercontent.com/25255815/95632754-a41a1400-0a86-11eb-8498-3d2af8e73e1a.png)

I found `inspection.summary.violations.offence.code` in the metadata in realm but it doesn't seem to be bound to the code from the MenuData (or is it?). 

2. Consequently: Do I have to make adjustments to Realm?
What is the ultimate goal of this issue? As far as I understand this: The user should be able to enter text freely, which is searched for within the arrays I showed in (1). And the text found in the array should be sent to the backend? But the text under "violation", shown in the picture in (1) is not connected to the violationDescriptions-Array, or is it? If so, then I would have to search for `inspection.summary.violations.offence.explanation` and probably `inspection.summary.violations.offence.code` in a custom aggregation, which still requires implementation. As far as I have seen it. 

Thank you for your patience 
Sheeri commented 3 years ago

Hi! The Menu Data is where the code and descriptions come from. Those particular entries were made when the menu data was different. If you made a new record for your agency, you would have the choice of what's in menu data now.

Regardless, the filter should be a text field that is applied to the violationsCode and violationsDescription arrays as part of boarding records. I recommend you look into how the nationality filter is done - it is also a filter where the user enters text and fields in the BoardingRecords collection are searched.

There is no need to search menuData or use values stored in it.

evayde commented 3 years ago

Thanks, @Sheeri one last confusion on my side. You said the code and the description should be searched. Do you mean that I have to add one text field to search both? This would be different from how the nationality thing works. I guess I'd have to add a custom type to the filter-panel or would you solve it differently? Should the violations search filter option be ordered under an existing list point?

This is what I have played with so far and it's working (having code and description separately):

image

Sheeri commented 3 years ago

You are correct, it does differ from nationality. I don't know what code you've implemented to get the code and description working separately, but I imagine it's something like "if code is checked, use the text the user typed in to search violationCode. If description is checked, use the text the user typed in to search violationDescription."

Can you do something like "If Violation is checked, use the text the user typed in, to search violationCode and violationDescription and put the results of both into a set (for deduplication), and return the set." ??

evayde commented 3 years ago

@Sheeri ok, I have seen an example for the date range on the dashboard, where "$and" is used, so I figured that I might be able to use "$or." It is working so far; however: If I refresh the page, the active filter disappears, while the search results are still available. The reason for this is that I do not have one single field that can be mapped to the value. (e.g., the URL will look like /#/vessels/{"$or":[{"inspection.summary.violations.offence.code":"Violation%20Code%201"},{"inspection.summary.violations.offence.explanation":"Violation%20Code%201"}]}

The website does not seem to have an example implementation for this, so I tried to find a way to solve this issue. I would have to fiddle with convertFilter, which sounds hacky to me.

Any thoughts on this? https://github.com/evayde/o-fish-web/commit/cacf9935cf3f12f25b6a59877082eaafc40df31f

Sheeri commented 3 years ago

@evayde I like that solution! I think we can consider this issue closed when the PR has been approved on the way you suggest. We can open a separate issue to ensure that filters are put into the URL, even the filters that look at multiple fields. (I'm thinking something like the filter wouldn't be the exact name of the field, it would be 'violation' or something, and then the code would look specifically for that. Although that is probably what convertFilter does too :D )