mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 01:13:23 -04:00
Update filterEditor directive to use default index pattern when none are provided. (#16235) (#16893)
* use default index pattern when filter-editor is not passed any index patterns * add functional test * pass indexPatterns to filterBar directive * handle check for [undefined] * use _.compact to test if index patterns are provided * simplify areIndexPatternsProvided
This commit is contained in:
parent
a1dd0704bc
commit
7eb2bfc2ba
7 changed files with 52 additions and 10 deletions
|
@ -27,7 +27,6 @@
|
|||
|
||||
<div
|
||||
class="filter-bar"
|
||||
ng-show="filters.length || showAddFilterButton()"
|
||||
>
|
||||
<filter-pill
|
||||
ng-repeat="filter in filters track by $index"
|
||||
|
@ -41,7 +40,6 @@
|
|||
|
||||
<div
|
||||
class="filter-link"
|
||||
ng-show="showAddFilterButton()"
|
||||
>
|
||||
<div class="filter-description small">
|
||||
<button
|
||||
|
|
|
@ -50,10 +50,6 @@ module.directive('filterBar', function (Private, Promise, getAppState) {
|
|||
|
||||
$scope.state = getAppState();
|
||||
|
||||
$scope.showAddFilterButton = () => {
|
||||
return _.compact($scope.indexPatterns).length > 0;
|
||||
};
|
||||
|
||||
$scope.applyFilters = function (filters) {
|
||||
addAndInvertFilters(filterAppliedAndUnwrap(filters));
|
||||
$scope.newFilters = [];
|
||||
|
|
|
@ -15,7 +15,8 @@ import {
|
|||
getOperatorFromFilter,
|
||||
getParamsFromFilter,
|
||||
isFilterValid,
|
||||
buildFilter
|
||||
buildFilter,
|
||||
areIndexPatternsProvided
|
||||
} from './lib/filter_editor_utils';
|
||||
import * as filterBuilder from '../filter_manager/lib';
|
||||
import { keyMap } from '../utils/key_map';
|
||||
|
@ -35,7 +36,13 @@ module.directive('filterEditor', function ($timeout, indexPatterns) {
|
|||
controllerAs: 'filterEditor',
|
||||
bindToController: true,
|
||||
controller: callAfterBindingsWorkaround(function ($scope, $element) {
|
||||
this.init = () => {
|
||||
this.init = async () => {
|
||||
if (!areIndexPatternsProvided(this.indexPatterns)) {
|
||||
const defaultIndexPattern = await indexPatterns.getDefault();
|
||||
if (defaultIndexPattern) {
|
||||
this.indexPatterns = [defaultIndexPattern];
|
||||
}
|
||||
}
|
||||
const { filter } = this;
|
||||
this.alias = filter.meta.alias;
|
||||
this.isEditingQueryDsl = false;
|
||||
|
|
|
@ -20,7 +20,8 @@ import {
|
|||
getFieldOptions,
|
||||
getOperatorOptions,
|
||||
isFilterValid,
|
||||
buildFilter
|
||||
buildFilter,
|
||||
areIndexPatternsProvided
|
||||
} from '../filter_editor_utils';
|
||||
|
||||
describe('FilterEditorUtils', function () {
|
||||
|
@ -339,4 +340,17 @@ describe('FilterEditorUtils', function () {
|
|||
expect(filterBuilder.buildExistsFilter.called).to.be.ok();
|
||||
});
|
||||
});
|
||||
|
||||
describe('areIndexPatternsProvided', function () {
|
||||
it('should return false when index patterns are not provided', function () {
|
||||
expect(areIndexPatternsProvided(undefined)).to.be(false);
|
||||
expect(areIndexPatternsProvided([])).to.be(false);
|
||||
expect(areIndexPatternsProvided([undefined])).to.be(false);
|
||||
});
|
||||
|
||||
it('should return true when index patterns are provided', function () {
|
||||
const indexPatternMock = {};
|
||||
expect(areIndexPatternsProvided([indexPatternMock])).to.be(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -81,3 +81,7 @@ export function buildFilter({ indexPattern, field, operator, params, filterBuild
|
|||
filter.meta.negate = operator.negate;
|
||||
return filter;
|
||||
}
|
||||
|
||||
export function areIndexPatternsProvided(indexPatterns) {
|
||||
return _.compact(indexPatterns).length !== 0;
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@ import { RegistryFieldFormatsProvider } from 'ui/registry/field_formats';
|
|||
import { uiModules } from 'ui/modules';
|
||||
const module = uiModules.get('kibana/index_patterns');
|
||||
|
||||
export function IndexPatternsProvider(Notifier, Private) {
|
||||
export function IndexPatternsProvider(Notifier, Private, config) {
|
||||
const self = this;
|
||||
|
||||
const IndexPattern = Private(IndexPatternProvider);
|
||||
|
@ -23,6 +23,15 @@ export function IndexPatternsProvider(Notifier, Private) {
|
|||
return cache || patternCache.set(id, self.make(id));
|
||||
};
|
||||
|
||||
self.getDefault = async () => {
|
||||
const defaultIndexPatternId = config.get('defaultIndex');
|
||||
if (defaultIndexPatternId) {
|
||||
return await self.get(defaultIndexPatternId);
|
||||
}
|
||||
|
||||
return null;
|
||||
};
|
||||
|
||||
self.make = function (id) {
|
||||
return (new IndexPattern(id)).init();
|
||||
};
|
||||
|
|
|
@ -9,6 +9,7 @@ import { PIE_CHART_VIS_NAME } from '../../page_objects/dashboard_page';
|
|||
export default function ({ getService, getPageObjects }) {
|
||||
const dashboardExpect = getService('dashboardExpect');
|
||||
const dashboardVisualizations = getService('dashboardVisualizations');
|
||||
const testSubjects = getService('testSubjects');
|
||||
const PageObjects = getPageObjects(['dashboard', 'header', 'visualize']);
|
||||
|
||||
describe('dashboard queries', function describeIndexTests() {
|
||||
|
@ -73,6 +74,19 @@ export default function ({ getService, getPageObjects }) {
|
|||
await dashboardExpect.pieSliceCount(0);
|
||||
});
|
||||
|
||||
describe('visualizations without SearchSource', async function () {
|
||||
before(async () => {
|
||||
await PageObjects.dashboard.gotoDashboardLandingPage();
|
||||
await PageObjects.dashboard.clickNewDashboard();
|
||||
await PageObjects.dashboard.addVisualizations(['Visualization InputControl']);
|
||||
});
|
||||
|
||||
it(`should have filter bar with 'Add a filter'`, async function () {
|
||||
const hasAddFilter = await testSubjects.exists('addFilter');
|
||||
expect(hasAddFilter).to.be(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('filters', async function () {
|
||||
before(async () => {
|
||||
await PageObjects.dashboard.gotoDashboardLandingPage();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue