From 44bdb68ccd4e8ab4226c51fbc7538540ca8320e9 Mon Sep 17 00:00:00 2001 From: Alexander Skvortsov <38059171+askvortsov1@users.noreply.github.com> Date: Wed, 20 Oct 2021 16:48:13 -0400 Subject: [PATCH] Comply with bypassTagCounts permission in UI (#148) --- .../forum/components/TagDiscussionModal.js | 30 ++++++++++--------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/extensions/tags/js/src/forum/components/TagDiscussionModal.js b/extensions/tags/js/src/forum/components/TagDiscussionModal.js index 8d0d015f1..3b020b1ac 100644 --- a/extensions/tags/js/src/forum/components/TagDiscussionModal.js +++ b/extensions/tags/js/src/forum/components/TagDiscussionModal.js @@ -71,11 +71,11 @@ export default class TagDiscussionModal extends Modal { // If this tag has a parent, we'll also need to add the parent tag to the // selected list if it's not already in there. const parent = tag.parent(); - if (parent && this.selected.indexOf(parent) === -1) { + if (parent && !this.selected.includes(parent)) { this.selected.push(parent); } - if (this.selected.indexOf(tag) === -1) { + if (!this.selected.includes(tag)) { this.selected.push(tag); } } @@ -109,6 +109,10 @@ export default class TagDiscussionModal extends Modal { } getInstruction(primaryCount, secondaryCount) { + if (app.forum.attribute('canBypassTagCounts')) { + return ''; + } + if (primaryCount < this.minPrimary) { const remaining = this.minPrimary - primaryCount; return app.translator.trans('flarum-tags.forum.choose_tags.choose_primary_placeholder', {count: remaining}); @@ -134,17 +138,17 @@ export default class TagDiscussionModal extends Modal { // makes it impossible to select a child if its parent hasn't been selected. tags = tags.filter(tag => { const parent = tag.parent(); - return parent === false || this.selected.indexOf(parent) !== -1; + return parent === false || this.selected.includes(parent); }); // If the number of selected primary/secondary tags is at the maximum, then // we'll filter out all other tags of that type. - if (primaryCount >= this.maxPrimary) { - tags = tags.filter(tag => !tag.isPrimary() || this.selected.indexOf(tag) !== -1); + if (primaryCount >= this.maxPrimary && !app.forum.attribute('canBypassTagCounts')) { + tags = tags.filter(tag => !tag.isPrimary() || this.selected.includes(tag)); } - if (secondaryCount >= this.maxSecondary) { - tags = tags.filter(tag => tag.isPrimary() || this.selected.indexOf(tag) !== -1); + if (secondaryCount >= this.maxSecondary && !app.forum.attribute('canBypassTagCounts')) { + tags = tags.filter(tag => tag.isPrimary() || this.selected.includes(tag)); } // If the user has entered text in the filter input, then filter by tags @@ -153,7 +157,7 @@ export default class TagDiscussionModal extends Modal { tags = tags.filter(tag => tag.name().substr(0, filter.length).toLowerCase() === filter); } - if (tags.indexOf(this.index) === -1) this.index = tags[0]; + if (!tags.includes(this.index)) this.index = tags[0]; const inputWidth = Math.max(extractText(this.getInstruction(primaryCount, secondaryCount)).length, this.filter().length); @@ -194,14 +198,14 @@ export default class TagDiscussionModal extends Modal {