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

Clean up SearchSource and get rid of AbstractDataSourceProvider #16932

Merged

Conversation

stacey-gammon
Copy link
Contributor

  • Merge search source and abstract
  • es6ify SearchSource class

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@stacey-gammon stacey-gammon force-pushed the search-source-abstract-cleanup branch from 1e9be7a to 8bc30fe Compare March 5, 2018 17:56
@elasticmachine
Copy link
Contributor

💚 Build Succeeded


index(indexPattern) {
const state = this._state;

Copy link
Contributor

Choose a reason for hiding this comment

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

Seems like there shouldn't be an empty line here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yea agree this looks weird. It was just part of the original code. :)

Copy link
Contributor

@chrisdavies chrisdavies left a comment

Choose a reason for hiding this comment

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

I don't know how to flag this as "LGTM w/ tweaks" so I'm marking it as "Request changes".

But yeah. LGTM w/ tweaks, and maybe a flag for some future revisit when we have the time. :)

delete state.source;
}

if (indexPattern === undefined) return state.index;
Copy link
Contributor

Choose a reason for hiding this comment

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

This distinction between undefined and null seems brittle to me. One returns the index, and one deletes it, but null and undefined are often treated as synonymous by developers. :/

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So strange indeed. I haven't had a chance to really investigate why this is, but don't want to get into it for this PR. As long as I haven't changed any logic in this PR, my only goal is to get rid of the unnecessary abstraction and turn into es6 style class.


// Return promises created by the completion handler so that
// errors will bubble properly
return req.getCompletePromise().then(addRequest);
Copy link
Contributor

Choose a reason for hiding this comment

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

This appears to be an infinite loop? Not sure if it is or not. If not, is there a way to make this clearer?

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 some funky logic for sure. Take a look at #16641 specifically this comment - #16641 (comment). I'm pretty sure this function is only used by discover and it's how it keeps a request always in the queue so auto refresh works.

We def want to clean this up (or just rewrite all the logic). Courier is some seriously old code that is pretty tricky to refactor because of all the subtle ways it's used.

For this current PR, I'd prefer to keep it simply the combining of the abstract class and switching to es6 styles (and i think I removed an unused function). I think it will be easier to isolate bugs if the PRs are relatively focused. But def a next step will be to do more refactoring/clean up here.

* @return {[type]} [description]
*/
toString() {
return angular.toJson(this.toJSON());
Copy link
Contributor

Choose a reason for hiding this comment

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

Couldn't we JSON.stringify here? If so, let's do that and drop one angular dependency.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There is actually one thing different. angular.toJson removes any variables that start with $. I think that's it actually. There was a bug we ran into once because of a swap. But I agree, we should get rid of the angular dependency. I think there might be a native toJSON that does the same thing with the $... I'll have to look later.

But prefer not to put that in this PR.

*/
_mergeProp(state, val, key) {
if (typeof val === 'function') {
const source = this;
Copy link
Contributor

Choose a reason for hiding this comment

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

Stopping the review here, as I realize you're just moving code around for the purpose of refactoring, and this code is already in the codebase. That said, I'd flag this as something that would benefit additional refactoring at some point. It's fairly difficult to follow. At ~700 loc, this feels like a "god class". Not sure what to do about it or whether it'll ever be worth it, but a lot of this appears as if it'd benefit from a conversion from OOP to a more functional approach, as it's conflating data transforms with a lot of other things (mutating the DOM, etc), so separating those things would be nice.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agree completely! Something I've been wanting to do forever is clean this code up but it's tricky and I've been taking very small steps to ensure forward progress (if I try to tackle too much at once I get down the rabbit hole and the changes become too huge and difficult to find the reason for bugs).

Copy link
Member

@ppisljar ppisljar left a comment

Choose a reason for hiding this comment

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

LGTM

@stacey-gammon
Copy link
Contributor Author

@chrisdavies - I'm going to go ahead and merge as is because I wanted to keep all the original logic the same. Def agree with your feedback, just think it belongs in a different PR.

@stacey-gammon stacey-gammon merged commit 516532e into elastic:master Mar 12, 2018
stacey-gammon added a commit to stacey-gammon/kibana that referenced this pull request Mar 12, 2018
…tic#16932)

* Merge search source and abstract and es6ify SearchSource class

* Remove duplicate function and rename SourceAbstracts to SearchSource
stacey-gammon added a commit that referenced this pull request Mar 12, 2018
…) (#17106)

* Merge search source and abstract and es6ify SearchSource class

* Remove duplicate function and rename SourceAbstracts to SearchSource
@stacey-gammon stacey-gammon deleted the search-source-abstract-cleanup branch May 31, 2018 17:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants