-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DEV: Improve
addToolbarPopupMenuOptionsCallback
plugin api (#23769)
Why this change? Previously just using the `addToolbarPopupMenuOptionsCallback` plugin API itself was insufficient because it required the return object to include an `action` key which only accepted a name of the action function as a string. This was highly problematic because the action function had to be defined on the `composer` service which means using the `modifyClass` API to add the action function. This made the API awkward to use leading to poor developer experiencec. What does this change do? This commit introduces a couple of improvemnts to the API. 1. First the API has been renamed to `addComposerToolbarPopupMenuOption` because the API no longer accepts a callback function which was quite redundant. Instead, it now accepts an Object. The `addToolbarPopupMenuOptionsCallback` API function is deprecated and will be dropped in Discourse 3.3. Note that passing the API a function is still supported but will be dropped when the `addToolbarPopupMenuOptionsCallback` is removed. 2. The `action` key in the Object passed to the function can now be a function and is passed the `toolbarEvent` object when called. 3. The `condition` on key in the Object passed to the function can now be a function and is passed the `composer` service when called.
- Loading branch information
Showing
17 changed files
with
185 additions
and
172 deletions.
There are no files selected for viewing
25 changes: 22 additions & 3 deletions
25
app/assets/javascripts/discourse/app/controllers/composer.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,38 @@ | ||
import Composer, { | ||
addComposerSaveErrorCallback, | ||
addPopupMenuOptionsCallback, | ||
clearComposerSaveErrorCallback, | ||
clearPopupMenuOptionsCallback, | ||
toggleCheckDraftPopup, | ||
} from "discourse/services/composer"; | ||
|
||
import { | ||
addPopupMenuOption, | ||
clearPopupMenuOptions, | ||
} from "discourse/lib/composer/custom-popup-menu-options"; | ||
|
||
import deprecated from "discourse-common/lib/deprecated"; | ||
|
||
// TODO add deprecation | ||
|
||
export default Composer; | ||
|
||
function clearPopupMenuOptionsCallback() { | ||
deprecated( | ||
"`clearPopupMenuOptionsCallback` is deprecated without replacement as the cleanup is handled automatically.", | ||
{ | ||
id: "discourse.composer-controller.clear-popup-menu-options-callback", | ||
since: "3.2", | ||
dropFrom: "3.3", | ||
} | ||
); | ||
|
||
clearPopupMenuOptions(); | ||
} | ||
|
||
export { | ||
addComposerSaveErrorCallback, | ||
addPopupMenuOptionsCallback, | ||
addPopupMenuOption, | ||
clearComposerSaveErrorCallback, | ||
clearPopupMenuOptions, | ||
clearPopupMenuOptionsCallback, | ||
toggleCheckDraftPopup, | ||
}; |
9 changes: 9 additions & 0 deletions
9
app/assets/javascripts/discourse/app/lib/composer/custom-popup-menu-options.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
export const customPopupMenuOptions = []; | ||
|
||
export function clearPopupMenuOptions() { | ||
customPopupMenuOptions.length = 0; | ||
} | ||
|
||
export function addPopupMenuOption(option) { | ||
customPopupMenuOptions.push(option); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.