From b398d8769ac3d8603b4e99a877cc722f631af449 Mon Sep 17 00:00:00 2001 From: Nick Peihl Date: Wed, 16 Oct 2024 11:58:49 -0400 Subject: [PATCH] [Canvas] Use core http method to access internal API (#195790) --- x-pack/plugins/canvas/public/application.tsx | 2 +- x-pack/plugins/canvas/public/functions/index.ts | 2 +- x-pack/plugins/canvas/public/functions/timelion.ts | 9 +++------ 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/x-pack/plugins/canvas/public/application.tsx b/x-pack/plugins/canvas/public/application.tsx index 222b64e4175e9..92ae3ebb6a00e 100644 --- a/x-pack/plugins/canvas/public/application.tsx +++ b/x-pack/plugins/canvas/public/application.tsx @@ -95,8 +95,8 @@ export const initializeCanvas = async ( // Some of these functions have deep dependencies into Canvas, which was bulking up the size // of our bundle entry point. Moving them here pushes that load to when canvas is actually loaded. const canvasFunctions = initFunctions({ + http: coreSetup.http, timefilter: setupPlugins.data.query.timefilter.timefilter, - prependBasePath: coreStart.http.basePath.prepend, types: setupPlugins.expressions.getTypes(), paletteService: await setupPlugins.charts.palettes.getPalettes(), }); diff --git a/x-pack/plugins/canvas/public/functions/index.ts b/x-pack/plugins/canvas/public/functions/index.ts index ad91d6b98fa7f..15985b0fa7628 100644 --- a/x-pack/plugins/canvas/public/functions/index.ts +++ b/x-pack/plugins/canvas/public/functions/index.ts @@ -15,7 +15,7 @@ import { plotFunctionFactory } from './plot'; import { pieFunctionFactory } from './pie'; export interface InitializeArguments { - prependBasePath: CoreSetup['http']['basePath']['prepend']; + http: CoreSetup['http']; paletteService: PaletteRegistry; types: ReturnType; timefilter: CanvasSetupDeps['data']['query']['timefilter']['timefilter']; diff --git a/x-pack/plugins/canvas/public/functions/timelion.ts b/x-pack/plugins/canvas/public/functions/timelion.ts index 7ab272911389d..8f2e2c6562bc0 100644 --- a/x-pack/plugins/canvas/public/functions/timelion.ts +++ b/x-pack/plugins/canvas/public/functions/timelion.ts @@ -11,7 +11,6 @@ import { i18n } from '@kbn/i18n'; import type { TimeRange } from '@kbn/es-query'; import { ExpressionFunctionDefinition, DatatableRow } from '@kbn/expressions-plugin/public'; -import { fetch } from '../../common/lib/fetch'; // @ts-expect-error untyped local import { buildBoolArray } from '../../common/lib/build_bool_array'; import { Datatable, ExpressionValueFilter } from '../../types'; @@ -132,16 +131,14 @@ export function timelionFunctionFactory(initialize: InitializeArguments): () => let result: any; try { - result = await fetch(initialize.prependBasePath(`/internal/timelion/run`), { - method: 'POST', - responseType: 'json', - data: body, + result = await initialize.http.post(`/internal/timelion/run`, { + body: JSON.stringify(body), }); } catch (e) { throw errors.timelionError(); } - const seriesList = result.data.sheet[0].list; + const seriesList = result.sheet[0].list; const rows = flatten( seriesList.map((series: { data: any[]; label: string }) => series.data.map((row) => ({