Skip to content

Commit

Permalink
get rid of giant union type
Browse files Browse the repository at this point in the history
  • Loading branch information
flash1293 committed Nov 17, 2021
1 parent 349434e commit e6426f9
Show file tree
Hide file tree
Showing 54 changed files with 812 additions and 749 deletions.
2 changes: 0 additions & 2 deletions x-pack/plugins/lens/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ export type { DatatableVisualizationState } from './datatable_visualization/visu
export type {
IndexPatternPersistedState,
PersistedIndexPatternLayer,
IndexPatternColumn,
FieldBasedIndexPatternColumn,
OperationType,
IncompleteColumn,
FiltersIndexPatternColumn,
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
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@ import { IUiSettingsClient, SavedObjectsClientContract, HttpSetup, CoreSetup } f
import { IStorageWrapper } from 'src/plugins/kibana_utils/public';
import { generateId } from '../../id_generator';
import { IndexPatternPrivateState } from '../types';
import { IndexPatternColumn, replaceColumn } from '../operations';
import {
FiltersIndexPatternColumn,
GenericIndexPatternColumn,
replaceColumn,
TermsIndexPatternColumn,
} from '../operations';
import { documentField } from '../document_field';
import { OperationMetadata } from '../../types';
import { DateHistogramIndexPatternColumn } from '../operations/definitions/date_histogram';
Expand Down Expand Up @@ -108,7 +113,7 @@ const expectedIndexPatterns = {
},
};

const bytesColumn: IndexPatternColumn = {
const bytesColumn: GenericIndexPatternColumn = {
label: 'Max of bytes',
dataType: 'number',
isBucketed: false,
Expand All @@ -133,7 +138,7 @@ describe('IndexPatternDimensionEditorPanel', () => {
let setState: jest.Mock;
let defaultProps: IndexPatternDimensionEditorProps;

function getStateWithColumns(columns: Record<string, IndexPatternColumn>) {
function getStateWithColumns(columns: Record<string, GenericIndexPatternColumn>) {
return {
...state,
layers: { first: { ...state.layers.first, columns, columnOrder: Object.keys(columns) } },
Expand Down Expand Up @@ -171,7 +176,7 @@ describe('IndexPatternDimensionEditorPanel', () => {
interval: '1d',
},
sourceField: 'timestamp',
},
} as DateHistogramIndexPatternColumn,
},
incompleteColumns: {},
},
Expand Down Expand Up @@ -264,7 +269,7 @@ describe('IndexPatternDimensionEditorPanel', () => {
// Private
operationType: 'filters',
params: { filters: [] },
},
} as FiltersIndexPatternColumn,
})}
/>
);
Expand Down Expand Up @@ -427,7 +432,7 @@ describe('IndexPatternDimensionEditorPanel', () => {
operationType: 'date_histogram',
sourceField: '@timestamp',
params: { interval: 'auto' },
},
} as DateHistogramIndexPatternColumn,
col1: {
label: 'Counter rate',
dataType: 'number',
Expand Down Expand Up @@ -464,7 +469,7 @@ describe('IndexPatternDimensionEditorPanel', () => {
operationType: 'date_histogram',
sourceField: '@timestamp',
params: { interval: 'auto' },
},
} as DateHistogramIndexPatternColumn,
col1: {
label: 'Cumulative sum',
dataType: 'number',
Expand Down Expand Up @@ -839,7 +844,7 @@ describe('IndexPatternDimensionEditorPanel', () => {
// Private
operationType: 'filters',
params: { filters: [] },
},
} as FiltersIndexPatternColumn,
})}
/>
);
Expand Down Expand Up @@ -1066,7 +1071,7 @@ describe('IndexPatternDimensionEditorPanel', () => {
});

