Skip to content
Closed
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
4 changes: 2 additions & 2 deletions src/fixtures/mock_index_patterns.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
import sinon from 'sinon';
import FixturesStubbedLogstashIndexPatternProvider from 'fixtures/stubbed_logstash_index_pattern';

export default function (Private, Promise) {
export default function (Private) {
const indexPatterns = Private(FixturesStubbedLogstashIndexPatternProvider);
const getIndexPatternStub = sinon.stub()
.returns(Promise.resolve(indexPatterns));
.resolves(indexPatterns);

return {
get: getIndexPatternStub,
Expand Down
4 changes: 4 additions & 0 deletions src/legacy/core_plugins/data/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ export default function DataPlugin(kibana: any) {
}).default();
},
init: (server: Legacy.Server) => ({}),
uiExports: {
injectDefaultVars: () => ({}),
styleSheetPaths: resolve(__dirname, 'public/index.scss'),
},
};

return new kibana.Plugin(config);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* Search Bar Service
* Apply Filters Service

(if this really needs to be a separate service -- see my other note on that)

*
* @internal
*/
export class ApplyFiltersService {
private setupDirectives: any;
public setup() {
this.setupDirectives = _.once(setupDirective);
Copy link
Member

Choose a reason for hiding this comment

The 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 import { once } from 'lodash'; instead of _

return {
ApplyFiltersPopover,
};
}

public stop() {
// nothing to do here yet
}

public loadLegacyDirectives() {
Copy link
Member

Choose a reason for hiding this comment

The 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 setup method. I propose we follow the same convention in our services for consistency.

In this case, that would mean making loadLegacyDirectives private, and returning it from the public setup method. Or even better, just add it to the setup method directly:

public setup() {
  return {
    ApplyFiltersPopover,
    loadLegacyDirectives: once(setupDirective),
  };
}

This also ensures that ReturnType<ApplyFiltersService['setup']> captures the entire contract of this service

this.setupDirectives();
}
}

/** @public */
export type ApplyFiltersSetup = ReturnType<ApplyFiltersService['setup']>;
60 changes: 60 additions & 0 deletions src/legacy/core_plugins/data/public/apply_filters/directive.js
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
Expand Up @@ -17,6 +17,4 @@
* under the License.
*/

import './directive';

export { FilterBar } from './filter_bar';
export { ApplyFiltersService } from './apply_filter_service';
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@

import 'ngreact';
import { wrapInI18nContext } from 'ui/i18n';
import { uiModules } from '../modules';
import { uiModules } from 'ui/modules';
import { FilterBar } from './filter_bar';

const app = uiModules.get('app/kibana', ['react']);
const app = uiModules.get('app/data', ['react']);

