Skip to content

Commit

Permalink
Merge pull request #1 from bjacomy/7.9.1
Browse files Browse the repository at this point in the history
7.9.1
  • Loading branch information
bjacomy authored Dec 8, 2020
2 parents 6ef4aea + 3036ebd commit fa16c24
Show file tree
Hide file tree
Showing 17 changed files with 483 additions and 100 deletions.
27 changes: 27 additions & 0 deletions config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* 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 { schema, TypeOf } from '@kbn/config-schema';

export const configSchema = schema.object({
enabled: schema.boolean({ defaultValue: true }),
enableExternalUrls: schema.boolean({ defaultValue: false }),
});

export type ConfigSchema = TypeOf<typeof configSchema>;
27 changes: 0 additions & 27 deletions index.ts

This file was deleted.

9 changes: 9 additions & 0 deletions kibana.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"id": "transformVis",
"version": "7.9.1",
"server": true,
"ui": true,
"requiredPlugins": ["navigation","data","kibanaReact","kibanaUtils", "visualizations", "expressions"],
"optionalPlugins": [],
"requiredBundles": []
}
10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"name": "transform_vis",
"version": "7.7.1.1",
"version": "7.9.1",
"description": "Transform Visualization",
"main": "index.js",
"kibana": {
"version": "7.8.1",
"version": "7.9.1",
"templateVersion": "1.0.0"
},
"license": "Apache-2.0",
Expand Down Expand Up @@ -47,8 +47,10 @@
},
"dependencies": {
"@babel/standalone": "7.9.4",
"react-shadow": "^16.3.2",
"@webcomponents/shadydom": "^1.6.0",
"brace": "^0.11.1"
"brace": "^0.11.1",
"mustache": "^4.0.1",
"react-shadow": "^16.3.2",
"timefilter": "^1.0.0"
}
}
2 changes: 1 addition & 1 deletion public/legacy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ const plugins: Readonly<TransformPluginSetupDependencies> = {
const pluginInstance = plugin({} as PluginInitializerContext);

export const setup = pluginInstance.setup(npSetup.core, plugins);
export const start = pluginInstance.start(npStart.core);
export const start = pluginInstance.start(npStart.core, plugins);
51 changes: 38 additions & 13 deletions public/plugin.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,34 @@
import { PluginInitializerContext, CoreSetup, CoreStart, Plugin } from 'kibana/public';
import { Plugin as ExpressionsPublicPlugin } from '../../../src/plugins/expressions/public';
import { VisualizationsSetup } from '../../../src/legacy/core_plugins/visualizations/public';

import { VisualizationsSetup } from '../../../src/plugins/visualizations/public';
import { createTransformVisDefinition } from './transform_vis';
import { createTransformVisFn } from './transform_fn';
import { DataPublicPluginSetup, DataPublicPluginStart } from '../../../src/plugins/data/public';
import { DataPublicPluginSetup, DataPublicPluginStart ,IDataPluginServices} from '../../../src/plugins/data/public';


import {
setNotifications,
setData,
setSavedObjects,
setInjectedMetadata,
} from './services';
import { setStartServices } from 'ui/new_platform/set_services';
import { HomeKibanaServices, setServices } from 'src/plugins/home/public/application/kibana_services';



/** @internal */
export interface TransformPluginSetupDependencies {
expressions: ReturnType<ExpressionsPublicPlugin['setup']>;
visualizations: VisualizationsSetup;
data: DataPublicPluginSetup;
dataStart: DataPublicPluginStart;

}
export interface TransformPluginStartDependencies {
expressions: ReturnType<ExpressionsPublicPlugin['setup']>;
visualizations: VisualizationsSetup;
data: DataPublicPluginStart;
uiActions:IDataPluginServices;
}

/** @internal */
Expand All @@ -24,15 +41,23 @@ export class TransformPlugin implements Plugin<void, void> {

public async setup(
core: CoreSetup,
{ expressions, visualizations, data, dataStart }: TransformPluginSetupDependencies
{ expressions, visualizations, data }: TransformPluginSetupDependencies
) {
visualizations.createReactVisualization(
createTransformVisDefinition({ uiSettings: core.uiSettings, es: dataStart.search.__LEGACY.esClient, data })
);
expressions.registerFunction(() =>
createTransformVisFn({ uiSettings: core.uiSettings, es: dataStart.search.__LEGACY.esClient })
);
//setData(dataStart);
const config = createTransformVisDefinition({ uiSettings: core.uiSettings, data });
visualizations.createReactVisualization(config);
expressions.registerFunction(() =>
createTransformVisFn({ uiSettings: core.uiSettings, timeFilter: data.query.timefilter.timefilter})
);

}

public async start(core: CoreStart,{ expressions, visualizations, data, uiActions }: TransformPluginStartDependencies){
setNotifications(core.notifications);
setSavedObjects(core.savedObjects);
setData(data);
setInjectedMetadata(core.injectedMetadata);


}

public async start(core: CoreStart) {}
}
63 changes: 41 additions & 22 deletions public/request_handler.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import { transform } from '@babel/standalone';
import { IUiSettingsClient } from 'kibana/public';
import Mustache from 'mustache';
import { timefilter } from 'ui/timefilter';
import chrome from 'ui/chrome';
import { esQuery, TimeRange, Query, Filter } from '../../../src/plugins/data/public';
import { VisParams } from '../../../src/legacy/core_plugins/visualizations/public/np_ready/public';
import { Timefilter } from '../../../src/plugins/data/public/query/timefilter';

import {InjectedMetadataSetup} from '../../../src/core/public/injected_metadata'
import { esQuery, TimeRange, Query, Filter} from '../../../src/plugins/data/public';
import { VisParams } from '../../../src/plugins/visualizations/public';
import { TransformVisData } from './types';
import { LegacyApiCaller } from '../../../src/plugins/data/public/search/es_client';

import { getData} from './services';
import { DataPublicPluginStart } from '../../../src/plugins/data/public';
import axios from 'axios'
import value from '@elastic/eui/dist/eui_theme_*.json';

const babelTransform = (code: string) => {
return transform(code, {
Expand All @@ -16,12 +21,12 @@ const babelTransform = (code: string) => {
};

export function getTransformRequestHandler({
uiSettings,
es,
uiSettings,
timeFilter
}: {
uiSettings: IUiSettingsClient;
es: LegacyApiCaller;
}) {
timeFilter:Timefilter
} ,abortSignal?: AbortSignal ) {
return async ({
timeRange,
filters,
Expand All @@ -33,9 +38,10 @@ export function getTransformRequestHandler({
query: Query | null;
visParams: VisParams;
}): Promise<TransformVisData> => {
const settings = chrome.getUiSettingsClient();
const options = chrome.getInjected('transformVisOptions');

//const data : DataPublicPluginStart = getData();
//const es = data.search.__LEGACY.esClient;
const settings = uiSettings;
const options : InjectedMetadataSetup["getInjectedVar"]= (name= 'transformVisOptions', defaultValue= 'undefined')=> {};
const _timeRange: TimeRange = timeRange || settings.get('timepicker:timeDefaults');
const _filters = filters || [];
const _query = query || { language: 'kquery', query: '' };
Expand All @@ -53,10 +59,10 @@ export function getTransformRequestHandler({

const bindme: Record<string, any> = {};
bindme.context = context;
bindme.timefilter = timefilter;
bindme.timefilter = timeFilter;
bindme.timeRange = _timeRange;
bindme.buildEsQuery = esQuery.buildEsQuery;
bindme.es = es;
//bindme.es = es;
bindme.response = {};

const parseMultiqueryDsl = (_multiquerydsltext: string | undefined): Record<string, any> => {
Expand Down Expand Up @@ -108,25 +114,38 @@ export function getTransformRequestHandler({
}
delete body.previousContextSource;
}
return es
const requestSearch = {
body: body
};
try{

const headers = {
'Content-Type': 'application/json',
'kbn-xsrf': 'reporting'
}

response = await axios.post(`../api/transform_vis/${index}/_search`,requestSearch,{headers: headers});
/* return es
.search({
index,
body,
})
.then(function (response) {
.then(function (response: { error: any; }) {*/
// @ts-ignore
if (response.error) throw response.error;
response = response.data.data;
//if (response.status) throw response.error;
if (queryName === '_single_') {
bindme.response = Object.assign(bindme.response, response);
} else {
bindme.response = Object.assign(bindme.response, { [queryName]: response });
}
})
.catch(error => logError('Elasticsearch Query Error', [ `"${queryName}" query:\nGET ${index}/_search\n${JSON.stringify(body, null, 2)}`, error ]));
}
catch(error: any) { logError('Elasticsearch Query Error', [ `"${queryName}" query:\nGET ${index}/_search\n${JSON.stringify(body, null, 2)}`, error ])};
return response;
};

const evalMeta = (response?: any) => {
if (options.allow_unsafe) {
if (options.name) {
try {
// @ts-ignore используется без var/let/const, а как необязатеьный параметр, чтобы не переименовывался при оптимизиции кода
response = bindme.response;
Expand Down Expand Up @@ -156,9 +175,9 @@ export function getTransformRequestHandler({
return {
transform: Mustache.render(formula, { ...bindme, meta: awaitContext }),
meta: bindme.meta,
es,
//es,
context,
timefilter,
timeFilter,
timeRange,
buildEsQuery: esQuery.buildEsQuery,
};
Expand Down
61 changes: 61 additions & 0 deletions public/services.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* 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 {
CoreStart,
SavedObjectsStart,
NotificationsStart,
IUiSettingsClient,
} from 'src/core/public';

import { DataPublicPluginStart } from '../../../src/plugins/data/public';
import { createGetterSetter } from '../../../src/plugins/kibana_utils/public';
import { MapsLegacyConfigType } from '../../../src/plugins/maps_legacy/public';

export const [getData, setData] = createGetterSetter<DataPublicPluginStart>('dataStart');

export const [getNotifications, setNotifications] = createGetterSetter<NotificationsStart>(
'Notifications'
);
export const [getKibanaMapFactory, setKibanaMapFactory] = createGetterSetter<any>(
'KibanaMapFactory'
);

export const [getUISettings, setUISettings] = createGetterSetter<IUiSettingsClient>('UISettings');

export const [getInjectedMetadata, setInjectedMetadata] = createGetterSetter<
CoreStart['injectedMetadata']
>('InjectedMetadata');

export const [getSavedObjects, setSavedObjects] = createGetterSetter<SavedObjectsStart>(
'SavedObjects'
);

export const [getInjectedVars, setInjectedVars] = createGetterSetter<{
esShardTimeout: number;
enableExternalUrls: boolean;
emsTileLayerId: unknown;
}>('InjectedVars');

export const [getMapsLegacyConfig, setMapsLegacyConfig] = createGetterSetter<MapsLegacyConfigType>(
'MapsLegacyConfig'
);

export const getEnableExternalUrls = () => getInjectedVars().enableExternalUrls;
export const getEmsTileLayerId = () => getMapsLegacyConfig().emsTileLayerId;
13 changes: 8 additions & 5 deletions public/transform_fn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ import { IUiSettingsClient } from 'kibana/public';
import { ExpressionFunctionDefinition, Render, KibanaContext } from '../../../src/plugins/expressions/public';
import { Arguments, TransformVisParams } from './types';
import { getTransformRequestHandler } from './request_handler';
import { LegacyApiCaller } from '../../../src/plugins/data/public/search/es_client';
import { Query} from '../../../src/plugins/data/public';
import { Timefilter } from 'src/plugins/data/public/query';


interface RenderValue {
visType: 'transform';
Expand All @@ -33,10 +35,10 @@ interface RenderValue {

export const createTransformVisFn = ({
uiSettings,
es,
timeFilter
}: {
uiSettings: IUiSettingsClient;
es: LegacyApiCaller;
timeFilter:Timefilter
}): ExpressionFunctionDefinition<'transform_vis', KibanaContext | null, Arguments, Promise<Render<RenderValue>>> => ({
name: 'transform_vis',
type: 'render',
Expand Down Expand Up @@ -68,10 +70,11 @@ export const createTransformVisFn = ({
},
},
async fn(input, args) {
const transformRequestHandler = getTransformRequestHandler({ uiSettings, es });

const transformRequestHandler = getTransformRequestHandler({ uiSettings, timeFilter});
const response = await transformRequestHandler({
timeRange: get(input, 'timeRange', null),
query: get(input, 'query', null),
query: <Query | null> get(input, 'query', null),
filters: get(input, 'filters', null),
visParams: args,
});
Expand Down
Loading

0 comments on commit fa16c24

Please sign in to comment.