describe('time scaling', () => {
function getProps(colOverrides: Partial<IndexPatternColumn>) {
function getProps(colOverrides: Partial<GenericIndexPatternColumn>) {
return {
...defaultProps,
state: getStateWithColumns({
Expand All @@ -1080,15 +1085,15 @@ describe('IndexPatternDimensionEditorPanel', () => {
params: {
interval: '1d',
},
},
} as DateHistogramIndexPatternColumn,
col2: {
dataType: 'number',
isBucketed: false,
label: 'Count of records',
operationType: 'count',
sourceField: 'Records',
...colOverrides,
} as IndexPatternColumn,
} as GenericIndexPatternColumn,
}),
columnId: 'col2',
};
Expand Down Expand Up @@ -1296,7 +1301,7 @@ describe('IndexPatternDimensionEditorPanel', () => {
});

describe('time shift', () => {
function getProps(colOverrides: Partial<IndexPatternColumn>) {
function getProps(colOverrides: Partial<GenericIndexPatternColumn>) {
return {
...defaultProps,
state: getStateWithColumns({
Expand All @@ -1310,15 +1315,15 @@ describe('IndexPatternDimensionEditorPanel', () => {
params: {
interval: '1d',
},
},
} as DateHistogramIndexPatternColumn,
col2: {
dataType: 'number',
isBucketed: false,
label: 'Count of records',
operationType: 'count',
sourceField: 'Records',
...colOverrides,
} as IndexPatternColumn,
} as GenericIndexPatternColumn,
}),
columnId: 'col2',
};
Expand All @@ -1334,7 +1339,7 @@ describe('IndexPatternDimensionEditorPanel', () => {
label: 'Count of records',
operationType: 'count',
sourceField: 'Records',
} as IndexPatternColumn,
} as GenericIndexPatternColumn,
}),
columnId: 'col2',
};
Expand Down Expand Up @@ -1483,7 +1488,7 @@ describe('IndexPatternDimensionEditorPanel', () => {
});

describe('filtering', () => {
function getProps(colOverrides: Partial<IndexPatternColumn>) {
function getProps(colOverrides: Partial<GenericIndexPatternColumn>) {
return {
...defaultProps,
state: getStateWithColumns({
Expand All @@ -1497,15 +1502,15 @@ describe('IndexPatternDimensionEditorPanel', () => {
params: {
interval: '1d',
},
},
} as DateHistogramIndexPatternColumn,
col2: {
dataType: 'number',
isBucketed: false,
label: 'Count of records',
operationType: 'count',
sourceField: 'Records',
...colOverrides,
} as IndexPatternColumn,
} as GenericIndexPatternColumn,
}),
columnId: 'col2',
};
Expand All @@ -1522,7 +1527,7 @@ describe('IndexPatternDimensionEditorPanel', () => {
orderBy: { type: 'alphabetical' },
size: 5,
},
})}
} as TermsIndexPatternColumn)}
/>
);
expect(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { IUiSettingsClient, SavedObjectsClientContract, HttpSetup } from 'kibana
import { IStorageWrapper } from 'src/plugins/kibana_utils/public';
import { DatasourceDimensionTriggerProps, DatasourceDimensionEditorProps } from '../../types';
import { DataPublicPluginStart } from '../../../../../../src/plugins/data/public';
import { IndexPatternColumn } from '../indexpattern';
import { GenericIndexPatternColumn } from '../indexpattern';
import { isColumnInvalid } from '../utils';
import { IndexPatternPrivateState } from '../types';
import { DimensionEditor } from './dimension_editor';
Expand Down Expand Up @@ -56,7 +56,7 @@ export const IndexPatternDimensionTriggerComponent = function IndexPatternDimens
[layer, columnId, currentIndexPattern, invalid]
);

const selectedColumn: IndexPatternColumn | null = layer.columns[props.columnId] ?? null;
const selectedColumn: GenericIndexPatternColumn | null = layer.columns[props.columnId] ?? null;

if (!selectedColumn) {
return null;
Expand Down Expand Up @@ -126,7 +126,7 @@ export const IndexPatternDimensionEditorComponent = function IndexPatternDimensi
}
const operationSupportMatrix = getOperationSupportMatrix(props);

const selectedColumn: IndexPatternColumn | null =
const selectedColumn: GenericIndexPatternColumn | null =
props.state.layers[layerId].columns[props.columnId] || null;
return (
<DimensionEditor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import './dimension_editor.scss';
import React from 'react';
import { i18n } from '@kbn/i18n';
import { EuiFormRow, EuiFieldText, EuiTabs, EuiTab, EuiCallOut } from '@elastic/eui';
import { IndexPatternColumn, operationDefinitionMap } from '../operations';
import { GenericIndexPatternColumn, operationDefinitionMap } from '../operations';
import { useDebouncedValue } from '../../shared_components';

export const formulaOperationName = 'formula';
Expand Down Expand Up @@ -176,7 +176,7 @@ export const DimensionEditorTabs = ({ tabs }: { tabs: DimensionEditorTab[] }) =>
};

export function getErrorMessage(
selectedColumn: IndexPatternColumn | undefined,
selectedColumn: GenericIndexPatternColumn | undefined,
incompleteOperation: boolean,
input: 'none' | 'field' | 'fullReference' | 'managedReference' | undefined,
fieldInvalid: boolean
Expand Down
Loading

0 comments on commit e6426f9

Please sign in to comment.