mirror of
https://github.com/valitydev/wazuh-kibana-app.git
synced 2024-11-06 18:05:20 +00:00
Updating filters at the same time that other visulizations do
This commit is contained in:
parent
6ceaf803c5
commit
ac2781c7c7
@ -39,6 +39,12 @@ import {
|
||||
import { isTermSizeZeroError } from 'ui/elasticsearch_errors';
|
||||
// @ts-ignore
|
||||
import { toastNotifications } from 'ui/notify';
|
||||
// @ts-ignore
|
||||
import { timezoneProvider } from 'ui/vis/lib/timezone';
|
||||
// @ts-ignore
|
||||
import { timefilter } from 'ui/timefilter';
|
||||
// @ts-ignore
|
||||
import { BuildESQueryProvider } from '@kbn/es-query';
|
||||
|
||||
function getHandler<T extends RequestHandler | ResponseHandler>(
|
||||
from: Array<{ name: string; handler: T }>,
|
||||
@ -62,12 +68,76 @@ export class VisualizeDataLoader {
|
||||
private previousVisState: any;
|
||||
private previousRequestHandlerResponse: any;
|
||||
|
||||
constructor(private readonly vis: Vis, Private: IPrivate) {
|
||||
constructor(private readonly vis: Vis, Private: IPrivate, $injector) {
|
||||
const { requestHandler, responseHandler } = vis.type;
|
||||
|
||||
const requestHandlers: RequestHandlerDescription[] = Private(RequestHandlersProvider);
|
||||
const responseHandlers: ResponseHandlerDescription[] = Private(ResponseHandlerProvider);
|
||||
this.requestHandler = getHandler(requestHandlers, requestHandler);
|
||||
|
||||
if (((vis || {}).type || {}).title === 'Visual Builder') {
|
||||
console.log(`Processing ${vis.title} with custom request handler`)
|
||||
const config = $injector.get('config');
|
||||
const $rootScope = $injector.get('$rootScope')
|
||||
const discoverPendingUpdates = $injector.get('discoverPendingUpdates')
|
||||
const $http = $injector.get('$http')
|
||||
const buildEsQuery = Private(BuildESQueryProvider);
|
||||
this.requestHandler = ({ uiState, timeRange, filters, query, visParams }) => {
|
||||
const timezone = Private(timezoneProvider)();
|
||||
return new Promise((resolve) => {
|
||||
const discoverList = discoverPendingUpdates.getList();
|
||||
try {
|
||||
if ((discoverList || []).length >= 2) {
|
||||
const implicitFilter = (discoverList || []).length ? discoverList[0].query : '';
|
||||
const parsedQuery = {
|
||||
language: discoverList[0].language || 'lucene',
|
||||
query: implicitFilter
|
||||
};
|
||||
const parsedFilters = discoverList[1];
|
||||
query = parsedQuery;
|
||||
filters = parsedFilters;
|
||||
}
|
||||
} catch (error) { }
|
||||
|
||||
const panel = visParams;
|
||||
const uiStateObj = {};
|
||||
const parsedTimeRange = timefilter.calculateBounds(timeRange);
|
||||
const scaledDataFormat = config.get('dateFormat:scaled');
|
||||
const dateFormat = config.get('dateFormat');
|
||||
if (panel && panel.id) {
|
||||
const params = {
|
||||
timerange: { timezone, ...parsedTimeRange },
|
||||
filters: [buildEsQuery(undefined, [query], filters)],
|
||||
panels: [panel],
|
||||
state: uiStateObj
|
||||
};
|
||||
|
||||
try {
|
||||
const maxBuckets = config.get('metrics:max_buckets');
|
||||
//validateInterval(parsedTimeRange, panel, maxBuckets);
|
||||
const httpResult = $http.post('../api/metrics/vis/data', params)
|
||||
.then(resp => ({ dateFormat, scaledDataFormat, timezone, ...resp.data }))
|
||||
.catch(resp => { throw resp.data; });
|
||||
|
||||
return httpResult
|
||||
.then(resolve)
|
||||
.catch(resp => {
|
||||
resolve({});
|
||||
const err = new Error(resp.message);
|
||||
err.stack = resp.stack;
|
||||
console.log('DEBUG', err)
|
||||
});
|
||||
} catch (e) {
|
||||
console.log('DEBUG 2', e)
|
||||
return resolve();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
this.requestHandler = getHandler(requestHandlers, requestHandler);
|
||||
}
|
||||
this.responseHandler = getHandler(responseHandlers, responseHandler);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user