Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Lens] Bundle Size Reduction #142938

Merged
merged 5 commits into from
Oct 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/plugins/chart_expressions/expression_xy/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
export const PLUGIN_ID = 'expressionXy';
export const PLUGIN_NAME = 'expressionXy';

export { LayerTypes } from './constants';

export type {
XYArgs,
EndValue,
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/chart_expressions/expression_xy/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ export function plugin() {
return new ExpressionXyPlugin();
}

export { LayerTypes } from '../common';

export type { ExpressionXyPluginSetup, ExpressionXyPluginStart } from './types';
6 changes: 0 additions & 6 deletions x-pack/plugins/lens/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,6 @@ export const LegendDisplay = {
HIDE: 'hide',
} as const;

export const layerTypes = {
DATA: 'data',
REFERENCELINE: 'referenceLine',
ANNOTATIONS: 'annotations',
} as const;

// might collide with user-supplied field names, try to make as unique as possible
export const DOCUMENT_FIELD_NAME = '___records___';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import type { Direction } from '@elastic/eui';
import type { PaletteOutput, CustomPaletteParams } from '@kbn/coloring';
import type { CustomPaletteState } from '@kbn/charts-plugin/common';
import type { ExpressionFunctionDefinition, DatatableColumn } from '@kbn/expressions-plugin/common';
import { SortingHint } from '../..';
import type { SortingHint } from '../..';

export type LensGridDirection = 'none' | Direction;

Expand Down
3 changes: 0 additions & 3 deletions x-pack/plugins/lens/common/expressions/datatable/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,5 @@

export * from './datatable_column';
export * from './datatable';
export * from './summary';
export * from './transpose_helpers';
export * from './utils';

export type { DatatableProps } from './types';
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@

import versionCompare from 'compare-versions';
import valid from 'semver/functions/valid';
import ipaddr from 'ipaddr.js';
import type { IPv4, IPv6 } from 'ipaddr.js';
import ipaddr, { type IPv4, type IPv6 } from 'ipaddr.js';
import type { FieldFormat } from '@kbn/field-formats-plugin/common';

function isIPv6Address(ip: IPv4 | IPv6): ip is IPv6 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ export function getSummaryRowOptions(): Array<{
];
}

