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

[indexPatterns/create] track loading state independently #11990

Merged
merged 4 commits into from
May 24, 2017

Conversation

spalger
Copy link
Contributor

@spalger spalger commented May 24, 2017

When the indexPattern view is in a loading state it communicates that by setting the fieldsFetchError to a loading message which is effective but renders the loading message like it's an error and isn't something we can use when other parts of the controller are loading (like the samples).

With this PR the loading state is now tracked with a LoadingTracker that wraps the async/loading methods in the controller and tracks how many of those functions are executing at a time, then surfaces this information with LoadingTracker#isLoading(), which is then exposed on the controller for use in the view.

Since this new condition made the logic for which message to display in the create button more complicated, the logic was moved to a helper function that is executed within a watcher.

Copy link
Contributor

@ycombinator ycombinator left a comment

Choose a reason for hiding this comment

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

@spalger I haven't done a full review of this PR but I looked at the most interesting bit, the loading_tracker module. If I understand its purpose and usage, it is to track whether the page is in a loading state, which may be determined by multiple async function calls (whether they are in progress or finished).

The loading_state module is very clever but I'm concerned that it might be too clever, unless I'm missing something. Could we "just" keep the loading count in the index pattern controller and have the async functions increment/decrement it as needed? I understand this puts more of a burden on each async caller but IMO the code becomes easier to follow. Again, its possible I'm missing something so please point it out if I am.

@cjcenizal
Copy link
Contributor

cjcenizal commented May 24, 2017

I love the intent behind this PR, but I agree with @ycombinator. When I read create_index_pattern.js, I don't understand how isLoading is determined based on the use of createLoadingTracker. And when I read the implementation of loading_tracker.js, I found myself needing to dive into our Promise service. This made me think: why is loading state so tightly coupled with this service? The concern of "loading state" isn't innately oriented around promises.

Can we look for a simpler way to track loading state? I think it's worth trying out @ycombinator's suggestion and seeing if that solves the problem and makes the code easier to follow.

@spalger
Copy link
Contributor Author

spalger commented May 24, 2017

I didn't want it to be so easy to break, and I didn't want to just copy past the same logic all over the controller, but I can inline everything if you both think that the loading tracker is too weird.

@@ -20,6 +21,7 @@ uiModules.get('apps/management')
const refreshKibanaIndex = Private(RefreshKibanaIndex);
const intervals = indexPatterns.intervals;
let samplePromise;
let loadingCount = 0;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ycombinator @cjcenizal Do you guys like this better?

Copy link
Contributor

Choose a reason for hiding this comment

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

I do find this pattern easier to follow. Thanks for considering the suggestion.

if (timeField) {
updateFieldListAndSetTimeField(results, timeField.name);
} else {
updateFieldList(results);
}
}).catch(() => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Did you mean for this to be a finally?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep

@spalger spalger force-pushed the index-patterns/loading-tracker branch from e4dc54c to b9568b0 Compare May 24, 2017 20:08
Copy link
Contributor

@cjcenizal cjcenizal left a comment

Choose a reason for hiding this comment

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

Thanks for making the change! This is easy for me to follow. LGTM.

Copy link
Contributor

@ycombinator ycombinator left a 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 the invalid-index-name case is working correctly:

screen shot 2017-05-24 at 1 26 59 pm

I would expect the button to say "Invalid index name pattern" instead.

@spalger
Copy link
Contributor Author

spalger commented May 24, 2017

That's not an invalid index name though, it just doesn't exist. An invalid index name contains any of the characters \/?"<>| , see https://github.com/elastic/kibana/blob/5c04ff65fbb3b16f8958f8241488463136415670/src/ui/public/directives/validate_index_name.js

Copy link
Contributor

@ycombinator ycombinator left a comment

Choose a reason for hiding this comment

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

LGTM.

@spalger spalger force-pushed the index-patterns/loading-tracker branch from b6c8ddb to 19c7ef4 Compare May 24, 2017 21:01
@spalger spalger merged commit dde4e9a into elastic:master May 24, 2017
spalger added a commit that referenced this pull request May 24, 2017
* [indexPatterns/create] make loading state independent of fieldsFetchError

* [indexPatterns/create] return promises while loading

* [indexPatterns/create] track loading count in controller

(cherry picked from commit dde4e9a)
@spalger
Copy link
Contributor Author

spalger commented May 24, 2017

5.5/5.x: 9712cf5

@spalger spalger deleted the index-patterns/loading-tracker branch May 24, 2017 21:03
snide pushed a commit to snide/kibana that referenced this pull request May 30, 2017
* [indexPatterns/create] make loading state independent of fieldsFetchError

* [indexPatterns/create] return promises while loading

* [indexPatterns/create] track loading count in controller
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.

None yet

3 participants