Skip to content
This repository has been archived by the owner on Feb 1, 2024. It is now read-only.

Add q= free text param to facilities API endpoint #675

Merged
merged 3 commits into from Jul 17, 2019

Conversation

kellyi
Copy link
Contributor

@kellyi kellyi commented Jul 15, 2019

Overview

  • Add q= free text param to facilities API endpoint
  • Update client to use q= param
  • Enable searches using q or name to search both name and OAR ID
    fields
  • Update client search input labels to indicate searches happen over
    names and OAR IDs
  • If only one facility returns from a given search, immediately push the details page for that facility using its OAR ID.

Connects #121

Demo

Screen Shot 2019-07-15 at 3 08 17 PM

Screen Shot 2019-07-15 at 3 08 34 PM

Notes

This currently uses id__icontains=q for the OAR ID which means that it'll return both 1 result which exactly matches the input OAR ID if it's a full OAR ID or any results that match a partial OAR ID. This is the logic we used for the name search, too.

I'm happy to make it an exact match but it seemed useful to have both available.

Testing Instructions

  • get branch then ./scripts/resetdb
  • visit localhost:6543 and search for some facilities to get an OAR ID
  • enter an OAR ID in the text search input and verify that it returns the single result, that the details page is immediately pushed, and that you can click back to see the facilities search tab with one result
  • search by partial OAR ID (US2019) and verify that that returns a list of results

Checklist

  • fixup! commits have been squashed
  • CI passes after rebase
  • CHANGELOG.md updated with summary of features or fixes, following Keep a Changelog guidelines

@kellyi kellyi requested a review from jwalgran July 15, 2019 19:14
@kellyi kellyi marked this pull request as ready for review July 15, 2019 19:15
@@ -131,7 +132,7 @@ class FilterSidebar extends Component {
case filterSidebarTabsEnum.guide:
return <FilterSidebarGuideTab />;
case filterSidebarTabsEnum.search:
return <FilterSidebarSearchTab />;
return <Route component={FilterSidebarSearchTab} />;
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 was done to have history.push available in the mapDispatchToProps function.

Copy link
Contributor

Choose a reason for hiding this comment

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

Consider an inline comment explaining our reasoning.

Copy link
Contributor

@jwalgran jwalgran left a comment

Choose a reason for hiding this comment

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

The code looks good. I don't have a dev environment up and running yet, so I have not exercised it.

coreapi.Field(
name='name',
location='query',
type='string',
required=False,
description='Facility Name',
description='Facility Name or OAR ID',
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider adding DEPRECATED. Use "q" instead. to the description.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds good. I added this in 56208cf

None)
free_text_query = request.query_params.get(FacilitiesQueryParams.Q,
None)
name = request.query_params.get(FacilitiesQueryParams.NAME, None)
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider adding an inline comment explaining that name is deprecated in favor of q

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍 Added in 56208cf

if name is not None:
queryset = queryset.filter(name__icontains=name)
queryset = queryset.filter(Q(name__icontains=name) |
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider adding an inline comment explaining that name is deprecated in favor of q

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍 see 56208cf

).length === 1;

if (responseHasOnlyOneFacility) {
flow(
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider this more procedural version that makes sure we don't push an invalid route and alerts us to a problem.

const id = get(data, `features[0].id`, '')
if (id) {
    pushNewRoute(makeFacilitiesDetailLink(id))
} else {
   // Raise an exception that we will see in Rollbar
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds good -- this is in 7327ad1

Since the code is in a promise the existing catch will handle the thrown error.

@@ -131,7 +132,7 @@ class FilterSidebar extends Component {
case filterSidebarTabsEnum.guide:
return <FilterSidebarGuideTab />;
case filterSidebarTabsEnum.search:
return <FilterSidebarSearchTab />;
return <Route component={FilterSidebarSearchTab} />;
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider an inline comment explaining our reasoning.

@kellyi
Copy link
Contributor Author

kellyi commented Jul 15, 2019

Consider an inline comment explaining our reasoning.

I added the comment in a3c186c

@kellyi kellyi changed the title WIP Add q= free text param to facilities API endpoint Add q= free text param to facilities API endpoint Jul 16, 2019
Kelly Innes added 3 commits July 16, 2019 19:55
- Add `q=` free text param to facilities API endpoint
- Update client to use `q=` param
- Enable searches using `q` or `name` to search both name and OAR ID
fields
- Update client search input labels to indicate searches happen over
names and OAR IDs
If only one facility returns in the search response, push the details
page for that facility. (The search tab will remain populated on clicking
back.)
@kellyi
Copy link
Contributor Author

kellyi commented Jul 16, 2019

I rebased this on develop and squashed the fixups.

Copy link
Contributor

@jwalgran jwalgran left a comment

Choose a reason for hiding this comment

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

Works well.

@jwalgran jwalgran assigned kellyi and unassigned jwalgran Jul 17, 2019
@kellyi
Copy link
Contributor Author

kellyi commented Jul 17, 2019

Thanks!

@kellyi kellyi merged commit 41820e7 into develop Jul 17, 2019
@kellyi kellyi deleted the ki/search-by-oar-id branch July 17, 2019 17:42
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants