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

Issue 470 refine state selection #476

Merged
merged 10 commits into from
Aug 12, 2021

Conversation

alexhuang091
Copy link
Contributor

@alexhuang091 alexhuang091 commented Aug 11, 2021

for #470

  1. states are populated by the selected country
  2. if
    • no country selected,
    • selected country not found (for exmpale we use United States but the API has states for United States of America so if user select United States, no state will be found
    • if failed to call the API
      original state list will be used.

This change also exposes /occurrences/getStates which need to be configured to expose

@alexhuang091
Copy link
Contributor Author

@nickdos
Copy link
Contributor

nickdos commented Aug 11, 2021

Thanks @alexhuang091, that looks really good!

I have one question about the states & territories drop-down (haven't run the PR myself) - when there is no country selected, does it still show every state/territory (same as current implementation)?

@@ -659,6 +659,32 @@ class WebServicesService {
dataQualityCodes
}

// maps from country name to iso code
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add proper Javadoc - /** Foo */ so IDE can display info about method from the controller code, etc...

@alexhuang091
Copy link
Contributor Author

alexhuang091 commented Aug 11, 2021 via email

return states.findAll { it -> beAValidCountryOrState(it) }.collect { it -> (String)it.get("name") }
}
}
[]
Copy link
Contributor

Choose a reason for hiding this comment

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

My preference is for a single return statement, when it is practical (you have 2 in this method) - as it makes the code easier to read. E.g.

List<String> getStates(String countryName) {
    List<String> matchingStates = []

    if (countryNameMap?.containsKey(countryName)) {
        def states = getJsonElements("${grailsApplication.config.userdetails.baseUrl}/ws/registration/states.json?country=" + countryNameMap.get(countryName))
        if (states) {
            // only return valid states
            matchingStates = states.findAll { it -> beAValidCountryOrState(it) }.collect { it -> (String)it.get("name") }
        }
    }

    matchingStates
}

Seeing [] as last statement is not ideal as it makes me think this is the "intended" output when its really the "exception" to the output.

