Skip to content

Commit

Permalink
Pro 6843 context menu additional items (#4819)
Browse files Browse the repository at this point in the history
* validate new type option for `addContextOperation` method
* if type is event emit event through bus event with the action as name instead of executing action
  • Loading branch information
ValJed authored Dec 17, 2024
1 parent 4f174ed commit 72eeeae
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
* Adds support for supplying CSS variable names to a color field's `presetColors` array as selectable values.
* Adds support for dynamic focus trap in Context menus (prop `dynamicFocus`). When set to `true`, the focusable elements are recalculated on each cycle step.
* Adds option to disable `tabindex` on `AposToggle` component. A new prop `disableFocus` can be set to `false` to disable the focus on the toggle button. It's enabled by default.
* Adds support for event on `addContextOperation`, an option `type` can now be passed and can be `modal` (default) or `event`, in this case it does not try to open a modal but emit a bus event using the action as name.

## 4.10.0 (2024-11-20)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import AposDocContextMenuLogic from 'Modules/@apostrophecms/doc-type/logic/AposD
export default {
name: 'AposDocContextMenu',
mixins: [ AposDocContextMenuLogic ],
// Satisfy linting.
emits: [ 'menu-open', 'menu-close', 'close' ]
};
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ export default {
}
] : [])
];

return menu;
},
customMenusByContext() {
Expand Down Expand Up @@ -394,6 +395,7 @@ export default {
this.customAction(this.context, operation);
return;
}

this[action](this.context);
},
async edit(doc) {
Expand Down Expand Up @@ -449,6 +451,10 @@ export default {
...docProps(doc),
...operation.props
};
if (operation.type === 'event') {
apos.bus.$emit(operation.action, props);
return;
}
await apos.modal.execute(operation.modal, props);
function docProps(doc) {
return Object.fromEntries(Object.entries(operation.docProps || {}).map(([ key, value ]) => {
Expand Down
10 changes: 7 additions & 3 deletions modules/@apostrophecms/doc/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1486,7 +1486,7 @@ module.exports = {
];

function validate ({
action, context, label, modal, conditions, if: ifProps
action, context, type = 'modal', label, modal, conditions, if: ifProps
}) {
const allowedConditions = [
'canPublish',
Expand All @@ -1503,8 +1503,12 @@ module.exports = {
'canShareDraft'
];

if (!action || !context || !label || !modal) {
throw self.apos.error('invalid', 'addContextOperation requires action, context, label and modal properties.');
if (![ 'event', 'modal' ].includes(type)) {
throw self.apos.error('invalid', '`type` option must be `modal` (default) or `event`');
}

if (!action || !context || !label || (type === 'modal' && !modal)) {
throw self.apos.error('invalid', 'addContextOperation requires action, context, label and modal (if type is set to `modal` or unset) properties.');
}

if (
Expand Down

0 comments on commit 72eeeae

Please sign in to comment.