Skip to content
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions changelogs/fragments/9696.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
feat:
- Ui action supports `isDisabled` and `getTooltip` ([#9696](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/9696))
7 changes: 7 additions & 0 deletions src/plugins/ui_actions/public/actions/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ export interface Action<Context extends BaseContext = {}, T = ActionType>
*/
readonly type: T;

isDisabled?(context: ActionExecutionContext<Context>): boolean;

getTooltip?(context: ActionExecutionContext<Context>): string;

/**
* Optional EUI icon type that can be displayed along with the title.
*/
Expand Down Expand Up @@ -157,6 +161,9 @@ export interface ActionDefinition<Context extends BaseContext = {}>
* without first showing up in context menu.
* false by default.
*/
isDisabled?(context: ActionExecutionContext<Context>): boolean;

getTooltip?(context: ActionExecutionContext<Context>): string;
shouldAutoExecute?(context: ActionDefinitionContext<Context>): Promise<boolean>;

/**
Expand Down
10 changes: 10 additions & 0 deletions src/plugins/ui_actions/public/actions/action_internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,16 @@
return await this.definition.isCompatible(context);
}

public isDisabled(context: Context<A>): boolean {
if (!this.definition.isDisabled) return false;
return this.definition.isDisabled(context);

Check warning on line 79 in src/plugins/ui_actions/public/actions/action_internal.ts

View check run for this annotation

Codecov / codecov/patch

src/plugins/ui_actions/public/actions/action_internal.ts#L79

Added line #L79 was not covered by tests
}

public getTooltip(context: Context<A>): string {
if (!this.definition.getTooltip) return '';
return this.definition.getTooltip(context);

Check warning on line 84 in src/plugins/ui_actions/public/actions/action_internal.ts

View check run for this annotation

Codecov / codecov/patch

src/plugins/ui_actions/public/actions/action_internal.ts#L84

Added line #L84 was not covered by tests
}

public async getHref(context: Context<A>): Promise<string | undefined> {
if (!this.definition.getHref) return undefined;
return await this.definition.getHref(context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@

// 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),
Expand All @@ -216,9 +216,15 @@
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);

Check warning on line 221 in src/plugins/ui_actions/public/context_menu/build_eui_context_menu_panels.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/ui_actions/public/context_menu/build_eui_context_menu_panels.tsx#L221

Added line #L221 was not covered by tests
}
if (typeof action?.isDisabled === 'function') {
contextItem.disabled = action?.isDisabled(context);

Check warning on line 224 in src/plugins/ui_actions/public/context_menu/build_eui_context_menu_panels.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/ui_actions/public/context_menu/build_eui_context_menu_panels.tsx#L224

Added line #L224 was not covered by tests
}
panels[parentGroupId || 'mainMenu'].items!.push(contextItem);
Comment on lines +220 to +226
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

would like have a unit test for this

});

await Promise.all(promises);

// For each panel, sort items by order and title
Expand Down
Loading