From dac4f97032a4932b822d6e972465d3074a7c796c Mon Sep 17 00:00:00 2001 From: Jarek Radosz Date: Thu, 31 Aug 2023 16:59:19 +0200 Subject: [PATCH] DEV: Convert reviewable-bundled-action to gjs (#23320) --- .../components/reviewable-bundled-action.gjs | 71 +++++++++++++++++++ .../components/reviewable-bundled-action.hbs | 29 -------- .../components/reviewable-bundled-action.js | 28 -------- 3 files changed, 71 insertions(+), 57 deletions(-) create mode 100644 app/assets/javascripts/discourse/app/components/reviewable-bundled-action.gjs delete mode 100644 app/assets/javascripts/discourse/app/components/reviewable-bundled-action.hbs delete mode 100644 app/assets/javascripts/discourse/app/components/reviewable-bundled-action.js diff --git a/app/assets/javascripts/discourse/app/components/reviewable-bundled-action.gjs b/app/assets/javascripts/discourse/app/components/reviewable-bundled-action.gjs new file mode 100644 index 00000000000..21d74a3bfc7 --- /dev/null +++ b/app/assets/javascripts/discourse/app/components/reviewable-bundled-action.gjs @@ -0,0 +1,71 @@ +import Component from "@glimmer/component"; +import DropdownSelectBox from "select-kit/components/dropdown-select-box"; +import DButton from "discourse/components/d-button"; +import concatClass from "discourse/helpers/concat-class"; +import { dasherize } from "@ember/string"; +import { hash } from "@ember/helper"; +import { inject as service } from "@ember/service"; +import { action } from "@ember/object"; +import { isRTL } from "discourse/lib/text-direction"; + +export default class ReviewableBundledAction extends Component { + + + @service site; + + get multiple() { + return this.args.bundle.actions.length > 1; + } + + get first() { + return this.args.bundle.actions[0]; + } + + get placement() { + const vertical = this.site.mobileView ? "top" : "bottom"; + const horizontal = isRTL() ? "end" : "start"; + + return `${vertical}-${horizontal}`; + } + + @action + perform(id) { + if (id) { + const _action = this.args.bundle.actions.find((a) => a.id === id); + this.args.performAction(_action); + } else { + this.args.performAction(this.first); + } + } +} diff --git a/app/assets/javascripts/discourse/app/components/reviewable-bundled-action.hbs b/app/assets/javascripts/discourse/app/components/reviewable-bundled-action.hbs deleted file mode 100644 index d4566708028..00000000000 --- a/app/assets/javascripts/discourse/app/components/reviewable-bundled-action.hbs +++ /dev/null @@ -1,29 +0,0 @@ -{{#if this.multiple}} - -{{else}} - -{{/if}} \ No newline at end of file diff --git a/app/assets/javascripts/discourse/app/components/reviewable-bundled-action.js b/app/assets/javascripts/discourse/app/components/reviewable-bundled-action.js deleted file mode 100644 index bc892b078db..00000000000 --- a/app/assets/javascripts/discourse/app/components/reviewable-bundled-action.js +++ /dev/null @@ -1,28 +0,0 @@ -import { alias, gt } from "@ember/object/computed"; -import Component from "@ember/component"; -import discourseComputed from "discourse-common/utils/decorators"; -import { isRTL } from "discourse/lib/text-direction"; - -export default Component.extend({ - tagName: "", - - multiple: gt("bundle.actions.length", 1), - first: alias("bundle.actions.firstObject"), - - @discourseComputed() - placement() { - const vertical = this.site.mobileView ? "top" : "bottom", - horizontal = isRTL() ? "end" : "start"; - return `${vertical}-${horizontal}`; - }, - - actions: { - performById(id) { - this.performAction(this.get("bundle.actions").findBy("id", id)); - }, - - performFirst() { - this.performAction(this.first); - }, - }, -});