-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
autodetect author ASIN, Youtube, storygraph ids #8203
Conversation
Codecov Report
@@ Coverage Diff @@
## master #8203 +/- ##
==========================================
+ Coverage 16.27% 16.97% +0.69%
==========================================
Files 69 72 +3
Lines 3816 3789 -27
Branches 668 654 -14
==========================================
+ Hits 621 643 +22
+ Misses 2765 2728 -37
+ Partials 430 418 -12
|
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 this PR, @davidscotson! With the exception of the Youtube identifier pattern, everything is working as expected.
The conditionals that determine the currently selected identifier type are becoming unwieldy, and will become worse as new identifiers are added in the future. In order to simplify things a bit, could you make the following changes?
- Create an object that maps detectable
selectedIdentifier
values to their patterns. This can be declared on the line following the opening<script>
tag. - Replace the conditionals with a
for...in
loop that iterates over the object's keys. While iterating, ifthis.inputValue
is a match, store the current key as the selected identifier and break out of the for loop.
While you work on this, I'll open a separate PR which updates our pg_dump
file to include the author configs for Youtube, Storygraph, and Amazon identifiers.
const wikiDatas = this.inputValue.match(/^Q[1-9]\d*$/i); | ||
const isnis = this.inputValue.match(/^\d{15}[\dX]$/i); | ||
const storygraphs = this.inputValue.match(/^[0-9a-f]{8}(-[0-9a-f]{4}){3}-[0-9a-f]{12}$/i); | ||
const asins = this.inputValue.match(/^B[0-9A-Za-z]{9}$/); | ||
const youtubes = this.inputValue.match(/^UC[-_0-9A-Za-z]{21}[AQgw]$/); |
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.
We're using handle URLs for our Youtube links, not the ID-based channel URLs, so this pattern will need to be updated. A Youtube identifier begins with an @
symbol, followed by the Youtuber's handle.
Handle naming guidelines can be found here.
Additional information about Youtube's many URL types can be found here.
I'll make those changes. A couple of things I've noticed while using the feature which I might look at too if they don't become tricky:
|
Thanks! To your points:
|
Pushed a rebased branch that makes the requested change to for .. in seperately, then adds new items, including Youtube handles, also fixes ISNI with spaces. |
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 @davidscotson! This looks good to me.
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.
Just noticed that the object name was in snake_case. Changing it to identifierPatterns
and merging.
Closes #8202
Autodects ASIN, Youtube and storygraph identifiers on the Author edit page.
Technical
Testing
Pasting in (or typing) one of the above ids should automatically set the dropdown to the appropriate id type. Wikidata and ISNI types should continue to be detected.
One note for testing, if the contents doesn't change, the code isn't triggered, so if you paste in a storygraph id, manually change the type of id in the selector to something else, then paste in the exact same storygraph id then it'll not do anything. Not an issue for real users but something that testers might do and wonder if it is a bug.
Screenshot
Stakeholders