-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make the actions plugin support generics #71439
Changes from 13 commits
867c0b7
5959946
bf29855
bd86577
5a408f7
55aad5a
f9885a4
e162fe4
350ee45
8d8e499
03ff0e0
4c2602b
35f95f0
418af31
ab64713
db68028
8106979
394e360
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,9 +8,15 @@ import Boom from 'boom'; | |
import { i18n } from '@kbn/i18n'; | ||
import { RunContext, TaskManagerSetupContract } from '../../task_manager/server'; | ||
import { ExecutorError, TaskRunnerFactory, ILicenseState } from './lib'; | ||
import { ActionType, PreConfiguredAction } from './types'; | ||
import { ActionType as CommonActionType } from '../common'; | ||
import { ActionsConfigurationUtilities } from './actions_config'; | ||
import { | ||
ActionType, | ||
PreConfiguredAction, | ||
ActionTypeConfig, | ||
ActionTypeSecrets, | ||
ActionTypeParams, | ||
} from './types'; | ||
|
||
export interface ActionTypeRegistryOpts { | ||
taskManager: TaskManagerSetupContract; | ||
|
@@ -77,7 +83,11 @@ export class ActionTypeRegistry { | |
/** | ||
* Registers an action type to the action type registry | ||
*/ | ||
public register(actionType: ActionType) { | ||
public register< | ||
Config extends ActionTypeConfig = ActionTypeConfig, | ||
Secrets extends ActionTypeSecrets = ActionTypeSecrets, | ||
Params extends ActionTypeParams = ActionTypeParams | ||
>(actionType: ActionType<Config, Secrets, Params>) { | ||
if (this.has(actionType.id)) { | ||
throw new Error( | ||
i18n.translate( | ||
|
@@ -91,7 +101,7 @@ export class ActionTypeRegistry { | |
) | ||
); | ||
} | ||
this.actionTypes.set(actionType.id, { ...actionType }); | ||
this.actionTypes.set(actionType.id, { ...actionType } as ActionType); | ||
this.taskManager.registerTaskDefinitions({ | ||
[`actions:${actionType.id}`]: { | ||
title: actionType.name, | ||
|
@@ -112,7 +122,11 @@ export class ActionTypeRegistry { | |
/** | ||
* Returns an action type, throws if not registered | ||
*/ | ||
public get(id: string): ActionType { | ||
public get< | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Haven't gotten to the point where this would be needed, but wondering what the real use case is to have There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @gmmorris would know more, he helped me come up with the design. From what I saw, it's the only way we could get it to work as I don't know if you can make an interface extend a generic while also having sub-generic types. (CustomActionType extends ActionType, then setting Config, Secrets, Params generics). |
||
Config extends ActionTypeConfig = ActionTypeConfig, | ||
Secrets extends ActionTypeSecrets = ActionTypeSecrets, | ||
Params extends ActionTypeParams = ActionTypeParams | ||
>(id: string): ActionType<Config, Secrets, Params> { | ||
if (!this.has(id)) { | ||
throw Boom.badRequest( | ||
i18n.translate('xpack.actions.actionTypeRegistry.get.missingActionTypeErrorMessage', { | ||
|
@@ -123,7 +137,7 @@ export class ActionTypeRegistry { | |
}) | ||
); | ||
} | ||
return this.actionTypes.get(id)!; | ||
return this.actionTypes.get(id)! as ActionType<Config, Secrets, Params>; | ||
} | ||
|
||
/** | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe I haven't gotten to the point where this cast is needed, but I woulda thought we could just do
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's to "cast" it to a generic, otherwise typescript complains that it can't convert Config, Secret and Params type to generics.