-
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
Remove dynamic mapped types from UiActions #87075
Conversation
return { | ||
getIconType: () => undefined, | ||
order: 0, | ||
id: action.type, |
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'm not sure why this wasn't failing before, but ActionDefintion
currently has id
marked as a required field, yet this function does provide a default fallback to the type
field.
TS was complaining here that this line would be overridden by the ...action
spread below which makes sense, so I removed this line. However, that also required me to add the id
field to many call sites of this function. I didn't want to change the types, but I think the desired behavior is:
ActionDefinition
should require eitherid
ORtype
- If
id
is undefined,createAction
should fallback totype
. Is that correct?
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.
However, that also required me to add the id field to many call sites of this function. I didn't want to change the types, but I think the desired behavior is:
ActionDefinition should require either id OR type
If id is undefined, createAction should fallback to type. Is that correct?
This seems correct, but to not add id
in bunch of call sites, why you didn't make id
optional for this function lit it was before?
See: https://github.com/elastic/kibana/pull/87075/files?file-filters%5B%5D=.ts&file-filters%5B%5D=.tsx#diff-4960a0b834fad6726535d59e6fc8b2febb31f0669916cbcfe9f19eec00478f46L26
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.
in the old implementation this was valid:
createAction({ execute() {} })
since both id
and type
used to be optional.
Josh decided to make id
required instead of introducing a union type ActionDefinitionWithId | ActionDefinitionWithType
ExecutionContext extends object = object, | ||
FactoryContext extends BaseActionFactoryContext = BaseActionFactoryContext |
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 switched the order of ExecutionContext and FactoryContext since there were a few use cases where the default for ExecutionContext needed to be overridden but not FactoryContext
fcd5f4d
to
a27d42e
Compare
Pinging @elastic/kibana-app-services (Team:AppServices) |
a27d42e
to
be317b3
Compare
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.
Kibana app stuff LGTM, left one small nit
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.
Code changes LGTM.
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.
ML changes LGTM
I understand that we have to do this to unblock typescript project refs effort, but I wouldn't agree with this statement:
Some example from top of my head where old system was useful: 1. getTrigger returns type safe triggers
The context shape passed into Same applies for 2. Drilldown definition listed a type safe list of supported triggers.Consumers who create their drilldowns had to specify supported triggers, we would caught on type check if they are trying to use not existing trigger. (e.g. typo or older trigger was removed or renamed) Same for embeddable listing a list of triggers they could emit. 3. We enforced Drilldown's context to be a superset of its triggers' contextsImagine a drilldown type supports both VALUE_CLICK_TRIGGER and RANGE_SELECT_TRIGGER, in such case before this pr we type checked that drilldown's context can handle |
return { | ||
getIconType: () => undefined, | ||
order: 0, | ||
id: action.type, |
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.
However, that also required me to add the id field to many call sites of this function. I didn't want to change the types, but I think the desired behavior is:
ActionDefinition should require either id OR type
If id is undefined, createAction should fallback to type. Is that correct?
This seems correct, but to not add id
in bunch of call sites, why you didn't make id
optional for this function lit it was before?
See: https://github.com/elastic/kibana/pull/87075/files?file-filters%5B%5D=.ts&file-filters%5B%5D=.tsx#diff-4960a0b834fad6726535d59e6fc8b2febb31f0669916cbcfe9f19eec00478f46L26
src/plugins/ui_actions/public/service/ui_actions_service.test.ts
Outdated
Show resolved
Hide resolved
src/plugins/ui_actions/public/tests/test_samples/hello_world_action.tsx
Outdated
Show resolved
Hide resolved
@Dosant as @joshdover is on PTO, I'm going to continue working on the task.
If I understand correctly, the point was that introduced complexity doesn't justify the effort. Since we do know the type of the action, the type safety can be achieved as simple as const triggerContext: ApplyGlobalFilterActionContext = {
filters,
embeddable: context.embeddable,
timeFieldName: context.data.timeFieldName,
};
uiActions.getTrigger(APPLY_FILTER_TRIGGER).exec(triggerContext);
A consumer can achieve the same importing Any input on an alternative implementation is appreciated. |
@restrry,
Unfortunately, don't have any alternatives on my mind. would appreciate those nit code comments clean up. Also. Does this mean we have to get rid of this pattern in other places? One other heavily used I am aware of is share plugin and Url generators. |
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.
Looks straight-forward to me. 👍
💚 Build SucceededMetrics [docs]Distributable file count
Page load bundle
History
To update your PR or re-run it, just comment with: |
* Remove dynamic mapped types from UiActions * Remove import between data <-> embeddables * remove outdated comments, export action types from discover_enhanced * fix notice.txt Co-authored-by: restrry <[email protected]>
* Remove dynamic mapped types from UiActions * Remove import between data <-> embeddables * remove outdated comments, export action types from discover_enhanced * fix notice.txt Co-authored-by: restrry <[email protected]> Co-authored-by: Josh Dover <[email protected]>
Summary
This removes the pseudo type safety in the UiActions framework that leveraged
declare module
to reopen theTriggerContextMapping
type. This pattern is not compatible with TS project references (#80508) and is not really type safe anyways. This PR removes this type and simplifies a lot of related code.Reasons we should feel comfortable removing this:
For maintainers