-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
using ui-select for field selection in visualize (#10998)
* using ui-select for field selection in visualize * adding a limit and infinite scroll * fixing based on CJ's comments * Add sort prefix first utility * Add sortPrefixFirst tests * updating uiSelect to use the new filter * rebasing on master * adding uiSelect to top hits sort-on input * fixing tests
- Loading branch information
Showing
9 changed files
with
168 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { uiModules } from 'ui/modules'; | ||
const module = uiModules.get('kibana'); | ||
|
||
module.directive('kbnScrollBottom', function () { | ||
return { | ||
restrict: 'A', | ||
link: function ($scope, $element, attr) { | ||
let checkTimer; | ||
|
||
function onScroll() { | ||
const position = $element.scrollTop() + $element.outerHeight(); | ||
const height = $element[0].scrollHeight; | ||
const remaining = height - position; | ||
const margin = 50; | ||
|
||
if (!height || !position) return; | ||
if (remaining <= margin) { | ||
$scope.$eval(attr.kbnScrollBottom); | ||
} | ||
} | ||
|
||
function scheduleCheck() { | ||
if (checkTimer) return; | ||
checkTimer = setTimeout(function () { | ||
checkTimer = null; | ||
onScroll(); | ||
}, 50); | ||
} | ||
|
||
$element.on('scroll', scheduleCheck); | ||
$scope.$on('$destroy', function () { | ||
clearTimeout(checkTimer); | ||
$element.off('scroll', scheduleCheck); | ||
}); | ||
scheduleCheck(); | ||
} | ||
}; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { uiModules } from 'ui/modules'; | ||
import { sortPrefixFirst } from '../utils/sort_prefix_first'; | ||
|
||
uiModules | ||
.get('kibana') | ||
.filter('sortPrefixFirst', function () { | ||
return sortPrefixFirst; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import expect from 'expect.js'; | ||
import { sortPrefixFirst } from '../sort_prefix_first'; | ||
|
||
describe('sortPrefixFirst', function () { | ||
it('should return the original unmodified array if no prefix is provided', function () { | ||
const array = ['foo', 'bar', 'baz']; | ||
const result = sortPrefixFirst(array); | ||
expect(result).to.be(array); | ||
expect(result).to.eql(['foo', 'bar', 'baz']); | ||
}); | ||
|
||
it('should sort items that match the prefix first without modifying the original array', function () { | ||
const array = ['foo', 'bar', 'baz']; | ||
const result = sortPrefixFirst(array, 'b'); | ||
expect(result).to.not.be(array); | ||
expect(result).to.eql(['bar', 'baz', 'foo']); | ||
expect(array).to.eql(['foo', 'bar', 'baz']); | ||
}); | ||
|
||
it('should not modify the order of the array other than matching prefix without modifying the original array', function () { | ||
const array = ['foo', 'bar', 'baz', 'qux', 'quux']; | ||
const result = sortPrefixFirst(array, 'b'); | ||
expect(result).to.not.be(array); | ||
expect(result).to.eql(['bar', 'baz', 'foo', 'qux', 'quux']); | ||
expect(array).to.eql(['foo', 'bar', 'baz', 'qux', 'quux']); | ||
}); | ||
|
||
it('should sort objects by property if provided', function () { | ||
const array = [{ name: 'foo' }, { name: 'bar' }, { name: 'baz' }, { name: 'qux' }, { name: 'quux' }]; | ||
const result = sortPrefixFirst(array, 'b', 'name'); | ||
expect(result).to.not.be(array); | ||
expect(result).to.eql([{ name: 'bar' }, { name: 'baz' }, { name: 'foo' }, { name: 'qux' }, { name: 'quux' }]); | ||
expect(array).to.eql([{ name: 'foo' }, { name: 'bar' }, { name: 'baz' }, { name: 'qux' }, { name: 'quux' }]); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
export function sortPrefixFirst(array, prefix, property) { | ||
if (!prefix) return array; | ||
return [...array].sort(sortPrefixFirstComparator); | ||
|
||
function sortPrefixFirstComparator(a, b) { | ||
const aValue = property ? a[property] : a; | ||
const bValue = property ? b[property] : b; | ||
|
||
const bothStartWith = aValue.startsWith(prefix) && bValue.startsWith(prefix); | ||
const neitherStartWith = !aValue.startsWith(prefix) && !bValue.startsWith(prefix); | ||
|
||
if (bothStartWith || neitherStartWith) return 0; | ||
if (aValue.startsWith(prefix)) return -1; | ||
else return 1; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters