Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update bulk tagger for collections #9907

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 = 'collectionID:';

/**
* Represents the Bulk Tagger tool.
*
Expand Down Expand Up @@ -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, [])
}
Expand Down Expand Up @@ -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 = {
Expand All @@ -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)
}

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 @@ -115,6 +115,9 @@
&--subject {
background-color: @primary-blue;
}
&--collection {
background-color: @black;
}
}

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

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

&--staged {
Expand Down