From 26209354e357cd4680cb1950945f12c5bd769738 Mon Sep 17 00:00:00 2001 From: OsamaSayegh Date: Wed, 10 May 2017 19:52:38 +0300 Subject: [PATCH] Don't hardcode code button index and remove the for loop and use .some() --- .../controllers/topic-bulk-actions.js.es6 | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/app/assets/javascripts/discourse/controllers/topic-bulk-actions.js.es6 b/app/assets/javascripts/discourse/controllers/topic-bulk-actions.js.es6 index 69cdc749832..af9deb0c216 100644 --- a/app/assets/javascripts/discourse/controllers/topic-bulk-actions.js.es6 +++ b/app/assets/javascripts/discourse/controllers/topic-bulk-actions.js.es6 @@ -26,18 +26,12 @@ export default Ember.Controller.extend(ModalFunctionality, { categoryId: Ember.computed.alias('model.category.id'), onShow() { - let showRelistButton = false; - const topics = this.get('model.topics'); - for (let t = 0; t < topics.length; t++) { - if (!topics[t].visible) { - showRelistButton = true; - break; - } - } - if (showRelistButton && !_buttons[9]) { + const showRelistButton = this.get('model.topics').some(t => !t.visible); + const relistButtonIndex = _buttons.findIndex(b => b.action === 'relistTopics'); + if (showRelistButton && relistButtonIndex === -1) { addBulkButton('relistTopics', 'relist_topics'); - } else if (!showRelistButton && _buttons[9]) { - _buttons.splice(9, 1); + } else if (!showRelistButton && relistButtonIndex !== -1) { + _buttons.splice(relistButtonIndex, 1); } this.set('modal.modalClass', 'topic-bulk-actions-modal small');