-
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
[Management] Address UI searching bug with index pattern creation #14646
[Management] Address UI searching bug with index pattern creation #14646
Conversation
} | ||
} | ||
|
||
$elem.on('keydown', (e) => { |
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.
Maybe a little concerned that this will not always work as intended (all work completing before watcher has a chance to fire). Maybe that is unfounded though.
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.
It's a good point and something I just assumed. I figured that the digest cycle doesn't kickoff until all interactions are "done", and I assumed that any listeners directly listening to UI interacts will be handled prior to anything angular does, but I could be mistaken there
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.
Methods run to completion in JS, so this should be good, just being paranoid.
event.preventDefault(); | ||
$elem.val(val); | ||
if (moveSelectionRange) { | ||
$elem[0].setSelectionRange(1, 1); |
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.
I had to think for a minute to grok why this line is doing what it does. Maybe parameter could be named better to make that clear.
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.
On it!
LGTM |
} | ||
|
||
$elem.on('keydown', (e) => { | ||
const charStr = String.fromCharCode(e.keyCode); |
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.
MDN warns against using KeyboardEvent.keyCode and recommends using KeyboardEvent.key. However, Chrome 51 was the first to introduce KeyboardEvent.key
, so it'd be nice if this "gracefully degrades" in unsupported versions, perhaps by simply not intelligently adding the *
.
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.
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 call! Addressing the first one fixes the second one
|
||
if (indexPatternName && indexPatternName.length === 1) { | ||
if (indexPatternName === '*') { | ||
if ($scope.appendedWildcard) { |
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.
This causes an interesting behavior, when the page first loads you're allowed to put *
as the index-pattern, but if I create an index pattern where we append the *
and $scope.appendedWildcard === true
, if I try to type *
again, it won't do anything, but if I press it again, it'll let me. This appears to be behavior that was carried over from the previous code, so if you'd prefer to create a separate PR/Issue to address this, I won't let it hold up my approval.
@kobelb Thanks for the great thoughts! I fixed a couple things and refactored some of the code to hopefully avoid some of the confusion/issues. Lemme know |
return; | ||
} | ||
|
||
// If the user is holdinng down ctrl/cmd, they are performing some shortcut |
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.
Bah, typo in the comment
|
||
let indexPatternName = $elem.val() + e.key; | ||
if (indexPatternName && indexPatternName.length === 1) { | ||
if (indexPatternName !== '*') { |
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.
This can be combined in the above if
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.
LGTM
281d3ab
to
f84e4be
Compare
…astic#14646) * Move this logic to a separate directive. Also fix a couple bugs with it around how it interacts with angular. * Updated variable name * Handle some edge cases and simplify code * Fixing typo and further simplyfing code
Backport 6.x: 076cea1 |
Overview
On the index pattern creation wizard, if the user types in a character into the input field, we have code that will automatically append a
*
character to the end of what they typed and then move the cursor back to right after the typed letter. This experience came from discussions on the original PR.Unfortunately, there is a bug with how we're transferring state between the angular directives where we weren't properly updating the state before the parent directive accessed it, leading to an initial query against the typed character, instead of the typed character plus the
*
.For super users, this isn't a big deal because they aren't any security gates against searching for indices, but it becomes a problem for restricted users who aren't able to query for certain indices.
Take this sample of queries for a restricted user who can only access the logstash index:
The UI bug caused a search for just
l
instead ofl*
which resulted in 403 errors in the browser.This PR addresses that and separates out the code into a separate directive. It also functions off
keydown
instead of an angular watch due to issues mutating that value post watch firing.It's very possible this is a hacky and there is a better way, so please let me know!
TODO