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

[Discover] Refactor discover.js controller topnav code #79062

Merged

Conversation

kertal
Copy link
Member

@kertal kertal commented Oct 1, 2020

Summary

This PR extracts logic & functionality of discover.js (containing the angular controller) related to the topnav/toolbar, field counting, search source updating to separate files and functions, converting to TypeScript.

Bildschirmfoto 2020-11-16 um 11 08 40

Testing

There shall be no regressions!

Checklist

@kertal kertal added the Feature:Discover Discover Application label Oct 1, 2020
@kertal kertal self-assigned this Oct 1, 2020
@kertal
Copy link
Member Author

kertal commented Nov 2, 2020

@elasticmachine merge upstream

import { updateSearchSource } from '../helpers/update_search_source';
import { calcFieldCounts } from '../helpers/calc_field_counts';

const services = getServices();
Copy link
Member Author

Choose a reason for hiding this comment

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

Note that the IDE did some of this reorderings, import before variable declaration, sort import alphabetical, kept it because they make sense

stateValFound: !!index && id === index,
});
}),
ip: loadIndexPattern(index, data.indexPatterns, config),
Copy link
Member Author

Choose a reason for hiding this comment

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

Note that the refactoring here is a first step, separate loading and resolving shouldn't be necessary, it improving it step by step

Comment on lines 156 to 159
removeField<K extends keyof SearchSourceFields>(field: K) {
delete this.fields[field];
return this;
}
Copy link
Member Author

@kertal kertal Nov 19, 2020

Choose a reason for hiding this comment

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

Why did I add this? To prevent TypeScript confusion, because when I used 'setFields(key, null)' to remove it, I got depending what I was trying to remove TypeScript errors

Copy link
Member

Choose a reason for hiding this comment

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

Would be nice if we could add a quick unit test for the new method

Copy link
Member Author

Choose a reason for hiding this comment

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

Absolutely! I've added a jest test.

@kertal kertal requested a review from a team November 19, 2020 15:22
Copy link
Member

@lukeelmers lukeelmers left a comment

Choose a reason for hiding this comment

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

Just looked at app services code -- The searchSource.removeField update makes sense to me 👍

@kertal
Copy link
Member Author

kertal commented Nov 20, 2020

I had another pass through this, both the code and a round of testing, and I don't have any major concerns around merging this. Let me know if you want to do some improvements to the code, and then I can approve 👍

@majagrubic from my side it should be fine, let me know if there's something else I should do

@kertal
Copy link
Member Author

kertal commented Nov 23, 2020

@elasticmachine merge upstream

@kertal
Copy link
Member Author

kertal commented Nov 24, 2020

@elasticmachine merge upstream

…github.com:kertal/kibana into kertal-pr-2020-10-01-discover-refactor-topnav-code
@kertal
Copy link
Member Author

kertal commented Nov 25, 2020

@elasticmachine merge upstream

Copy link
Contributor

@majagrubic majagrubic left a comment

Choose a reason for hiding this comment

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

I haven't tested it since the last revision, but code changes look good 👍

…github.com:kertal/kibana into kertal-pr-2020-10-01-discover-refactor-topnav-code
@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
discover 273 279 +6

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
discover 420.9KB 430.2KB +9.3KB

Page load bundle

Size of the bundles that are downloaded on every page load. Target size is below 100kb

id before after diff
data 973.5KB 973.5KB +57.0B
discover 82.0KB 81.8KB -131.0B
total -74.0B

History

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

@kertal kertal merged commit f294a9e into elastic:master Nov 25, 2020
kertal added a commit to kertal/kibana that referenced this pull request Nov 25, 2020
* Move discover.js functions to helper functions in separate files

* Convert to TypeScript

* Add unit tests

* Add removeField function to SearchSource
kertal added a commit that referenced this pull request Nov 25, 2020
* Move discover.js functions to helper functions in separate files

* Convert to TypeScript

* Add unit tests

* Add removeField function to SearchSource
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:Discover Discover Application release_note:skip Skip the PR/issue when compiling release notes Team:Visualizations Visualization editors, elastic-charts and infrastructure v7.11.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants