From e0199e80944e55bf0adcd6b60ca811956d8102ce Mon Sep 17 00:00:00 2001 From: Blake Erickson Date: Mon, 25 Nov 2019 18:02:55 -0700 Subject: [PATCH] DEV: Remove buffered rendering from admin-directory toggle This is another refactoring in the multi-step process to remove all uses of our custom Render Buffer. Previous commit: d0ad5ecc6dd69db5c4550d921bc5de99b9a47687 in this series. This commit affects the table header sorting on the admin directory page. It is just a refactor and should not change any functionality. --- .../components/admin-directory-toggle.js.es6 | 58 +++++++++---------- .../components/admin-directory-toggle.hbs | 1 + 2 files changed, 27 insertions(+), 32 deletions(-) create mode 100644 app/assets/javascripts/admin/templates/components/admin-directory-toggle.hbs diff --git a/app/assets/javascripts/admin/components/admin-directory-toggle.js.es6 b/app/assets/javascripts/admin/components/admin-directory-toggle.js.es6 index f110293a745..093f29826b8 100644 --- a/app/assets/javascripts/admin/components/admin-directory-toggle.js.es6 +++ b/app/assets/javascripts/admin/components/admin-directory-toggle.js.es6 @@ -1,36 +1,30 @@ import Component from "@ember/component"; import { iconHTML } from "discourse-common/lib/icon-library"; -import { bufferedRender } from "discourse-common/lib/buffered-render"; -export default Component.extend( - bufferedRender({ - tagName: "th", - classNames: ["sortable"], - rerenderTriggers: ["order", "ascending"], - - buildBuffer(buffer) { - const icon = this.icon; - - if (icon) { - buffer.push(iconHTML(icon)); - } - - buffer.push(I18n.t(this.i18nKey)); - - if (this.field === this.order) { - buffer.push(iconHTML(this.ascending ? "chevron-up" : "chevron-down")); - } - }, - - click() { - const currentOrder = this.order; - const field = this.field; - - if (currentOrder === field) { - this.set("ascending", this.ascending ? null : true); - } else { - this.setProperties({ order: field, ascending: null }); - } +export default Component.extend({ + tagName: "th", + classNames: ["sortable"], + chevronIcon: null, + toggleProperties() { + if (this.order === this.field) { + this.set("ascending", this.ascending ? null : true); + } else { + this.setProperties({ order: this.field, ascending: null }); } - }) -); + }, + toggleChevron() { + if (this.order === this.field) { + let chevron = iconHTML(this.ascending ? "chevron-up" : "chevron-down"); + this.set("chevronIcon", `${chevron}`.htmlSafe()); + } else { + this.set("chevronIcon", null); + } + }, + click() { + this.toggleProperties(); + }, + didReceiveAttrs() { + this._super(...arguments); + this.toggleChevron(); + } +}); diff --git a/app/assets/javascripts/admin/templates/components/admin-directory-toggle.hbs b/app/assets/javascripts/admin/templates/components/admin-directory-toggle.hbs new file mode 100644 index 00000000000..7ea697404f6 --- /dev/null +++ b/app/assets/javascripts/admin/templates/components/admin-directory-toggle.hbs @@ -0,0 +1 @@ +{{i18n this.i18nKey}}{{chevronIcon}}