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() {
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 0d2837db5dc..52fcb67ec31 100644 --- a/static/css/components/tagging-menu.less +++ b/static/css/components/tagging-menu.less @@ -115,6 +115,9 @@ &--subject { background-color: @primary-blue; } + &--collection { + background-color: @black; + } } .search-subject-row-name { @@ -244,6 +247,10 @@ &--subject { background-color: @primary-blue; } + + &--collection { + background-color: @black; + } } &--staged { From ddc5e18b7c8b5f3e6297c5e36aa03433b559c569 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 24 Sep 2024 22:36:14 +0000 Subject: [PATCH 2/3] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- openlibrary/plugins/openlibrary/js/bulk-tagger/BulkTagger.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openlibrary/plugins/openlibrary/js/bulk-tagger/BulkTagger.js b/openlibrary/plugins/openlibrary/js/bulk-tagger/BulkTagger.js index f074f36c1d2..6d8023b40f6 100644 --- a/openlibrary/plugins/openlibrary/js/bulk-tagger/BulkTagger.js +++ b/openlibrary/plugins/openlibrary/js/bulk-tagger/BulkTagger.js @@ -19,7 +19,7 @@ const maxDisplayResults = 25; * Subject labels that begin with this string are identified as type `collection`. * @type {string} */ -const COLLECTION_PREFIX = "collectionID:"; +const COLLECTION_PREFIX = 'collectionID:'; /** * Represents the Bulk Tagger tool. From 57b3511c8919020b9240d5773f9d1c18622a41c7 Mon Sep 17 00:00:00 2001 From: Mek Date: Mon, 30 Sep 2024 11:53:48 -0700 Subject: [PATCH 3/3] add support for collection: prefix --- openlibrary/plugins/openlibrary/js/bulk-tagger/BulkTagger.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openlibrary/plugins/openlibrary/js/bulk-tagger/BulkTagger.js b/openlibrary/plugins/openlibrary/js/bulk-tagger/BulkTagger.js index 6d8023b40f6..9470b570cd8 100644 --- a/openlibrary/plugins/openlibrary/js/bulk-tagger/BulkTagger.js +++ b/openlibrary/plugins/openlibrary/js/bulk-tagger/BulkTagger.js @@ -19,7 +19,7 @@ const maxDisplayResults = 25; * Subject labels that begin with this string are identified as type `collection`. * @type {string} */ -const COLLECTION_PREFIX = 'collectionID:'; +const COLLECTION_PREFIX = 'collection:'; /** * Represents the Bulk Tagger tool.