diff --git a/CHANGELOG.md b/CHANGELOG.md index 23a2fe3225d1..21d2da842300 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -89,6 +89,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) - Move HITs counter to be closer to table & show results count ([#9498](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/9498)) - Add the ability to export to CSV from the discover page ([#9530](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/9530)) - Append prompt for query assistant in request payload ([#9532](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/9532)) + - Add tooltip and disabled to panel item ([#9696](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/9696)) ### 🐛 Bug Fixes diff --git a/changelogs/fragments/9696.yml b/changelogs/fragments/9696.yml new file mode 100644 index 000000000000..e624fff04465 --- /dev/null +++ b/changelogs/fragments/9696.yml @@ -0,0 +1,2 @@ +feat: +- Ui action supports `isDisabled` and `getTooltip` ([#9696](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/9696)) \ No newline at end of file diff --git a/src/plugins/ui_actions/public/actions/action.ts b/src/plugins/ui_actions/public/actions/action.ts index 76fc2ddb3bed..7cb91c208308 100644 --- a/src/plugins/ui_actions/public/actions/action.ts +++ b/src/plugins/ui_actions/public/actions/action.ts @@ -83,6 +83,10 @@ export interface Action */ readonly type: T; + isDisabled?(context: ActionExecutionContext): boolean; + + getTooltip?(context: ActionExecutionContext): string; + /** * Optional EUI icon type that can be displayed along with the title. */ @@ -157,6 +161,9 @@ export interface ActionDefinition * without first showing up in context menu. * false by default. */ + isDisabled?(context: ActionExecutionContext): boolean; + + getTooltip?(context: ActionExecutionContext): string; shouldAutoExecute?(context: ActionDefinitionContext): Promise; /** diff --git a/src/plugins/ui_actions/public/actions/action_internal.ts b/src/plugins/ui_actions/public/actions/action_internal.ts index 5610051dc3f7..c757b99e4410 100644 --- a/src/plugins/ui_actions/public/actions/action_internal.ts +++ b/src/plugins/ui_actions/public/actions/action_internal.ts @@ -74,6 +74,16 @@ export class ActionInternal return await this.definition.isCompatible(context); } + public isDisabled(context: Context): boolean { + if (!this.definition.isDisabled) return false; + return this.definition.isDisabled(context); + } + + public getTooltip(context: Context): string { + if (!this.definition.getTooltip) return ''; + return this.definition.getTooltip(context); + } + public async getHref(context: Context): Promise { if (!this.definition.getHref) return undefined; return await this.definition.getHref(context); diff --git a/src/plugins/ui_actions/public/context_menu/build_eui_context_menu_panels.tsx b/src/plugins/ui_actions/public/context_menu/build_eui_context_menu_panels.tsx index 81710767e0a9..77b0c5ef7855 100644 --- a/src/plugins/ui_actions/public/context_menu/build_eui_context_menu_panels.tsx +++ b/src/plugins/ui_actions/public/context_menu/build_eui_context_menu_panels.tsx @@ -206,7 +206,7 @@ export async function buildContextMenuForActions({ // Add a context menu item for this action so it shows up on a context menu panel. // We add this within the parent group or default to the mainMenu panel. - panels[parentGroupId || 'mainMenu'].items!.push({ + const contextItem = { name: action.MenuItem ? React.createElement(uiToReactComponent(action.MenuItem), { context }) : action.getDisplayName(context), @@ -216,9 +216,15 @@ export async function buildContextMenuForActions({ href: action.getHref ? await action.getHref(context) : undefined, _order: action.order || 0, _title: action.getDisplayName(context), - }); + }; + if (typeof action?.getTooltip === 'function') { + contextItem.toolTipContent = action.getTooltip(context); + } + if (typeof action?.isDisabled === 'function') { + contextItem.disabled = action?.isDisabled(context); + } + panels[parentGroupId || 'mainMenu'].items!.push(contextItem); }); - await Promise.all(promises); // For each panel, sort items by order and title