From f2972d732846f3e3fe00a0cf25e3d38eb8f7eb0a Mon Sep 17 00:00:00 2001 From: jachamp <28732543+jimchamp@users.noreply.github.com> Date: Tue, 24 Sep 2024 14:45:16 -0700 Subject: [PATCH 1/3] Update bulk tagger for collections --- .../openlibrary/js/bulk-tagger/BulkTagger.js | 17 +++++++++++++++++ .../js/bulk-tagger/BulkTagger/MenuOption.js | 3 ++- .../plugins/openlibrary/js/bulk-tagger/index.js | 1 + .../openlibrary/js/bulk-tagger/models/Tag.js | 6 ++++-- static/css/components/tagging-menu.less | 7 +++++++ 5 files changed, 31 insertions(+), 3 deletions(-) diff --git a/openlibrary/plugins/openlibrary/js/bulk-tagger/BulkTagger.js b/openlibrary/plugins/openlibrary/js/bulk-tagger/BulkTagger.js index 2f993b59b27..f074f36c1d2 100644 --- a/openlibrary/plugins/openlibrary/js/bulk-tagger/BulkTagger.js +++ b/openlibrary/plugins/openlibrary/js/bulk-tagger/BulkTagger.js @@ -15,6 +15,12 @@ import { FadingToast } from '../Toast' */ const maxDisplayResults = 25; +/** + * Subject labels that begin with this string are identified as type `collection`. + * @type {string} + */ +const COLLECTION_PREFIX = "collectionID:"; + /** * Represents the Bulk Tagger tool. * @@ -246,6 +252,13 @@ export class BulkTagger { subject_places: data.subject_places || [], subject_times: data.subject_times || [] } + // Move collection labels from `subjects` to `collections` + entry.collections = entry.subjects.filter((label) => label.startsWith(COLLECTION_PREFIX)) + entry.subjects = entry.subjects.filter((label) => !entry.collections.includes(label)) + for (let i = 0; i < entry.collections.length; ++i) { + // Remove collection prefix from label + entry.collections[i] = entry.collections[i].substring(COLLECTION_PREFIX.length) + } if (!this.existingSubjects.has(id)) { this.existingSubjects.set(id, []) } @@ -551,6 +564,8 @@ export class BulkTagger { subject_places: this.findMatches(this.tagsToAdd, 'subject_places'), subject_times: this.findMatches(this.tagsToAdd, 'subject_times') } + const collectionsToAdd = this.findMatches(this.tagsToAdd, 'collections') + collectionsToAdd.forEach(label => addSubjectsValue.subjects.push(`${COLLECTION_PREFIX}${label}`)) this.addSubjectsInput.value = JSON.stringify(addSubjectsValue) const removeSubjectsValue = { @@ -559,6 +574,8 @@ export class BulkTagger { subject_places: this.findMatches(this.tagsToRemove, 'subject_places'), subject_times: this.findMatches(this.tagsToRemove, 'subject_times') } + const collectionsToRemove = this.findMatches(this.tagsToRemove, 'collections') + collectionsToRemove.forEach(label => removeSubjectsValue.subjects.push(`${COLLECTION_PREFIX}${label}`)) this.removeSubjectsInput.value = JSON.stringify(removeSubjectsValue) } diff --git a/openlibrary/plugins/openlibrary/js/bulk-tagger/BulkTagger/MenuOption.js b/openlibrary/plugins/openlibrary/js/bulk-tagger/BulkTagger/MenuOption.js index f302db1c74f..a2280150267 100644 --- a/openlibrary/plugins/openlibrary/js/bulk-tagger/BulkTagger/MenuOption.js +++ b/openlibrary/plugins/openlibrary/js/bulk-tagger/BulkTagger/MenuOption.js @@ -5,7 +5,8 @@ const classTypeSuffixes = { subjects: '--subject', subject_people: '--person', subject_places: '--place', - subject_times: '--time' + subject_times: '--time', + collections: '--collection' } /** diff --git a/openlibrary/plugins/openlibrary/js/bulk-tagger/index.js b/openlibrary/plugins/openlibrary/js/bulk-tagger/index.js index 263b5407d55..6da43278fd3 100644 --- a/openlibrary/plugins/openlibrary/js/bulk-tagger/index.js +++ b/openlibrary/plugins/openlibrary/js/bulk-tagger/index.js @@ -28,6 +28,7 @@ export function renderBulkTagger() {