app.directive('filterBar', reactDirective => {
return reactDirective(wrapInI18nContext(FilterBar));
});
export function setupDirective() {
app.directive('filterBar', reactDirective => {
return reactDirective(wrapInI18nContext(FilterBar));
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* Search Bar Service
* Filter Bar Service

(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() {
Copy link
Member

Choose a reason for hiding this comment

The 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 setup method

this.setupDirectives();
}
}

/** @public */
export type FilterBarSetup = ReturnType<FilterBarService['setup']>;
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { EuiBadge } from '@elastic/eui';
import { Filter, isFilterPinned } from '@kbn/es-query';
import { i18n } from '@kbn/i18n';
import React, { SFC } from 'react';
import { existsOperator, isOneOfOperator } from 'ui/filter_bar/filter_editor/lib/filter_operators';
import { existsOperator, isOneOfOperator } from '../filter_editor/lib/filter_operators';

interface Props {
filter: Filter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,4 @@
* under the License.
*/

import './directive';

export { ApplyFiltersPopover } from './apply_filters_popover';
export { FilterBarService } from './filter_bar_service';
3 changes: 3 additions & 0 deletions src/legacy/core_plugins/data/public/index.scss
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';
16 changes: 16 additions & 0 deletions src/legacy/core_plugins/data/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Copy link
Member

Choose a reason for hiding this comment

The 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 filter service that includes both filter bar and apply filters... along with any other filter-related utilities we may add in the future.

...this.filterBar.setup(),
},
};
}

public stop() {
this.indexPatterns.stop();
this.applyFilters.stop();
this.filterBar.stop();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ import setupRouteWithDefaultPattern from 'ui/index_patterns/route_setup/load_def
import { getFromSavedObject, isFilterable } from 'ui/index_patterns/static_utils';

// IndexPattern, StaticIndexPattern, StaticIndexPatternField, Field
import * as types from 'ui/index_patterns/index.d.ts';
// import * as types from 'ui/index_patterns/index.d.ts';

/**
* Index Patterns Service
Expand Down Expand Up @@ -91,9 +91,6 @@ export class IndexPatternsService {
mockFields,
mockIndexPattern,
},
types: {
...types,
},
ui: {
IndexPatternSelect,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { AggConfigs } from 'ui/vis/agg_configs';
// need to get rid of angular from these
import { IndexPatternsProvider } from 'ui/index_patterns';
import { SearchSourceProvider } from 'ui/courier/search_source';
import { FilterBarQueryFilterProvider } from 'ui/filter_bar/query_filter';
import { FilterBarQueryFilterProvider } from 'ui/filter_manager/query_filter';

import chrome from 'ui/chrome';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { VisRequestHandlersRegistryProvider as RequestHandlersProvider } from 'u
import { VisResponseHandlersRegistryProvider as ResponseHandlerProvider } from 'ui/registry/vis_response_handlers';
import { VisTypesRegistryProvider } from 'ui/registry/vis_types';
import { IndexPatternsProvider } from 'ui/index_patterns';
import { FilterBarQueryFilterProvider } from 'ui/filter_bar/query_filter';
import { FilterBarQueryFilterProvider } from 'ui/filter_manager/query_filter';
import { PersistedState } from 'ui/persisted_state';

function getHandler(from, type) {
Expand Down
4 changes: 3 additions & 1 deletion src/legacy/core_plugins/kibana/public/context/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import _ from 'lodash';
import { callAfterBindingsWorkaround } from 'ui/compat';
import { uiModules } from 'ui/modules';
import contextAppTemplate from './app.html';
import 'ui/filter_bar';
import './components/loading_button';
import './components/size_picker/size_picker';
import { getFirstSortableField } from './api/utils/sorting';
Expand All @@ -39,6 +38,9 @@ import {
} from './query';
import { timefilter } from 'ui/timefilter';

import data from 'plugins/data';
data.filter.loadLegacyDirectives();

const module = uiModules.get('apps/context', [
'elasticsearch',
'kibana',
Expand Down
2 changes: 1 addition & 1 deletion src/legacy/core_plugins/kibana/public/context/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import _ from 'lodash';

import { FilterBarQueryFilterProvider } from 'ui/filter_bar/query_filter';
import { FilterBarQueryFilterProvider } from 'ui/filter_manager/query_filter';
import 'ui/listen';
import uiRoutes from 'ui/routes';
import { i18n } from '@kbn/i18n';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import _ from 'lodash';

import { FilterBarQueryFilterProvider } from 'ui/filter_bar/query_filter';
import { FilterBarQueryFilterProvider } from 'ui/filter_manager/query_filter';
import { FilterManagerProvider } from 'ui/filter_manager';
import {
MAX_CONTEXT_SIZE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,17 @@ import { toastNotifications } from 'ui/notify';

import 'ui/listen';
import 'ui/search_bar';
import 'ui/apply_filters';

import data from 'plugins/data';
data.filter.loadLegacyDirectives();

import { panelActionsStore } from './store/panel_actions_store';

import { getDashboardTitle } from './dashboard_strings';
import { DashboardViewMode } from './dashboard_view_mode';
import { TopNavIds } from './top_nav/top_nav_ids';
import { ConfirmationButtonTypes } from 'ui/modals/confirm_modal';
import { FilterBarQueryFilterProvider } from 'ui/filter_bar/query_filter';
import { FilterBarQueryFilterProvider } from 'ui/filter_manager/query_filter';
import { DocTitleProvider } from 'ui/doc_title';
import { getTopNavConfig } from './top_nav/get_top_nav_config';
import { DashboardConstants, createDashboardEditUrl } from './dashboard_constants';
Expand Down
4 changes: 3 additions & 1 deletion src/legacy/core_plugins/kibana/public/dashboard/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import './saved_dashboard/saved_dashboards';
import './dashboard_config';
import uiRoutes from 'ui/routes';
import chrome from 'ui/chrome';
import 'ui/filter_bar';
import { wrapInI18nContext } from 'ui/i18n';
import { toastNotifications } from 'ui/notify';

Expand All @@ -39,6 +38,9 @@ import { DashboardListing, EMPTY_FILTER } from './listing/dashboard_listing';
import { uiModules } from 'ui/modules';
import 'ui/capabilities/route_setup';

import data from 'plugins/data';
data.filter.loadLegacyDirectives();

const app = uiModules.get('app/dashboard', [
'ngRoute',
'react',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import { toastNotifications } from 'ui/notify';
import { VisProvider } from 'ui/vis';
import { VislibSeriesResponseHandlerProvider } from 'ui/vis/response_handlers/vislib';
import { DocTitleProvider } from 'ui/doc_title';
import { FilterBarQueryFilterProvider } from 'ui/filter_bar/query_filter';
import { FilterBarQueryFilterProvider } from 'ui/filter_manager/query_filter';
import { intervalOptions } from 'ui/agg_types/buckets/_interval_options';
import { stateMonitorFactory } from 'ui/state_management/state_monitor_factory';
import uiRoutes from 'ui/routes';
Expand Down
Loading