Skip to content

Commit a37c8ea

Browse files
Add tooltip and disabled to panel item (#9696)
* add action id Signed-off-by: yyfamazon <yyf@amazon.com> * add change log Signed-off-by: yyfamazon <yyf@amazon.com> * add tooltip and disable to context Signed-off-by: yyfamazon <yyf@amazon.com> * fix test Signed-off-by: yyfamazon <yyf@amazon.com> * fix test Signed-off-by: yyfamazon <yyf@amazon.com> * resolve comment Signed-off-by: yyfamazon <yyf@amazon.com> * resolve comments Signed-off-by: yyfamazon <yyf@amazon.com> * Changeset file for PR #9696 created/updated --------- Signed-off-by: yyfamazon <yyf@amazon.com> Co-authored-by: opensearch-changeset-bot[bot] <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com>
1 parent 57f3390 commit a37c8ea

File tree

5 files changed

+29
-3
lines changed

5 files changed

+29
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
8989
- Move HITs counter to be closer to table & show results count ([#9498](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/9498))
9090
- Add the ability to export to CSV from the discover page ([#9530](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/9530))
9191
- Append prompt for query assistant in request payload ([#9532](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/9532))
92+
- Add tooltip and disabled to panel item ([#9696](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/9696))
9293

9394
### 🐛 Bug Fixes
9495

changelogs/fragments/9696.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
feat:
2+
- Ui action supports `isDisabled` and `getTooltip` ([#9696](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/9696))

src/plugins/ui_actions/public/actions/action.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,10 @@ export interface Action<Context extends BaseContext = {}, T = ActionType>
8383
*/
8484
readonly type: T;
8585

86+
isDisabled?(context: ActionExecutionContext<Context>): boolean;
87+
88+
getTooltip?(context: ActionExecutionContext<Context>): string;
89+
8690
/**
8791
* Optional EUI icon type that can be displayed along with the title.
8892
*/
@@ -157,6 +161,9 @@ export interface ActionDefinition<Context extends BaseContext = {}>
157161
* without first showing up in context menu.
158162
* false by default.
159163
*/
164+
isDisabled?(context: ActionExecutionContext<Context>): boolean;
165+
166+
getTooltip?(context: ActionExecutionContext<Context>): string;
160167
shouldAutoExecute?(context: ActionDefinitionContext<Context>): Promise<boolean>;
161168

162169
/**

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,16 @@ export class ActionInternal<A extends ActionDefinition = ActionDefinition>
7474
return await this.definition.isCompatible(context);
7575
}
7676

77+
public isDisabled(context: Context<A>): boolean {
78+
if (!this.definition.isDisabled) return false;
79+
return this.definition.isDisabled(context);
80+
}
81+
82+
public getTooltip(context: Context<A>): string {
83+
if (!this.definition.getTooltip) return '';
84+
return this.definition.getTooltip(context);
85+
}
86+
7787
public async getHref(context: Context<A>): Promise<string | undefined> {
7888
if (!this.definition.getHref) return undefined;
7989
return await this.definition.getHref(context);

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ export async function buildContextMenuForActions({
206206

207207
// Add a context menu item for this action so it shows up on a context menu panel.
208208
// We add this within the parent group or default to the mainMenu panel.
209-
panels[parentGroupId || 'mainMenu'].items!.push({
209+
const contextItem = {
210210
name: action.MenuItem
211211
? React.createElement(uiToReactComponent(action.MenuItem), { context })
212212
: action.getDisplayName(context),
@@ -216,9 +216,15 @@ export async function buildContextMenuForActions({
216216
href: action.getHref ? await action.getHref(context) : undefined,
217217
_order: action.order || 0,
218218
_title: action.getDisplayName(context),
219-
});
219+
};
220+
if (typeof action?.getTooltip === 'function') {
221+
contextItem.toolTipContent = action.getTooltip(context);
222+
}
223+
if (typeof action?.isDisabled === 'function') {
224+
contextItem.disabled = action?.isDisabled(context);
225+
}
226+
panels[parentGroupId || 'mainMenu'].items!.push(contextItem);
220227
});
221-
222228
await Promise.all(promises);
223229

224230
// For each panel, sort items by order and title

0 commit comments

Comments
 (0)