@@ -27,44 +27,48 @@ export const USER_TRIGGER = 'USER_TRIGGER';
2727export const COUNTRY_TRIGGER = 'COUNTRY_TRIGGER' ;
2828export 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
102106export 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
122123export 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 } ) ;
0 commit comments