Skip to content

Commit

Permalink
DEV: Switch to new addComposerToolbarPopupMenuOption plugin API (#460)
Browse files Browse the repository at this point in the history
Why this change?

`api.addToolbarPopupMenuOptionsCallback` has been deprecated in discourse/discourse@913fd3a
  • Loading branch information
tgxworld authored Oct 23, 2023
1 parent 09583aa commit 1964912
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 49 deletions.
1 change: 1 addition & 0 deletions .discourse-compatibility
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
< 3.2.0.beta2: 6c659020ab5cca4af846b4b78e4ed0b4e06a2bca
3.1.0.beta3: 10077ca904956005f9fa83c3d9fb124b59e8c47b
2.9.0.beta13: b4c366b35d6f9778e54a878aa083348e8a45e86e
2.9.0.beta9: 6f16ae10dc0306d6e1369e0d1414416d7e72141d
Expand Down
78 changes: 34 additions & 44 deletions assets/javascripts/discourse/initializers/add-event-ui-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,50 +3,40 @@ import showModal from "discourse/lib/show-modal";

function initializeEventBuilder(api) {
const currentUser = api.getCurrentUser();

api.addToolbarPopupMenuOptionsCallback((composerController) => {
if (!currentUser || !currentUser.can_create_discourse_post_event) {
return;
}

const composerModel = composerController.model;
if (
composerModel &&
!composerModel.replyingToTopic &&
(composerModel.topicFirstPost ||
composerModel.creatingPrivateMessage ||
(composerModel.editingPost &&
composerModel.post &&
composerModel.post.post_number === 1))
) {
return {
label: "discourse_post_event.builder_modal.attach",
id: "insertEvent",
group: "insertions",
icon: "calendar-day",
action: "insertEvent",
};
}
});

api.modifyClass("controller:composer", {
pluginId: "discourse-calendar",

actions: {
insertEvent() {
const eventModel = this.store.createRecord(
"discourse-post-event-event"
);
eventModel.set("status", "public");
eventModel.set("custom_fields", {});
eventModel.set("starts_at", moment());
eventModel.set("timezone", moment.tz.guess());

showModal("discourse-post-event-builder").setProperties({
toolbarEvent: this.toolbarEvent,
model: { eventModel },
});
},
const store = api.container.lookup("service:store");

api.addComposerToolbarPopupMenuOption({
action: (toolbarEvent) => {
const eventModel = store.createRecord("discourse-post-event-event");
eventModel.set("status", "public");
eventModel.set("custom_fields", {});
eventModel.set("starts_at", moment());
eventModel.set("timezone", moment.tz.guess());

showModal("discourse-post-event-builder").setProperties({
toolbarEvent,
model: { eventModel },
});
},
group: "insertions",
icon: "calendar-day",
label: "discourse_post_event.builder_modal.attach",
condition: (composer) => {
if (!currentUser || !currentUser.can_create_discourse_post_event) {
return false;
}

const composerModel = composer.model;

return (
composerModel &&
!composerModel.replyingToTopic &&
(composerModel.topicFirstPost ||
composerModel.creatingPrivateMessage ||
(composerModel.editingPost &&
composerModel.post &&
composerModel.post.post_number === 1))
);
},
});
}
Expand Down
19 changes: 14 additions & 5 deletions test/javascripts/acceptance/post-event-builder-test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
import { test } from "qunit";
import { click, fillIn, visit } from "@ember/test-helpers";
import selectKit from "discourse/tests/helpers/select-kit-helper";
import { test } from "qunit";
import sinon from "sinon";
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
import selectKit from "discourse/tests/helpers/select-kit-helper";
import I18n from "discourse-i18n";

acceptance("Post event - composer", function (needs) {
needs.user({ admin: true, can_create_discourse_post_event: true });
Expand All @@ -21,7 +22,11 @@ acceptance("Post event - composer", function (needs) {
await categoryChooser.expand();
await categoryChooser.selectRowByValue(2);
await click(".toolbar-popup-menu-options .dropdown-select-box-header");
await click(".toolbar-popup-menu-options *[data-value='insertEvent']");
await click(
`.toolbar-popup-menu-options *[data-name='${I18n.t(
"discourse_post_event.builder_modal.attach"
)}']`
);

const modal = ".discourse-post-event-builder-modal";

Expand Down Expand Up @@ -87,7 +92,11 @@ acceptance("Post event - composer", function (needs) {
await categoryChooser.selectRowByValue(2);

await click(".toolbar-popup-menu-options .dropdown-select-box-header");
await click(".toolbar-popup-menu-options *[data-value='insertEvent']");
await click(
`.toolbar-popup-menu-options *[data-name='${I18n.t(
"discourse_post_event.builder_modal.attach"
)}']`
);

const modal = ".discourse-post-event-builder-modal";

Expand Down

0 comments on commit 1964912

Please sign in to comment.