-
Notifications
You must be signed in to change notification settings - Fork 8.2k
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 visualization typings #79128
Improve visualization typings #79128
Conversation
@@ -55,7 +55,6 @@ export function createTileMapTypeDefinition(dependencies) { | |||
wms: uiSettings.get('visualization:tileMap:WMSdefaults'), | |||
}, | |||
}, | |||
requiresPartialRows: true, |
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.
ℹ️ This flag was never passed through the BaseVisType, so it seems this feature is no longer needed for anything and I removed the flag completely.
this.editorConfig = _.defaultsDeep({}, opts.editorConfig, { collections: {} }); | ||
this.options = _.defaultsDeep({}, opts.options, defaultOptions); | ||
this.stage = opts.stage || 'production'; | ||
this.isExperimental = opts.stage === 'experimental'; |
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.
ℹ️ The isExperimental
flag was only used in one place. I just inlined the check against stage
there, so keep the VisType
interface a bit smaller.
@@ -107,6 +118,30 @@ describe('NewVisModal', () => { | |||
expect(wrapper.find('[data-test-subj="visType-vis"]').exists()).toBe(true); | |||
}); | |||
|
|||
it('should sort promoted visualizations first', () => { |
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've added this test mainly, because during work on this I broke it, and the only thing that catched the broken ordering was a snapshot test, where it was not quit clear in the beginning that it was the ordering that was broken. So I added a more explicit test on this.
} else { | ||
const q = query.toLowerCase(); | ||
entries = allTypes.map((type) => { | ||
const matchesQuery = | ||
type.name.toLowerCase().includes(q) || | ||
type.title.toLowerCase().includes(q) || | ||
(typeof type.description === 'string' && type.description.toLowerCase().includes(q)); | ||
return { ...type, highlighted: matchesQuery }; |
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.
ℹ️ The main problem here was that we were spreading the type here and thus losing the actual BaseVisTypeClass
that has getters on it. I changed this structure slightly, so that we now just assign the type
as a reference into each VisTypeListEntry
. All the further changes in this file are related to this minor change.
if (this.unregisteredHiddenTypes.includes(visDefinition.name)) { | ||
visDefinition.hidden = true; | ||
} | ||
private registerVisualization<TVisParam>(visDefinition: VisType<TVisParam>) { |
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.
ℹ️ Just pulling this into an actual class method, instead of defining it as a closure, since it did not needed any access to anything that closure would have had.
/** | ||
* The editor that should be used to edit visualizations of this type. | ||
*/ | ||
readonly editor?: any; |
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 still plan to type this properly, but I need to touch a bit more plugins for this, thus I'd prefer doing it in a separate PR.
hierarchicalData: false, // we should get rid of this i guess ? | ||
}; | ||
|
||
export class BaseVisType<TVisParams = VisParams> implements VisType<TVisParams> { |
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.
ℹ️ Those now properly implement
the interface and thus you also don't need to type the properties here again, since it can pull it automatically from the interface.
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.
Nice 🙂
@elasticmachine merge upstream |
Pinging @elastic/kibana-app (Team:KibanaApp) |
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 LGTM, also tested it locally, can't find any regressions. 🍪
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.
Didn't find any issues - great start for cleaning up the types in here!
@@ -155,7 +158,8 @@ export const getSchemas = (vis: Vis, { timeRange, timefilter }: BuildPipelinePar | |||
} | |||
} | |||
if (schemaName === 'split') { | |||
schemaName = `split_${vis.params.row ? 'row' : 'column'}`; | |||
// TODO: We should check if there's a better way then casting to `any` here | |||
schemaName = `split_${(vis.params as any).row ? 'row' : 'column'}`; |
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.
We could restrict TVisParams
a little further (<TVisParams extends { row?: boolean }>
), but this file is not properly typed in a lot of places so I wouldn't bother improving it. We should be able to remove it and move the logic into the individual visualizations where they can be typed explicitly anyway.
💚 Build SucceededMetrics [docs]@kbn/optimizer bundle module count
async chunks size
page load bundle size
History
To update your PR or re-run it, just comment with: |
* Improve visualization typings * Fix vis selection dialog * Fix broken getInfoMessage type Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
* Improve visualization typings * Fix vis selection dialog * Fix broken getInfoMessage type Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
Summary
This PR improves the typings of the
visualizations
plugin and types theVisType
interface explicitly and remove theany
index signature of it. I still have some types in there (like the editor) I want to improve, but since they touch multiple plugins I want to improve them in separate PRs after this.For more details on the typings check the inline comments.
This PR should not change any functionality.
Checklist
Delete any items that are not applicable to this PR.
[ ] Any text added follows EUI's writing guidelines, uses sentence case text and includes i18n support[ ] Documentation was added for features that require explanation or tutorials[ ] This was checked for keyboard-only and screenreader accessibility[ ] This renders correctly on smaller devices using a responsive layout. (You can test this in your browser[ ] This was checked for cross-browser compatibilityFor maintainers
[ ] This was checked for breaking API changes and was labeled appropriately