Map countryNameMap = grailsApplication.mainContext.getBean('webServicesService').getCountryNameMap()
// if a known country name
if (countryNameMap?.containsKey(countryName)) {
def states = getJsonElements("${grailsApplication.config.userdetails.baseUrl}/ws/registration/states.json?country=" + countryNameMap.get(countryName))
Copy link
Contributor

@nickdos nickdos Aug 11, 2021

Choose a reason for hiding this comment

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

Just checking if this needs to be (exception) caught? What happens if the service throws an error? Does the user (or ALA staff) have anyway to know that its not working or will it silently fail and be an empty list (that you could interpret as "we don't have any states for this country")?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi Nick, for frontend, only when request is successful will be state list be re-constructed.
$.getJSON(url, function(data)

  1. If not empty, populate it
  2. If empty (no matter because originally empty or backend error), populate with the original list.

Copy link
Contributor Author

@alexhuang091 alexhuang091 Aug 11, 2021

Choose a reason for hiding this comment

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

For the backend.

def getCountryNameMap() {
    def countryUrl = "${grailsApplication.config.userdetails.baseUrl}/ws/registration/countries.json"
    def countries = getJsonElements(countryUrl)

getJsonElements might throw an exception, why it doesn't have a throws in definition
JSONElement getJsonElements(String url, String apiKey = null) {

I should catch it I think. So frontend always get 200, in case of error we return an empty list.

@nickdos nickdos self-requested a review August 11, 2021 03:19
@alexhuang091 alexhuang091 merged commit 319e6ae into develop Aug 12, 2021
@alexhuang091 alexhuang091 deleted the issue_470_refine_state_selection branch August 12, 2021 00:52
alexhuang091 added a commit that referenced this pull request Sep 7, 2021
* #379 Records from DigiVol don't show "Flag an issue" button

* updated version to 3.0.3-SNAPSHOT for next iteration

* Feature/duplicate record (#429)

Add duplicate assertion type to flag an issue

* enhanced duplicate record flag (#431)

* release 3.0.3 (#432)

* version to 3.0.4-SNAPSHOT

* #434 fix duplicate record facet labels

Code formatting

* Feature my annotation (#435)

* allow user to subscribe to 'my annotation' alert when flagging an issue

* Fix jquery.i18n load errors

* $.param() doesn't format object correctly (#438)

* Release/3.0.4 (#442)

* 3.0.5-SNAPSHOT

* #443 fixes for flash.message exposing apiKey

* Revert "Fix jquery.i18n load errors"

* Translation of Map legend button and pagination next and previous button

* release 3.0.5 (#449)

* 3.0.6-SNAPSHOT

* AtlasOfLivingAustralia/la-pipelines#372 hide passed assertions by default

* i18n en differentiate between duplicate_status and duplicate_type

* Bugfix/la pipelines 445 dq profile category dialog display (#456)

* AtlasOfLivingAustralia/la-pipelines#445 process array of filters rather then combined filter

* AtlasOfLivingAustralia/la-pipelines#445 increase width of DQ profile modal

* AtlasOfLivingAustralia/la-pipelines#372 removed test for data quality assertion code `1`

* Fix for AtlasOfLivingAustralia/la-pipelines/issues/467

Fix for incorrect sort param for subsequent (paginated) calls for the species list column in EYA.

* update biocache-hubs since backend now returns 404 when no record found.

* Update README.md

* fixed an issue in reading local json files

* border-radius for active filters (#462)

* wrap taxon name with ""

* removed log code

* clean log

* AtlasOfLivingAustralia/la-pipelines#419 (#465)

pass filters and descriptions as JSON array
standardise display of filters for DQ profile and category

* Release/3.0.6 (#468)

* 3.0.7-SNAPSHOT

* no strip . in taxon (#469)

* handle the case where taxa query returns empty JSON object (404) (#472)

* make 'disableAll' and 'expand' configurable (#473)

* make 'disableAll' and 'expand' configurable

* when 'quality profile' is changed, update drop-down immediately (#474)

* use 'fa' for font-awesome 4.x

* Issue 470 refine state selection (#476)

advanced search UI refine: state list be populated per country selected

* style changes to admin page for dq admin link (#477)

* fixed a type in flag an issue error message (#478)

* added sound file metadata and sound file link to record detail page. (#479)

* explicitly set 'user_facets' as String in cookie (#480)

* updated css style for #occurrenceSounds

* updated message.properties

* location display logic updated (#485)

* Avh issue120 avh styling (#487)

* remove some inline styles

* updated left side panel dq filters display

* fix the 'view excluded records' on left side panel doesn't work issue.

* fix the 'filter details' not shown on left side panel issue

* style change, left side panel dq spin

* Issue 334 update ehcache (#488)

updated to ehcache 3.0

* updated getJsonElements to handle JSON error better (#490)

* removed persistence settings

* release 3.0.7

Co-authored-by: Rita Chen <[email protected]>
Co-authored-by: Nick dos Remedios <[email protected]>
Co-authored-by: vjrj <[email protected]>
Co-authored-by: alice.ainsa <[email protected]>
Co-authored-by: Dave Martin <[email protected]>
Co-authored-by: Bruce Hyslop <[email protected]>
Co-authored-by: adam-collins <[email protected]>
alexhuang091 added a commit that referenced this pull request Sep 8, 2021
* #379 Records from DigiVol don't show "Flag an issue" button

* updated version to 3.0.3-SNAPSHOT for next iteration

* Feature/duplicate record (#429)

Add duplicate assertion type to flag an issue

* enhanced duplicate record flag (#431)

* release 3.0.3 (#432)

* version to 3.0.4-SNAPSHOT

* #434 fix duplicate record facet labels

Code formatting

* Feature my annotation (#435)

* allow user to subscribe to 'my annotation' alert when flagging an issue

* Fix jquery.i18n load errors

* $.param() doesn't format object correctly (#438)

* Release/3.0.4 (#442)

* 3.0.5-SNAPSHOT

* #443 fixes for flash.message exposing apiKey

* Revert "Fix jquery.i18n load errors"

* Translation of Map legend button and pagination next and previous button

* release 3.0.5 (#449)

* 3.0.6-SNAPSHOT

* AtlasOfLivingAustralia/la-pipelines#372 hide passed assertions by default

* i18n en differentiate between duplicate_status and duplicate_type

* Bugfix/la pipelines 445 dq profile category dialog display (#456)

* AtlasOfLivingAustralia/la-pipelines#445 process array of filters rather then combined filter

* AtlasOfLivingAustralia/la-pipelines#445 increase width of DQ profile modal

* AtlasOfLivingAustralia/la-pipelines#372 removed test for data quality assertion code `1`

* Fix for AtlasOfLivingAustralia/la-pipelines/issues/467

Fix for incorrect sort param for subsequent (paginated) calls for the species list column in EYA.

* update biocache-hubs since backend now returns 404 when no record found.

* Update README.md

* fixed an issue in reading local json files

* border-radius for active filters (#462)

* wrap taxon name with ""

* removed log code

* clean log

* AtlasOfLivingAustralia/la-pipelines#419 (#465)

pass filters and descriptions as JSON array
standardise display of filters for DQ profile and category

* Release/3.0.6 (#468)

* 3.0.7-SNAPSHOT

* no strip . in taxon (#469)

* handle the case where taxa query returns empty JSON object (404) (#472)

* make 'disableAll' and 'expand' configurable (#473)

* make 'disableAll' and 'expand' configurable

* when 'quality profile' is changed, update drop-down immediately (#474)

* use 'fa' for font-awesome 4.x

* Issue 470 refine state selection (#476)

advanced search UI refine: state list be populated per country selected

* style changes to admin page for dq admin link (#477)

* fixed a type in flag an issue error message (#478)

* added sound file metadata and sound file link to record detail page. (#479)

* explicitly set 'user_facets' as String in cookie (#480)

* updated css style for #occurrenceSounds

* updated message.properties

* location display logic updated (#485)

* Avh issue120 avh styling (#487)

* remove some inline styles

* updated left side panel dq filters display

* fix the 'view excluded records' on left side panel doesn't work issue.

* fix the 'filter details' not shown on left side panel issue

* style change, left side panel dq spin

* Issue 334 update ehcache (#488)

updated to ehcache 3.0

* updated getJsonElements to handle JSON error better (#490)

* removed persistence settings

* release 3.0.7 (#493)

* 3.0.8-SNAPSHOT

* the converted value should be put back to map to be used somewhere else

* updated 'exclude count' font style

* release 3.0.8

Co-authored-by: Rita Chen <[email protected]>
Co-authored-by: Nick dos Remedios <[email protected]>
Co-authored-by: vjrj <[email protected]>
Co-authored-by: alice.ainsa <[email protected]>
Co-authored-by: Dave Martin <[email protected]>
Co-authored-by: Bruce Hyslop <[email protected]>
Co-authored-by: adam-collins <[email protected]>
djtfmartin pushed a commit that referenced this pull request Dec 9, 2021
advanced search UI refine: state list be populated per country selected
djtfmartin pushed a commit that referenced this pull request Dec 9, 2021
advanced search UI refine: state list be populated per country selected
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

2 participants