Skip to content
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

Improve action and trigger types #58657

Merged
merged 3 commits into from
Feb 28, 2020

Conversation

stacey-gammon
Copy link
Contributor

@stacey-gammon stacey-gammon commented Feb 26, 2020

You will now get a warning if you try to use a trigger with an id that has not been added to the TriggerContextMapping with a context shape:

Screen Shot 2020-02-26 at 3 32 58 PM

Screen Shot 2020-02-26 at 3 32 30 PM

This is good because before, if you didn't register your trigger id, you could pass it any context object and typescript wouldn't complain.

  • Made it possible to have an undefined context as well as a non-object shape context like a string or a number.

Small cleanups:

  • Refactored and remove two unused exported types
  • Fixed up one example usage where the action was being added to the registry in the start method when it should have gone in the setup method.

Step two will be attempting to get a warning if doing
uiActions.attachAction(triggerId, helloWorldActionId);
if the expected context shapes are mismatched.

@stacey-gammon stacey-gammon requested a review from a team February 26, 2020 20:38
@stacey-gammon stacey-gammon requested a review from a team as a code owner February 26, 2020 20:38
@@ -60,7 +60,7 @@ const ActionsExplorer = ({ uiActionsApi, openModal }: Props) => {
</EuiText>
<EuiButton
data-test-subj="emitHelloWorldTrigger"
onClick={() => uiActionsApi.executeTriggerActions(HELLO_WORLD_TRIGGER_ID, {})}
onClick={() => uiActionsApi.executeTriggerActions(HELLO_WORLD_TRIGGER_ID, undefined)}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is pretty weird, but, typescript complained if I didn't explicitly send over undefined.

@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-app-arch (Team:AppArch)

@stacey-gammon stacey-gammon added chore release_note:skip Skip the PR/issue when compiling release notes v7.7.0 review labels Feb 26, 2020
@stacey-gammon stacey-gammon force-pushed the 2020-02-26-action-types branch 2 times, most recently from 8a5f8a0 to e5ff89a Compare February 26, 2020 20:56
…using a trigger id that has not been added to the trigger context mapping.
Copy link
Contributor

@Dosant Dosant left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes LGTM 👍

src/plugins/ui_actions/public/types.ts Outdated Show resolved Hide resolved
if (this.actions.has(action.id)) {
throw new Error(`Action [action.id = ${action.id}] already registered.`);
}

this.actions.set(action.id, action);
};

public readonly attachAction = (triggerId: string, actionId: string): void => {
// TODO: make this
// <T extends TriggerId>(triggerId: T, action: Action<TriggerContextMapping[T]>): \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting! Have you checked if it works? Or it will be not that simple?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does seem to be working in my PR (still wip)!

Screen Shot 2020-02-27 at 11 53 34 AM

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

@stacey-gammon stacey-gammon merged commit ad0aa12 into elastic:master Feb 28, 2020
stacey-gammon added a commit to stacey-gammon/kibana that referenced this pull request Feb 28, 2020
* Improve types so emitting the wrong context shape complains, as does using a trigger id that has not been added to the trigger context mapping.

* remove unneccessary code
stacey-gammon added a commit that referenced this pull request Feb 28, 2020
* Improve types so emitting the wrong context shape complains, as does using a trigger id that has not been added to the trigger context mapping.

* remove unneccessary code
jloleysens added a commit to jloleysens/kibana that referenced this pull request Mar 2, 2020
…dex-server-side

* 'master' of github.com:elastic/kibana: (34 commits)
  [Upgrade Assistant] Remove "boom" from reindex service (elastic#58715)
  [data] Clean up QueryStringInput unit tests (elastic#58704)
  [SIEM] Detection Fix typo in Adobe Hijack Persistence rule (elastic#58804)
  Restores [SIEM][CASE] Init Configure Case Page (elastic#58121) (elastic#58924)
  Skips additional failing Ingest Manager integration tests
  Skips failing Ingest Manager integration tests
  Move dev tools styles to NP (elastic#58855)
  change to have kibana --ssl cli option use more recent certs (elastic#57933)
  disable failing suite (elastic#58942)
  Don't start pollEsNodesVersion unless someone subscribes (elastic#56923)
  Do not write UUID file during optimize process (elastic#58899)
  [Endpoint] Task/add nav bar (elastic#58604)
  [Metric Alerts] Add backend support for multiple expressions per alert  (elastic#58672)
  [Metrics Alerts] Fix alerting on a rate aggregation (elastic#58789)
  disable flaky suite (elastic#55953)
  Revert "[SIEM] apollo@3 (elastic#51926)" and "[SIEM][CASE] Init Confi… (elastic#58806)
  [resubmit] Prep agg types for new platform (elastic#58893)
  [Lens] Allow number formatting within Lens (elastic#56253)
  [Autocomplete] Use settings from config rather than UI settings (elastic#58784)
  Improve action and trigger types (elastic#58657)
  ...

# Conflicts:
#	x-pack/plugins/upgrade_assistant/server/routes/reindex_indices/reindex_indices.ts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
chore release_note:skip Skip the PR/issue when compiling release notes review v7.7.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants