-
Notifications
You must be signed in to change notification settings - Fork 915
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
enhance grouping for context menu options #3924
Changes from 3 commits
b98934b
232fc03
867978f
41daddd
c5ce04d
967a8f1
575bae7
39f0f1b
649b21a
a25cbc4
d9bf726
4c7fece
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -83,6 +83,12 @@ interface Props { | |
SavedObjectFinder: React.ComponentType<any>; | ||
stateTransfer?: EmbeddableStateTransfer; | ||
hideHeader?: boolean; | ||
// By default, embeddable.destroy() is called when this component unmounts. | ||
// To prevent this default behavior, set this prop to true. | ||
isDestroyPrevented?: boolean; | ||
// Toggle off the border and shadow applied around the embeddable. | ||
// By default, the embeddable will have a shadow and border around it. | ||
isBorderless?: boolean; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hey @sikhote, why are these two changes necessary? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the process of checking creating an example of this in the |
||
} | ||
|
||
interface State { | ||
|
@@ -200,7 +206,10 @@ export class EmbeddablePanel extends React.Component<Props, State> { | |
if (this.state.errorEmbeddable) { | ||
this.state.errorEmbeddable.destroy(); | ||
} | ||
this.props.embeddable.destroy(); | ||
|
||
if (!this.props.isDestroyPrevented) { | ||
this.props.embeddable.destroy(); | ||
} | ||
} | ||
|
||
public onFocus = (focusedPanelIndex: string) => { | ||
|
@@ -234,6 +243,8 @@ export class EmbeddablePanel extends React.Component<Props, State> { | |
paddingSize="none" | ||
role="figure" | ||
aria-labelledby={headerId} | ||
hasBorder={!this.props.isBorderless} | ||
hasShadow={!this.props.isBorderless} | ||
> | ||
{!this.props.hideHeader && ( | ||
<PanelHeader | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -92,7 +92,7 @@ export interface Action<Context extends BaseContext = {}, T = ActionType> | |
* Returns a title to be displayed to the user. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If it helps, I can change this comment to inform users that a React element is also supported here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, that'd be helpful. |
||
* @param context | ||
*/ | ||
getDisplayName(context: ActionExecutionContext<Context>): string; | ||
getDisplayName(context: ActionExecutionContext<Context>): JSX.Element | string; | ||
|
||
/** | ||
* `UiComponent` to render when displaying this action as a context menu item. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,7 +59,7 @@ export class ActionInternal<A extends ActionDefinition = ActionDefinition> | |
return this.definition.getIconType(context); | ||
} | ||
|
||
public getDisplayName(context: Context<A>): string { | ||
public getDisplayName(context: Context<A>): JSX.Element | string { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we rename this since Display name is misleading here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed that name would be better, but I'd recommend against it at this point, because it would mean a lot of downstream changes as well (such as other plugins not in this repository). |
||
if (!this.definition.getDisplayName) return `Action: ${this.id}`; | ||
return this.definition.getDisplayName(context); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -157,35 +157,51 @@ export async function buildContextMenuForActions({ | |
const context: ActionExecutionContext<object> = { ...item.context, trigger: item.trigger }; | ||
const isCompatible = await item.action.isCompatible(context); | ||
if (!isCompatible) return; | ||
let parentPanel = ''; | ||
let currentPanel = ''; | ||
|
||
// Reference to the last group...groups are provided in array order of | ||
// parent to children (or outer to inner) | ||
let parentPanelId = ''; | ||
|
||
if (action.grouping) { | ||
for (let i = 0; i < action.grouping.length; i++) { | ||
const group = action.grouping[i]; | ||
currentPanel = group.id; | ||
if (!panels[currentPanel]) { | ||
const groupId = group.id; | ||
|
||
if (!panels[groupId]) { | ||
const name = group.getDisplayName ? group.getDisplayName(context) : group.id; | ||
panels[currentPanel] = { | ||
id: currentPanel, | ||
|
||
// Create panel for group | ||
panels[groupId] = { | ||
id: groupId, | ||
title: name, | ||
items: [], | ||
_level: i, | ||
_icon: group.getIconType ? group.getIconType(context) : 'empty', | ||
}; | ||
if (parentPanel) { | ||
panels[parentPanel].items!.push({ | ||
|
||
// If there are multiple groups and this is not the first group, | ||
// then add an item to the parent panel relating to this group | ||
if (parentPanelId) { | ||
panels[parentPanelId].items!.push({ | ||
name, | ||
panel: currentPanel, | ||
panel: groupId, | ||
icon: group.getIconType ? group.getIconType(context) : 'empty', | ||
_order: group.order || 0, | ||
_title: group.getDisplayName ? group.getDisplayName(context) : '', | ||
}); | ||
} | ||
} | ||
parentPanel = currentPanel; | ||
|
||
// Save the current panel, because this will be used for adding items | ||
// to it from later groups in the array | ||
parentPanelId = groupId; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just to make sure, nothing functionally chnages here right? You are just renaming currentPannel to groupId There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Correct, renaming and adding comments for future users. |
||
} | ||
} | ||
panels[parentPanel || 'mainMenu'].items!.push({ | ||
|
||
// If grouping exists, parentPanelId will be the most-inner group, | ||
// otherwise use the mainMenu panel. | ||
// Add item for action to this most-inner panel or mainMenu. | ||
panels[parentPanelId || 'mainMenu'].items!.push({ | ||
name: action.MenuItem | ||
? React.createElement(uiToReactComponent(action.MenuItem), { context }) | ||
: action.getDisplayName(context), | ||
|
@@ -197,6 +213,7 @@ export async function buildContextMenuForActions({ | |
_title: action.getDisplayName(context), | ||
}); | ||
}); | ||
|
||
await Promise.all(promises); | ||
|
||
for (const panel of Object.values(panels)) { | ||
|
@@ -211,10 +228,17 @@ export async function buildContextMenuForActions({ | |
wrapMainPanelItemsIntoSubmenu(panels, 'mainMenu'); | ||
|
||
for (const panel of Object.values(panels)) { | ||
// If the panel is a root-level panel, such as a group-based panel, | ||
// then create mainMenu item for this panel | ||
if (panel._level === 0) { | ||
// TODO: Add separator line here once it is available in EUI. | ||
// See https://github.com/elastic/eui/pull/4018 | ||
if (panel.items.length > 3) { | ||
// Add separator with unique key if needed | ||
if (panels.mainMenu.items.length) { | ||
panels.mainMenu.items.push({ isSeparator: true, key: `${panel.id}separator` }); | ||
} | ||
|
||
// If a panel has more than one child, then allow item's to be grouped | ||
// and link to it in the mainMenu. Otherwise, flatten the group. | ||
if (panel.items.length > 1) { | ||
panels.mainMenu.items.push({ | ||
name: panel.title || panel.id, | ||
icon: panel._icon || 'empty', | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -60,7 +60,7 @@ export interface Presentable<Context extends object = object> { | |
/** | ||
* Returns a title to be displayed to the user. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here for changing this comment to inform users that a React element is also supported here. |
||
*/ | ||
getDisplayName(context: Context): string; | ||
getDisplayName(context: Context): JSX.Element | string; | ||
|
||
/** | ||
* Returns tooltip text which should be displayed when user hovers this object. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it helps, I can change this comment to inform users that a React element is also supported here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need this change? This is for the Create new button for embeddables right?