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

[Management] Address UI searching bug with index pattern creation #14646

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { uiModules } from 'ui/modules';

const module = uiModules.get('apps/management');

/**
* This directive automatically appends a wildcard to the input field
* after the user starts typing. It lets the user delete the wildcard
* if necessary. If the value of the input field is set back to an empty
* string, the wildcard is immediately re-appended after the user starts
* typing. This is intended to be a UX improvement for the index pattern
* creation page. See https://github.com/elastic/kibana/pull/13454
*/
module.directive('appendWildcard', function () {
return {
require: 'ngModel',
link: function ($scope, $elem, $attrs, $ctrl) {
$elem.on('keydown', (e) => {
// https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/keyCode
// is not recommended so we need to rely on `key` but browser support
// is still spotty (https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key)
// so just bail if it's not supported
if (!e.key) {
return;
}

if (!/[a-z0-9]/i.test(e.key)) {
return;
}

// If the user is holding down ctrl/cmd, they are performing some shortcut
// and do not interpret literally
if (e.metaKey) {
return;
}

let indexPatternName = $elem.val() + e.key;
if (indexPatternName.length === 1 && indexPatternName !== '*') {
indexPatternName += '*';
e.preventDefault();
$elem.val(indexPatternName);
$elem[0].setSelectionRange(1, 1);
}

$ctrl.$setViewValue(indexPatternName);
});
}
};
});
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ <h2 class="kuiPanelHeader__title">
placeholder="index-name-*"
validate-index-pattern
validate-index-pattern-allow-wildcard
append-wildcard
name="name"
required
type="text"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { uiModules } from 'ui/modules';
import './step_index_pattern.less';
import template from './step_index_pattern.html';
import './append_wildcard';

const module = uiModules.get('apps/management');

Expand All @@ -23,24 +24,10 @@ module.directive('stepIndexPattern', function () {
matchingIndices: '=',
goToNextStep: '&',
},
link: function (scope, element) {
scope.stepIndexPattern.appendedWildcard = false;

link: function (scope) {
scope.$watch('stepIndexPattern.allIndices', scope.stepIndexPattern.updateList);
scope.$watch('stepIndexPattern.matchingIndices', scope.stepIndexPattern.updateList);
scope.$watch('stepIndexPattern.indexPatternName', () => {
if (scope.stepIndexPattern.indexPatternName && scope.stepIndexPattern.indexPatternName.length === 1) {
if (scope.stepIndexPattern.indexPatternName === '*') {
if (scope.stepIndexPattern.appendedWildcard) {
scope.stepIndexPattern.indexPatternName = '';
scope.stepIndexPattern.appendedWildcard = false;
}
} else {
scope.stepIndexPattern.indexPatternName += '*';
scope.stepIndexPattern.appendedWildcard = true;
setTimeout(() => element.find('#indexPatternNameField')[0].setSelectionRange(1, 1));
}
}
// Only send the request if there's valid input.
if (scope.stepIndexPattern.indexPatternNameForm && scope.stepIndexPattern.indexPatternNameForm.$valid) {
scope.stepIndexPattern.fetchMatchingIndices();
Expand Down