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

Prevents canceling index pattern modal from throwing error #13488

Merged
merged 2 commits into from
Aug 15, 2017

Conversation

tylersmalley
Copy link
Contributor

We provide a modal on index pattern creation when a matching pattern exists. This allows the user to either cancel the modal window or edit the existing pattern.

Previously an exception was being bubbled up when they clicked cancel.

Fixes #12818

@tylersmalley tylersmalley changed the title Prevents canceling modal from throwing error Prevents canceling index pattern modal from throwing error Aug 11, 2017
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.

Nice! I only found a couple minor problems.

Tangentially, I noticed that if you click the "Edit existing pattern" button, then there's a full refresh. I'm pretty sure this is an error, because we're still in the same app. I wonder if this is something to do with kbnUrl? I created #13489 to track this.

.catch(() => {
throw new IndexPatternAlreadyExists(this.title);
});
.catch(() => Promise.reject());
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a reason to return a Promise rejection here or on line 372? If I'm following this logic correctly, we just want to tell the call site of this function "Hey, stop what you're doing, because you can't actually create an index pattern."

In which case, the Promise rejection has nothing to do with the confirm modal, and should probably happen outside of it:

          confirmModalPromise(confirmMessage, { confirmButtonText: 'Edit existing pattern' })
            .then(() => {
              kbnUrl.change('/management/kibana/indices/{{id}}', { id: duplicate.id });
            });

          // Abort index pattern creation.
          return Promise.reject();

Copy link
Contributor

Choose a reason for hiding this comment

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

Unfortunately (and ironically?) the decision to use Promise rejections as the early exit mechanism means that we're once again dealing with error states. This rejection still causes an error state to be triggered, except the error itself is null, resulting in a TypeError in create_index_pattern.js:

image

The least invasive solution is to probably change that file on line 227, to check for the presence of an error before doing anything with it:

      if (err) {
        notify.fatal(err);
      }

@tylersmalley
Copy link
Contributor Author

tylersmalley commented Aug 14, 2017

Thanks @cjcenizal, mind taking another look? A couple things:

  • I changed kbnUrl.change to kbnUrl.redirect and it no longer refreshes. Not sure if that is the correct route, but it accomplishes the desired behavior.
  • Instead of handling the cancellation as a promise, I am returning a boolean to indicate the presence of a duplicate.

@tylersmalley
Copy link
Contributor Author

Most recent change should fix #13489

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.

Awesome!! This UX is so much better now.

This code LGTM but I have one suggestion that you might find worth implementing. Returning true twice in the promise handlers looks like a mistake, though it isn't.

Because the rejection/acceptance of this promise has no effect on the return value, perhaps it would be clearest to just move the return value out of it?

confirmModalPromise(confirmMessage, { confirmButtonText: 'Edit existing pattern' })
  .then(() => {
    kbnUrl.redirect('/management/kibana/indices/{{id}}', { id: duplicate.id });
  });

return true;

Or if you still want to respect the asynchronous nature of the modal, could we move it into a finally handler?

confirmModalPromise(confirmMessage, { confirmButtonText: 'Edit existing pattern' })
  .then(() => {
    kbnUrl.redirect('/management/kibana/indices/{{id}}', { id: duplicate.id });
  }).finally(() => {
    return true;
  });

@tylersmalley
Copy link
Contributor Author

@cjcenizal the return needs to be asynchronous, as create respects the return value to determine if it's a duplicate and exits early. If we use finally it would not resolve until after then then in create resulting in the same issue.

@tylersmalley tylersmalley merged commit 071e983 into elastic:master Aug 15, 2017
tylersmalley added a commit that referenced this pull request Aug 15, 2017
* Prevents canceling modal from throwing error

Fixes #12818

Signed-off-by: Tyler Smalley <[email protected]>

* Prevents refresh and removes returned promise

Signed-off-by: Tyler Smalley <[email protected]>
tylersmalley added a commit that referenced this pull request Aug 15, 2017
* Prevents canceling modal from throwing error

Fixes #12818

Signed-off-by: Tyler Smalley <[email protected]>

* Prevents refresh and removes returned promise

Signed-off-by: Tyler Smalley <[email protected]>
tylersmalley added a commit that referenced this pull request Aug 15, 2017
* Prevents canceling modal from throwing error

Fixes #12818

Signed-off-by: Tyler Smalley <[email protected]>

* Prevents refresh and removes returned promise

Signed-off-by: Tyler Smalley <[email protected]>
@tylersmalley
Copy link
Contributor Author

6.x/6.1: ff40688
6.0: f08a511
5.6: 47c3854

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.

3 participants