forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "Fix invisible filters caused by missing index pattern (elasti…
- Loading branch information
1 parent
b25acc0
commit 9c89215
Showing
7 changed files
with
117 additions
and
88 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import expect from 'expect.js'; | ||
import ngMock from 'ng_mock'; | ||
import { FilterBarLibMapScriptProvider } from 'ui/filter_bar/lib/map_script'; | ||
|
||
describe('Filter Bar Directive', function () { | ||
describe('mapScript()', function () { | ||
let mapScript; | ||
let $rootScope; | ||
|
||
beforeEach(ngMock.module( | ||
'kibana', | ||
'kibana/courier', | ||
function ($provide) { | ||
$provide.service('courier', require('fixtures/mock_courier')); | ||
} | ||
)); | ||
|
||
beforeEach(ngMock.inject(function (Private, _$rootScope_) { | ||
$rootScope = _$rootScope_; | ||
mapScript = Private(FilterBarLibMapScriptProvider); | ||
})); | ||
|
||
it('should return the key and value for matching filters', function (done) { | ||
const filter = { | ||
meta: { index: 'logstash-*', field: 'script number' }, | ||
script: { script: { inline: 'doc["script number"].value * 5', params: { value: 35 } } } | ||
}; | ||
mapScript(filter).then(function (result) { | ||
expect(result).to.have.property('key', 'script number'); | ||
expect(result).to.have.property('value', '35'); | ||
done(); | ||
}); | ||
$rootScope.$apply(); | ||
}); | ||
|
||
it('should return undefined for none matching', function (done) { | ||
const filter = { meta: { index: 'logstash-*' }, query: { query_string: { query: 'foo:bar' } } }; | ||
mapScript(filter).catch(function (result) { | ||
expect(result).to.be(filter); | ||
done(); | ||
}); | ||
$rootScope.$apply(); | ||
}); | ||
|
||
it('should return a value for a range/histogram filter from a scripted field', (done) => { | ||
const filter = { | ||
meta: { | ||
index: 'logstash-*', | ||
formattedValue: '1,000.00 to 2,000.00', | ||
field: 'script number' | ||
}, | ||
script: { | ||
script: { | ||
params: { | ||
gte: 1000, | ||
lt: 2000, | ||
value: '>=1,000.00 <2,000.00' | ||
} | ||
} | ||
} | ||
}; | ||
mapScript(filter).then((result) => { | ||
expect(result).to.have.property('value', filter.meta.formattedValue); | ||
done(); | ||
}); | ||
$rootScope.$apply(); | ||
}); | ||
}); | ||
}); |
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
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,24 @@ | ||
export function FilterBarLibMapScriptProvider(Promise, courier) { | ||
return function (filter) { | ||
if (filter.script) { | ||
return courier | ||
.indexPatterns | ||
.get(filter.meta.index).then(function (indexPattern) { | ||
const type = 'scripted'; | ||
const key = filter.meta.field; | ||
const field = indexPattern.fields.byName[key]; | ||
|
||
let value; | ||
if (filter.meta.formattedValue) { | ||
value = filter.meta.formattedValue; | ||
} else { | ||
value = filter.script.script.params.value; | ||
value = field.format.convert(value); | ||
} | ||
|
||
return { type, key, value }; | ||
}); | ||
} | ||
return Promise.reject(filter); | ||
}; | ||
} |