From 58bd7871502bfc86839111fa20f83ee1408303c3 Mon Sep 17 00:00:00 2001 From: Danielle <54275830+DanielleInkster@users.noreply.github.com> Date: Mon, 9 Dec 2024 21:22:05 -0700 Subject: [PATCH] Displays author name in Merge UI (#9920) * added get_author_names function * created enhanced records * added author name and css * Added enhancedRecord to merge function * remove from enhanced records * Update book path to search * throws new error * added comment * used try/catch * updated enhancedRecords to use for loop * add author name as td * Moved bold to css * Small style tweaks to author names in merge table * Fix undefined variable in AuthorRoleTable.vue * Handle cases where authors are missing in MergeTable --- .../components/MergeUI/AuthorRoleTable.vue | 2 +- openlibrary/components/MergeUI/MergeTable.vue | 30 ++++++++++++++-- openlibrary/components/MergeUI/utils.js | 36 +++++++++++++++++++ 3 files changed, 65 insertions(+), 3 deletions(-) diff --git a/openlibrary/components/MergeUI/AuthorRoleTable.vue b/openlibrary/components/MergeUI/AuthorRoleTable.vue index b109df1df78..b414a9aa0d6 100644 --- a/openlibrary/components/MergeUI/AuthorRoleTable.vue +++ b/openlibrary/components/MergeUI/AuthorRoleTable.vue @@ -19,7 +19,7 @@ {{role[field].key.slice("/authors/".length)}} -
{{a[k]}}
+
{{role[field]}}
diff --git a/openlibrary/components/MergeUI/MergeTable.vue b/openlibrary/components/MergeUI/MergeTable.vue index 5148640e374..bed7fd87360 100644 --- a/openlibrary/components/MergeUI/MergeTable.vue +++ b/openlibrary/components/MergeUI/MergeTable.vue @@ -8,7 +8,7 @@ } A response to the request + */ +export async function get_author_names(works) { + const authorIds = _.uniq(works).flatMap(record => + (record.authors || []).map(authorEntry => authorEntry.author.key) + ) + + if (!authorIds.length) return {}; + + const queryParams = new URLSearchParams({ + q: `key:(${authorIds.join(' OR ')})`, + mode: 'everything', + fields: 'key,name', + }) + + const response = await fetch(`${CONFIGS.OL_BASE_SEARCH}/search/authors.json?${queryParams}`) + + if (!response.ok) { + throw new Error('Failed to fetch author data'); + } + + const results = await response.json() + + const authorDirectory = {} + + for (const doc of results.docs) { + authorDirectory[doc.key] = doc.name; + } + + return authorDirectory +} + + // /** // * @param {Object} record // * @param {string} comment