Skip to content

Commit

Permalink
require object context, which seems to fix the partial requirement in…
Browse files Browse the repository at this point in the history
… type and thus the type issue
  • Loading branch information
stacey-gammon committed Mar 2, 2020
1 parent f97c9c3 commit 5e50447
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 11 deletions.
4 changes: 2 additions & 2 deletions examples/ui_action_examples/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ interface UiActionExamplesSetupDependencies {

declare module '../../../src/plugins/ui_actions/public' {
export interface TriggerContextMapping {
[HELLO_WORLD_TRIGGER_ID]: undefined;
[HELLO_WORLD_TRIGGER_ID]: {};
}

export interface ActionContextMapping {
[ACTION_HELLO_WORLD]: undefined;
[ACTION_HELLO_WORLD]: {};
}
}

Expand Down
4 changes: 2 additions & 2 deletions examples/ui_actions_explorer/public/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ const ActionsExplorer = ({ uiActionsApi, openModal }: Props) => {
</EuiText>
<EuiButton
data-test-subj="emitHelloWorldTrigger"
onClick={() => uiActionsApi.executeTriggerActions(HELLO_WORLD_TRIGGER_ID, undefined)}
onClick={() => uiActionsApi.executeTriggerActions(HELLO_WORLD_TRIGGER_ID, {})}
>
Say hello world!
</EuiButton>
Expand Down Expand Up @@ -99,7 +99,7 @@ const ActionsExplorer = ({ uiActionsApi, openModal }: Props) => {
uiActionsApi.attachAction(HELLO_WORLD_TRIGGER_ID, dynamicAction);
setConfirmationText(
`You've successfully added a new action: ${dynamicAction.getDisplayName(
undefined
{}
)}. Refresh the page to reset state. It's up to the user of the system to persist state like this.`
);
}}
Expand Down
2 changes: 1 addition & 1 deletion examples/ui_actions_explorer/public/plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ declare module '../../../src/plugins/ui_actions/public' {

export interface ActionContextMapping {
[ACTION_EDIT_USER]: UserContext;
[ACTION_SHOWCASE_PLUGGABILITY]: undefined;
[ACTION_SHOWCASE_PLUGGABILITY]: {};
[ACTION_CALL_PHONE_NUMBER]: PhoneContext;
[ACTION_TRAVEL_GUIDE]: CountryContext;
[ACTION_VIEW_IN_MAPS]: CountryContext;
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/ui_actions/public/actions/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { ActionType, ActionContextMapping } from '../types';

export type ActionByType<T extends ActionType> = Action<ActionContextMapping[T], T>;

export interface Action<Context = undefined, T = ActionType> {
export interface Action<Context = {}, T = ActionType> {
/**
* Determined the order when there is more than one action matched to a trigger.
* Higher numbers are displayed first.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ describe('UiActionsService', () => {
});

describe('.getTriggerActions()', () => {
const action1: Action<undefined, ActionType> = {
const action1: Action = {
id: 'action1',
order: 1,
type: 'type1' as ActionType,
Expand All @@ -114,7 +114,7 @@ describe('UiActionsService', () => {
getIconType: () => '',
isCompatible: async () => true,
};
const action2: Action<undefined, ActionType> = {
const action2: Action = {
id: 'action2',
order: 2,
type: 'type2' as ActionType,
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/ui_actions/public/service/ui_actions_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export class UiActionsService {
triggerId: TType,
// The action can accept partial or no context, but if it needs context not provided
// by this type of trigger, typescript will complain. yay!
action: Action<Partial<TriggerContextMapping[TType]> | undefined> & ActionByType<AType>
action: ActionByType<AType> & Action<TriggerContextMapping[TType]>
): void => {
if (!this.actions.has(action.id)) {
this.registerAction(action);
Expand Down Expand Up @@ -157,7 +157,7 @@ export class UiActionsService {
public readonly getTriggerCompatibleActions = async <T extends TriggerId>(
triggerId: T,
context: TriggerContextMapping[T]
): Promise<Array<Action<TriggerContextMapping[T] | undefined>>> => {
): Promise<Array<Action<TriggerContextMapping[T]>>> => {
const actions = this.getTriggerActions!(triggerId);
const isCompatibles = await Promise.all(actions.map(action => action.isCompatible(context)));
return actions.reduce(
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/ui_actions/public/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ const DEFAULT_TRIGGER = '';

export type TriggerId = keyof TriggerContextMapping;

export type BaseContext = object;
export type TriggerContext = BaseContext;
export type BaseContext = object | undefined | string | number;

export interface TriggerContextMapping {
[DEFAULT_TRIGGER]: TriggerContext;
Expand Down

0 comments on commit 5e50447

Please sign in to comment.