/** @internal **/
export function computeSummaryRowForColumn(
columnArgs: ColumnConfigArg,
table: Datatable,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const TRANSPOSE_SEPARATOR = '---';

const TRANSPOSE_VISUAL_SEPARATOR = '›';

export function getTransposeId(value: string, columnId: string) {
function getTransposeId(value: string, columnId: string) {
return `${value}${TRANSPOSE_SEPARATOR}${columnId}`;
}

Expand All @@ -36,6 +36,7 @@ export function getOriginalId(id: string) {
*
* If the table is tranposed by multiple columns, this process is repeated on top of the previous transformation.
*
* @internal
* @param args Arguments for the table visualization
* @param firstTable datatable object containing the actual data
* @param formatters Formatters for all columns to transpose columns by actual display values
Expand Down
15 changes: 3 additions & 12 deletions x-pack/plugins/lens/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,9 @@ import type { $Values } from '@kbn/utility-types';
import type { CustomPaletteParams, PaletteOutput } from '@kbn/coloring';
import type { IFieldFormat, SerializedFieldFormat } from '@kbn/field-formats-plugin/common';
import type { ColorMode } from '@kbn/charts-plugin/common';
import { LayerTypes } from '@kbn/expression-xy-plugin/common';
import type { LegendSize } from '@kbn/visualizations-plugin/common';
import {
CategoryDisplay,
layerTypes,
LegendDisplay,
NumberDisplay,
PieChartTypes,
} from './constants';
import { CategoryDisplay, LegendDisplay, NumberDisplay, PieChartTypes } from './constants';

export type { OriginalColumn } from './expressions/map_to_columns';

Expand All @@ -44,11 +39,7 @@ export interface PersistableFilter extends Filter {

export type SortingHint = 'version';

export type CustomPaletteParamsConfig = CustomPaletteParams & {
maxSteps?: number;
};

export type LayerType = typeof layerTypes[keyof typeof layerTypes];
export type LayerType = typeof LayerTypes[keyof typeof LayerTypes];

export type ValueLabelConfig = 'hide' | 'show';

Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/lens/kibana.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@
"expressionGauge",
"expressionMetricVis",
"expressionHeatmap",
"expressionXY",
"eventAnnotation",
"unifiedSearch",
"unifiedFieldList"
],
"optionalPlugins": [
"expressionXY",
"usageCollection",
"taskManager",
"globalSearch",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import {
EuiFlexGroup,
} from '@elastic/eui';
import { i18n } from '@kbn/i18n';

import { LayerType, layerTypes } from '../../../../common';
import { LayerTypes } from '@kbn/expression-xy-plugin/public';
import type { LayerType } from '../../../../common';
import type { FramePublicAPI, Visualization } from '../../../types';

interface AddLayerButtonProps {
Expand All @@ -29,7 +29,7 @@ interface AddLayerButtonProps {
}

export function getLayerType(visualization: Visualization, state: unknown, layerId: string) {
return visualization.getLayerType(layerId, state) || layerTypes.DATA;
return visualization.getLayerType(layerId, state) || LayerTypes.DATA;
}

export function AddLayerButton({
Expand Down Expand Up @@ -120,7 +120,7 @@ export function AddLayerButton({
toolTipContent,
disabled,
name:
type === layerTypes.ANNOTATIONS ? (
type === LayerTypes.ANNOTATIONS ? (
<EuiFlexGroup gutterSize="m">
<EuiFlexItem>
<span className="lnsLayerAddButton__label">{label}</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ import { UiActionsStart } from '@kbn/ui-actions-plugin/public';
import { uiActionsPluginMock } from '@kbn/ui-actions-plugin/public/mocks';
import { generateId } from '../../../id_generator';
import { mountWithProvider } from '../../../mocks';
import { LayerType, layerTypes } from '../../../../common';
import { LayerTypes } from '@kbn/expression-xy-plugin/public';
import type { LayerType } from '../../../../common';
import { ReactWrapper } from 'enzyme';
import { addLayer } from '../../../state_management';
import { AddLayerButton } from './add_layer';
Expand Down Expand Up @@ -266,7 +267,7 @@ describe('ConfigPanel', () => {
describe('initial default value', () => {
function clickToAddLayer(
instance: ReactWrapper,
layerType: LayerType = layerTypes.REFERENCELINE
layerType: LayerType = LayerTypes.REFERENCELINE
) {
act(() => {
instance.find('[data-test-subj="lnsLayerAddButton"]').first().simulate('click');
Expand Down Expand Up @@ -295,9 +296,9 @@ describe('ConfigPanel', () => {
const visualizationMap = mockVisualizationMap();

visualizationMap.testVis.getSupportedLayers = jest.fn(() => [
{ type: layerTypes.DATA, label: 'Data Layer' },
{ type: LayerTypes.DATA, label: 'Data Layer' },
{
type: layerTypes.REFERENCELINE,
type: LayerTypes.REFERENCELINE,
label: 'Reference layer',
},
]);
Expand All @@ -318,7 +319,7 @@ describe('ConfigPanel', () => {

visualizationMap.testVis.getSupportedLayers = jest.fn(() => [
{
type: layerTypes.DATA,
type: LayerTypes.DATA,
label: 'Data Layer',
initialDimensions: [
{
Expand All @@ -329,7 +330,7 @@ describe('ConfigPanel', () => {
],
},
{
type: layerTypes.REFERENCELINE,
type: LayerTypes.REFERENCELINE,
label: 'Reference layer',
},
]);
Expand All @@ -345,9 +346,9 @@ describe('ConfigPanel', () => {
const datasourceMap = mockDatasourceMap();
const visualizationMap = mockVisualizationMap();
visualizationMap.testVis.getSupportedLayers = jest.fn(() => [
{ type: layerTypes.DATA, label: 'Data Layer' },
{ type: LayerTypes.DATA, label: 'Data Layer' },
{
type: layerTypes.REFERENCELINE,
type: LayerTypes.REFERENCELINE,
label: 'Reference layer',
initialDimensions: [
{
Expand Down Expand Up @@ -383,7 +384,7 @@ describe('ConfigPanel', () => {
const visualizationMap = mockVisualizationMap();
visualizationMap.testVis.getSupportedLayers = jest.fn(() => [
{
type: layerTypes.DATA,
type: LayerTypes.DATA,
label: 'Data Layer',
initialDimensions: [
{
Expand Down Expand Up @@ -420,7 +421,7 @@ describe('ConfigPanel', () => {
visualizationMap.testVis.setDimension = jest.fn();
visualizationMap.testVis.getSupportedLayers = jest.fn(() => [
{
type: layerTypes.DATA,
type: LayerTypes.DATA,
label: 'Data Layer',
initialDimensions: [
{
Expand All @@ -431,11 +432,11 @@ describe('ConfigPanel', () => {
],
},
{
type: layerTypes.REFERENCELINE,
type: LayerTypes.REFERENCELINE,
label: 'Reference layer',
},
{
type: layerTypes.ANNOTATIONS,
type: LayerTypes.ANNOTATIONS,
label: 'Annotations Layer',
noDatasource: true,
initialDimensions: [
Expand All @@ -451,7 +452,7 @@ describe('ConfigPanel', () => {
datasourceMap.testDatasource.initializeDimension = jest.fn();
const props = getDefaultProps({ visualizationMap, datasourceMap });
const { instance, lensStore } = await prepareAndMountComponent(props);
await clickToAddLayer(instance, layerTypes.ANNOTATIONS);
await clickToAddLayer(instance, LayerTypes.ANNOTATIONS);
expect(lensStore.dispatch).toHaveBeenCalledTimes(1);

expect(visualizationMap.testVis.setDimension).toHaveBeenCalledWith({
Expand All @@ -478,9 +479,9 @@ describe('ConfigPanel', () => {
const visualizationMap = mockVisualizationMap();

visualizationMap.testVis.getSupportedLayers = jest.fn(() => [
{ type: layerTypes.DATA, label: 'Data Layer' },
{ type: LayerTypes.DATA, label: 'Data Layer' },
{
type: layerTypes.REFERENCELINE,
type: LayerTypes.REFERENCELINE,
label: 'Reference layer',
},
]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ import {
import { i18n } from '@kbn/i18n';
import { toMountPoint } from '@kbn/kibana-react-plugin/public';
import { Storage } from '@kbn/kibana-utils-plugin/public';
import { LayerTypes } from '@kbn/expression-xy-plugin/public';
import type { LayerAction, Visualization } from '../../../../types';
import { LOCAL_STORAGE_LENS_KEY } from '../../../../settings_storage';
import { type LayerType, layerTypes } from '../../../..';
import type { LayerType } from '../../../../../common/types';

interface RemoveLayerAction {
execute: () => void;
Expand Down Expand Up @@ -54,11 +55,11 @@ const getButtonCopy = (layerType: LayerType, canBeRemoved?: boolean, isOnlyLayer
let ariaLabel;

const layerTypeCopy =
layerType === layerTypes.DATA
layerType === LayerTypes.DATA
? i18n.translate('xpack.lens.modalTitle.layerType.data', {
defaultMessage: 'visualization',
})
: layerType === layerTypes.ANNOTATIONS
: layerType === LayerTypes.ANNOTATIONS
? i18n.translate('xpack.lens.modalTitle.layerType.annotation', {
defaultMessage: 'annotations',
})
Expand All @@ -80,9 +81,9 @@ const getButtonCopy = (layerType: LayerType, canBeRemoved?: boolean, isOnlyLayer
modalDesc = modalDescClear;
}

if (layerType === layerTypes.ANNOTATIONS) {
if (layerType === LayerTypes.ANNOTATIONS) {
modalDesc = modalDescAnnotation;
} else if (layerType === layerTypes.REFERENCELINE) {
} else if (layerType === LayerTypes.REFERENCELINE) {
modalDesc = modalDescRefLine;
}

Expand Down Expand Up @@ -200,7 +201,7 @@ const RemoveConfirmModal = ({

export const getRemoveLayerAction = (props: RemoveLayerAction): LayerAction => {
const { ariaLabel, modalTitle, modalDesc } = getButtonCopy(
props.layerType || layerTypes.DATA,
props.layerType || LayerTypes.DATA,
!!props.activeVisualization.removeLayer,
props.isOnlyLayer
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
* 2.0.
*/

import { Datatable } from '@kbn/expressions-plugin/common';
import type { Datatable } from '@kbn/expressions-plugin/common';
import type { PaletteOutput } from '@kbn/coloring';
import { VisualizeFieldContext } from '@kbn/ui-actions-plugin/public';
import type { VisualizeFieldContext } from '@kbn/ui-actions-plugin/public';
import { LayerTypes } from '@kbn/expression-xy-plugin/public';
import { showMemoizedErrorNotification } from '../../lens_ui_errors';
import {
import type {
Visualization,
Datasource,
TableSuggestion,
Expand All @@ -20,8 +21,8 @@ import {
Suggestion,
DatasourceLayers,
} from '../../types';
import { DragDropIdentifier } from '../../drag_drop';
import { LayerType, layerTypes } from '../../../common';
import type { DragDropIdentifier } from '../../drag_drop';
import type { LayerType } from '../../../common';
import { getLayerType } from './config_panel/add_layer';
import {
LensDispatch,
Expand Down Expand Up @@ -83,7 +84,7 @@ export function getSuggestions({
}, {} as Record<string, LayerType>);

const isLayerSupportedByVisualization = (layerId: string, supportedTypes: LayerType[]) =>
supportedTypes.includes(layerTypesMap[layerId] ?? layerTypes.DATA);
supportedTypes.includes(layerTypesMap[layerId] ?? LayerTypes.DATA);

// Collect all table suggestions from available datasources
const datasourceTableSuggestions = datasources.flatMap(([datasourceId, datasource]) => {
Expand Down Expand Up @@ -112,14 +113,14 @@ export function getSuggestions({
dataSourceSuggestions = datasource.getDatasourceSuggestionsForField(
datasourceState,
field,
(layerId) => isLayerSupportedByVisualization(layerId, [layerTypes.DATA]), // a field dragged to workspace should added to data layer
(layerId) => isLayerSupportedByVisualization(layerId, [LayerTypes.DATA]), // a field dragged to workspace should added to data layer
dataViews.indexPatterns
);
} else {
dataSourceSuggestions = datasource.getDatasourceSuggestionsFromCurrentState(
datasourceState,
dataViews.indexPatterns,
(layerId) => isLayerSupportedByVisualization(layerId, [layerTypes.DATA]),
(layerId) => isLayerSupportedByVisualization(layerId, [LayerTypes.DATA]),
activeData
);
}
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/lens/public/expressions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { mapToColumns } from '../common/expressions/map_to_columns/map_to_column
import { formatColumn } from '../common/expressions/format_column';
import { counterRate } from '../common/expressions/counter_rate';
import { getTimeScale } from '../common/expressions/time_scale/time_scale';
import { collapse } from '../common/expressions';
import { collapse } from '../common/expressions/collapse';

type TimeScaleArguments = Parameters<typeof getTimeScale>;

Expand Down
5 changes: 4 additions & 1 deletion x-pack/plugins/lens/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* 2.0.
*/

import { LayerTypes } from '@kbn/expression-xy-plugin/public';
import { LensPlugin } from './plugin';

export type {
Expand Down Expand Up @@ -101,9 +102,11 @@ export type {
ReferenceLineLayerArgs,
ReferenceLineLayerConfig,
} from '@kbn/expression-xy-plugin/common';

export type { LensEmbeddableInput, LensSavedObjectAttributes, Embeddable } from './embeddable';

export { layerTypes } from '../common';
/** @deprecated Please use LayerTypes from @kbn/expression-xy-plugin **/
export const layerTypes = LayerTypes;

export type { LensPublicStart, LensPublicSetup } from './plugin';

Expand Down
Loading