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] Get rid of giant union type #118848

Merged
merged 8 commits into from
Nov 19, 2021
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
3 changes: 2 additions & 1 deletion x-pack/examples/embedded_lens_example/public/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
PersistedIndexPatternLayer,
XYState,
LensEmbeddableInput,
DateHistogramIndexPatternColumn,
} from '../../../plugins/lens/public';
import { StartDependencies } from './plugin';

Expand Down Expand Up @@ -55,7 +56,7 @@ function getLensAttributes(
params: { interval: 'auto' },
scale: 'interval',
sourceField: defaultIndexPattern.timeFieldName!,
},
} as DateHistogramIndexPatternColumn,
},
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,18 @@ import type { Filter } from '@kbn/es-query';
import type { IndexPattern } from '../../../../../../../../../src/plugins/data/common';
import type { CombinedQuery } from '../../../../index_data_visualizer/types/combined_query';
import type {
IndexPatternColumn,
DateHistogramIndexPatternColumn,
GenericIndexPatternColumn,
RangeIndexPatternColumn,
TermsIndexPatternColumn,
TypedLensByValueInput,
XYLayerConfig,
} from '../../../../../../../lens/public';
import { FieldVisConfig } from '../../stats_table/types';
import { JOB_FIELD_TYPES } from '../../../../../../common';

interface ColumnsAndLayer {
columns: Record<string, IndexPatternColumn>;
columns: Record<string, GenericIndexPatternColumn>;
layer: XYLayerConfig;
}

