Skip to content

Commit

Permalink
Update bulk tagger for collections (#9907)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
3 people committed Sep 30, 2024
1 parent 1689116 commit 5a93da5
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 3 deletions.
17 changes: 17 additions & 0 deletions openlibrary/plugins/openlibrary/js/bulk-tagger/BulkTagger.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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, [])
}
Expand Down Expand Up @@ -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 = {
Expand All @@ -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)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ const classTypeSuffixes = {
subjects: '--subject',
subject_people: '--person',
subject_places: '--place',
subject_times: '--time'
subject_times: '--time',
collections: '--collection'
}

/**
Expand Down
1 change: 1 addition & 0 deletions openlibrary/plugins/openlibrary/js/bulk-tagger/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export function renderBulkTagger() {
<div class="subject-type-option subject-type-option--person" data-tag-type="subject_people">person</div>
<div class="subject-type-option subject-type-option--place" data-tag-type="subject_places">place</div>
<div class="subject-type-option subject-type-option--time" data-tag-type="subject_times">time</div>
<div class="subject-type-option subject-type-option--collection" data-tag-type="collections">collection</div>
</div>
</div>
</div>
Expand Down
6 changes: 4 additions & 2 deletions openlibrary/plugins/openlibrary/js/bulk-tagger/models/Tag.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ const displayTypeMapping = {
subjects: 'subject',
subject_people: 'person',
subject_places: 'place',
subject_times: 'time'
subject_times: 'time',
collections: 'collection',
}

/**
Expand All @@ -17,7 +18,8 @@ export const subjectTypeMapping = {
subject: 'subjects',
person: 'subject_people',
place: 'subject_places',
time: 'subject_times'
time: 'subject_times',
collection: 'collections'
}

/**
Expand Down
7 changes: 7 additions & 0 deletions static/css/components/tagging-menu.less
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@
&--subject {
background-color: @primary-blue;
}
&--collection {
background-color: @black;
}
}

.search-subject-row-name {
Expand Down Expand Up @@ -189,6 +192,10 @@
&--subject {
background-color: @primary-blue;
}

&--collection {
background-color: @black;
}
}

&--staged {
Expand Down

0 comments on commit 5a93da5

Please sign in to comment.