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

Dynamic Context Menu #284

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from

Conversation

tdakanalis
Copy link
Contributor

Define the nodes with a context menu and the actions that are permitted for each node by defining the 'context' option in the editor's options.

For example the options below define that only node1, node2, and all the children of node3 and node4 will have a context menu. Moreover, node1 and node2 allow only the 'Remove' action while the children of node3 and node4 allow both the 'Duplicate' and 'Remove' actions:

context: {
    items: { 
        node1: ['Remove'], 
        node2: ['Remove'] 
    }, 
    children: { 
        node3: ['Duplicate', 'Remove'], 
        node4: ['Duplicate', 'Remove'] 
    } 
}

Define the nodes that will have a context menu and which actions are permitted for each node by defining the 'context' option in the editor's options. For example the options below define that only node1, node2, and all the children of node3 and node4 will have a context menu. Moreover, node1 and node2 allow only the 'Remove' action while the children of node3 and node4 allow both the 'Duplicate' and 'Remove' actions.

context: {
  items: {
    node1: ['Remove'],
    node2: ['Remove']
  },
  children: {
    node3: ['Duplicate', 'Remove'],
    node4: ['Duplicate', 'Remove']
  }
}
@josdejong
Copy link
Owner

Thanks Themistoklis. This looks interesting.

Some thoughts:

  • It may be a good idea to look a bit broader. There is a long standing feature request to allow for custom entries in the context menu, see Custom items in contextual menu #75. Maybe we can pick this up together with restricting the allowed actions in the context menu.

  • There are shortcuts to create/duplicate/remove entries. I guess we should disable these too to truly restrict options.

  • The current configuration where you can enter "items" and "children" may be a bit restrictive. Does "children" hold only for direct children or also recursively for nested children (grandchildren)?
    It can be interesting to look into how JSONEditor currently allows to configure editability of fields and values, and use a similar solution to allow/restrict actions on nodes by providing a callback function:

    {function} onEditable
    Set a callback function to determine whether individual nodes are editable or read-only. Only applicable when option mode is tree. The callback is invoked as editable(node), where node is an object {field: string, value: string, path: string[]}. The function must either return a boolean value to set both the nodes field and value editable or read-only, or return an object {field: boolean, value: boolean}.

    Maybe we could reuse the existing onEditable and extend it with options to return "actionable" properties as well as "editable" properties. Or maybe we should make a new option onActionable or something like that.

@tdakanalis
Copy link
Contributor Author

Yes, definitely a completely dynamic context menu would be much more useful! We can proceed the way you suggest! I prefer we to introduce a new option, instead of using the onEditable, in order to keep it clear.

@josdejong
Copy link
Owner

Agree

@dhughes-xumak
Copy link
Contributor

#438 adds support for custom context menu items.

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.

None yet

3 participants