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 visualization typings #79128

Merged
merged 6 commits into from
Oct 6, 2020

Conversation

timroes
Copy link
Contributor

@timroes timroes commented Oct 1, 2020

Summary

This PR improves the typings of the visualizations plugin and types the VisType interface explicitly and remove the any 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.

For maintainers

@@ -55,7 +55,6 @@ export function createTileMapTypeDefinition(dependencies) {
wms: uiSettings.get('visualization:tileMap:WMSdefaults'),
},
},
requiresPartialRows: true,
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 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';
Copy link
Contributor Author

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', () => {
Copy link
Contributor Author

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 };
Copy link
Contributor Author

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>) {
Copy link
Contributor Author

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;
Copy link
Contributor Author

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> {
Copy link
Contributor Author

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.

Copy link
Contributor

Choose a reason for hiding this comment

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

Nice 🙂

@timroes
Copy link
Contributor Author

timroes commented Oct 5, 2020

@elasticmachine merge upstream

@timroes timroes added Feature:Visualizations Generic visualization features (in case no more specific feature label is available) release_note:skip Skip the PR/issue when compiling release notes Team:Visualizations Visualization editors, elastic-charts and infrastructure v7.10.0 v8.0.0 labels Oct 5, 2020
@timroes timroes marked this pull request as ready for review October 5, 2020 09:19
@timroes timroes requested a review from a team October 5, 2020 09:19
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-app (Team:KibanaApp)

@timroes timroes changed the title Improve visualization typings [WIP] Improve visualization typings Oct 5, 2020
Copy link
Contributor

@stratoula stratoula left a 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. 🍪

Copy link
Contributor

@flash1293 flash1293 left a 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'}`;
Copy link
Contributor

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.

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

@kbn/optimizer bundle module count

id before after diff
visualizations 134 135 +1

async chunks size

id before after diff
visDefaultEditor 409.7KB 409.7KB -37.0B
visualize 271.4KB 271.4KB +8.0B
total -29.0B

page load bundle size

id before after diff
tileMap 49.1KB 49.2KB +87.0B
visTypeMetric 27.2KB 27.1KB -30.0B
visTypeTable 77.8KB 78.1KB +228.0B
visTypeTagcloud 22.1KB 22.0KB -30.0B
visualizations 273.3KB 273.5KB +170.0B
total +425.0B

History

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

@timroes timroes merged commit b8f4ea1 into elastic:master Oct 6, 2020
@timroes timroes deleted the chore/improve-visualization-typings branch October 6, 2020 11:05
timroes pushed a commit to timroes/kibana that referenced this pull request Oct 6, 2020
* Improve visualization typings

* Fix vis selection dialog

* Fix broken getInfoMessage type

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
timroes pushed a commit that referenced this pull request Oct 6, 2020
* 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>
@timroes timroes added the hacktoberfest-accepted https://hacktoberfest.digitalocean.com/hacktoberfest-update label Oct 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:Visualizations Generic visualization features (in case no more specific feature label is available) hacktoberfest-accepted https://hacktoberfest.digitalocean.com/hacktoberfest-update release_note:skip Skip the PR/issue when compiling release notes Team:Visualizations Visualization editors, elastic-charts and infrastructure v7.10.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants