DEV: Add remove button function to PluginAPI (#9627)
This commit is contained in:
parent
6b14a0f352
commit
8010e1ab2e
|
@ -5,7 +5,7 @@ import { addPluginOutletDecorator } from "discourse/components/plugin-connector"
|
|||
import { addTopicTitleDecorator } from "discourse/components/topic-title";
|
||||
import ComposerEditor from "discourse/components/composer-editor";
|
||||
import DiscourseBanner from "discourse/components/discourse-banner";
|
||||
import { addButton } from "discourse/widgets/post-menu";
|
||||
import { addButton, removeButton } from "discourse/widgets/post-menu";
|
||||
import { includeAttributes } from "discourse/lib/transform-post";
|
||||
import { registerHighlightJSLanguage } from "discourse/lib/highlight-syntax";
|
||||
import { addToolbarCallback } from "discourse/components/d-editor";
|
||||
|
@ -399,11 +399,25 @@ class PluginApi {
|
|||
* position: 'first' // can be `first`, `last` or `second-last-hidden`
|
||||
* };
|
||||
* });
|
||||
* ```
|
||||
**/
|
||||
addPostMenuButton(name, callback) {
|
||||
addButton(name, callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove existing button below a post with your plugin.
|
||||
*
|
||||
* Example:
|
||||
*
|
||||
* ```
|
||||
* api.removePostMenuButton('like');
|
||||
* ```
|
||||
**/
|
||||
removePostMenuButton(name) {
|
||||
removeButton(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* A hook that is called when the editor toolbar is created. You can
|
||||
* use this to add custom editor buttons.
|
||||
|
|
|
@ -41,6 +41,11 @@ export function addButton(name, builder) {
|
|||
_extraButtons[name] = builder;
|
||||
}
|
||||
|
||||
export function removeButton(name) {
|
||||
if (_extraButtons[name]) delete _extraButtons[name];
|
||||
if (_builders[name]) delete _builders[name];
|
||||
}
|
||||
|
||||
function registerButton(name, builder) {
|
||||
_builders[name] = builder;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,44 @@
|
|||
import { moduleForWidget, widgetTest } from "helpers/widget-test";
|
||||
import { withPluginApi } from "discourse/lib/plugin-api";
|
||||
|
||||
moduleForWidget("post-menu");
|
||||
|
||||
widgetTest("add extra button", {
|
||||
template: '{{mount-widget widget="post-menu" args=args}}',
|
||||
beforeEach() {
|
||||
this.set("args", {});
|
||||
withPluginApi("0.8", api => {
|
||||
api.addPostMenuButton("coffee", () => {
|
||||
return {
|
||||
action: "drinkCoffee",
|
||||
icon: "coffee",
|
||||
className: "hot-coffee",
|
||||
title: "coffee.title",
|
||||
position: "first"
|
||||
};
|
||||
});
|
||||
});
|
||||
},
|
||||
async test(assert) {
|
||||
assert.ok(
|
||||
find(".actions .extra-buttons .hot-coffee").length === 1,
|
||||
"It renders extra button"
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
widgetTest("remove extra button", {
|
||||
template: '{{mount-widget widget="post-menu" args=args}}',
|
||||
beforeEach() {
|
||||
this.set("args", {});
|
||||
withPluginApi("0.8", api => {
|
||||
api.removePostMenuButton("coffee");
|
||||
});
|
||||
},
|
||||
async test(assert) {
|
||||
assert.ok(
|
||||
find(".actions .extra-buttons .hot-coffee").length === 0,
|
||||
"It doesn't removes coffee button"
|
||||
);
|
||||
}
|
||||
});
|
Loading…
Reference in New Issue