Expand All @@ -32,7 +35,7 @@ const COUNT = i18n.translate('xpack.dataVisualizer.index.lensChart.countLabel',
export function getNumberSettings(item: FieldVisConfig, defaultIndexPattern: IndexPattern) {
// if index has no timestamp field
if (defaultIndexPattern.timeFieldName === undefined) {
const columns: Record<string, IndexPatternColumn> = {
const columns: Record<string, GenericIndexPatternColumn> = {
col1: {
label: item.fieldName!,
dataType: 'number',
Expand All @@ -44,7 +47,7 @@ export function getNumberSettings(item: FieldVisConfig, defaultIndexPattern: Ind
ranges: [],
},
sourceField: item.fieldName!,
},
} as RangeIndexPatternColumn,
col2: {
label: COUNT,
dataType: 'number',
Expand All @@ -64,7 +67,7 @@ export function getNumberSettings(item: FieldVisConfig, defaultIndexPattern: Ind
return { columns, layer };
}

const columns: Record<string, IndexPatternColumn> = {
const columns: Record<string, GenericIndexPatternColumn> = {
col2: {
dataType: 'number',
isBucketed: false,
Expand All @@ -83,7 +86,7 @@ export function getNumberSettings(item: FieldVisConfig, defaultIndexPattern: Ind
params: { interval: 'auto' },
scale: 'interval',
sourceField: defaultIndexPattern.timeFieldName!,
},
} as DateHistogramIndexPatternColumn,
};

const layer: XYLayerConfig = {
Expand All @@ -97,7 +100,7 @@ export function getNumberSettings(item: FieldVisConfig, defaultIndexPattern: Ind
return { columns, layer };
}
export function getDateSettings(item: FieldVisConfig) {
const columns: Record<string, IndexPatternColumn> = {
const columns: Record<string, GenericIndexPatternColumn> = {
col2: {
dataType: 'number',
isBucketed: false,
Expand All @@ -114,7 +117,7 @@ export function getDateSettings(item: FieldVisConfig) {
params: { interval: 'auto' },
scale: 'interval',
sourceField: item.fieldName!,
},
} as DateHistogramIndexPatternColumn,
};
const layer: XYLayerConfig = {
accessors: ['col2'],
Expand All @@ -128,7 +131,7 @@ export function getDateSettings(item: FieldVisConfig) {
}

export function getKeywordSettings(item: FieldVisConfig) {
const columns: Record<string, IndexPatternColumn> = {
const columns: Record<string, GenericIndexPatternColumn> = {
col1: {
label: TOP_VALUES_LABEL,
dataType: 'string',
Expand All @@ -140,7 +143,7 @@ export function getKeywordSettings(item: FieldVisConfig) {
orderDirection: 'desc',
},
sourceField: item.fieldName!,
},
} as TermsIndexPatternColumn,
col2: {
label: COUNT,
dataType: 'number',
Expand All @@ -161,7 +164,7 @@ export function getKeywordSettings(item: FieldVisConfig) {
}

export function getBooleanSettings(item: FieldVisConfig) {
const columns: Record<string, IndexPatternColumn> = {
const columns: Record<string, GenericIndexPatternColumn> = {
col1: {
label: TOP_VALUES_LABEL,
dataType: 'string',
Expand All @@ -173,7 +176,7 @@ export function getBooleanSettings(item: FieldVisConfig) {
orderDirection: 'desc',
},
sourceField: item.fieldName!,
},
} as TermsIndexPatternColumn,
col2: {
label: COUNT,
dataType: 'number',
Expand Down
4 changes: 2 additions & 2 deletions x-pack/plugins/lens/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ export type { DatatableVisualizationState } from './datatable_visualization/visu
export type {
IndexPatternPersistedState,
PersistedIndexPatternLayer,
IndexPatternColumn,
FieldBasedIndexPatternColumn,
OperationType,
IncompleteColumn,
GenericIndexPatternColumn,
FieldBasedIndexPatternColumn,
FiltersIndexPatternColumn,
RangeIndexPatternColumn,
TermsIndexPatternColumn,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { fieldFormatsServiceMock } from '../../../../../src/plugins/field_format
import { indexPatternFieldEditorPluginMock } from '../../../../../src/plugins/index_pattern_field_editor/public/mocks';
import { getFieldByNameFactory } from './pure_helpers';
import { uiActionsPluginMock } from '../../../../../src/plugins/ui_actions/public/mocks';
import { TermsIndexPatternColumn } from './operations';

const fieldsOne = [
{
Expand Down Expand Up @@ -173,7 +174,7 @@ const initialState: IndexPatternPrivateState = {
type: 'alphabetical',
},
},
},
} as TermsIndexPatternColumn,
col2: {
label: 'My Op',
dataType: 'number',
Expand All @@ -200,7 +201,7 @@ const initialState: IndexPatternPrivateState = {
type: 'alphabetical',
},
},
},
} as TermsIndexPatternColumn,
col2: {
label: 'My Op',
dataType: 'number',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import { mount } from 'enzyme';
import React from 'react';
import { BucketNestingEditor } from './bucket_nesting_editor';
import { IndexPatternColumn } from '../indexpattern';
import { GenericIndexPatternColumn } from '../indexpattern';
import { IndexPatternField } from '../types';

const fieldMap: Record<string, IndexPatternField> = {
Expand All @@ -20,7 +20,7 @@ const fieldMap: Record<string, IndexPatternField> = {
const getFieldByName = (name: string): IndexPatternField | undefined => fieldMap[name];

describe('BucketNestingEditor', () => {
function mockCol(col: Partial<IndexPatternColumn> = {}): IndexPatternColumn {
function mockCol(col: Partial<GenericIndexPatternColumn> = {}): GenericIndexPatternColumn {
const result = {
dataType: 'string',
isBucketed: true,
Expand All @@ -35,7 +35,7 @@ describe('BucketNestingEditor', () => {
...col,
};

return result as IndexPatternColumn;
return result as GenericIndexPatternColumn;
}

it('should display the top level grouping when at the root', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { i18n } from '@kbn/i18n';
import { EuiFormRow, EuiSwitch, EuiSelect } from '@elastic/eui';
import { IndexPatternLayer, IndexPatternField } from '../types';
import { hasField } from '../utils';
import { IndexPatternColumn } from '../operations';
import { GenericIndexPatternColumn } from '../operations';

function nestColumn(columnOrder: string[], outer: string, inner: string) {
const result = columnOrder.filter((c) => c !== inner);
Expand All @@ -22,7 +22,7 @@ function nestColumn(columnOrder: string[], outer: string, inner: string) {
}

function getFieldName(
column: IndexPatternColumn,
column: GenericIndexPatternColumn,
getFieldByName: (name: string) => IndexPatternField | undefined
) {
return hasField(column)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
} from '@elastic/eui';
import { IndexPatternDimensionEditorProps } from './dimension_panel';
import { OperationSupportMatrix } from './operation_support';
import { IndexPatternColumn } from '../indexpattern';
import { GenericIndexPatternColumn } from '../indexpattern';
import {
operationDefinitionMap,
getOperationDisplay,
Expand Down Expand Up @@ -62,7 +62,7 @@ import type { TemporaryState } from './dimensions_editor_helpers';
const operationPanels = getOperationDisplay();

export interface DimensionEditorProps extends IndexPatternDimensionEditorProps {
selectedColumn?: IndexPatternColumn;
selectedColumn?: GenericIndexPatternColumn;
layerType: LayerType;
operationSupportMatrix: OperationSupportMatrix;
currentIndexPattern: IndexPattern;
Expand Down
Loading