DEV: Convert reviewable-bundled-action to gjs (#23320)

This commit is contained in:
Jarek Radosz 2023-08-31 16:59:19 +02:00 committed by GitHub
parent 06a9963cbb
commit dac4f97032
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 71 additions and 57 deletions

View File

@ -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 {
<template>
{{#if this.multiple}}
<DropdownSelectBox
@nameProperty="label"
@content={{@bundle.actions}}
@onChange={{this.perform}}
@options={{hash
showCaret=true
disabled=@reviewableUpdating
placement=this.placement
translatedNone=@bundle.label
}}
@class={{concatClass
"reviewable-action-dropdown"
"btn-icon-text"
(dasherize this.first.id)
this.first.button_class
}}
/>
{{else}}
<DButton
@action={{this.perform}}
@translatedLabel={{this.first.label}}
@disabled={{@reviewableUpdating}}
class={{concatClass
"reviewable-action"
(dasherize this.first.id)
this.first.button_class
}}
/>
{{/if}}
</template>
@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);
}
}
}

View File

@ -1,29 +0,0 @@
{{#if this.multiple}}
<DropdownSelectBox
@class={{concat-class
"reviewable-action-dropdown btn-icon-text"
(dasherize this.first.id)
this.first.button_class
}}
@nameProperty="label"
@content={{this.bundle.actions}}
@onChange={{action "performById"}}
@options={{hash
showCaret=true
disabled=this.reviewableUpdating
placement=this.placement
translatedNone=this.bundle.label
}}
/>
{{else}}
<DButton
@class={{concat-class
"reviewable-action"
(dasherize this.first.id)
this.first.button_class
}}
@action={{action "performFirst"}}
@translatedLabel={{this.first.label}}
@disabled={{this.reviewableUpdating}}
/>
{{/if}}

View File

@ -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);
},
},
});