feat: enable autodetect of Wikidata/ISNI on Edition/Work identifier inputs#11429
feat: enable autodetect of Wikidata/ISNI on Edition/Work identifier inputs#11429akramcodez wants to merge 1 commit intointernetarchive:masterfrom
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR enhances the identifier auto-detection functionality in the IdentifiersInput component by enabling it for editions and works (previously restricted to authors only) and adding validation to ensure only supported identifier types are selected.
Key changes:
- Removed the early return that disabled auto-detection for editions/works (
saveIdentifiersAsListcheck) - Added validation to only auto-select identifier types that are available in the current page's configuration
- Added comprehensive JSDoc documentation explaining the function's behavior
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| this.selectedIdentifier = idtype; | ||
| break; | ||
| /** Only select identifier types available in page config (prevents selecting unsupported types) */ | ||
| if (this.identifierConfigsByKey && this.identifierConfigsByKey[idtype]) { |
There was a problem hiding this comment.
The check for this.identifierConfigsByKey being truthy is unnecessary. According to the computed property at line 195-196, identifierConfigsByKey is always defined as an object (even if idConfigs is empty, Object.fromEntries returns {}). This defensive check adds unnecessary complexity.
| if (this.identifierConfigsByKey && this.identifierConfigsByKey[idtype]) { | |
| if (this.identifierConfigsByKey[idtype]) { |
| } | ||
| // Selects the dropdown identifier based on the input value when possible | ||
| for (const idtype in identifierPatterns) { | ||
| if (this.inputValue.match(identifierPatterns[idtype])){ |
There was a problem hiding this comment.
The match() method can throw an error if this.inputValue is not a string. While Vue's v-model.trim on line 53 typically ensures string values, defensive handling should be added to prevent potential runtime errors if the value is unexpectedly null or undefined.
| if (this.inputValue.match(identifierPatterns[idtype])){ | |
| if ((this.inputValue || '').match(identifierPatterns[idtype])){ |
Closes #11428
Solution
The autodetection logic already existed in the
IdentifiersInput.vuecomponent through theselectIdentifierByInputValue()function andidentifierPatternsobject. However, it wasn't being triggered for Editions/Works.What was changed:
watchhandler on theinputValuefieldQ[digits]), the dropdown auto-selects that ID typeTechnical detail:
The function loops through predefined regex patterns (Wikidata, ISNI, LC NAF, Amazon, YouTube) and matches them against user input in real-time.
What works now
Q12345→ Auto-selects Wikidata0000 1234 5678 9012→ Auto-selects ISNIn12345→ Auto-selects LC NAFWorks on Authors, Editions, and Works.