Skip to content

Commit

Permalink
Filter by usernote tag (#546)
Browse files Browse the repository at this point in the history
* Filter by usernote tag

* Update with recommendations
  • Loading branch information
dequeues committed Dec 15, 2021
1 parent ac348bd commit d19e58a
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions extension/data/modules/usernotes.js
Original file line number Diff line number Diff line change
Expand Up @@ -1045,6 +1045,10 @@ function usernotes () {
<div class="tb-un-info">
<span class="tb-info">There are ${userCount} users with ${noteCount} notes.</span>
<br> <input id="tb-unote-user-search" type="text" class="tb-input" placeholder="search for user"> <input id="tb-unote-contents-search" type="text" class="tb-input" placeholder="search for note contents">
<select name="tb-un-filter" id="tb-un-filter" class="selector tb-action-button">
<option value="all" default>All</option>
${colors.map(op => `<option value=${TBHelpers.htmlEncode(op.key)}>${TBHelpers.htmlEncode(op.text)}</option>`).join('')}
</select>
<br><br>
<button id="tb-un-prune-sb" class="tb-general-button">Prune deleted/suspended profiles</button>
</div></br></br>
Expand Down Expand Up @@ -1082,6 +1086,7 @@ function usernotes () {
// Variables to store the filter text
let userText = '';
let contentText = '';
let filterKey = 'all';

// Creates a new pager with the correct filtered items and replace
// the current one with the new one, debounced because typing delay
Expand All @@ -1090,8 +1095,18 @@ function usernotes () {
// notes based on `userText` and `contentText`
const filteredData = allUsers.map(user => ({
name: user.name,
// Filter out notes not matching `contentText`
notes: user.notes.filter(note => note.note.toLowerCase().includes(contentText.toLowerCase())),
// Filter out notes not matching `contentText` as well as filtering out keys
notes: user.notes.filter(note => {
if (!note.note.toLowerCase().includes(contentText.toLowerCase())) {
return false;
}

if (filterKey !== 'all' && filterKey !== note.type) {
return false;
}

return true;
}),
})).filter(user => {
// Filter out users not matching `userText`
if (userText && !user.name.toLowerCase().includes(userText.toLowerCase())) {
Expand Down Expand Up @@ -1128,6 +1143,10 @@ function usernotes () {
contentText = $(this).val();
refreshPager();
});
$body.find('#tb-un-filter').change(function () {
filterKey = $(this).val();
refreshPager();
});

// Process done
self.endProfile('manager-render');
Expand Down

0 comments on commit d19e58a

Please sign in to comment.