From 1eb4ef258edd126439e0160137e7ca5cbc069800 Mon Sep 17 00:00:00 2001 From: DanielleInkster Date: Tue, 1 Oct 2024 14:13:22 +0100 Subject: [PATCH 01/12] added get_author_names function --- openlibrary/components/MergeUI/utils.js | 32 +++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/openlibrary/components/MergeUI/utils.js b/openlibrary/components/MergeUI/utils.js index 79c3a44a772..06585472b3d 100644 --- a/openlibrary/components/MergeUI/utils.js +++ b/openlibrary/components/MergeUI/utils.js @@ -230,6 +230,38 @@ function save_many(items, comment, action, data) { }); } +/** + * Fetches name associated with the author key + * @param {Object[]} works + * @returns {Promise} 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) + ) + + const queryParams = new URLSearchParams({ + q: `key:(${authorIds.join(' OR ')})`, + mode: 'everything', + fields: 'key,name', + }) + + const response = await fetch(`${CONFIGS.OL_BASE_BOOKS}/search/authors.json?${queryParams}`) + + if (!response.ok) return {error: true}; + + 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 From 7521d9371e9a736de1f8371db1645eb7083ca80a Mon Sep 17 00:00:00 2001 From: DanielleInkster Date: Tue, 1 Oct 2024 14:31:38 +0100 Subject: [PATCH 02/12] created enhanced records --- openlibrary/components/MergeUI/MergeTable.vue | 24 +++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/openlibrary/components/MergeUI/MergeTable.vue b/openlibrary/components/MergeUI/MergeTable.vue index 5148640e374..166b8cc7ed8 100644 --- a/openlibrary/components/MergeUI/MergeTable.vue +++ b/openlibrary/components/MergeUI/MergeTable.vue @@ -8,7 +8,7 @@ + record.authors.map(entry=> { + for (const [key, value] of Object.entries(author_names)) { + if (entry.author.key === `/authors/${key}`){ + entry.author.name = value + } + } + }) + ) + + return enhanced_records + }, + async editions() { if (!this.records) return null; From d572576121c284e06c19bf2ef8a6d6136dfd20b1 Mon Sep 17 00:00:00 2001 From: DanielleInkster Date: Tue, 1 Oct 2024 14:45:47 +0100 Subject: [PATCH 03/12] added author name and css --- openlibrary/components/MergeUI/AuthorRoleTable.vue | 3 ++- openlibrary/components/MergeUI/MergeTable.vue | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/openlibrary/components/MergeUI/AuthorRoleTable.vue b/openlibrary/components/MergeUI/AuthorRoleTable.vue index b109df1df78..4f74f769c83 100644 --- a/openlibrary/components/MergeUI/AuthorRoleTable.vue +++ b/openlibrary/components/MergeUI/AuthorRoleTable.vue @@ -15,9 +15,10 @@ {{(role[field].key || role[field]).slice("/type/".length)}}
{{a[k]}}
diff --git a/openlibrary/components/MergeUI/MergeTable.vue b/openlibrary/components/MergeUI/MergeTable.vue index 166b8cc7ed8..48b92cd6172 100644 --- a/openlibrary/components/MergeUI/MergeTable.vue +++ b/openlibrary/components/MergeUI/MergeTable.vue @@ -494,6 +494,11 @@ li.excerpt-item { } .field-authors { + .author-author-children { + display: inline-block; + padding-right: 2em; + } + thead, td.author-index, td.author-type { display: none; } From 6220b671625b381ccdc121f178b102cc7fcdf90a Mon Sep 17 00:00:00 2001 From: DanielleInkster Date: Tue, 1 Oct 2024 16:48:27 +0100 Subject: [PATCH 04/12] Added enhancedRecord to merge function --- openlibrary/components/MergeUI/MergeTable.vue | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/openlibrary/components/MergeUI/MergeTable.vue b/openlibrary/components/MergeUI/MergeTable.vue index 48b92cd6172..e38fdd45d02 100644 --- a/openlibrary/components/MergeUI/MergeTable.vue +++ b/openlibrary/components/MergeUI/MergeTable.vue @@ -192,8 +192,8 @@ export default { if (!this.master_key || !this.records || !this.editions) return undefined; - const master = this.records.find(r => r.key === this.master_key); - const all_dupes = this.records + const master = this.enhancedRecords.find(r => r.key === this.master_key); + const all_dupes = this.enhancedRecords .filter(r => this.selected[r.key]) .filter(r => r.key !== this.master_key); const dupes = all_dupes.filter(r => r.type.key === '/type/work'); From e50573cf66eba4aa90c65b52a119a3a82adf674c Mon Sep 17 00:00:00 2001 From: DanielleInkster Date: Tue, 1 Oct 2024 17:08:01 +0100 Subject: [PATCH 05/12] remove from enhanced records --- openlibrary/components/MergeUI/MergeTable.vue | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/openlibrary/components/MergeUI/MergeTable.vue b/openlibrary/components/MergeUI/MergeTable.vue index e38fdd45d02..48b92cd6172 100644 --- a/openlibrary/components/MergeUI/MergeTable.vue +++ b/openlibrary/components/MergeUI/MergeTable.vue @@ -192,8 +192,8 @@ export default { if (!this.master_key || !this.records || !this.editions) return undefined; - const master = this.enhancedRecords.find(r => r.key === this.master_key); - const all_dupes = this.enhancedRecords + const master = this.records.find(r => r.key === this.master_key); + const all_dupes = this.records .filter(r => this.selected[r.key]) .filter(r => r.key !== this.master_key); const dupes = all_dupes.filter(r => r.type.key === '/type/work'); From 834935ec56a0409f4be670e90acac79000ed3693 Mon Sep 17 00:00:00 2001 From: DanielleInkster Date: Sat, 5 Oct 2024 11:42:26 +0100 Subject: [PATCH 06/12] Update book path to search --- openlibrary/components/MergeUI/utils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openlibrary/components/MergeUI/utils.js b/openlibrary/components/MergeUI/utils.js index 06585472b3d..01e120ed386 100644 --- a/openlibrary/components/MergeUI/utils.js +++ b/openlibrary/components/MergeUI/utils.js @@ -246,7 +246,7 @@ export async function get_author_names(works) { fields: 'key,name', }) - const response = await fetch(`${CONFIGS.OL_BASE_BOOKS}/search/authors.json?${queryParams}`) + const response = await fetch(`${CONFIGS.OL_BASE_SEARCH}/search/authors.json?${queryParams}`) if (!response.ok) return {error: true}; From 2edfbc602387c0cc19693f16d8036d8a8b2b385d Mon Sep 17 00:00:00 2001 From: DanielleInkster Date: Sat, 5 Oct 2024 11:44:19 +0100 Subject: [PATCH 07/12] throws new error --- openlibrary/components/MergeUI/utils.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/openlibrary/components/MergeUI/utils.js b/openlibrary/components/MergeUI/utils.js index 01e120ed386..4bd45653972 100644 --- a/openlibrary/components/MergeUI/utils.js +++ b/openlibrary/components/MergeUI/utils.js @@ -248,7 +248,9 @@ export async function get_author_names(works) { const response = await fetch(`${CONFIGS.OL_BASE_SEARCH}/search/authors.json?${queryParams}`) - if (!response.ok) return {error: true}; + if (!response.ok) { + throw new Error('Failed to fetch author data'); + } const results = await response.json() From 32e476ed75080ada6d585580df25cde86133536e Mon Sep 17 00:00:00 2001 From: DanielleInkster Date: Sat, 5 Oct 2024 11:52:02 +0100 Subject: [PATCH 08/12] added comment --- openlibrary/components/MergeUI/MergeTable.vue | 1 + 1 file changed, 1 insertion(+) diff --git a/openlibrary/components/MergeUI/MergeTable.vue b/openlibrary/components/MergeUI/MergeTable.vue index 48b92cd6172..9fff1ab5170 100644 --- a/openlibrary/components/MergeUI/MergeTable.vue +++ b/openlibrary/components/MergeUI/MergeTable.vue @@ -113,6 +113,7 @@ export default { return records; }, + /** The records, with extra helpful metadata attached for display. Should NOT be saved to Open Library */ async enhancedRecords(){ if (!this.records) return null; From a28967da8e75c6a5c2c6c259dfd36673ecdc9212 Mon Sep 17 00:00:00 2001 From: DanielleInkster Date: Sat, 5 Oct 2024 11:57:33 +0100 Subject: [PATCH 09/12] used try/catch --- openlibrary/components/MergeUI/MergeTable.vue | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/openlibrary/components/MergeUI/MergeTable.vue b/openlibrary/components/MergeUI/MergeTable.vue index 9fff1ab5170..ed8d49ca804 100644 --- a/openlibrary/components/MergeUI/MergeTable.vue +++ b/openlibrary/components/MergeUI/MergeTable.vue @@ -117,7 +117,13 @@ export default { async enhancedRecords(){ if (!this.records) return null; - const author_names = await get_author_names(this.records) + let author_names; + + try { + author_names = await get_author_names(this.records); + } catch (error) { + console.error('Error creating enhancedRecords:', error); + } const enhanced_records = _.cloneDeep(this.records) From d6e087ee8f7ccabb419960f9a74b98e926edda27 Mon Sep 17 00:00:00 2001 From: DanielleInkster Date: Sat, 5 Oct 2024 12:00:34 +0100 Subject: [PATCH 10/12] updated enhancedRecords to use for loop --- openlibrary/components/MergeUI/MergeTable.vue | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/openlibrary/components/MergeUI/MergeTable.vue b/openlibrary/components/MergeUI/MergeTable.vue index ed8d49ca804..270e9b33ca1 100644 --- a/openlibrary/components/MergeUI/MergeTable.vue +++ b/openlibrary/components/MergeUI/MergeTable.vue @@ -127,15 +127,11 @@ export default { const enhanced_records = _.cloneDeep(this.records) - enhanced_records.flatMap(record => - record.authors.map(entry=> { - for (const [key, value] of Object.entries(author_names)) { - if (entry.author.key === `/authors/${key}`){ - entry.author.name = value - } - } - }) - ) + for (const record of enhanced_records) { + for (const entry of record.authors) { + entry.author.name = author_names[entry.author.key]; + } + } return enhanced_records }, From a014aac4d743d61eac8153307be07ccf9ab2d79a Mon Sep 17 00:00:00 2001 From: DanielleInkster Date: Sat, 5 Oct 2024 14:09:28 +0100 Subject: [PATCH 11/12] add author name as td --- openlibrary/components/MergeUI/AuthorRoleTable.vue | 6 ++++-- openlibrary/components/MergeUI/MergeTable.vue | 5 ++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/openlibrary/components/MergeUI/AuthorRoleTable.vue b/openlibrary/components/MergeUI/AuthorRoleTable.vue index 4f74f769c83..2fd4dc3112c 100644 --- a/openlibrary/components/MergeUI/AuthorRoleTable.vue +++ b/openlibrary/components/MergeUI/AuthorRoleTable.vue @@ -15,10 +15,12 @@ {{(role[field].key || role[field]).slice("/type/".length)}} +
+ {{role[field]}}
{{a[k]}}
diff --git a/openlibrary/components/MergeUI/MergeTable.vue b/openlibrary/components/MergeUI/MergeTable.vue index 270e9b33ca1..3d04a71e022 100644 --- a/openlibrary/components/MergeUI/MergeTable.vue +++ b/openlibrary/components/MergeUI/MergeTable.vue @@ -129,10 +129,9 @@ export default { for (const record of enhanced_records) { for (const entry of record.authors) { - entry.author.name = author_names[entry.author.key]; + entry.name = author_names[entry.author.key.slice('/authors/'.length)]; } } - return enhanced_records }, @@ -497,7 +496,7 @@ li.excerpt-item { } .field-authors { - .author-author-children { + td.author-author, td.author-name { display: inline-block; padding-right: 2em; } From 48a717819fde2cee5470a8b73f01a255b9db2bcb Mon Sep 17 00:00:00 2001 From: DanielleInkster Date: Sat, 12 Oct 2024 16:10:27 +0100 Subject: [PATCH 12/12] Moved bold to css --- openlibrary/components/MergeUI/AuthorRoleTable.vue | 2 +- openlibrary/components/MergeUI/MergeTable.vue | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/openlibrary/components/MergeUI/AuthorRoleTable.vue b/openlibrary/components/MergeUI/AuthorRoleTable.vue index 2fd4dc3112c..a9deaee47dc 100644 --- a/openlibrary/components/MergeUI/AuthorRoleTable.vue +++ b/openlibrary/components/MergeUI/AuthorRoleTable.vue @@ -20,7 +20,7 @@
- {{role[field]}} + {{role[field]}}
{{a[k]}}
diff --git a/openlibrary/components/MergeUI/MergeTable.vue b/openlibrary/components/MergeUI/MergeTable.vue index 3d04a71e022..6d3228bb125 100644 --- a/openlibrary/components/MergeUI/MergeTable.vue +++ b/openlibrary/components/MergeUI/MergeTable.vue @@ -496,11 +496,16 @@ li.excerpt-item { } .field-authors { - td.author-author, td.author-name { + td.author-author { display: inline-block; padding-right: 2em; } + td.author-name { + display: inline-block; + font-weight: bold; + } + thead, td.author-index, td.author-type { display: none; }