Skip to content

Commit

Permalink
legacy agg vis tag cloud convert to lens (elastic#159348)
Browse files Browse the repository at this point in the history
Part of elastic#154307

Add convert to lens logic for tag cloud visualization

---------

Co-authored-by: kibanamachine <[email protected]>
Co-authored-by: Stratoula Kalafateli <[email protected]>
  • Loading branch information
3 people authored Jun 12, 2023
1 parent 5fd356a commit e8e5cec
Show file tree
Hide file tree
Showing 26 changed files with 336 additions and 163 deletions.
29 changes: 5 additions & 24 deletions src/plugins/vis_types/gauge/public/convert_to_lens/gauge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,15 @@
*/

import { v4 as uuidv4 } from 'uuid';
import {
Column,
ColumnWithMeta,
PercentageModeConfigWithMinMax,
} from '@kbn/visualizations-plugin/common';
import { PercentageModeConfigWithMinMax } from '@kbn/visualizations-plugin/common';
import {
convertToLensModule,
getDataViewByIndexPatternId,
} from '@kbn/visualizations-plugin/public';
import { excludeMetaFromColumn } from '@kbn/visualizations-plugin/common/convert_to_lens';
import { getDataViewsStart } from '../services';
import { ConvertGaugeVisToLensVisualization } from './types';

export const isColumnWithMeta = (column: Column): column is ColumnWithMeta => {
if ((column as ColumnWithMeta).meta) {
return true;
}
return false;
};

export const excludeMetaFromColumn = (column: Column) => {
if (isColumnWithMeta(column)) {
const { meta, ...rest } = column;
return rest;
}
return column;
};
import { getConfiguration } from './configurations/gauge';

export const convertToLens: ConvertGaugeVisToLensVisualization = async (vis, timefilter) => {
if (!timefilter) {
Expand All @@ -46,10 +29,8 @@ export const convertToLens: ConvertGaugeVisToLensVisualization = async (vis, tim
return null;
}

const [
{ getColumnsFromVis, createStaticValueColumn, getPalette, getPercentageModeConfig },
{ getConfiguration },
] = await Promise.all([convertToLensModule, import('./configurations/gauge')]);
const { getColumnsFromVis, createStaticValueColumn, getPalette, getPercentageModeConfig } =
await convertToLensModule;

const percentageModeConfig = getPercentageModeConfig(vis.params.gauge, false);

Expand Down
29 changes: 5 additions & 24 deletions src/plugins/vis_types/gauge/public/convert_to_lens/goal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,15 @@
*/

import { v4 as uuidv4 } from 'uuid';
import {
Column,
ColumnWithMeta,
PercentageModeConfigWithMinMax,
} from '@kbn/visualizations-plugin/common';
import { PercentageModeConfigWithMinMax } from '@kbn/visualizations-plugin/common';
import {
convertToLensModule,
getDataViewByIndexPatternId,
} from '@kbn/visualizations-plugin/public';
import { excludeMetaFromColumn } from '@kbn/visualizations-plugin/common/convert_to_lens';
import { getDataViewsStart } from '../services';
import { ConvertGoalVisToLensVisualization } from './types';

export const isColumnWithMeta = (column: Column): column is ColumnWithMeta => {
if ((column as ColumnWithMeta).meta) {
return true;
}
return false;
};

export const excludeMetaFromColumn = (column: Column) => {
if (isColumnWithMeta(column)) {
const { meta, ...rest } = column;
return rest;
}
return column;
};
import { getConfiguration } from './configurations/goal';

export const convertToLens: ConvertGoalVisToLensVisualization = async (vis, timefilter) => {
if (!timefilter) {
Expand All @@ -46,10 +29,8 @@ export const convertToLens: ConvertGoalVisToLensVisualization = async (vis, time
return null;
}

const [
{ getColumnsFromVis, getPalette, getPercentageModeConfig, createStaticValueColumn },
{ getConfiguration },
] = await Promise.all([convertToLensModule, import('./configurations/goal')]);
const { getColumnsFromVis, getPalette, getPercentageModeConfig, createStaticValueColumn } =
await convertToLensModule;

const percentageModeConfig = getPercentageModeConfig(vis.params.gauge, false);

Expand Down
7 changes: 5 additions & 2 deletions src/plugins/vis_types/gauge/public/vis_type/gauge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import { toExpressionAst } from '../to_ast';
import { getGaugeOptions } from '../editor/components';
import { GaugeVisParams } from '../types';
import { SplitTooltip } from './split_tooltip';
import { convertGaugeToLens } from '../convert_to_lens';

export const getGaugeVisTypeDefinition = (
props: GaugeTypeProps
Expand Down Expand Up @@ -130,8 +129,12 @@ export const getGaugeVisTypeDefinition = (
],
},
requiresSearch: true,
navigateToLens: async (vis, timefilter) => (vis ? convertGaugeToLens(vis, timefilter) : null),
navigateToLens: async (vis, timefilter) => {
const { convertGaugeToLens } = await import('../convert_to_lens');
return vis ? convertGaugeToLens(vis, timefilter) : null;
},
getExpressionVariables: async (vis, timeFilter) => {
const { convertGaugeToLens } = await import('../convert_to_lens');
return {
canNavigateToLens: Boolean(vis?.params ? await convertGaugeToLens(vis, timeFilter) : null),
};
Expand Down
7 changes: 5 additions & 2 deletions src/plugins/vis_types/gauge/public/vis_type/goal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import { getGaugeOptions } from '../editor/components';
import { toExpressionAst } from '../to_ast';
import { GaugeVisParams, GaugeType, GaugeTypeProps } from '../types';
import { SplitTooltip } from './split_tooltip';
import { convertGoalToLens } from '../convert_to_lens';

export const getGoalVisTypeDefinition = (
props: GaugeTypeProps
Expand Down Expand Up @@ -122,8 +121,12 @@ export const getGoalVisTypeDefinition = (
],
},
requiresSearch: true,
navigateToLens: async (vis, timefilter) => (vis ? convertGoalToLens(vis, timefilter) : null),
navigateToLens: async (vis, timefilter) => {
const { convertGoalToLens } = await import('../convert_to_lens');
return vis ? convertGoalToLens(vis, timefilter) : null;
},
getExpressionVariables: async (vis, timeFilter) => {
const { convertGoalToLens } = await import('../convert_to_lens');
return {
canNavigateToLens: Boolean(vis?.params ? await convertGoalToLens(vis, timeFilter) : null),
};
Expand Down
17 changes: 1 addition & 16 deletions src/plugins/vis_types/heatmap/public/convert_to_lens/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,16 @@
* Side Public License, v 1.
*/

import { Column, ColumnWithMeta } from '@kbn/visualizations-plugin/common';
import {
convertToLensModule,
getDataViewByIndexPatternId,
} from '@kbn/visualizations-plugin/public';
import { excludeMetaFromColumn } from '@kbn/visualizations-plugin/common/convert_to_lens';
import { v4 as uuidv4 } from 'uuid';
import { getDataViewsStart } from '../services';
import { getConfiguration } from './configurations';
import { ConvertHeatmapToLensVisualization } from './types';

export const isColumnWithMeta = (column: Column): column is ColumnWithMeta => {
if ((column as ColumnWithMeta).meta) {
return true;
}
return false;
};

export const excludeMetaFromColumn = (column: Column) => {
if (isColumnWithMeta(column)) {
const { meta, ...rest } = column;
return rest;
}
return column;
};

export const convertToLens: ConvertHeatmapToLensVisualization = async (vis, timefilter) => {
if (!timefilter) {
return null;
Expand Down
7 changes: 5 additions & 2 deletions src/plugins/vis_types/heatmap/public/vis_type/heatmap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import { VIS_EVENT_TO_TRIGGER, VisTypeDefinition } from '@kbn/visualizations-plu
import { HeatmapTypeProps, HeatmapVisParams, AxisType, ScaleType } from '../types';
import { toExpressionAst } from '../to_ast';
import { getHeatmapOptions } from '../editor/components';
import { convertToLens } from '../convert_to_lens';

export const getHeatmapVisTypeDefinition = ({
showElasticChartsOptions = false,
Expand Down Expand Up @@ -145,8 +144,12 @@ export const getHeatmapVisTypeDefinition = ({
],
},
requiresSearch: true,
navigateToLens: async (vis, timefilter) => (vis ? convertToLens(vis, timefilter) : null),
navigateToLens: async (vis, timefilter) => {
const { convertToLens } = await import('../convert_to_lens');
return vis ? convertToLens(vis, timefilter) : null;
},
getExpressionVariables: async (vis, timeFilter) => {
const { convertToLens } = await import('../convert_to_lens');
return {
canNavigateToLens: Boolean(vis?.params ? await convertToLens(vis, timeFilter) : null),
};
Expand Down
21 changes: 3 additions & 18 deletions src/plugins/vis_types/metric/public/convert_to_lens/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,14 @@
*/

import { v4 as uuidv4 } from 'uuid';
import { Column, ColumnWithMeta } from '@kbn/visualizations-plugin/common';
import {
convertToLensModule,
getDataViewByIndexPatternId,
} from '@kbn/visualizations-plugin/public';
import { excludeMetaFromColumn } from '@kbn/visualizations-plugin/common/convert_to_lens';
import { getDataViewsStart } from '../services';
import { ConvertMetricVisToLensVisualization } from './types';

export const isColumnWithMeta = (column: Column): column is ColumnWithMeta => {
if ((column as ColumnWithMeta).meta) {
return true;
}
return false;
};

export const excludeMetaFromColumn = (column: Column) => {
if (isColumnWithMeta(column)) {
const { meta, ...rest } = column;
return rest;
}
return column;
};
import { getConfiguration } from './configurations';

export const convertToLens: ConvertMetricVisToLensVisualization = async (vis, timefilter) => {
if (!timefilter) {
Expand All @@ -42,8 +28,7 @@ export const convertToLens: ConvertMetricVisToLensVisualization = async (vis, ti
return null;
}

const [{ getColumnsFromVis, getPalette, getPercentageModeConfig }, { getConfiguration }] =
await Promise.all([convertToLensModule, import('./configurations')]);
const { getColumnsFromVis, getPalette, getPercentageModeConfig } = await convertToLensModule;

const percentageModeConfig = getPercentageModeConfig(vis.params.metric);
const layers = getColumnsFromVis(
Expand Down
7 changes: 5 additions & 2 deletions src/plugins/vis_types/metric/public/metric_vis_type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import { AggGroupNames } from '@kbn/data-plugin/public';
import { MetricVisOptions } from './components';
import { toExpressionAst } from './to_ast';
import { VisParams } from './types';
import { convertToLens } from './convert_to_lens';

export const createMetricVisTypeDefinition = (): VisTypeDefinition<VisParams> => ({
name: 'metric',
Expand Down Expand Up @@ -103,8 +102,12 @@ export const createMetricVisTypeDefinition = (): VisTypeDefinition<VisParams> =>
],
},
requiresSearch: true,
navigateToLens: async (vis, timefilter) => (vis ? convertToLens(vis, timefilter) : null),
navigateToLens: async (vis, timefilter) => {
const { convertToLens } = await import('./convert_to_lens');
return vis ? convertToLens(vis, timefilter) : null;
},
getExpressionVariables: async (vis, timeFilter) => {
const { convertToLens } = await import('./convert_to_lens');
return {
canNavigateToLens: Boolean(vis?.params ? await convertToLens(vis, timeFilter) : null),
};
Expand Down
17 changes: 1 addition & 16 deletions src/plugins/vis_types/pie/public/convert_to_lens/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,16 @@
* Side Public License, v 1.
*/

import { Column, ColumnWithMeta } from '@kbn/visualizations-plugin/common';
import {
convertToLensModule,
getDataViewByIndexPatternId,
} from '@kbn/visualizations-plugin/public';
import { excludeMetaFromColumn } from '@kbn/visualizations-plugin/common/convert_to_lens';
import { v4 as uuidv4 } from 'uuid';
import { getDataViewsStart } from '../services';
import { getConfiguration } from './configurations';
import { ConvertPieToLensVisualization } from './types';

export const isColumnWithMeta = (column: Column): column is ColumnWithMeta => {
if ((column as ColumnWithMeta).meta) {
return true;
}
return false;
};

export const excludeMetaFromColumn = (column: Column) => {
if (isColumnWithMeta(column)) {
const { meta, ...rest } = column;
return rest;
}
return column;
};

export const convertToLens: ConvertPieToLensVisualization = async (vis, timefilter) => {
if (!timefilter) {
return null;
Expand Down
7 changes: 5 additions & 2 deletions src/plugins/vis_types/pie/public/vis_type/pie.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import { DEFAULT_PERCENT_DECIMALS } from '../../common';
import { PieTypeProps } from '../types';
import { toExpressionAst } from '../to_ast';
import { getPieOptions } from '../editor/components';
import { convertToLens } from '../convert_to_lens';

export const getPieVisTypeDefinition = ({
showElasticChartsOptions = false,
Expand Down Expand Up @@ -122,8 +121,12 @@ export const getPieVisTypeDefinition = ({
},
hierarchicalData: true,
requiresSearch: true,
navigateToLens: async (vis, timefilter) => (vis ? convertToLens(vis, timefilter) : null),
navigateToLens: async (vis, timefilter) => {
const { convertToLens } = await import('../convert_to_lens');
return vis ? convertToLens(vis, timefilter) : null;
},
getExpressionVariables: async (vis, timeFilter) => {
const { convertToLens } = await import('../convert_to_lens');
return {
canNavigateToLens: Boolean(vis?.params ? await convertToLens(vis, timeFilter) : null),
};
Expand Down
18 changes: 2 additions & 16 deletions src/plugins/vis_types/table/public/convert_to_lens/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,18 @@
*/

import { METRIC_TYPES } from '@kbn/data-plugin/common';
import { Column, ColumnWithMeta, SchemaConfig } from '@kbn/visualizations-plugin/common';
import { SchemaConfig } from '@kbn/visualizations-plugin/common';
import {
convertToLensModule,
getVisSchemas,
getDataViewByIndexPatternId,
} from '@kbn/visualizations-plugin/public';
import { excludeMetaFromColumn } from '@kbn/visualizations-plugin/common/convert_to_lens';
import { v4 as uuidv4 } from 'uuid';
import { getDataViewsStart } from '../services';
import { getConfiguration } from './configurations';
import { ConvertTableToLensVisualization } from './types';

export const isColumnWithMeta = (column: Column): column is ColumnWithMeta => {
if ((column as ColumnWithMeta).meta) {
return true;
}
return false;
};

export const excludeMetaFromColumn = (column: Column) => {
if (isColumnWithMeta(column)) {
const { meta, ...rest } = column;
return rest;
}
return column;
};

export const convertToLens: ConvertTableToLensVisualization = async (vis, timefilter) => {
if (!timefilter) {
return null;
Expand Down
7 changes: 5 additions & 2 deletions src/plugins/vis_types/table/public/table_vis_type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import { VIS_EVENT_TO_TRIGGER, VisTypeDefinition } from '@kbn/visualizations-plu
import { TableVisParams, VIS_TYPE_TABLE } from '../common';
import { TableOptions } from './components/table_vis_options_lazy';
import { toExpressionAst } from './to_ast';
import { convertToLens } from './convert_to_lens';

export const tableVisTypeDefinition: VisTypeDefinition<TableVisParams> = {
name: VIS_TYPE_TABLE,
Expand Down Expand Up @@ -103,8 +102,12 @@ export const tableVisTypeDefinition: VisTypeDefinition<TableVisParams> = {
hasPartialRows: (vis) => vis.params.showPartialRows,
hierarchicalData: (vis) => vis.params.showPartialRows || vis.params.showMetricsAtAllLevels,
requiresSearch: true,
navigateToLens: async (vis, timefilter) => (vis ? convertToLens(vis, timefilter) : null),
navigateToLens: async (vis, timefilter) => {
const { convertToLens } = await import('./convert_to_lens');
return vis ? convertToLens(vis, timefilter) : null;
},
getExpressionVariables: async (vis, timeFilter) => {
const { convertToLens } = await import('./convert_to_lens');
return {
canNavigateToLens: Boolean(vis?.params ? await convertToLens(vis, timeFilter) : null),
};
Expand Down
6 changes: 4 additions & 2 deletions src/plugins/vis_types/tagcloud/kibana.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@
"data",
"expressions",
"visualizations",
"charts"
"charts",
"dataViews"
],
"requiredBundles": [
"kibanaReact",
"visDefaultEditor"
"visDefaultEditor",
"kibanaUtils"
]
}
}
Loading

0 comments on commit e8e5cec

Please sign in to comment.