mirror of
https://github.com/discourse/discourse.git
synced 2025-01-19 03:32:45 +08:00
DEV: Convert reviewable-bundled-action to gjs (#23320)
This commit is contained in:
parent
06a9963cbb
commit
dac4f97032
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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}}
|
|
@ -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);
|
||||
},
|
||||
},
|
||||
});
|
Loading…
Reference in New Issue
Block a user