@@ -34,16 +34,18 @@ export const EDIT_USER_ACTION = 'EDIT_USER_ACTION';
3434export const PHONE_USER_ACTION = 'PHONE_USER_ACTION' ;
3535export const SHOWCASE_PLUGGABILITY_ACTION = 'SHOWCASE_PLUGGABILITY_ACTION' ;
3636
37- export const showcasePluggability = createAction < { } > ( {
37+ export const showcasePluggability = createAction ( {
3838 type : SHOWCASE_PLUGGABILITY_ACTION ,
3939 getDisplayName : ( ) => 'This is pluggable! Any plugin can inject their actions here.' ,
40- execute : async ( { } ) => alert ( "Isn't that cool?!" ) ,
40+ execute : async ( ) => alert ( "Isn't that cool?!" ) ,
4141} ) ;
4242
43- export const makePhoneCallAction = createAction < { phone : string } > ( {
43+ export type PhoneContext = string ;
44+
45+ export const makePhoneCallAction = createAction < PhoneContext > ( {
4446 type : CALL_PHONE_NUMBER_ACTION ,
4547 getDisplayName : ( ) => 'Call phone number' ,
46- execute : async ( { phone } ) => alert ( `Pretend calling ${ phone } ...` ) ,
48+ execute : async phone => alert ( `Pretend calling ${ phone } ...` ) ,
4749} ) ;
4850
4951export const lookUpWeatherAction = createAction < { country : string } > ( {
@@ -55,11 +57,13 @@ export const lookUpWeatherAction = createAction<{ country: string }>({
5557 } ,
5658} ) ;
5759
58- export const viewInMapsAction = createAction < { country : string } > ( {
60+ export type CountryContext = string ;
61+
62+ export const viewInMapsAction = createAction < CountryContext > ( {
5963 type : VIEW_IN_MAPS_ACTION ,
6064 getIconType : ( ) => 'popout' ,
6165 getDisplayName : ( ) => 'View in maps' ,
62- execute : async ( { country } ) => {
66+ execute : async country => {
6367 window . open ( `https://www.google.com/maps/place/${ country } ` , '_blank' ) ;
6468 } ,
6569} ) ;
@@ -110,11 +114,13 @@ export const createEditUserAction = (getOpenModal: () => Promise<OverlayStart['o
110114 } ,
111115 } ) ;
112116
117+ export interface UserContext {
118+ user : User ;
119+ update : ( user : User ) => void ;
120+ }
121+
113122export const createPhoneUserAction = ( getUiActionsApi : ( ) => Promise < UiActionsStart > ) =>
114- createAction < {
115- user : User ;
116- update : ( user : User ) => void ;
117- } > ( {
123+ createAction < UserContext > ( {
118124 type : PHONE_USER_ACTION ,
119125 getDisplayName : ( ) => 'Call phone number' ,
120126 isCompatible : async ( { user } ) => user . phone !== undefined ,
@@ -126,6 +132,8 @@ export const createPhoneUserAction = (getUiActionsApi: () => Promise<UiActionsSt
126132 // to the phone number trigger.
127133 // TODO: we need to figure out the best way to handle these nested actions however, since
128134 // we don't want multiple context menu's to pop up.
129- ( await getUiActionsApi ( ) ) . executeTriggerActions ( PHONE_TRIGGER , { phone : user . phone } ) ;
135+ if ( user . phone !== undefined ) {
136+ ( await getUiActionsApi ( ) ) . executeTriggerActions ( PHONE_TRIGGER , user . phone ) ;
137+ }
130138 } ,
131139 } ) ;
0 commit comments