Skip to content

Commit 9cd3718

Browse files
author
Stacey Gammon
committed
Merge branch 'master' of github.com:elastic/kibana into 2020-02-11-url-service
2 parents e36d64b + d2cbc59 commit 9cd3718

File tree

119 files changed

+1036
-508
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

119 files changed

+1036
-508
lines changed

examples/ui_action_examples/public/hello_world_action.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@ import { OverlayStart } from '../../../src/core/public';
2222
import { createAction } from '../../../src/plugins/ui_actions/public';
2323
import { toMountPoint } from '../../../src/plugins/kibana_react/public';
2424

25-
export const HELLO_WORLD_ACTION_TYPE = 'HELLO_WORLD_ACTION_TYPE';
25+
export const ACTION_HELLO_WORLD = 'ACTION_HELLO_WORLD';
2626

2727
interface StartServices {
2828
openModal: OverlayStart['openModal'];
2929
}
3030

3131
export const createHelloWorldAction = (getStartServices: () => Promise<StartServices>) =>
3232
createAction({
33-
type: HELLO_WORLD_ACTION_TYPE,
33+
type: ACTION_HELLO_WORLD,
3434
getDisplayName: () => 'Hello World!',
3535
execute: async () => {
3636
const { openModal } = await getStartServices();

examples/ui_action_examples/public/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,4 @@ import { PluginInitializer } from '../../../src/core/public';
2323
export const plugin: PluginInitializer<void, void> = () => new UiActionExamplesPlugin();
2424

2525
export { HELLO_WORLD_TRIGGER_ID } from './hello_world_trigger';
26-
export { HELLO_WORLD_ACTION_TYPE } from './hello_world_action';
26+
export { ACTION_HELLO_WORLD } from './hello_world_action';

examples/ui_action_examples/public/plugin.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
import { Plugin, CoreSetup } from '../../../src/core/public';
2121
import { UiActionsSetup } from '../../../src/plugins/ui_actions/public';
22-
import { createHelloWorldAction } from './hello_world_action';
22+
import { createHelloWorldAction, ACTION_HELLO_WORLD } from './hello_world_action';
2323
import { helloWorldTrigger, HELLO_WORLD_TRIGGER_ID } from './hello_world_trigger';
2424

2525
interface UiActionExamplesSetupDependencies {
@@ -28,7 +28,11 @@ interface UiActionExamplesSetupDependencies {
2828

2929
declare module '../../../src/plugins/ui_actions/public' {
3030
export interface TriggerContextMapping {
31-
[HELLO_WORLD_TRIGGER_ID]: undefined;
31+
[HELLO_WORLD_TRIGGER_ID]: {};
32+
}
33+
34+
export interface ActionContextMapping {
35+
[ACTION_HELLO_WORLD]: {};
3236
}
3337
}
3438

@@ -42,7 +46,7 @@ export class UiActionExamplesPlugin
4246
}));
4347

4448
uiActions.registerAction(helloWorldAction);
45-
uiActions.attachAction(helloWorldTrigger.id, helloWorldAction.id);
49+
uiActions.attachAction(helloWorldTrigger.id, helloWorldAction);
4650
}
4751

4852
public start() {}

examples/ui_actions_explorer/public/actions/actions.tsx

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -27,44 +27,48 @@ export const USER_TRIGGER = 'USER_TRIGGER';
2727
export const COUNTRY_TRIGGER = 'COUNTRY_TRIGGER';
2828
export const PHONE_TRIGGER = 'PHONE_TRIGGER';
2929

30-
export const VIEW_IN_MAPS_ACTION = 'VIEW_IN_MAPS_ACTION';
31-
export const TRAVEL_GUIDE_ACTION = 'TRAVEL_GUIDE_ACTION';
32-
export const CALL_PHONE_NUMBER_ACTION = 'CALL_PHONE_NUMBER_ACTION';
33-
export const EDIT_USER_ACTION = 'EDIT_USER_ACTION';
34-
export const PHONE_USER_ACTION = 'PHONE_USER_ACTION';
35-
export const SHOWCASE_PLUGGABILITY_ACTION = 'SHOWCASE_PLUGGABILITY_ACTION';
30+
export const ACTION_VIEW_IN_MAPS = 'ACTION_VIEW_IN_MAPS';
31+
export const ACTION_TRAVEL_GUIDE = 'ACTION_TRAVEL_GUIDE';
32+
export const ACTION_CALL_PHONE_NUMBER = 'ACTION_CALL_PHONE_NUMBER';
33+
export const ACTION_EDIT_USER = 'ACTION_EDIT_USER';
34+
export const ACTION_PHONE_USER = 'ACTION_PHONE_USER';
35+
export const ACTION_SHOWCASE_PLUGGABILITY = 'ACTION_SHOWCASE_PLUGGABILITY';
3636

37-
export const showcasePluggability = createAction({
38-
type: SHOWCASE_PLUGGABILITY_ACTION,
37+
export const showcasePluggability = createAction<typeof ACTION_SHOWCASE_PLUGGABILITY>({
38+
type: ACTION_SHOWCASE_PLUGGABILITY,
3939
getDisplayName: () => 'This is pluggable! Any plugin can inject their actions here.',
4040
execute: async () => alert("Isn't that cool?!"),
4141
});
4242

43-
export type PhoneContext = string;
43+
export interface PhoneContext {
44+
phone: string;
45+
}
4446

45-
export const makePhoneCallAction = createAction<PhoneContext>({
46-
type: CALL_PHONE_NUMBER_ACTION,
47+
export const makePhoneCallAction = createAction<typeof ACTION_CALL_PHONE_NUMBER>({
48+
type: ACTION_CALL_PHONE_NUMBER,
4749
getDisplayName: () => 'Call phone number',
48-
execute: async phone => alert(`Pretend calling ${phone}...`),
50+
execute: async context => alert(`Pretend calling ${context.phone}...`),
4951
});
5052

51-
export const lookUpWeatherAction = createAction<{ country: string }>({
52-
type: TRAVEL_GUIDE_ACTION,
53+
export const lookUpWeatherAction = createAction<typeof ACTION_TRAVEL_GUIDE>({
54+
type: ACTION_TRAVEL_GUIDE,
5355
getIconType: () => 'popout',
5456
getDisplayName: () => 'View travel guide',
55-
execute: async ({ country }) => {
56-
window.open(`https://www.worldtravelguide.net/?s=${country},`, '_blank');
57+
execute: async context => {
58+
window.open(`https://www.worldtravelguide.net/?s=${context.country}`, '_blank');
5759
},
5860
});
5961

60-
export type CountryContext = string;
62+
export interface CountryContext {
63+
country: string;
64+
}
6165

62-
export const viewInMapsAction = createAction<CountryContext>({
63-
type: VIEW_IN_MAPS_ACTION,
66+
export const viewInMapsAction = createAction<typeof ACTION_VIEW_IN_MAPS>({
67+
type: ACTION_VIEW_IN_MAPS,
6468
getIconType: () => 'popout',
6569
getDisplayName: () => 'View in maps',
66-
execute: async country => {
67-
window.open(`https://www.google.com/maps/place/${country}`, '_blank');
70+
execute: async context => {
71+
window.open(`https://www.google.com/maps/place/${context.country}`, '_blank');
6872
},
6973
});
7074

@@ -100,11 +104,8 @@ function EditUserModal({
100104
}
101105

102106
export const createEditUserAction = (getOpenModal: () => Promise<OverlayStart['openModal']>) =>
103-
createAction<{
104-
user: User;
105-
update: (user: User) => void;
106-
}>({
107-
type: EDIT_USER_ACTION,
107+
createAction<typeof ACTION_EDIT_USER>({
108+
type: ACTION_EDIT_USER,
108109
getIconType: () => 'pencil',
109110
getDisplayName: () => 'Edit user',
110111
execute: async ({ user, update }) => {
@@ -120,8 +121,8 @@ export interface UserContext {
120121
}
121122

122123
export const createPhoneUserAction = (getUiActionsApi: () => Promise<UiActionsStart>) =>
123-
createAction<UserContext>({
124-
type: PHONE_USER_ACTION,
124+
createAction<typeof ACTION_PHONE_USER>({
125+
type: ACTION_PHONE_USER,
125126
getDisplayName: () => 'Call phone number',
126127
isCompatible: async ({ user }) => user.phone !== undefined,
127128
execute: async ({ user }) => {
@@ -133,7 +134,7 @@ export const createPhoneUserAction = (getUiActionsApi: () => Promise<UiActionsSt
133134
// TODO: we need to figure out the best way to handle these nested actions however, since
134135
// we don't want multiple context menu's to pop up.
135136
if (user.phone !== undefined) {
136-
(await getUiActionsApi()).executeTriggerActions(PHONE_TRIGGER, user.phone);
137+
(await getUiActionsApi()).executeTriggerActions(PHONE_TRIGGER, { phone: user.phone });
137138
}
138139
},
139140
});

examples/ui_actions_explorer/public/app.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import { EuiModalBody } from '@elastic/eui';
3535
import { toMountPoint } from '../../../src/plugins/kibana_react/public';
3636
import { UiActionsStart, createAction } from '../../../src/plugins/ui_actions/public';
3737
import { AppMountParameters, OverlayStart } from '../../../src/core/public';
38-
import { HELLO_WORLD_TRIGGER_ID, HELLO_WORLD_ACTION_TYPE } from '../../ui_action_examples/public';
38+
import { HELLO_WORLD_TRIGGER_ID, ACTION_HELLO_WORLD } from '../../ui_action_examples/public';
3939
import { TriggerContextExample } from './trigger_context_example';
4040

4141
interface Props {
@@ -60,7 +60,7 @@ const ActionsExplorer = ({ uiActionsApi, openModal }: Props) => {
6060
</EuiText>
6161
<EuiButton
6262
data-test-subj="emitHelloWorldTrigger"
63-
onClick={() => uiActionsApi.executeTriggerActions(HELLO_WORLD_TRIGGER_ID, undefined)}
63+
onClick={() => uiActionsApi.executeTriggerActions(HELLO_WORLD_TRIGGER_ID, {})}
6464
>
6565
Say hello world!
6666
</EuiButton>
@@ -76,8 +76,9 @@ const ActionsExplorer = ({ uiActionsApi, openModal }: Props) => {
7676
<EuiButton
7777
data-test-subj="addDynamicAction"
7878
onClick={() => {
79-
const dynamicAction = createAction<{}>({
80-
type: `${HELLO_WORLD_ACTION_TYPE}-${name}`,
79+
const dynamicAction = createAction<typeof ACTION_HELLO_WORLD>({
80+
id: `${ACTION_HELLO_WORLD}-${name}`,
81+
type: ACTION_HELLO_WORLD,
8182
getDisplayName: () => `Say hello to ${name}`,
8283
execute: async () => {
8384
const overlay = openModal(
@@ -95,7 +96,7 @@ const ActionsExplorer = ({ uiActionsApi, openModal }: Props) => {
9596
},
9697
});
9798
uiActionsApi.registerAction(dynamicAction);
98-
uiActionsApi.attachAction(HELLO_WORLD_TRIGGER_ID, dynamicAction.type);
99+
uiActionsApi.attachAction(HELLO_WORLD_TRIGGER_ID, dynamicAction);
99100
setConfirmationText(
100101
`You've successfully added a new action: ${dynamicAction.getDisplayName(
101102
{}

examples/ui_actions_explorer/public/plugin.tsx

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,17 @@ import {
2727
lookUpWeatherAction,
2828
viewInMapsAction,
2929
createEditUserAction,
30-
CALL_PHONE_NUMBER_ACTION,
31-
VIEW_IN_MAPS_ACTION,
32-
TRAVEL_GUIDE_ACTION,
33-
PHONE_USER_ACTION,
34-
EDIT_USER_ACTION,
3530
makePhoneCallAction,
3631
showcasePluggability,
37-
SHOWCASE_PLUGGABILITY_ACTION,
3832
UserContext,
3933
CountryContext,
4034
PhoneContext,
35+
ACTION_EDIT_USER,
36+
ACTION_SHOWCASE_PLUGGABILITY,
37+
ACTION_CALL_PHONE_NUMBER,
38+
ACTION_TRAVEL_GUIDE,
39+
ACTION_VIEW_IN_MAPS,
40+
ACTION_PHONE_USER,
4141
} from './actions/actions';
4242

4343
interface StartDeps {
@@ -54,6 +54,15 @@ declare module '../../../src/plugins/ui_actions/public' {
5454
[COUNTRY_TRIGGER]: CountryContext;
5555
[PHONE_TRIGGER]: PhoneContext;
5656
}
57+
58+
export interface ActionContextMapping {
59+
[ACTION_EDIT_USER]: UserContext;
60+
[ACTION_SHOWCASE_PLUGGABILITY]: {};
61+
[ACTION_CALL_PHONE_NUMBER]: PhoneContext;
62+
[ACTION_TRAVEL_GUIDE]: CountryContext;
63+
[ACTION_VIEW_IN_MAPS]: CountryContext;
64+
[ACTION_PHONE_USER]: UserContext;
65+
}
5766
}
5867

5968
export class UiActionsExplorerPlugin implements Plugin<void, void, {}, StartDeps> {
@@ -67,29 +76,24 @@ export class UiActionsExplorerPlugin implements Plugin<void, void, {}, StartDeps
6776
deps.uiActions.registerTrigger({
6877
id: USER_TRIGGER,
6978
});
70-
deps.uiActions.registerAction(lookUpWeatherAction);
71-
deps.uiActions.registerAction(viewInMapsAction);
72-
deps.uiActions.registerAction(makePhoneCallAction);
73-
deps.uiActions.registerAction(showcasePluggability);
7479

7580
const startServices = core.getStartServices();
76-
deps.uiActions.registerAction(
81+
82+
deps.uiActions.attachAction(
83+
USER_TRIGGER,
7784
createPhoneUserAction(async () => (await startServices)[1].uiActions)
7885
);
79-
deps.uiActions.registerAction(
86+
deps.uiActions.attachAction(
87+
USER_TRIGGER,
8088
createEditUserAction(async () => (await startServices)[0].overlays.openModal)
8189
);
82-
deps.uiActions.attachAction(USER_TRIGGER, PHONE_USER_ACTION);
83-
deps.uiActions.attachAction(USER_TRIGGER, EDIT_USER_ACTION);
8490

85-
// What's missing here is type analysis to ensure the context emitted by the trigger
86-
// is the same context that the action requires.
87-
deps.uiActions.attachAction(COUNTRY_TRIGGER, VIEW_IN_MAPS_ACTION);
88-
deps.uiActions.attachAction(COUNTRY_TRIGGER, TRAVEL_GUIDE_ACTION);
89-
deps.uiActions.attachAction(COUNTRY_TRIGGER, SHOWCASE_PLUGGABILITY_ACTION);
90-
deps.uiActions.attachAction(PHONE_TRIGGER, CALL_PHONE_NUMBER_ACTION);
91-
deps.uiActions.attachAction(PHONE_TRIGGER, SHOWCASE_PLUGGABILITY_ACTION);
92-
deps.uiActions.attachAction(USER_TRIGGER, SHOWCASE_PLUGGABILITY_ACTION);
91+
deps.uiActions.attachAction(COUNTRY_TRIGGER, viewInMapsAction);
92+
deps.uiActions.attachAction(COUNTRY_TRIGGER, lookUpWeatherAction);
93+
deps.uiActions.attachAction(COUNTRY_TRIGGER, showcasePluggability);
94+
deps.uiActions.attachAction(PHONE_TRIGGER, makePhoneCallAction);
95+
deps.uiActions.attachAction(PHONE_TRIGGER, showcasePluggability);
96+
deps.uiActions.attachAction(USER_TRIGGER, showcasePluggability);
9397

9498
core.application.register({
9599
id: 'uiActionsExplorer',

examples/ui_actions_explorer/public/trigger_context_example.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ const createRowData = (
4747
<Fragment>
4848
<EuiButtonEmpty
4949
onClick={() => {
50-
uiActionsApi.executeTriggerActions(COUNTRY_TRIGGER, user.countryOfResidence);
50+
uiActionsApi.executeTriggerActions(COUNTRY_TRIGGER, { country: user.countryOfResidence });
5151
}}
5252
>
5353
{user.countryOfResidence}
@@ -59,7 +59,7 @@ const createRowData = (
5959
<EuiButtonEmpty
6060
disabled={user.phone === undefined}
6161
onClick={() => {
62-
uiActionsApi.executeTriggerActions(PHONE_TRIGGER, user.phone!);
62+
uiActionsApi.executeTriggerActions(PHONE_TRIGGER, { phone: user.phone! });
6363
}}
6464
>
6565
{user.phone}

0 commit comments

Comments
 (0)