Skip to content

Commit e6f5ed9

Browse files
authored
[Examples plugin] Deprecated uiAction methods – Search panel rewrite (elastic#230400)
Solves partially elastic#227743
1 parent 0f06a68 commit e6f5ed9

File tree

5 files changed

+68
-53
lines changed

5 files changed

+68
-53
lines changed

examples/embeddable_examples/public/app/register_embeddable.tsx

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ import { EuiCodeBlock, EuiSpacer, EuiText } from '@elastic/eui';
1212
// @ts-ignore
1313
import registerSearchEmbeddableSource from '../react_embeddables/search/register_search_embeddable?raw';
1414
// @ts-ignore
15-
import registerAttachActionSource from '../react_embeddables/search/register_add_search_panel_action?raw';
15+
import registerSearchPanelAction from '../react_embeddables/search/register_search_panel_action?raw';
16+
// @ts-ignore
17+
import createPanelAction from '../react_embeddables/search/create_search_panel_action?raw';
1618
// @ts-ignore
1719
import registerFieldListEmbeddableSource from '../react_embeddables/field_list/register_field_list_embeddable?raw';
1820
// @ts-ignore
@@ -50,14 +52,20 @@ export const RegisterEmbeddable = () => {
5052
<h2>Show embeddables in the Add panel menu</h2>
5153
<p>
5254
Add your own embeddables to <em>Add panel</em> menu by attaching an action to the{' '}
53-
<strong>ADD_PANEL_TRIGGER</strong> trigger. Notice usage of <strong>grouping</strong> to
54-
nest related panel types and avoid bloating <em>Add panel</em> menu. Please reach out to
55+
<strong>ADD_PANEL_TRIGGER</strong> trigger. Register the action asynchronously to reduce
56+
initial plugin bundle size. The example below uses <strong>addTriggerActionAsync </strong>
57+
to register the action lazily. Notice usage of <strong>grouping</strong> to nest related
58+
panel types and avoid bloating <em>Add panel</em> menu. Please reach out to
5559
@elastic/kibana-presentation team to coordinate menu updates.
5660
</p>
5761
</EuiText>
5862
<EuiSpacer size="s" />
5963
<EuiCodeBlock language="jsx" fontSize="m" paddingSize="m">
60-
{registerAttachActionSource}
64+
{registerSearchPanelAction}
65+
</EuiCodeBlock>
66+
<EuiSpacer size="s" />
67+
<EuiCodeBlock language="jsx" fontSize="m" paddingSize="m">
68+
{createPanelAction}
6169
</EuiCodeBlock>
6270

6371
<EuiSpacer size="l" />

examples/embeddable_examples/public/plugin.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ import { FIELD_LIST_ID } from './react_embeddables/field_list/constants';
3131
import { ADD_SAVED_BOOK_ACTION_ID } from './react_embeddables/saved_book/constants';
3232
import { ADD_FIELD_LIST_ACTION_ID } from './react_embeddables/field_list/constants';
3333
import { registerFieldListPanelPlacementSetting } from './react_embeddables/field_list/register_field_list_embeddable';
34-
import { registerAddSearchPanelAction } from './react_embeddables/search/register_add_search_panel_action';
3534
import { registerSearchEmbeddable } from './react_embeddables/search/register_search_embeddable';
3635
import { setKibanaServices } from './kibana_services';
3736
import { setupBookEmbeddable } from './react_embeddables/saved_book/setup_book_embeddable';
37+
import { registerSearchPanelAction } from './react_embeddables/search/register_search_panel_action';
3838

3939
export interface SetupDeps {
4040
contentManagement: ContentManagementPublicSetup;
@@ -107,21 +107,22 @@ export class EmbeddableExamplesPlugin implements Plugin<void, void, SetupDeps, S
107107

108108
registerFieldListPanelPlacementSetting(deps.dashboard);
109109

110+
registerSearchPanelAction(deps.uiActions);
111+
110112
deps.uiActions.registerActionAsync(ADD_EUI_MARKDOWN_ACTION_ID, async () => {
111113
const { createEuiMarkdownAction } = await import(
112114
'./react_embeddables/eui_markdown/create_eui_markdown_action'
113115
);
114116
return createEuiMarkdownAction();
115117
});
116118
deps.uiActions.attachAction(ADD_PANEL_TRIGGER, ADD_EUI_MARKDOWN_ACTION_ID);
119+
117120
if (deps.uiActions.hasTrigger('ADD_CANVAS_ELEMENT_TRIGGER')) {
118121
// Because Canvas is not enabled in Serverless, this trigger might not be registered - only attach
119122
// the create action if the Canvas-specific trigger does indeed exist.
120123
deps.uiActions.attachAction('ADD_CANVAS_ELEMENT_TRIGGER', ADD_EUI_MARKDOWN_ACTION_ID);
121124
}
122125

123-
registerAddSearchPanelAction(deps.uiActions);
124-
125126
deps.uiActions.addTriggerActionAsync(ADD_PANEL_TRIGGER, ADD_DATA_TABLE_ACTION_ID, async () => {
126127
const { createDataTableAction } = await import(
127128
'./react_embeddables/data_table/create_data_table_action'
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the "Elastic License
4+
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
5+
* Public License v 1"; you may not use this file except in compliance with, at
6+
* your election, the "Elastic License 2.0", the "GNU Affero General Public
7+
* License v3.0 only", or the "Server Side Public License, v 1".
8+
*/
9+
10+
import { apiCanAddNewPanel } from '@kbn/presentation-containers';
11+
import { EmbeddableApiContext } from '@kbn/presentation-publishing';
12+
import { IncompatibleActionError } from '@kbn/ui-actions-plugin/public';
13+
import { SearchSerializedState } from './types';
14+
import { embeddableExamplesGrouping } from '../embeddable_examples_grouping';
15+
import { ADD_SEARCH_ACTION_ID, SEARCH_EMBEDDABLE_TYPE } from './constants';
16+
17+
export const createSearchPanelAction = {
18+
id: ADD_SEARCH_ACTION_ID,
19+
grouping: [embeddableExamplesGrouping],
20+
getDisplayName: () => 'Search example',
21+
getIconType: () => 'search',
22+
isCompatible: async ({ embeddable }: EmbeddableApiContext) => {
23+
return apiCanAddNewPanel(embeddable);
24+
},
25+
execute: async ({ embeddable }: EmbeddableApiContext) => {
26+
if (!apiCanAddNewPanel(embeddable)) throw new IncompatibleActionError();
27+
embeddable.addNewPanel<SearchSerializedState>(
28+
{
29+
panelType: SEARCH_EMBEDDABLE_TYPE,
30+
},
31+
true
32+
);
33+
},
34+
};

examples/embeddable_examples/public/react_embeddables/search/register_add_search_panel_action.tsx

Lines changed: 0 additions & 46 deletions
This file was deleted.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the "Elastic License
4+
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
5+
* Public License v 1"; you may not use this file except in compliance with, at
6+
* your election, the "Elastic License 2.0", the "GNU Affero General Public
7+
* License v3.0 only", or the "Server Side Public License, v 1".
8+
*/
9+
10+
import { UiActionsStart, ADD_PANEL_TRIGGER } from '@kbn/ui-actions-plugin/public';
11+
import { ADD_SEARCH_ACTION_ID } from './constants';
12+
13+
export const registerSearchPanelAction = (uiActions: UiActionsStart) => {
14+
uiActions.addTriggerActionAsync(ADD_PANEL_TRIGGER, ADD_SEARCH_ACTION_ID, async () => {
15+
const { createSearchPanelAction } = await import('./create_search_panel_action');
16+
return createSearchPanelAction;
17+
});
18+
};

0 commit comments

Comments
 (0)