From 5a93da5f328a92d821ef45d06edd057c2f5ea903 Mon Sep 17 00:00:00 2001 From: jimchamp <28732543+jimchamp@users.noreply.github.com> Date: Mon, 30 Sep 2024 11:54:26 -0700 Subject: [PATCH] Update bulk tagger for collections (#9907) * Update bulk tagger for collections --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Mek --- .../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 a3e9bf7e0bf..29e2e93021b 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 = 'collection:'; + /** * Represents the Bulk Tagger tool. * @@ -235,6 +241,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, []) } @@ -540,6 +553,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 = { @@ -548,6 +563,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() {
person
place
time
+
collection
diff --git a/openlibrary/plugins/openlibrary/js/bulk-tagger/models/Tag.js b/openlibrary/plugins/openlibrary/js/bulk-tagger/models/Tag.js index 9eb580b3630..aa3bb1887b3 100644 --- a/openlibrary/plugins/openlibrary/js/bulk-tagger/models/Tag.js +++ b/openlibrary/plugins/openlibrary/js/bulk-tagger/models/Tag.js @@ -6,7 +6,8 @@ const displayTypeMapping = { subjects: 'subject', subject_people: 'person', subject_places: 'place', - subject_times: 'time' + subject_times: 'time', + collections: 'collection', } /** @@ -17,7 +18,8 @@ export const subjectTypeMapping = { subject: 'subjects', person: 'subject_people', place: 'subject_places', - time: 'subject_times' + time: 'subject_times', + collection: 'collections' } /** diff --git a/static/css/components/tagging-menu.less b/static/css/components/tagging-menu.less index 582c9446a64..6cc4507373c 100644 --- a/static/css/components/tagging-menu.less +++ b/static/css/components/tagging-menu.less @@ -99,6 +99,9 @@ &--subject { background-color: @primary-blue; } + &--collection { + background-color: @black; + } } .search-subject-row-name { @@ -189,6 +192,10 @@ &--subject { background-color: @primary-blue; } + + &--collection { + background-color: @black; + } } &--staged {