-
Notifications
You must be signed in to change notification settings - Fork 1
feat: add geocode-autocomplete for free-text address lookup
#562
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
Conversation
✅ Deploy Preview for oslmap ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
jessicamcinchak
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This works exactly as a I expect! Welcome to geo web component land 🌟
A few minor comments below - think "option" display is the big one to address before merging, but very close to ready !
src/components/geocode-autocomplete/geocode-autocomplete.doc.js
Outdated
Show resolved
Hide resolved
|
thanks for the review @jessicamcinchak -- i think this should be good to go now! |
DafyddLlyr
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking great! A few nitpick comments on the code - please feel free to fix or ignore as you see fit.
A few other comments below to be addressed. Happy to talk these through if you'd like, just let me know.
Sorting
We should sort the results in a format expected by the user - currently they're sorted lexicographic which put 1, 10, 11 before 2, 3, 4. I think a user would expect these to be naturally sorted (localCompare()?).
See PlanX for reference -
A quick glance at the docs didn't show a param for this, so we might need to do this ourselves. We probably want to account for MATCH and MATCH_DESCRIPTION here - we don't want to sort naturally, but discounting exactness here. I guess we could group results by MATCH and then sort the subgroups? You could write this by hand or reach for something like orderBy() from lodash which allows sorting by multiple properties (docs).
Number of results
This might be too restrictive - populateResults(options.slice(0, 5))
It's possible that a user would type an address to the greatest accuracy they can (e.g. a full postcode, or street name) and still not be able to select their address. We're fetching up to 100 records from the OS on each request - should we just show them all here? If we decide that a more limited subset is best (e.g 30, 50?) we should match this value with maxResults so that we're never over-fetching 👍
| name: "osApiKey", | ||
| type: "String", | ||
| values: "https://osdatahub.os.uk/plans", | ||
| required: true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: This should be optional (as long as a proxyEndpoint is provided). I don't think the docs let us express that level of conditionality so it's probably best we just say required: false here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for updating the links here 💪
| @@ -0,0 +1,63 @@ | |||
| @import "govuk-frontend/dist/govuk/index"; | |||
| // @import "accessible-autocomplete"; | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Could we tidy up this commented out line?
| : html` | ||
| <link | ||
| rel="stylesheet" | ||
| href="https://cdn.jsdelivr.net/npm/[email protected]/dist/accessible-autocomplete.min.css" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like we missed this link when updating the package. I guess this should point to 3.0.1 both here and in the other autocomplete?
| // min query length of 3 before fetching | ||
| if (query.length >= 3) { | ||
| this._fetchData(query, populateResults); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great! I think ideally we'd use the same logic before displaying the tNoResults value also. Currently I get "no addressed found" as soon as I type the first character.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It actually looks like there might be a parameter for this we can use? https://github.com/alphagov/accessible-autocomplete?tab=readme-ov-file#minlength-default-0
| type ArrowStyleEnum = "default" | "light"; | ||
| type LabelStyleEnum = "responsive" | "static"; | ||
|
|
||
| // debounce function |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Slightly redundant comment?
| import styles from "./styles.scss?inline"; | ||
| import { getServiceURL } from "../../lib/ordnanceSurvey"; | ||
|
|
||
| // https://apidocs.os.uk/docs/os-places-lpi-output |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This link doesn't work for me - I just get redirected to their docs homepage.
Should it be https://docs.os.uk/os-apis/accessing-os-apis/os-places-api/technical-specification/find?
| type Address = { | ||
| LPI: any; | ||
| }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where possible, I'd recommend avoiding the use of any.
A few options -
- Type out the whole object (using something like https://transform.tools/json-to-typescript to copy the response object from the OS docs)
- Not actually a great solution as it's potentially brittle if they change their API, and adds a lot of boilerplate here for us to maintain without that much benefit
- Using
unknown- Much better than
any- means we can code defensively
- Much better than
- Sketching out just the shape we care about, so that we at least get type safety within this library (e.g.
LPI.ADDRESSon line 108`)
I'd probably go for the third option here 👍
|
hey @DafyddLlyr, thanks for your comments and the helpful example search -- I did choose to dedupe based on UPRN as the Find endpoint returns some duplicate addresses, example here: as far as I can tell the main difference is the |
|
@jmcbroom This is a fun UK one to welcome you to the team 😂 The OS Places API is returning both English and Welsh results 🏴 🏴 {
"LPI" : {
...
"LANGUAGE" : "CY",
}
}
{
"LPI" : {
...
"LANGUAGE" : "EN",
}
}It's not actually obvious in this instance as this is an all Welsh address example I've unwittingly provided sorry - if you try a Cardiff postcode you'll probably spot a difference in Cardiff / Caerdydd in the address line for example. As PlanX is currently England only we can safely just set the |
|
thanks for catching that! also note: I kept the |
DafyddLlyr
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking great @jmcbroom - thanks for resolving all this 👍
Next steps would be to merge this and then publish a new version of the repo so that we can integrate this into LPS.
a very rough start -- more or less taking code from the existing
address-autocomplete.some questions/thoughts i have:
findas the user enters text with some kind of debounce/min length before fetching? or should it wait until Enter is hit?