diff --git a/src/legacy/core_plugins/vis_type_vega/public/plugin.ts b/src/legacy/core_plugins/vis_type_vega/public/plugin.ts index 419c5d07fb4b7..039ef49cb2289 100644 --- a/src/legacy/core_plugins/vis_type_vega/public/plugin.ts +++ b/src/legacy/core_plugins/vis_type_vega/public/plugin.ts @@ -27,13 +27,11 @@ import { LegacyDependenciesPlugin, LegacyDependenciesPluginSetup } from './shim' import { Plugin as DataPublicPlugin } from '../../../../plugins/data/public'; import { VisualizationsSetup } from '../../visualizations/public'; -// @ts-ignore import { createVegaFn } from './vega_fn'; -// @ts-ignore import { createVegaTypeDefinition } from './vega_type'; -/** @private */ -interface VegaVisualizationDependencies extends LegacyDependenciesPluginSetup { +/** @internal */ +export interface VegaVisualizationDependencies extends LegacyDependenciesPluginSetup { uiSettings: UiSettingsClientContract; } diff --git a/src/legacy/core_plugins/vis_type_vega/public/vega_fn.js b/src/legacy/core_plugins/vis_type_vega/public/vega_fn.ts similarity index 66% rename from src/legacy/core_plugins/vis_type_vega/public/vega_fn.js rename to src/legacy/core_plugins/vis_type_vega/public/vega_fn.ts index e92d51668989c..6bbeec38039aa 100644 --- a/src/legacy/core_plugins/vis_type_vega/public/vega_fn.js +++ b/src/legacy/core_plugins/vis_type_vega/public/vega_fn.ts @@ -19,16 +19,35 @@ import { get } from 'lodash'; import { i18n } from '@kbn/i18n'; + +import { ExpressionFunction, KibanaContext, Render } from '../../interpreter/types'; +import { VegaVisualizationDependencies } from './plugin'; import { createVegaRequestHandler } from './vega_request_handler'; -export const createVegaFn = (dependencies) => ({ - name: 'vega', +const name = 'vega'; +type Context = KibanaContext | null; + +interface Arguments { + spec: string; +} + +export type VisParams = Required; + +interface RenderValue { + visData: Context; + visType: typeof name; + visConfig: VisParams; +} + +type Return = Promise>; + +export const createVegaFn = ( + dependencies: VegaVisualizationDependencies +): ExpressionFunction => ({ + name, type: 'render', context: { - types: [ - 'kibana_context', - 'null', - ], + types: ['kibana_context', 'null'], }, help: i18n.translate('visTypeVega.function.help', { defaultMessage: 'Vega visualization', @@ -37,17 +56,17 @@ export const createVegaFn = (dependencies) => ({ spec: { types: ['string'], default: '', + help: '', }, }, async fn(context, args) { const vegaRequestHandler = createVegaRequestHandler(dependencies); const response = await vegaRequestHandler({ - timeRange: get(context, 'timeRange', null), - query: get(context, 'query', null), - filters: get(context, 'filters', null), + timeRange: get(context, 'timeRange'), + query: get(context, 'query'), + filters: get(context, 'filters'), visParams: { spec: args.spec }, - forceFetch: true, }); return { @@ -55,7 +74,7 @@ export const createVegaFn = (dependencies) => ({ as: 'visualization', value: { visData: response, - visType: 'vega', + visType: name, visConfig: { spec: args.spec, }, diff --git a/src/legacy/core_plugins/vis_type_vega/public/vega_request_handler.js b/src/legacy/core_plugins/vis_type_vega/public/vega_request_handler.ts similarity index 69% rename from src/legacy/core_plugins/vis_type_vega/public/vega_request_handler.js rename to src/legacy/core_plugins/vis_type_vega/public/vega_request_handler.ts index 1bffafded4474..a930e369c3e1c 100644 --- a/src/legacy/core_plugins/vis_type_vega/public/vega_request_handler.js +++ b/src/legacy/core_plugins/vis_type_vega/public/vega_request_handler.ts @@ -16,18 +16,38 @@ * specific language governing permissions and limitations * under the License. */ -import { timefilter } from 'ui/timefilter'; -import { buildEsQuery, getEsQueryConfig } from '@kbn/es-query'; +import { Filter } from '@kbn/es-query'; +import { timefilter, TimeRange } from 'ui/timefilter'; +import { Query } from 'src/legacy/core_plugins/data/public'; +// @ts-ignore +import { buildEsQuery, getEsQueryConfig } from '@kbn/es-query'; +// @ts-ignore import { VegaParser } from './data_model/vega_parser'; +// @ts-ignore import { SearchCache } from './data_model/search_cache'; +// @ts-ignore import { TimeCache } from './data_model/time_cache'; -export function createVegaRequestHandler({ uiSettings, es, serviceSettings }) { +import { VegaVisualizationDependencies } from './plugin'; +import { VisParams } from './vega_fn'; + +interface VegaRequestHandlerParams { + query: Query; + filters: Filter; + timeRange: TimeRange; + visParams: VisParams; +} + +export function createVegaRequestHandler({ + es, + uiSettings, + serviceSettings, +}: VegaVisualizationDependencies) { const searchCache = new SearchCache(es, { max: 10, maxAge: 4 * 1000 }); const timeCache = new TimeCache(timefilter, 3 * 1000); - return ({ timeRange, filters, query, visParams }) => { + return ({ timeRange, filters, query, visParams }: VegaRequestHandlerParams) => { timeCache.setTimeRange(timeRange); const esQueryConfigs = getEsQueryConfig(uiSettings); diff --git a/src/legacy/core_plugins/vis_type_vega/public/vega_type.js b/src/legacy/core_plugins/vis_type_vega/public/vega_type.ts similarity index 91% rename from src/legacy/core_plugins/vis_type_vega/public/vega_type.js rename to src/legacy/core_plugins/vis_type_vega/public/vega_type.ts index b4e516cd873f1..6ffcd8867ffea 100644 --- a/src/legacy/core_plugins/vis_type_vega/public/vega_type.js +++ b/src/legacy/core_plugins/vis_type_vega/public/vega_type.ts @@ -18,19 +18,23 @@ */ import { i18n } from '@kbn/i18n'; -import { DefaultEditorSize } from 'ui/vis/editor_size'; import { Status } from 'ui/vis/update_status'; +// @ts-ignore +import { DefaultEditorSize } from 'ui/vis/editor_size'; +// @ts-ignore import { defaultFeedbackMessage } from 'ui/vis/default_feedback_message'; +import vegaEditorTemplate from './vega_editor_template.html'; +import { visFactory } from '../../visualizations/public'; +import { VegaVisualizationDependencies } from './plugin'; + import { createVegaRequestHandler } from './vega_request_handler'; +// @ts-ignore import { createVegaVisualization } from './vega_visualization'; - -import vegaEditorTemplate from './vega_editor_template.html'; +// @ts-ignore import defaultSpec from '!!raw-loader!./default.spec.hjson'; -import { visFactory } from '../../visualizations/public'; - -export const createVegaTypeDefinition = (dependencies) => { +export const createVegaTypeDefinition = (dependencies: VegaVisualizationDependencies) => { const requestHandler = createVegaRequestHandler(dependencies); const visualization = createVegaVisualization(dependencies); diff --git a/src/legacy/ui/public/timefilter/index.d.ts b/src/legacy/ui/public/timefilter/index.d.ts index db6ead9d17a18..ce1ae86bb93ba 100644 --- a/src/legacy/ui/public/timefilter/index.d.ts +++ b/src/legacy/ui/public/timefilter/index.d.ts @@ -18,3 +18,4 @@ */ export { timefilter, Timefilter } from './timefilter'; +export { timeHistory, TimeRange } from './time_history';