Skip to content

feat: enable autodetect of Wikidata/ISNI on Edition/Work identifier inputs#11429

Open
akramcodez wants to merge 1 commit intointernetarchive:masterfrom
akramcodez:feat/autodetect-identifiers-edition-work
Open

feat: enable autodetect of Wikidata/ISNI on Edition/Work identifier inputs#11429
akramcodez wants to merge 1 commit intointernetarchive:masterfrom
akramcodez:feat/autodetect-identifiers-edition-work

Conversation

@akramcodez
Copy link
Contributor

@akramcodez akramcodez commented Nov 6, 2025

Closes #11428

Solution

The autodetection logic already existed in the IdentifiersInput.vue component through the selectIdentifierByInputValue() function and identifierPatterns object. However, it wasn't being triggered for Editions/Works.

What was changed:

  • Added a Vue watch handler on the inputValue field
  • When user types in the ID input box, it now automatically checks against known patterns
  • If the input matches a pattern (like Wikidata's Q[digits]), the dropdown auto-selects that ID type
  • Only selects ID types that are available in the current page's configuration (safe validation)

Technical 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

  • Type Q12345 → Auto-selects Wikidata
  • Type 0000 1234 5678 9012 → Auto-selects ISNI
  • Type n12345 → Auto-selects LC NAF

Works on Authors, Editions, and Works.

Copilot AI review requested due to automatic review settings November 6, 2025 16:41
@akramcodez akramcodez changed the title feat: enable autodetect of Wikidata/ISNI on Ed ition/Work identifier inputs feat: enable autodetect of Wikidata/ISNI on Edition/Work identifier inputs Nov 6, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 (saveIdentifiersAsList check)
  • 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]) {
Copy link

Copilot AI Nov 6, 2025

Choose a reason for hiding this comment

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

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.

Suggested change
if (this.identifierConfigsByKey && this.identifierConfigsByKey[idtype]) {
if (this.identifierConfigsByKey[idtype]) {

Copilot uses AI. Check for mistakes.
}
// Selects the dropdown identifier based on the input value when possible
for (const idtype in identifierPatterns) {
if (this.inputValue.match(identifierPatterns[idtype])){
Copy link

Copilot AI Nov 6, 2025

Choose a reason for hiding this comment

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

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.

Suggested change
if (this.inputValue.match(identifierPatterns[idtype])){
if ((this.inputValue || '').match(identifierPatterns[idtype])){

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Autodetect ID

2 participants