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

Conversation

ValJed
Copy link
Contributor

@ValJed ValJed commented Dec 11, 2024

PRO-6843

Summary

I need to add in palette a new item in the context menu.
This item should not open any modal but just emit an event I could listen to know user clicked on it. So I cannot use customOperations here.

I just added the possibility to pass an array of extra items to a AposDocContextMenu component.
This one can be used to call an action like we already do, or to emit a simple event when closing to the parent, like I do with palette.

It allows me to do this in palette:

          <AposDocContextMenu
            :doc="docFields.data"
            :show-edit="false"
            :additional-menu-items="[{
              label: 'aposPalette:resetPalettePosition',
              action: 'reset-position',
              emitEvent: true
            }]"
            @close="menuCloseHandler"
          />
       ...
    menuCloseHandler(_doc, action) {
      if (action === 'reset-position') {
        this.resetPosition();
      }
    }

If I pass emitEvent it will simply emit close with the action as parameter.

What are the specific steps to test this change?

See above

What kind of change does this PR introduce?

  • Bug fix
  • New feature
  • Refactor
  • Documentation
  • Build-related changes
  • Other

Make sure the PR fulfills these requirements:

  • It includes a) the existing issue ID being resolved, b) a convincing reason for adding this feature, or c) a clear description of the bug it resolves
  • The changelog is updated
  • Related documentation has been updated
  • Related tests have been updated

@ValJed ValJed requested review from boutell and haroun December 11, 2024 17:26
@ValJed ValJed force-pushed the pro-6843-context-menu-additional-items branch from e112914 to 6cd08f1 Compare December 12, 2024 09:38
haroun
haroun previously approved these changes Dec 12, 2024
Copy link
Member

@boutell boutell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is already a way to register additional context operations server side. The palette module can call:

self.apos.doc.addContextOperation({
  action: 'reset-palette-position',
  if: {
    type: self.__meta.name
  }  
});

This will make the operation available only for palette.

So there is no need to introduce a redundant way of registering custom context operations.

However I do think you may need a patch to allow them to trigger a bus event rather than opening a modal. This is the current logic that implements the "operation" property:

      const props = {
        moduleName: operation.moduleName || this.moduleName,
        // For backwards compatibility
        doc,
        ...docProps(doc),
        ...operation.props
      };
      await apos.modal.execute(operation.modal, props);

This will need an update to support emitting a bus event with an object containing the props as an alternative.

@boutell
Copy link
Member

boutell commented Dec 16, 2024

(Excuse me, self.__meta.name, which is just a cute way of saying this module's name, you could also hardcode the string)

@ValJed ValJed requested a review from boutell December 16, 2024 16:23
boutell
boutell previously approved these changes Dec 16, 2024
Copy link
Member

@boutell boutell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving for time but please fix changelog

CHANGELOG.md Outdated
@@ -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 new prop `additionalMenuItems` to `AposDocContextMenu`. Allow to pass additional menu items that can trigger an action when clicked, or simply pass the action as the close event parameter.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

@ValJed ValJed merged commit 72eeeae into main Dec 17, 2024
9 checks passed
@ValJed ValJed deleted the pro-6843-context-menu-additional-items branch December 17, 2024 08:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants