Skip to content

Commit

Permalink
remove dashboardContext (#23227)
Browse files Browse the repository at this point in the history
  • Loading branch information
ppisljar authored Nov 6, 2018
1 parent a4d108d commit cc46def
Show file tree
Hide file tree
Showing 12 changed files with 32 additions and 233 deletions.

This file was deleted.

60 changes: 0 additions & 60 deletions src/core_plugins/kibana/public/dashboard/dashboard_context.js

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@
*/

import { validateInterval } from '../lib/validate_interval';
import { dashboardContextProvider } from 'plugins/kibana/dashboard/dashboard_context';
import { timezoneProvider } from 'ui/vis/lib/timezone';
import { timefilter } from 'ui/timefilter';
import { BuildESQueryProvider } from 'ui/courier';

const MetricsRequestHandlerProvider = function (Private, Notifier, config, $http) {
const dashboardContext = Private(dashboardContextProvider);
const notify = new Notifier({ location: 'Metrics' });
const buildEsQuery = Private(BuildESQueryProvider);

return {
name: 'metrics',
handler: function (vis, { uiState, timeRange }) {
handler: function (vis, { uiState, timeRange, filters, query }) {
const timezone = Private(timezoneProvider)();
return new Promise((resolve) => {
const panel = vis.params;
Expand All @@ -39,7 +39,7 @@ const MetricsRequestHandlerProvider = function (Private, Notifier, config, $http
if (panel && panel.id) {
const params = {
timerange: { timezone, ...parsedTimeRange },
filters: [dashboardContext()],
filters: [buildEsQuery(vis.indexPattern, [query], filters)],
panels: [panel],
state: uiStateObj
};
Expand Down
10 changes: 5 additions & 5 deletions src/core_plugins/timelion/public/vis/timelion_request_handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,20 @@
*/

import _ from 'lodash';
import { dashboardContextProvider } from 'plugins/kibana/dashboard/dashboard_context';

import { BuildESQueryProvider } from 'ui/courier';
import { timezoneProvider } from 'ui/vis/lib/timezone';

const TimelionRequestHandlerProvider = function (Private, Notifier, $http) {
const timezone = Private(timezoneProvider)();
const dashboardContext = Private(dashboardContextProvider);
const buildEsQuery = Private(BuildESQueryProvider);

const notify = new Notifier({
location: 'Timelion'
});

return {
name: 'timelion',
handler: function (vis, { timeRange }) {
handler: function (vis, { timeRange, filters, query }) {

return new Promise((resolve, reject) => {
const expression = vis.params.expression;
Expand All @@ -41,7 +41,7 @@ const TimelionRequestHandlerProvider = function (Private, Notifier, $http) {
sheet: [expression],
extended: {
es: {
filter: dashboardContext()
filter: buildEsQuery(vis.indexPattern, [query], filters)
}
},
time: _.extend(timeRange, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function create(min, max, dashboardCtx) {
getTimeBounds: () => ({ min, max })
},
() => {},
() => _.cloneDeep(dashboardCtx),
_.cloneDeep(dashboardCtx),
() => (inst.$$$warnCount = (inst.$$$warnCount || 0) + 1)
);
return inst;
Expand Down
8 changes: 4 additions & 4 deletions src/core_plugins/vega/public/data_model/es_query_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ const TIMEFIELD = '%timefield%';
*/
export class EsQueryParser {

constructor(timeCache, searchCache, dashboardContext, onWarning) {
constructor(timeCache, searchCache, filters, onWarning) {
this._timeCache = timeCache;
this._searchCache = searchCache;
this._dashboardContext = dashboardContext;
this._filters = filters;
this._onWarning = onWarning;
}

Expand Down Expand Up @@ -134,7 +134,7 @@ export class EsQueryParser {

if (context) {
// Use dashboard context
const newQuery = this._dashboardContext();
const newQuery = _.cloneDeep(this._filters);
if (timefield) {
newQuery.bool.must.push(body.query);
}
Expand Down Expand Up @@ -174,7 +174,7 @@ export class EsQueryParser {
const item = obj[pos];
if (isQuery && (item === MUST_CLAUSE || item === MUST_NOT_CLAUSE)) {
const ctxTag = item === MUST_CLAUSE ? 'must' : 'must_not';
const ctx = this._dashboardContext();
const ctx = _.cloneDeep(this._filters);
if (ctx && ctx.bool && ctx.bool[ctxTag]) {
if (Array.isArray(ctx.bool[ctxTag])) {
// replace one value with an array of values
Expand Down
4 changes: 2 additions & 2 deletions src/core_plugins/vega/public/data_model/vega_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,15 @@ const DEFAULT_PARSER = 'elasticsearch';

export class VegaParser {

constructor(spec, searchCache, timeCache, dashboardContext, serviceSettings) {
constructor(spec, searchCache, timeCache, filters, serviceSettings) {
this.spec = spec;
this.hideWarnings = false;
this.error = undefined;
this.warnings = [];

const onWarn = this._onWarning.bind(this);
this._urlParsers = {
elasticsearch: new EsQueryParser(timeCache, searchCache, dashboardContext, onWarn),
elasticsearch: new EsQueryParser(timeCache, searchCache, filters, onWarn),
emsfile: new EmsFileParser(serviceSettings),
url: new UrlParser(onWarn),
};
Expand Down
11 changes: 6 additions & 5 deletions src/core_plugins/vega/public/vega_request_handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,25 @@
*/

import { VegaParser } from './data_model/vega_parser';
import { dashboardContextProvider } from 'plugins/kibana/dashboard/dashboard_context';
import { SearchCache } from './data_model/search_cache';
import { TimeCache } from './data_model/time_cache';
import { timefilter } from 'ui/timefilter';
import { BuildESQueryProvider } from 'ui/courier';

export function VegaRequestHandlerProvider(Private, es, serviceSettings) {

const dashboardContext = Private(dashboardContextProvider);
const buildEsQuery = Private(BuildESQueryProvider);
const searchCache = new SearchCache(es, { max: 10, maxAge: 4 * 1000 });
const timeCache = new TimeCache(timefilter, 3 * 1000);


return {

name: 'vega',

handler(vis, { timeRange }) {
handler(vis, { timeRange, filters, query }) {
timeCache.setTimeRange(timeRange);
const vp = new VegaParser(vis.params.spec, searchCache, timeCache, dashboardContext, serviceSettings);
const filtersDsl = buildEsQuery(vis.indexPattern, [query], filters);
const vp = new VegaParser(vis.params.spec, searchCache, timeCache, filtersDsl, serviceSettings);
return vp.parseAsync();
}

Expand Down
1 change: 1 addition & 0 deletions src/ui/public/courier/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export {
decorateQuery,
buildQueryFromFilters,
luceneStringToDsl,
BuildESQueryProvider
} from './search_source';

export {
Expand Down
2 changes: 1 addition & 1 deletion src/ui/public/courier/search_source/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@
export { SearchSourceProvider } from './search_source';
export { migrateFilter } from './migrate_filter';
export { decorateQuery } from './decorate_query';
export { buildQueryFromFilters, luceneStringToDsl } from './build_query';
export { buildQueryFromFilters, luceneStringToDsl, BuildESQueryProvider } from './build_query';
6 changes: 5 additions & 1 deletion src/ui/public/visualize/loader/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,12 @@ export interface TimeRange {
to: string;
}

export interface FilterMeta {
disabled: boolean;
}

export interface Filter {
meta: object;
meta: FilterMeta;
query: object;
}

Expand Down
Loading

0 comments on commit cc46def

Please sign in to comment.