-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
Prevents canceling index pattern modal from throwing error #13488
Conversation
Fixes elastic#12818 Signed-off-by: Tyler Smalley <[email protected]>
There was a problem hiding this 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()); |
There was a problem hiding this comment.
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();
There was a problem hiding this comment.
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
:
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);
}
Signed-off-by: Tyler Smalley <[email protected]>
Thanks @cjcenizal, mind taking another look? A couple things:
|
Most recent change should fix #13489 |
There was a problem hiding this 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;
});
@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 |
* 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]>
* 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]>
* 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]>
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