Skip to content

Commit

Permalink
lens should register expression functions in setup contract
Browse files Browse the repository at this point in the history
  • Loading branch information
alexwizp committed Aug 31, 2021
1 parent 257cddd commit 441e18d
Show file tree
Hide file tree
Showing 23 changed files with 151 additions and 199 deletions.
10 changes: 5 additions & 5 deletions x-pack/plugins/lens/public/app_plugin/mounter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ import { getPreloadedState } from '../state_management/lens_slice';
export async function getLensServices(
coreStart: CoreStart,
startDependencies: LensPluginStartDependencies,
attributeService: () => Promise<LensAttributeService>
attributeService: LensAttributeService
): Promise<LensAppServices> {
const {
data,
Expand All @@ -70,7 +70,7 @@ export async function getLensServices(
stateTransfer,
usageCollection,
savedObjectsTagging,
attributeService: await attributeService(),
attributeService,
http: coreStart.http,
chrome: coreStart.chrome,
overlays: coreStart.overlays,
Expand All @@ -95,8 +95,8 @@ export async function mountApp(
params: AppMountParameters,
mountProps: {
createEditorFrame: EditorFrameStart['createInstance'];
attributeService: () => Promise<LensAttributeService>;
getPresentationUtilContext: () => Promise<FC>;
attributeService: LensAttributeService;
getPresentationUtilContext: () => FC;
}
) {
const { createEditorFrame, attributeService, getPresentationUtilContext } = mountProps;
Expand Down Expand Up @@ -248,7 +248,7 @@ export async function mountApp(

params.element.classList.add('lnsAppWrapper');

const PresentationUtilContext = await getPresentationUtilContext();
const PresentationUtilContext = getPresentationUtilContext();

render(
<I18nProvider>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import React, { Suspense, useEffect, useState } from 'react';
import { EuiLoadingSpinner, EuiOverlayMask } from '@elastic/eui';
import { CoreStart } from 'kibana/public';
import type { SaveModalContainerProps } from '../save_modal_container';
import type { LensAttributeService } from '../../lens_attribute_service';
import type { LensPluginStartDependencies } from '../../plugin';
import type { LensAppServices } from '../types';
const SaveModal = React.lazy(() => import('../save_modal_container'));
Expand All @@ -33,16 +32,20 @@ const LensSavedModalLazy = (props: SaveModalContainerProps) => {

export function getSaveModalComponent(
coreStart: CoreStart,
startDependencies: LensPluginStartDependencies,
attributeService: () => Promise<LensAttributeService>
startDependencies: LensPluginStartDependencies
) {
return (props: Omit<SaveModalContainerProps, 'lensServices'>) => {
const [lensServices, setLensServices] = useState<LensAppServices>();

useEffect(() => {
async function loadLensService() {
const { getLensServices } = await import('../../async_services');
const lensServicesT = await getLensServices(coreStart, startDependencies, attributeService);
const { getLensServices, getLensAttributeService } = await import('../../async_services');

const lensServicesT = await getLensServices(
coreStart,
startDependencies,
getLensAttributeService(coreStart, startDependencies)
);

setLensServices(lensServicesT);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import type { DatatableProps } from '../../common/expressions';
import type { LensMultiTable } from '../../common';
import { createMockExecutionContext } from '../../../../../src/plugins/expressions/common/mocks';
import type { FormatFactory } from '../../common';
import { getDatatable } from './expression';
import { getDatatable } from '../../common/expressions';

function sampleArgs() {
const indexPatternId = 'indexPatternId';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ import { DatatableComponent } from './components/table_basic';

import type { ILensInterpreterRenderHandlers } from '../types';
import type { FormatFactory } from '../../common';
import { DatatableProps } from '../../common/expressions';

export { datatableColumn, getDatatable } from '../../common/expressions';
import type { DatatableProps } from '../../common/expressions';

export const getDatatableRenderer = (dependencies: {
formatFactory: FormatFactory;
Expand Down
12 changes: 2 additions & 10 deletions x-pack/plugins/lens/public/datatable_visualization/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,14 @@ export interface DatatableVisualizationPluginSetupPlugins {
}

export class DatatableVisualization {
constructor() {}

setup(
core: CoreSetup<DatatableVisualizationPluginStartPlugins, void>,
{ expressions, formatFactory, editorFrame, charts }: DatatableVisualizationPluginSetupPlugins
) {
editorFrame.registerVisualization(async () => {
const {
getDatatable,
datatableColumn,
getDatatableRenderer,
getDatatableVisualization,
} = await import('../async_services');
const { getDatatableRenderer, getDatatableVisualization } = await import('../async_services');
const palettes = await charts.palettes.getPalettes();

expressions.registerFunction(() => datatableColumn);
expressions.registerFunction(() => getDatatable(() => formatFactory));
expressions.registerRenderer(() =>
getDatatableRenderer({
formatFactory,
Expand All @@ -50,6 +41,7 @@ export class DatatableVisualization {
uiSettings: core.uiSettings,
})
);

return getDatatableVisualization({ paletteService: palettes });
});
}
Expand Down
12 changes: 2 additions & 10 deletions x-pack/plugins/lens/public/editor_frame_service/service.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import React from 'react';
import { CoreSetup, CoreStart } from 'kibana/public';
import { CoreStart } from 'kibana/public';
import { UsageCollectionSetup } from 'src/plugins/usage_collection/public';
import { ExpressionsSetup, ExpressionsStart } from '../../../../../src/plugins/expressions/public';
import { EmbeddableSetup, EmbeddableStart } from '../../../../../src/plugins/embeddable/public';
Expand All @@ -22,7 +22,6 @@ import {
EditorFrameStart,
} from '../types';
import { Document } from '../persistence/saved_object_store';
import { mergeTables } from '../../common/expressions';
import { UiActionsStart } from '../../../../../src/plugins/ui_actions/public';
import { ChartsPluginSetup } from '../../../../../src/plugins/charts/public';
import { DashboardStart } from '../../../../../src/plugins/dashboard/public';
Expand Down Expand Up @@ -59,8 +58,6 @@ async function collectAsyncDefinitions<T extends { id: string }>(
}

export class EditorFrameService {
constructor() {}

private readonly datasources: Array<Datasource | (() => Promise<Datasource>)> = [];
private readonly visualizations: Array<Visualization | (() => Promise<Visualization>)> = [];

Expand All @@ -81,12 +78,7 @@ export class EditorFrameService {
return await persistedStateToExpression(resolvedDatasources, resolvedVisualizations, doc);
};

public setup(
core: CoreSetup<EditorFrameStartPlugins>,
plugins: EditorFrameSetupPlugins
): EditorFrameSetup {
plugins.expressions.registerFunction(() => mergeTables);

public setup(): EditorFrameSetup {
return {
registerDatasource: (datasource) => {
this.datasources.push(datasource as Datasource<unknown, unknown>);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ import type { ChartsPluginSetup, PaletteRegistry } from '../../../../../src/plug
import { HeatmapChartReportable } from './chart_component';
import type { HeatmapExpressionProps } from './types';

export { heatmapGridConfig, heatmapLegendConfig, heatmap } from '../../common/expressions';

export const getHeatmapRenderer = (dependencies: {
formatFactory: FormatFactory;
chartsThemeService: ChartsPluginSetup['theme'];
Expand Down
15 changes: 1 addition & 14 deletions x-pack/plugins/lens/public/heatmap_visualization/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,15 @@ export interface HeatmapVisualizationPluginSetupPlugins {
}

export class HeatmapVisualization {
constructor() {}

setup(
core: CoreSetup,
{ expressions, formatFactory, editorFrame, charts }: HeatmapVisualizationPluginSetupPlugins
) {
editorFrame.registerVisualization(async () => {
const timeZone = getTimeZone(core.uiSettings);

const {
getHeatmapVisualization,
heatmap,
heatmapLegendConfig,
heatmapGridConfig,
getHeatmapRenderer,
} = await import('../async_services');
const { getHeatmapVisualization, getHeatmapRenderer } = await import('../async_services');
const palettes = await charts.palettes.getPalettes();

expressions.registerFunction(() => heatmap);
expressions.registerFunction(() => heatmapLegendConfig);
expressions.registerFunction(() => heatmapGridConfig);

expressions.registerRenderer(
getHeatmapRenderer({
formatFactory,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,16 @@
* 2.0.
*/

import { EuiToolTip } from '@elastic/eui';
import { EuiIcon } from '@elastic/eui';
import { EuiFormRow, EuiSelect, EuiFlexItem, EuiFlexGroup, EuiButtonIcon } from '@elastic/eui';
import {
EuiToolTip,
EuiIcon,
EuiFormRow,
EuiSelect,
EuiFlexItem,
EuiFlexGroup,
EuiButtonIcon,
} from '@elastic/eui';

import { i18n } from '@kbn/i18n';
import React from 'react';
import {
Expand All @@ -17,7 +24,7 @@ import {
} from '../operations';
import type { TimeScaleUnit } from '../../../common/expressions';
import { unitSuffixesLong } from '../../../common/suffix_formatter';
import { IndexPatternLayer } from '../types';
import type { IndexPatternLayer } from '../types';

export function setTimeScaling(
columnId: string,
Expand Down
20 changes: 3 additions & 17 deletions x-pack/plugins/lens/public/indexpattern_datasource/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import type {
FieldFormatsStart,
FieldFormatsSetup,
} from '../../../../../src/plugins/field_formats/public';
import { getTimeZone } from '../utils';

export interface IndexPatternDatasourceSetupPlugins {
expressions: ExpressionsSetup;
Expand All @@ -38,8 +37,6 @@ export interface IndexPatternDatasourceStartPlugins {
}

export class IndexPatternDatasource {
constructor() {}

setup(
core: CoreSetup<IndexPatternDatasourceStartPlugins>,
{
Expand All @@ -50,15 +47,9 @@ export class IndexPatternDatasource {
}: IndexPatternDatasourceSetupPlugins
) {
editorFrame.registerDatasource(async () => {
const {
getIndexPatternDatasource,
renameColumns,
formatColumn,
counterRate,
getTimeScale,
getSuffixFormatter,
suffixFormatterId,
} = await import('../async_services');
const { getIndexPatternDatasource, getSuffixFormatter, suffixFormatterId } = await import(
'../async_services'
);

if (!fieldFormatsSetup.has(suffixFormatterId)) {
const startServices = createStartServicesGetter(core.getStartServices);
Expand All @@ -69,11 +60,6 @@ export class IndexPatternDatasource {
fieldFormatsSetup.register([suffixFormatter]);
}

expressions.registerFunction(getTimeScale(() => getTimeZone(core.uiSettings)));
expressions.registerFunction(counterRate);
expressions.registerFunction(renameColumns);
expressions.registerFunction(formatColumn);

const [
coreStart,
{ indexPatternFieldEditor, uiActions, data, fieldFormats },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,19 +70,18 @@ export function columnToOperation(column: IndexPatternColumn, uniqueLabel?: stri
};
}

export {
export type {
FormatColumnArgs,
TimeScaleArgs,
CounterRateArgs,
ExpressionFunctionCounterRate,
counterRate,
} from '../../common/expressions';
export { FormatColumnArgs, supportedFormats, formatColumn } from '../../common/expressions';

export {
getSuffixFormatter,
unitSuffixesLong,
suffixFormatterId,
} from '../../common/suffix_formatter';
export { getTimeScale, TimeScaleArgs } from '../../common/expressions';
export { renameColumns } from '../../common/expressions';

export function getIndexPatternDatasource({
core,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import { flatten, minBy, pick, mapValues, partition } from 'lodash';
import { i18n } from '@kbn/i18n';
import { generateId } from '../id_generator';
import { DatasourceSuggestion, TableChangeType } from '../types';
import type { DatasourceSuggestion, TableChangeType } from '../types';
import { columnToOperation } from './indexpattern';
import {
insertNewColumn,
Expand All @@ -23,7 +23,7 @@ import {
getReferencedColumnIds,
} from './operations';
import { hasField } from './utils';
import {
import type {
IndexPattern,
IndexPatternPrivateState,
IndexPatternLayer,
Expand Down
9 changes: 5 additions & 4 deletions x-pack/plugins/lens/public/lens_attribute_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
* 2.0.
*/

import { CoreStart } from '../../../../src/core/public';
import { LensPluginStartDependencies } from './plugin';
import { AttributeService } from '../../../../src/plugins/embeddable/public';
import {
import type { CoreStart } from '../../../../src/core/public';
import type { LensPluginStartDependencies } from './plugin';
import type { AttributeService } from '../../../../src/plugins/embeddable/public';
import type {
LensSavedObjectAttributes,
LensByValueInput,
LensByReferenceInput,
} from './embeddable/embeddable';

import { SavedObjectIndexStore, Document } from './persistence';
import { checkForDuplicateTitle, OnSaveProps } from '../../../../src/plugins/saved_objects/public';
import { DOC_TYPE } from '../common';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ import { EmptyPlaceholder } from '../shared_components';
import { LensIconChartMetric } from '../assets/chart_metric';
import type { FormatFactory } from '../../common';
import type { MetricChartProps } from '../../common/expressions';

export { metricChart } from '../../common/expressions';
export type { MetricState, MetricConfig } from '../../common/expressions';
export type { MetricChartProps, MetricState, MetricConfig } from '../../common/expressions';

export const getMetricChartRenderer = (
formatFactory: FormatFactory
Expand Down
8 changes: 1 addition & 7 deletions x-pack/plugins/lens/public/metric_visualization/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,12 @@ export interface MetricVisualizationPluginSetupPlugins {
}

export class MetricVisualization {
constructor() {}

setup(
_core: CoreSetup | null,
{ expressions, formatFactory, editorFrame }: MetricVisualizationPluginSetupPlugins
) {
editorFrame.registerVisualization(async () => {
const { metricVisualization, metricChart, getMetricChartRenderer } = await import(
'../async_services'
);

expressions.registerFunction(() => metricChart);
const { metricVisualization, getMetricChartRenderer } = await import('../async_services');

expressions.registerRenderer(() => getMetricChartRenderer(formatFactory));
return metricVisualization;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import { SuggestionRequest, VisualizationSuggestion, TableSuggestion } from '../types';
import { MetricState } from '../../common/expressions';
import type { MetricState } from '../../common/expressions';
import { layerTypes } from '../../common';
import { LensIconChartMetric } from '../assets/chart_metric';

Expand Down
2 changes: 0 additions & 2 deletions x-pack/plugins/lens/public/pie_visualization/expression.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ import type { FormatFactory } from '../../common';
import type { PieExpressionProps } from '../../common/expressions';
import type { ChartsPluginSetup, PaletteRegistry } from '../../../../../src/plugins/charts/public';

export { pie } from '../../common/expressions';

export const getPieRenderer = (dependencies: {
formatFactory: FormatFactory;
chartsThemeService: ChartsPluginSetup['theme'];
Expand Down
Loading

0 comments on commit 441e18d

Please sign in to comment.