-
Notifications
You must be signed in to change notification settings - Fork 8.5k
Move filter bar into data plugin #35460
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
Changes from all commits
e9212d7
dd1f3d9
4998bd9
23d99f1
942d083
227dec9
c19644c
9215077
b233d38
edc0d7d
8ec5f6a
8b6db9d
6336612
92d758e
788c4a5
580e927
a4c7519
e8eb8a9
57ae861
1a97718
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,18 +17,33 @@ | |
| * under the License. | ||
| */ | ||
|
|
||
| import _ from 'lodash'; | ||
| import { FilterBarLibMapAndFlattenFiltersProvider } from './map_and_flatten_filters'; | ||
| import { ApplyFiltersPopover } from './apply_filters_popover'; | ||
|
|
||
| export function FilterBarLibMapFlattenAndWrapFiltersProvider(Private) { | ||
| const mapAndFlattenFilters = Private(FilterBarLibMapAndFlattenFiltersProvider); | ||
| return function (filters) { | ||
| return mapAndFlattenFilters(filters).then(function (filters) { | ||
| return _.map(filters, function (filter) { | ||
| filter.meta = filter.meta || {}; | ||
| filter.meta.apply = true; | ||
| return filter; | ||
| }); | ||
| }); | ||
| }; | ||
| // @ts-ignore | ||
| import { setupDirective } from './directive'; | ||
|
|
||
| /** | ||
| * Search Bar Service | ||
| * | ||
| * @internal | ||
| */ | ||
| export class ApplyFiltersService { | ||
| private setupDirectives: any; | ||
| public setup() { | ||
| this.setupDirectives = _.once(setupDirective); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. looks like lodash isn't imported in this file... should probably also prefer |
||
| return { | ||
| ApplyFiltersPopover, | ||
| }; | ||
| } | ||
|
|
||
| public stop() { | ||
| // nothing to do here yet | ||
| } | ||
|
|
||
| public loadLegacyDirectives() { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the new platform, any items that are part of a plugin's public contract should be returned by that plugin's In this case, that would mean making public setup() {
return {
ApplyFiltersPopover,
loadLegacyDirectives: once(setupDirective),
};
}This also ensures that |
||
| this.setupDirectives(); | ||
| } | ||
| } | ||
|
|
||
| /** @public */ | ||
| export type ApplyFiltersSetup = ReturnType<ApplyFiltersService['setup']>; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| /* | ||
| * Licensed to Elasticsearch B.V. under one or more contributor | ||
| * license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright | ||
| * ownership. Elasticsearch B.V. licenses this file to you under | ||
| * the Apache License, Version 2.0 (the "License"); you may | ||
| * not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| import 'ngreact'; | ||
| import { uiModules } from 'ui/modules'; | ||
| import template from './directive.html'; | ||
| import { ApplyFiltersPopover } from './apply_filters_popover'; | ||
| import { mapAndFlattenFilters } from 'ui/filter_manager/lib/map_and_flatten_filters'; | ||
| import { wrapInI18nContext } from 'ui/i18n'; | ||
|
|
||
| const app = uiModules.get('app/data', ['react']); | ||
|
|
||
| export function setupDirective() { | ||
| app.directive('applyFiltersPopoverComponent', (reactDirective) => { | ||
| return reactDirective(wrapInI18nContext(ApplyFiltersPopover)); | ||
| }); | ||
|
|
||
| app.directive('applyFiltersPopover', (indexPatterns) => { | ||
| return { | ||
| template, | ||
| restrict: 'E', | ||
| scope: { | ||
| filters: '=', | ||
| onCancel: '=', | ||
| onSubmit: '=', | ||
| }, | ||
| link: function ($scope) { | ||
| $scope.state = {}; | ||
|
|
||
| // Each time the new filters change we want to rebuild (not just re-render) the "apply filters" | ||
| // popover, because it has to reset its state whenever the new filters change. Setting a `key` | ||
| // property on the component accomplishes this due to how React handles the `key` property. | ||
| $scope.$watch('filters', filters => { | ||
| Promise.resolve(mapAndFlattenFilters(indexPatterns, filters).then(mappedFilters => { | ||
| $scope.state = { | ||
| filters: mappedFilters, | ||
| key: Date.now(), | ||
| }; | ||
| })); | ||
| }); | ||
| } | ||
| }; | ||
| }); | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -17,24 +17,34 @@ | |||||
| * under the License. | ||||||
| */ | ||||||
|
|
||||||
| export function FilterBarLibGenerateMappingChainProvider(Promise) { | ||||||
| import { FilterBar } from './filter_bar'; | ||||||
|
|
||||||
| const noop = function () { | ||||||
| return Promise.reject(new Error('No mappings have been found for filter.')); | ||||||
| }; | ||||||
| // @ts-ignore | ||||||
| import { setupDirective } from './directive'; | ||||||
|
|
||||||
| return function (fn) { | ||||||
| return function (next) { | ||||||
| next = next || noop; | ||||||
| return function (filter) { | ||||||
| return fn(filter).catch(function (result) { | ||||||
| if (result === filter) { | ||||||
| return next(filter); | ||||||
| } | ||||||
| return Promise.reject(result); | ||||||
| }); | ||||||
| }; | ||||||
| /** | ||||||
| * Search Bar Service | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
(if this needs to be it's own service) |
||||||
| * | ||||||
| * @internal | ||||||
| */ | ||||||
| export class FilterBarService { | ||||||
| private setupDirectives: any; | ||||||
|
|
||||||
| public setup() { | ||||||
| this.setupDirectives = _.once(setupDirective); | ||||||
| return { | ||||||
| FilterBar, | ||||||
| }; | ||||||
| }; | ||||||
| } | ||||||
|
|
||||||
| public stop() { | ||||||
| // nothing to do here yet | ||||||
| } | ||||||
|
|
||||||
| public loadLegacyDirectives() { | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same note here on the convention of returning the public contract from the |
||||||
| this.setupDirectives(); | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| /** @public */ | ||||||
| export type FilterBarSetup = ReturnType<FilterBarService['setup']>; | ||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| @import 'src/legacy/ui/public/styles/styling_constants'; | ||
|
|
||
| @import './filter_bar/index'; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,22 +18,38 @@ | |
| */ | ||
|
|
||
| import { IndexPatternsService } from './index_patterns'; | ||
| import { ApplyFiltersService } from './apply_filters'; | ||
| import { FilterBarService } from './filter_bar'; | ||
|
|
||
| class DataService { | ||
| private readonly indexPatterns: IndexPatternsService; | ||
| private readonly applyFilters: ApplyFiltersService; | ||
| private readonly filterBar: FilterBarService; | ||
|
|
||
| constructor() { | ||
| this.indexPatterns = new IndexPatternsService(); | ||
| this.applyFilters = new ApplyFiltersService(); | ||
| this.filterBar = new FilterBarService(); | ||
| } | ||
|
|
||
| public setup() { | ||
| return { | ||
| indexPatterns: this.indexPatterns.setup(), | ||
| filter: { | ||
| loadLegacyDirectives: () => { | ||
| this.applyFilters.loadLegacyDirectives(); | ||
| this.filterBar.loadLegacyDirectives(); | ||
| }, | ||
| ...this.applyFilters.setup(), | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it necessary for apply filters to be its own service? It doesn't feel like it has much going on to justify existing as an independent service. To me it would feel more natural to have a |
||
| ...this.filterBar.setup(), | ||
| }, | ||
| }; | ||
| } | ||
|
|
||
| public stop() { | ||
| this.indexPatterns.stop(); | ||
| this.applyFilters.stop(); | ||
| this.filterBar.stop(); | ||
| } | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(if this really needs to be a separate service -- see my other note on that)