Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pro 6843 context menu additional items #4819

Merged
merged 8 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,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
Loading