DEV: Switch to new addComposerToolbarPopupMenuOption plugin API (#66)

Why this change?

`api.addToolbarPopupMenuOptionsCallback` has been deprecated in 913fd3a7b3
This commit is contained in:
Alan Guo Xiang Tan 2023-10-23 08:08:36 +08:00 committed by GitHub
parent f076c50946
commit a6a86163a7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 27 deletions

View File

@ -1,2 +1,3 @@
< 3.2.0.beta2: f076c50946b5969175d45fdd2fb6194f43394e24
3.1.999: 04b36c68012fba9778e400e83b0b01d7947b2cdf 3.1.999: 04b36c68012fba9778e400e83b0b01d7947b2cdf
3.1.0.beta2: 850e31c83d310a1b52e6105fe201eb96f9e33deb 3.1.0.beta2: 850e31c83d310a1b52e6105fe201eb96f9e33deb

View File

@ -1,30 +1,19 @@
import { apiInitializer } from "discourse/lib/api"; import { apiInitializer } from "discourse/lib/api";
import SpreadsheetEditor from "../components/spreadsheet-editor"; import SpreadsheetEditor from "../components/spreadsheet-editor";
import { action } from "@ember/object";
import { inject as service } from "@ember/service";
export default apiInitializer("0.11.1", (api) => { export default apiInitializer("1.15.0", (api) => {
api.modifyClass("controller:composer", { const modal = api.container.lookup("service:modal");
pluginId: "discourse-table-builder",
modal: service(),
@action api.addComposerToolbarPopupMenuOption({
showTableBuilder() { icon: "table",
this.modal.show(SpreadsheetEditor, { label: themePrefix("discourse_table_builder.composer.button"),
action: (toolbarEvent) => {
modal.show(SpreadsheetEditor, {
model: { model: {
toolbarEvent: this.toolbarEvent, toolbarEvent,
tableTokens: null, tableTokens: null,
}, },
}); });
}, },
}); });
api.addToolbarPopupMenuOptionsCallback(() => {
return {
id: "table-builder",
action: "showTableBuilder",
icon: "table",
label: themePrefix("discourse_table_builder.composer.button"),
};
});
}); });

View File

@ -1,3 +1,4 @@
import I18n from "discourse-i18n";
import { acceptance, exists } from "discourse/tests/helpers/qunit-helpers"; import { acceptance, exists } from "discourse/tests/helpers/qunit-helpers";
import { click, visit } from "@ember/test-helpers"; import { click, visit } from "@ember/test-helpers";
import { test } from "qunit"; import { test } from "qunit";
@ -13,10 +14,14 @@ acceptance("Table Builder", function (needs) {
await click("#create-topic"); await click("#create-topic");
await click(".d-editor-button-bar .options"); await click(".d-editor-button-bar .options");
await selectKit(".toolbar-popup-menu-options").expand(); await selectKit(".toolbar-popup-menu-options").expand();
assert.ok(
exists(".select-kit-row[data-value='showTableBuilder']"), assert
"it shows the builder button" .dom(
); `.select-kit-row[data-name='${I18n.t(
themePrefix("discourse_table_builder.composer.button")
)}']`
)
.exists("it shows the builder button");
}); });
test("Can see table builder button when editing post", async function (assert) { test("Can see table builder button when editing post", async function (assert) {
@ -26,9 +31,13 @@ acceptance("Table Builder", function (needs) {
assert.ok(exists("#reply-control")); assert.ok(exists("#reply-control"));
await click(".d-editor-button-bar .options"); await click(".d-editor-button-bar .options");
await selectKit(".toolbar-popup-menu-options").expand(); await selectKit(".toolbar-popup-menu-options").expand();
assert.ok(
exists(".select-kit-row[data-value='showTableBuilder']"), assert
"it shows the builder button" .dom(
); `.select-kit-row[data-name='${I18n.t(
themePrefix("discourse_table_builder.composer.button")
)}']`
)
.exists("it shows the builder button");
}); });
}); });