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

Use config filters:pinnedByDefault for filters created with filter editor #20359

Merged
merged 1 commit into from
Jul 10, 2018
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
10 changes: 6 additions & 4 deletions src/ui/public/filter_editor/filter_editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ import {
getParamsFromFilter,
isFilterValid,
buildFilter,
areIndexPatternsProvided
areIndexPatternsProvided,
isFilterPinned
} from './lib/filter_editor_utils';
import * as filterBuilder from '../filter_manager/lib';
import { keyMap } from '../utils/key_map';
Expand All @@ -54,7 +55,9 @@ module.directive('filterEditor', function ($timeout, indexPatterns) {
},
controllerAs: 'filterEditor',
bindToController: true,
controller: callAfterBindingsWorkaround(function ($scope, $element) {
controller: callAfterBindingsWorkaround(function ($scope, $element, config) {
const pinnedByDefault = config.get('filters:pinnedByDefault');

this.init = async () => {
if (!areIndexPatternsProvided(this.indexPatterns)) {
const defaultIndexPattern = await indexPatterns.getDefault();
Expand Down Expand Up @@ -144,8 +147,7 @@ module.directive('filterEditor', function ($timeout, indexPatterns) {
}
newFilter.meta.disabled = filter.meta.disabled;
newFilter.meta.alias = alias;

const isPinned = _.get(filter, ['$state', 'store']) === 'globalState';
const isPinned = isFilterPinned(filter, pinnedByDefault);
return this.onSave({ filter, newFilter, isPinned });
};

Expand Down
23 changes: 22 additions & 1 deletion src/ui/public/filter_editor/lib/__tests__/filter_editor_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ import {
getOperatorOptions,
isFilterValid,
buildFilter,
areIndexPatternsProvided
areIndexPatternsProvided,
isFilterPinned
} from '../filter_editor_utils';

describe('FilterEditorUtils', function () {
Expand Down Expand Up @@ -372,4 +373,24 @@ describe('FilterEditorUtils', function () {
expect(areIndexPatternsProvided([indexPatternMock])).to.be(true);
});
});

describe('isFilterPinned', function () {
it('should return false when the store is appState', function () {
const filter = { $state: { store: 'appState' } };
expect(isFilterPinned(filter, false)).to.be(false);
expect(isFilterPinned(filter, true)).to.be(false);
});

it('should return true when the store is globalState', function () {
const filter = { $state: { store: 'globalState' } };
expect(isFilterPinned(filter, false)).to.be(true);
expect(isFilterPinned(filter, true)).to.be(true);
});

it('should return the default when the store does not exist', function () {
const filter = {};
expect(isFilterPinned(filter, false)).to.be(false);
expect(isFilterPinned(filter, true)).to.be(true);
});
});
});
5 changes: 5 additions & 0 deletions src/ui/public/filter_editor/lib/filter_editor_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,8 @@ export function buildFilter({ indexPattern, field, operator, params, filterBuild
export function areIndexPatternsProvided(indexPatterns) {
return _.compact(indexPatterns).length !== 0;
}

export function isFilterPinned(filter, pinnedByDefault) {
if (!filter.hasOwnProperty('$state')) return pinnedByDefault;
return filter.$state.store === 'globalState';
}