mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 09:19:04 -04:00
[indexedArray] fix an inflector bug with four-letter keys
This commit is contained in:
parent
d6f50443df
commit
704e99d53a
6 changed files with 40 additions and 10 deletions
|
@ -7,7 +7,7 @@
|
|||
<div class="fill visualize-spy-nav">
|
||||
<a
|
||||
class="btn btn-default"
|
||||
ng-repeat="mode in modes.inOrderOrder"
|
||||
ng-repeat="mode in modes.inOrder"
|
||||
ng-class="{ active: spyMode.name === mode.name }"
|
||||
ng-click="setSpyMode(mode)">
|
||||
{{mode.display}}
|
||||
|
|
|
@ -9,7 +9,7 @@ define(function (require) {
|
|||
require('components/visualize/spy/_req_resp_stats');
|
||||
|
||||
var modes = Private(require('registry/spy_modes'));
|
||||
var defaultMode = modes.inOrderOrder[0];
|
||||
var defaultMode = modes.inOrder[0];
|
||||
|
||||
return {
|
||||
restrict: 'E',
|
||||
|
|
|
@ -48,7 +48,7 @@
|
|||
<!-- Full navbar -->
|
||||
<div collapse="!showCollapsed" class="navbar-collapse" id="kibana-primary-navbar">
|
||||
<ul class="nav navbar-nav">
|
||||
<li ng-repeat="app in apps.inOrderOrder" ng-class="{active: activeApp == app.id}">
|
||||
<li ng-repeat="app in apps.inOrder" ng-class="{active: activeApp == app.id}">
|
||||
<a ng-href="#{{app.lastPath}}" bo-text="app.name"></a>
|
||||
</li>
|
||||
</ul>
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
define(function (require) {
|
||||
return require('registry/_registry')('visTypes');
|
||||
return require('registry/_registry')('visTypes', {
|
||||
index: ['name'],
|
||||
order: ['name']
|
||||
});
|
||||
});
|
|
@ -4,8 +4,18 @@ define(function (require) {
|
|||
return str.charAt(0).toUpperCase() + (total ? str.substr(1).toLowerCase() : str.substr(1));
|
||||
}
|
||||
|
||||
function inflector(prefix, postfix) {
|
||||
function startsWith(str, test) {
|
||||
return str.substr(0, test.length).toLowerCase() === test.toLowerCase();
|
||||
}
|
||||
|
||||
function endsWith(str, test) {
|
||||
var tooShort = str.length < test.length;
|
||||
if (tooShort) return;
|
||||
|
||||
return str.substr(str.length - test.length).toLowerCase() === test.toLowerCase();
|
||||
}
|
||||
|
||||
function inflector(prefix, postfix) {
|
||||
return function inflect(key) {
|
||||
var inflected;
|
||||
|
||||
|
@ -17,14 +27,14 @@ define(function (require) {
|
|||
})
|
||||
.join('');
|
||||
} else {
|
||||
inflected = key.toLowerCase();
|
||||
inflected = key;
|
||||
}
|
||||
|
||||
if (prefix && key.indexOf(prefix) !== 0) {
|
||||
if (prefix && !startsWith(key, prefix)) {
|
||||
inflected = prefix + upFirst(inflected);
|
||||
}
|
||||
|
||||
if (postfix && key.lastIndexOf(postfix) !== key.length - postfix.length) {
|
||||
if (postfix && !endsWith(key, postfix)) {
|
||||
inflected = inflected + postfix;
|
||||
}
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@ define(function (require) {
|
|||
|
||||
expect(inflect('Family')).to.be('myFamily');
|
||||
expect(inflect('family')).to.be('myFamily');
|
||||
expect(inflect('fAmIlY')).to.be('myFamily');
|
||||
expect(inflect('fAmIlY')).to.be('myFAmIlY');
|
||||
});
|
||||
|
||||
it('adds both a prefix and suffix', function () {
|
||||
|
@ -22,7 +22,24 @@ define(function (require) {
|
|||
|
||||
expect(inflect('box')).to.be('fooBoxBar');
|
||||
expect(inflect('box.car.MAX')).to.be('fooBoxCarMaxBar');
|
||||
expect(inflect('BaZzY')).to.be('fooBazzyBar');
|
||||
expect(inflect('BaZzY')).to.be('fooBaZzYBar');
|
||||
});
|
||||
|
||||
it('ignores prefix if it is already at the end of the inflected string', function () {
|
||||
var inflect = inflector('foo', 'Bar');
|
||||
expect(inflect('fooBox')).to.be('fooBoxBar');
|
||||
expect(inflect('FooBox')).to.be('FooBoxBar');
|
||||
});
|
||||
|
||||
it('ignores postfix if it is already at the end of the inflected string', function () {
|
||||
var inflect = inflector('foo', 'Bar');
|
||||
expect(inflect('bar')).to.be('fooBar');
|
||||
expect(inflect('showBoxBar')).to.be('fooShowBoxBar');
|
||||
});
|
||||
|
||||
it('works with "name"', function () {
|
||||
var inflect = inflector('in', 'Order');
|
||||
expect(inflect('name')).to.be('inNameOrder');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue