From f2f309b5529af33f58618ca1b0e2004e3a4b613b Mon Sep 17 00:00:00 2001 From: Alan Guo Xiang Tan Date: Mon, 23 Oct 2023 08:09:06 +0800 Subject: [PATCH] DEV: Switch to new addComposerToolbarPopupMenuOption plugin API (#65) Why this change? `api.addToolbarPopupMenuOptionsCallback` has been deprecated in https://github.com/discourse/discourse/commit/913fd3a7b392b492f6344102577960a6eada00ce --- .discourse-compatibility | 1 + .../initializers/disco-toc-composer.js | 32 +++++++------------ test/acceptance/toc-composer-test.js | 9 ++++-- 3 files changed, 20 insertions(+), 22 deletions(-) diff --git a/.discourse-compatibility b/.discourse-compatibility index 20d31e7..bb1b784 100644 --- a/.discourse-compatibility +++ b/.discourse-compatibility @@ -1,3 +1,4 @@ +< 3.2.0.beta2: 0f2a0e73e6c2924f2b44d3241931f2bd5f77a9ae 3.1.999: 323bd485b08889360edcae826d6272fd8e77d180 2.7.13: 5b2f5a455e1adf8ce5e8c1cfb7fbc3c388d3d82a 2.6.0.beta3: 68d40fe9f5b625cf465adc31b502a54e16d02cc6 diff --git a/javascripts/discourse/initializers/disco-toc-composer.js b/javascripts/discourse/initializers/disco-toc-composer.js index 6305d12..5d1e321 100644 --- a/javascripts/discourse/initializers/disco-toc-composer.js +++ b/javascripts/discourse/initializers/disco-toc-composer.js @@ -19,27 +19,19 @@ export default { } I18n.translations[I18n.currentLocale()].js.composer.contains_dtoc = " "; - api.modifyClass("controller:composer", { - pluginId: "DiscoTOC", - - actions: { - insertDtoc() { - this.get("toolbarEvent").applySurround( - `
`, - `
`, - "contains_dtoc" - ); - }, + api.addComposerToolbarPopupMenuOption({ + action: (toolbarEvent) => { + toolbarEvent.applySurround( + `
`, + `
`, + "contains_dtoc" + ); + }, + icon: "align-left", + label: themePrefix("insert_table_of_contents"), + condition: (composer) => { + return composer.model.topicFirstPost; }, - }); - - api.addToolbarPopupMenuOptionsCallback((controller) => { - return { - action: "insertDtoc", - icon: "align-left", - label: themePrefix("insert_table_of_contents"), - condition: controller.get("model.topicFirstPost"), - }; }); } }); diff --git a/test/acceptance/toc-composer-test.js b/test/acceptance/toc-composer-test.js index 0e3d77f..f1bf688 100644 --- a/test/acceptance/toc-composer-test.js +++ b/test/acceptance/toc-composer-test.js @@ -1,3 +1,4 @@ +import I18n from "discourse-i18n"; import { acceptance, exists, @@ -19,7 +20,9 @@ acceptance("DiscoTOC - Composer", function (needs) { await click("#create-topic"); const toolbarPopupMenu = selectKit(".toolbar-popup-menu-options"); await toolbarPopupMenu.expand(); - await toolbarPopupMenu.selectRowByValue("insertDtoc"); + await toolbarPopupMenu.selectRowByName( + I18n.t(themePrefix("insert_table_of_contents")) + ); assert.ok(query(".d-editor-input").value.includes('data-theme-toc="true"')); }); @@ -33,7 +36,9 @@ acceptance("DiscoTOC - Composer", function (needs) { const toolbarPopupMenu = selectKit(".toolbar-popup-menu-options"); await toolbarPopupMenu.expand(); - await toolbarPopupMenu.selectRowByValue("insertDtoc"); + await toolbarPopupMenu.selectRowByName( + I18n.t(themePrefix("insert_table_of_contents")) + ); assert.ok(query(".d-editor-input").value.includes('data-theme-toc="true"')); });