Skip to content

Commit

Permalink
[Canvas] Use core http method to access internal API (elastic#195790)
Browse files Browse the repository at this point in the history
  • Loading branch information
nickpeihl authored and hop-dev committed Oct 16, 2024
1 parent a80567d commit b398d87
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 8 deletions.
2 changes: 1 addition & 1 deletion x-pack/plugins/canvas/public/application.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
});
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/canvas/public/functions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<CanvasSetupDeps['expressions']['getTypes']>;
timefilter: CanvasSetupDeps['data']['query']['timefilter']['timefilter'];
Expand Down
9 changes: 3 additions & 6 deletions x-pack/plugins/canvas/public/functions/timelion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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) => ({
Expand Down

0 comments on commit b398d87

Please sign in to comment.