Skip to content

Add id= URL query parameter - #3358

Merged
bhousel merged 1 commit into
masterfrom
1ec5-param-id
Jan 16, 2020
Merged

bhousel merged 1 commit into
masterfrom
1ec5-param-id

Conversation

@1ec5

@1ec5 1ec5 commented Nov 9, 2019

Copy link
Copy Markdown
Member

Added id as an alternative URL query parameter to k and v that takes an entry identifier. For example, ?id=amenity/fast_food|McDonald's not only goes to the amenity/fast_food category but also highlights the McDonald’s entry, just as ?k=amenity&v=fast_food#McDonald's would. This unified query parameter would make it possible for a proposed Wikidata external identifier property (#2620) to automatically link to NSI.

I considered also filtering on the name part of the identifier, which would be quite nice for discovering internationalized variants of a brand, but I couldn’t figure out how to get the name to show up in the “Tag text” field.

nom run docbuild also made tons of changes in docs/src.a2b27638.js due to a React version mismatch. I can commit that too if desired, but it’s probably better for someone who’s been building the app lately to take care of that before release.

@1ec5 1ec5 added the enhancement Actionable - add an enhancement to the source code label Nov 9, 2019
@1ec5
1ec5 requested a review from bhousel November 9, 2019 17:24
@1ec5 1ec5 self-assigned this Nov 9, 2019
@bhousel

bhousel commented Nov 11, 2019 •

Copy link
Copy Markdown
Member

This seems ok.. I'm still kind of wary of considering these NSI keys as stable, but we can try it. You might need to include the disambiguation text too. (I really consider the keys like key/value|name~disambiguator - this is why all the code contains kvnd everywhere).

nom run docbuild also made tons of changes in docs/src.a2b27638.js due to a React version mismatch. I can commit that too if desired, but it’s probably better for someone who’s been building the app lately to take care of that before release.

Yes this is ok to commit.. We change this pretty infrequently, and it needs to be committed because the site is hosted on a GitHub page.

Comment thread app/src/Category.js
const kv = `${k}/${v}`;
const entries = data.dict && data.dict[k] && data.dict[k][v];
const hash = props.location.hash;
const slug = id ? id[3] : (hash && hash.slice(1)); // remove leading '#'

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

We need to prefer the hash over the slug in the ID. In fact, when the user clicks one of the “#” links, we should erase that part of the slug in the id parameter.

Comment thread app/src/App.js
const params = parseParams(routeProps.location.search);
if (params.k && params.v) {
if ((params.k && params.v) || params.id) {
return (

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

What if params are null or undefined?
Can we add a null check for params as well, something like below
let paramObj = params ? params : {}
if ((paramObj.k && paramObj.v) || paramObj.id) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

ParseParams will not return null or undefined. It returns Array.reduce seeded with an empty Object.

Comment thread app/src/Category.js
const k = props.k;
const v = props.v;
const id = props.id && props.id.match(/^(\w+?)\/(\w+?)\|(.+)$/);
const k = id ? id[1] : props.k;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Again check if props are not undefined

@bhousel
bhousel merged commit 5f49b8c into master Jan 16, 2020
@bhousel
bhousel deleted the 1ec5-param-id branch January 16, 2020 19:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Actionable - add an enhancement to the source code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants