[Lens] Rename datasources (#142553)

* Rename to textBased instead of textBasedLanguages

* [Lens] Rename datasources to textBased and formBased

* Fix css

* [CI] Auto-commit changed files from 'node scripts/eslint --no-cache --fix'

* Move datasources under a common foler

* Fix types

* Revert css classes

* Add migration script

* Fix lens embeddable functional tests

* Fix types

* Fixes cases test

* Adds migration script test

* Revert

* Update jest integration test

* Fix security solution tests

* Fix jest test

* Address type nit

* Fix types

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
Stratoula Kalafateli 2022-10-12 11:25:24 +03:00 committed by GitHub
parent 005a6eabb5
commit 8c4976f25d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
271 changed files with 1309 additions and 1282 deletions

View file

@ -62,11 +62,11 @@ describe('checking migration metadata changes on all registered SO types', () =>
"app_search_telemetry": "7fc4fc08852bf0924ee29942bb394fda9aa8954d",
"application_usage_daily": "6e645e0b60ef3af2e8fde80963c2a4f09a190d61",
"application_usage_totals": "b2af3577dcd50bfae492b166a7804f69e2cc41dc",
"canvas-element": "5f32b99ba6ff9c1f17cc093591b975be65a27b9b",
"canvas-workpad": "b60252414fb6159a14f9febf98dbe41e5a8bf199",
"canvas-workpad-template": "c371cad0a8d61385f4782cab9a9063d3cf241ee0",
"canvas-element": "c27505dcf2970760bea8a0fe1d000253f0c40f08",
"canvas-workpad": "eb7b28a3b1c24af615edbf29becddf2e750a4bb5",
"canvas-workpad-template": "34454b811e32993eaa55c6ec85a7aecca00c4cfc",
"cases": "7ff5ce930146a2d6fc8fbf536ce2ee16e9df296f",
"cases-comments": "8cfbad4ede637305eb6fb79db680f03dc0ce5ec4",
"cases-comments": "d7c4c1d24e97620cd415e27e5eb7d5b5f2c5b461",
"cases-configure": "1afc414f5563a36e4612fa269193d3ed7277c7bd",
"cases-connector-mappings": "4b16d440af966e5d6e0fa33368bfa15d987a4b69",
"cases-telemetry": "16e261e7378a72acd0806f18df92525dd1da4f37",
@ -76,7 +76,7 @@ describe('checking migration metadata changes on all registered SO types', () =>
"core-usage-stats": "f40a213da2c597b0de94e364a4326a5a1baa4ca9",
"csp-rule-template": "3679c5f2431da8153878db79c78a4e695357fb61",
"csp_rule": "d2bb53ea5d2bdfba1a835ad8956dfcd2b2c32e19",
"dashboard": "0b0842b6aa40c125d64233fd81cee11080580dc2",
"dashboard": "742f2d9f110709fd8599b14f7766f38efc30de61",
"endpoint:user-artifact": "f94c250a52b30d0a2d32635f8b4c5bdabd1e25c0",
"endpoint:user-artifact-manifest": "8c14d49a385d5d1307d956aa743ec78de0b2be88",
"enterprise_search_telemetry": "fafcc8318528d34f721c42d1270787c52565bad5",
@ -103,7 +103,7 @@ describe('checking migration metadata changes on all registered SO types', () =>
"inventory-view": "bc2bd1e7ec7c186159447ab228d269f22bd39056",
"kql-telemetry": "29544cd7d3b767c5399878efae6bd724d24c03fd",
"legacy-url-alias": "7172dfd54f2e0c89fe263fd7095519b2d826a930",
"lens": "08769c789ad6d1b8a4d0cffebc9d9bb08bf01ad9",
"lens": "236ecd358ed3a4ecfc03ed676d958b64acf0b697",
"lens-ui-telemetry": "df2844565c9e18fed2bdb1f6cc3aadd58cf1e45b",
"map": "00ca6c4cf46ae59f70f1436262eb9f457b45eb14",
"maps-telemetry": "5adbde35bd50ec2b8e9ea5b96d4d9f886e31ecfb",

View file

@ -100,7 +100,7 @@ function getLensAttributes(
],
state: {
datasourceStates: {
indexpattern: {
formBased: {
layers: {
layer1: dataLayer!,
},

View file

@ -148,7 +148,7 @@ function getBaseAttributes(
],
state: {
datasourceStates: {
indexpattern: {
formBased: {
layers: {
layer1: finalDataLayer,
},

View file

@ -71,7 +71,7 @@ function getLensAttributes(defaultDataView: DataView): TypedLensByValueInput['at
],
state: {
datasourceStates: {
indexpattern: {
formBased: {
layers: {
layer1: dataLayer,
},

View file

@ -16,7 +16,7 @@ To test the migration, you can import the following ndjson file via saved object
```
{"attributes":{"fieldFormatMap":"{\"hour_of_day\":{}}","runtimeFieldMap":"{\"hour_of_day\":{\"type\":\"long\",\"script\":{\"source\":\"emit(doc['timestamp'].value.getHour());\"}}}","timeFieldName":"timestamp","title":"kibana_sample_data_logs"},"coreMigrationVersion":"8.0.0","id":"90943e30-9a47-11e8-b64d-95841ca0b247","migrationVersion":{"index-pattern":"8.0.0"},"references":[],"type":"index-pattern","updated_at":"2022-01-24T10:54:24.209Z","version":"WzQzMTQ3LDFd"}
{"attributes":{"description":"","state":{"datasourceStates":{"indexpattern":{"layers":{"f2700077-50bf-48e4-829c-f695f87e226d":{"columnOrder":["5e704cac-8490-457a-b635-01f3a5a132b7"],"columns":{"5e704cac-8490-457a-b635-01f3a5a132b7":{"dataType":"number","isBucketed":false,"label":"Count of records","operationType":"count","scale":"ratio","sourceField":"Records"}},"incompleteColumns":{}}}}},"filters":[],"query":{"language":"kuery","query":""},"visualization":{"column":"5e704cac-8490-457a-b635-01f3a5a132b7","layerId":"f2700077-50bf-48e4-829c-f695f87e226d"}},"title":"Rotating number test","visualizationType":"rotatingNumber"},"coreMigrationVersion":"8.0.0","id":"468f0be0-7e86-11ec-9739-d570ffd3fbe4","migrationVersion":{"lens":"8.0.0"},"references":[{"id":"90943e30-9a47-11e8-b64d-95841ca0b247","name":"indexpattern-datasource-current-indexpattern","type":"index-pattern"},{"id":"90943e30-9a47-11e8-b64d-95841ca0b247","name":"indexpattern-datasource-layer-f2700077-50bf-48e4-829c-f695f87e226d","type":"index-pattern"}],"type":"lens","updated_at":"2022-01-26T08:59:31.618Z","version":"WzQzNjUzLDFd"}
{"attributes":{"description":"","state":{"datasourceStates":{"formBased":{"layers":{"f2700077-50bf-48e4-829c-f695f87e226d":{"columnOrder":["5e704cac-8490-457a-b635-01f3a5a132b7"],"columns":{"5e704cac-8490-457a-b635-01f3a5a132b7":{"dataType":"number","isBucketed":false,"label":"Count of records","operationType":"count","scale":"ratio","sourceField":"Records"}},"incompleteColumns":{}}}}},"filters":[],"query":{"language":"kuery","query":""},"visualization":{"column":"5e704cac-8490-457a-b635-01f3a5a132b7","layerId":"f2700077-50bf-48e4-829c-f695f87e226d"}},"title":"Rotating number test","visualizationType":"rotatingNumber"},"coreMigrationVersion":"8.0.0","id":"468f0be0-7e86-11ec-9739-d570ffd3fbe4","migrationVersion":{"lens":"8.0.0"},"references":[{"id":"90943e30-9a47-11e8-b64d-95841ca0b247","name":"indexpattern-datasource-current-indexpattern","type":"index-pattern"},{"id":"90943e30-9a47-11e8-b64d-95841ca0b247","name":"indexpattern-datasource-layer-f2700077-50bf-48e4-829c-f695f87e226d","type":"index-pattern"}],"type":"lens","updated_at":"2022-01-26T08:59:31.618Z","version":"WzQzNjUzLDFd"}
{"excludedObjects":[],"excludedObjectsCount":0,"exportedCount":2,"missingRefCount":0,"missingReferences":[]}
```

View file

@ -67,7 +67,7 @@ function getLensAttributes(defaultDataView: DataView): TypedLensByValueInput['at
],
state: {
datasourceStates: {
indexpattern: {
formBased: {
layers: {
layer1: dataLayer,
},

View file

@ -282,7 +282,7 @@ export function getLensAttributes(
],
state: {
datasourceStates: {
indexpattern: {
formBased: {
layers: {
layer1: {
columnOrder: ['col1', 'col2'],

View file

@ -35,7 +35,7 @@ const getLensHostsTable = (
],
state: {
datasourceStates: {
indexpattern: {
formBased: {
layers: {
'cbe5d8a0-381d-49bf-b8ac-f8f312ec7129': {
columns: {

View file

@ -644,7 +644,7 @@ export const LensTopNavMenu = ({
setIsOnTextBasedMode(true);
dispatch(
switchAndCleanDatasource({
newDatasourceId: 'textBasedLanguages',
newDatasourceId: 'textBased',
visualizationId: visualization?.activeId,
currentIndexPatternId: currentIndexPattern?.id,
})
@ -764,7 +764,7 @@ export const LensTopNavMenu = ({
if (isOnTextBasedMode) {
dispatch(
switchAndCleanDatasource({
newDatasourceId: 'indexpattern',
newDatasourceId: 'formBased',
visualizationId: visualization?.activeId,
currentIndexPatternId: dataView?.id,
})
@ -795,7 +795,7 @@ export const LensTopNavMenu = ({
if (isOnTextBasedMode) {
dispatch(
switchAndCleanDatasource({
newDatasourceId: 'indexpattern',
newDatasourceId: 'formBased',
visualizationId: visualization?.activeId,
currentIndexPatternId: dataView?.id,
})
@ -838,7 +838,7 @@ export const LensTopNavMenu = ({
if (isOnTextBasedMode) {
dispatch(
switchAndCleanDatasource({
newDatasourceId: 'indexpattern',
newDatasourceId: 'formBased',
visualizationId: visualization?.activeId,
currentIndexPatternId: newIndexPatternId,
})

View file

@ -93,7 +93,7 @@ describe('getLayerMetaInfo', () => {
it('should return error in case of getFilters returning errors', () => {
const mockDatasource = createMockDatasource('testDatasource');
const updatedPublicAPI: DatasourcePublicAPI = {
datasourceId: 'indexpattern',
datasourceId: 'formBased',
getOperationForColumnId: jest.fn(),
getTableSpec: jest.fn(() => [{ columnId: 'col1', fields: ['bytes'] }]),
getVisualDefaults: jest.fn(),
@ -166,7 +166,7 @@ describe('getLayerMetaInfo', () => {
it('should basically work collecting fields and filters in the visualization', () => {
const mockDatasource = createMockDatasource('testDatasource');
const updatedPublicAPI: DatasourcePublicAPI = {
datasourceId: 'indexpattern',
datasourceId: 'formBased',
getOperationForColumnId: jest.fn(),
getTableSpec: jest.fn(() => [{ columnId: 'col1', fields: ['bytes'] }]),
getVisualDefaults: jest.fn(),

View file

@ -29,12 +29,12 @@ export * from './visualizations/heatmap';
export * from './visualizations/gauge/gauge_visualization';
export * from './visualizations/gauge';
export * from './indexpattern_datasource/indexpattern';
export { getTextBasedLanguagesDatasource } from './text_based_languages_datasource/text_based_languages';
export { createFormulaPublicApi } from './indexpattern_datasource/operations/definitions/formula/formula_public_api';
export * from './datasources/form_based/form_based';
export { getTextBasedDatasource } from './datasources/text_based/text_based_languages';
export { createFormulaPublicApi } from './datasources/form_based/operations/definitions/formula/formula_public_api';
export * from './text_based_languages_datasource';
export * from './indexpattern_datasource';
export * from './datasources/text_based';
export * from './datasources/form_based';
export * from './lens_ui_telemetry';
export * from './lens_ui_errors';
export * from './editor_frame_service/editor_frame';

View file

@ -14,7 +14,7 @@ import {
syncExistingFields,
} from './loader';
import { sampleIndexPatterns, mockDataViewsService } from './mocks';
import { documentField } from '../indexpattern_datasource/document_field';
import { documentField } from '../datasources/form_based/document_field';
import { coreMock } from '@kbn/core/public/mocks';
import { dataViewPluginMocks } from '@kbn/data-views-plugin/public/mocks';
import type { DataView } from '@kbn/data-views-plugin/public';

View file

@ -12,7 +12,7 @@ import { CoreStart } from '@kbn/core/public';
import { DataPublicPluginStart } from '@kbn/data-plugin/public';
import { loadFieldExisting } from '@kbn/unified-field-list-plugin/public';
import { IndexPattern, IndexPatternField, IndexPatternMap, IndexPatternRef } from '../types';
import { documentField } from '../indexpattern_datasource/document_field';
import { documentField } from '../datasources/form_based/document_field';
import { DateRange } from '../../common';
import { DataViewsState } from '../state_management';

View file

@ -6,11 +6,11 @@
*/
import { DataViewsContract } from '@kbn/data-views-plugin/common';
import { documentField } from '../indexpattern_datasource/document_field';
import { documentField } from '../datasources/form_based/document_field';
import {
createMockedIndexPattern,
createMockedRestrictedIndexPattern,
} from '../indexpattern_datasource/mocks';
} from '../datasources/form_based/mocks';
import { DataViewsState } from '../state_management';
import { ExistingFieldsMap, IndexPattern } from '../types';
import { getFieldByNameFactory } from './loader';

View file

@ -6,11 +6,11 @@
*/
import { createMockedIndexPattern, createMockedRestrictedIndexPattern } from '../mocks';
import { IndexPatternPrivateState } from '../types';
import { FormBasedPrivateState } from '../types';
export function loadInitialState() {
const indexPattern = createMockedIndexPattern();
const result: IndexPatternPrivateState = {
const result: FormBasedPrivateState = {
currentIndexPatternId: indexPattern.id,
layers: {},
};

View file

@ -13,13 +13,13 @@ import {
dataViewPluginMocks,
Start as DataViewPublicStart,
} from '@kbn/data-views-plugin/public/mocks';
import { InnerIndexPatternDataPanel, IndexPatternDataPanel, Props } from './datapanel';
import { InnerFormBasedDataPanel, FormBasedDataPanel, Props } from './datapanel';
import { FieldList } from './field_list';
import { FieldItem } from './field_item';
import { NoFieldsCallout } from './no_fields_callout';
import { act } from 'react-dom/test-utils';
import { coreMock } from '@kbn/core/public/mocks';
import { IndexPatternPrivateState } from './types';
import { FormBasedPrivateState } from './types';
import { mountWithIntl, shallowWithIntl } from '@kbn/test-jest-helpers';
import { EuiProgress, EuiLoadingSpinner } from '@elastic/eui';
import { documentField } from './document_field';
@ -29,12 +29,12 @@ import { indexPatternFieldEditorPluginMock } from '@kbn/data-view-field-editor-p
import { getFieldByNameFactory } from './pure_helpers';
import { uiActionsPluginMock } from '@kbn/ui-actions-plugin/public/mocks';
import { TermsIndexPatternColumn } from './operations';
import { DOCUMENT_FIELD_NAME } from '../../common';
import { createIndexPatternServiceMock } from '../mocks/data_views_service_mock';
import { createMockFramePublicAPI } from '../mocks';
import { DataViewsState } from '../state_management';
import { ExistingFieldsMap, FramePublicAPI, IndexPattern } from '../types';
import { IndexPatternServiceProps } from '../data_views_service/service';
import { DOCUMENT_FIELD_NAME } from '../../../common';
import { createIndexPatternServiceMock } from '../../mocks/data_views_service_mock';
import { createMockFramePublicAPI } from '../../mocks';
import { DataViewsState } from '../../state_management';
import { ExistingFieldsMap, FramePublicAPI, IndexPattern } from '../../types';
import { IndexPatternServiceProps } from '../../data_views_service/service';
import { FieldSpec, DataView } from '@kbn/data-views-plugin/public';
import { UI_SETTINGS } from '@kbn/data-plugin/public';
@ -174,7 +174,7 @@ function getExistingFields(indexPatterns: Record<string, IndexPattern>) {
return existingFields;
}
const initialState: IndexPatternPrivateState = {
const initialState: FormBasedPrivateState = {
currentIndexPatternId: '1',
layers: {
first: {
@ -285,7 +285,7 @@ const dslQuery = { bool: { must: [], filter: [], should: [], must_not: [] } };
// @ts-expect-error Portal mocks are notoriously difficult to type
ReactDOM.createPortal = jest.fn((element) => element);
describe('IndexPattern Data Panel', () => {
describe('FormBased Data Panel', () => {
const indexPatterns = {
a: {
id: 'a',
@ -304,7 +304,7 @@ describe('IndexPattern Data Panel', () => {
hasRestrictions: false,
},
};
let defaultProps: Parameters<typeof InnerIndexPatternDataPanel>[0] & {
let defaultProps: Parameters<typeof InnerFormBasedDataPanel>[0] & {
showNoDataPopover: () => void;
};
let core: ReturnType<typeof coreMock['createStart']>;
@ -340,7 +340,7 @@ describe('IndexPattern Data Panel', () => {
it('should render a warning if there are no index patterns', () => {
const wrapper = shallowWithIntl(
<IndexPatternDataPanel
<FormBasedDataPanel
{...defaultProps}
state={{
...initialState,
@ -405,16 +405,16 @@ describe('IndexPattern Data Panel', () => {
columns: {},
},
},
} as IndexPatternPrivateState,
} as FormBasedPrivateState,
};
}
async function testExistenceLoading(
props: Props,
stateChanges?: Partial<IndexPatternPrivateState>,
stateChanges?: Partial<FormBasedPrivateState>,
propChanges?: Partial<Props>
) {
const inst = mountWithIntl<Props>(<IndexPatternDataPanel {...props} />);
const inst = mountWithIntl<Props>(<FormBasedDataPanel {...props} />);
await act(async () => {
inst.update();
@ -601,7 +601,7 @@ describe('IndexPattern Data Panel', () => {
it('shows a loading indicator when loading', async () => {
const updateIndexPatterns = jest.fn();
const load = async () => {};
const inst = mountWithIntl(<IndexPatternDataPanel {...testProps(updateIndexPatterns)} />);
const inst = mountWithIntl(<FormBasedDataPanel {...testProps(updateIndexPatterns)} />);
expect(inst.find(EuiProgress).length).toEqual(1);
await act(load);
inst.update();
@ -629,7 +629,7 @@ describe('IndexPattern Data Panel', () => {
return result;
});
const inst = mountWithIntl(<IndexPatternDataPanel {...props} />);
const inst = mountWithIntl(<FormBasedDataPanel {...props} />);
inst.update();
@ -676,7 +676,7 @@ describe('IndexPattern Data Panel', () => {
});
describe('displaying field list', () => {
let props: Parameters<typeof InnerIndexPatternDataPanel>[0];
let props: Parameters<typeof InnerFormBasedDataPanel>[0];
beforeEach(() => {
props = {
...defaultProps,
@ -691,7 +691,7 @@ describe('IndexPattern Data Panel', () => {
};
});
it('should list all supported fields in the pattern sorted alphabetically in groups', async () => {
const wrapper = mountWithIntl(<InnerIndexPatternDataPanel {...props} />);
const wrapper = mountWithIntl(<InnerFormBasedDataPanel {...props} />);
expect(wrapper.find(FieldItem).first().prop('field').displayName).toEqual('Records');
expect(
wrapper
@ -715,7 +715,7 @@ describe('IndexPattern Data Panel', () => {
it('should show meta fields accordion', async () => {
const wrapper = mountWithIntl(
<InnerIndexPatternDataPanel
<InnerFormBasedDataPanel
{...props}
frame={getFrameAPIMock({
indexPatterns: {
@ -753,7 +753,7 @@ describe('IndexPattern Data Panel', () => {
it('should display NoFieldsCallout when all fields are empty', async () => {
const wrapper = mountWithIntl(
<InnerIndexPatternDataPanel
<InnerFormBasedDataPanel
{...defaultProps}
frame={getFrameAPIMock({ existingFields: { idx1: {} } })}
/>
@ -780,7 +780,7 @@ describe('IndexPattern Data Panel', () => {
it('should display spinner for available fields accordion if existing fields are not loaded yet', async () => {
const wrapper = mountWithIntl(
<InnerIndexPatternDataPanel
<InnerFormBasedDataPanel
{...defaultProps}
frame={getFrameAPIMock({ existingFields: {} })}
/>
@ -795,7 +795,7 @@ describe('IndexPattern Data Panel', () => {
it('should not allow field details when error', () => {
const wrapper = mountWithIntl(
<InnerIndexPatternDataPanel
<InnerFormBasedDataPanel
{...props}
frame={getFrameAPIMock({ existenceFetchFailed: true })}
/>
@ -810,7 +810,7 @@ describe('IndexPattern Data Panel', () => {
it('should allow field details when timeout', () => {
const wrapper = mountWithIntl(
<InnerIndexPatternDataPanel
<InnerFormBasedDataPanel
{...props}
frame={getFrameAPIMock({ existenceFetchTimeout: true })}
/>
@ -824,7 +824,7 @@ describe('IndexPattern Data Panel', () => {
});
it('should filter down by name', () => {
const wrapper = mountWithIntl(<InnerIndexPatternDataPanel {...props} />);
const wrapper = mountWithIntl(<InnerFormBasedDataPanel {...props} />);
act(() => {
wrapper.find('[data-test-subj="lnsIndexPatternFieldSearch"]').simulate('change', {
target: { value: 'me' },
@ -843,7 +843,7 @@ describe('IndexPattern Data Panel', () => {
});
it('should announce filter in live region', () => {
const wrapper = mountWithIntl(<InnerIndexPatternDataPanel {...props} />);
const wrapper = mountWithIntl(<InnerFormBasedDataPanel {...props} />);
act(() => {
wrapper.find('[data-test-subj="lnsIndexPatternFieldSearch"]').simulate('change', {
target: { value: 'me' },
@ -862,7 +862,7 @@ describe('IndexPattern Data Panel', () => {
});
it('should filter down by type', () => {
const wrapper = mountWithIntl(<InnerIndexPatternDataPanel {...props} />);
const wrapper = mountWithIntl(<InnerFormBasedDataPanel {...props} />);
wrapper.find('[data-test-subj="lnsIndexPatternFiltersToggle"]').first().simulate('click');
@ -874,7 +874,7 @@ describe('IndexPattern Data Panel', () => {
});
it('should display no fields in groups when filtered by type Record', () => {
const wrapper = mountWithIntl(<InnerIndexPatternDataPanel {...props} />);
const wrapper = mountWithIntl(<InnerFormBasedDataPanel {...props} />);
wrapper.find('[data-test-subj="lnsIndexPatternFiltersToggle"]').first().simulate('click');
@ -887,7 +887,7 @@ describe('IndexPattern Data Panel', () => {
});
it('should toggle type if clicked again', () => {
const wrapper = mountWithIntl(<InnerIndexPatternDataPanel {...props} />);
const wrapper = mountWithIntl(<InnerFormBasedDataPanel {...props} />);
wrapper.find('[data-test-subj="lnsIndexPatternFiltersToggle"]').first().simulate('click');
wrapper.find('[data-test-subj="typeFilter-number"]').first().simulate('click');
@ -903,7 +903,7 @@ describe('IndexPattern Data Panel', () => {
});
it('should filter down by type and by name', () => {
const wrapper = mountWithIntl(<InnerIndexPatternDataPanel {...props} />);
const wrapper = mountWithIntl(<InnerFormBasedDataPanel {...props} />);
act(() => {
wrapper.find('[data-test-subj="lnsIndexPatternFieldSearch"]').simulate('change', {
target: { value: 'me' },

View file

@ -39,18 +39,18 @@ import type {
FramePublicAPI,
IndexPattern,
IndexPatternField,
} from '../types';
import { ChildDragDropProvider, DragContextState } from '../drag_drop';
import type { IndexPatternPrivateState } from './types';
import { Loader } from '../loader';
import { LensFieldIcon } from '../shared_components/field_picker/lens_field_icon';
} from '../../types';
import { ChildDragDropProvider, DragContextState } from '../../drag_drop';
import type { FormBasedPrivateState } from './types';
import { Loader } from '../../loader';
import { LensFieldIcon } from '../../shared_components/field_picker/lens_field_icon';
import { getFieldType } from './pure_utils';
import { FieldGroups, FieldList } from './field_list';
import { fieldContainsData, fieldExists } from '../shared_components';
import { IndexPatternServiceAPI } from '../data_views_service/service';
import { fieldContainsData, fieldExists } from '../../shared_components';
import { IndexPatternServiceAPI } from '../../data_views_service/service';
export type Props = Omit<
DatasourceDataPanelProps<IndexPatternPrivateState>,
DatasourceDataPanelProps<FormBasedPrivateState>,
'core' | 'onChangeIndexPattern'
> & {
data: DataPublicPluginStart;
@ -124,7 +124,7 @@ function buildSafeEsQuery(
}
}
export function IndexPatternDataPanel({
export function FormBasedDataPanel({
state,
dragDropContext,
core,
@ -264,7 +264,7 @@ const defaultFieldGroups: {
const htmlId = htmlIdGenerator('datapanel');
const fieldSearchDescriptionId = htmlId();
export const InnerIndexPatternDataPanel = function InnerIndexPatternDataPanel({
export const InnerFormBasedDataPanel = function InnerFormBasedDataPanel({
currentIndexPatternId,
query,
dateRange,
@ -751,4 +751,4 @@ export const InnerIndexPatternDataPanel = function InnerIndexPatternDataPanel({
);
};
export const MemoizedDataPanel = memo(InnerIndexPatternDataPanel);
export const MemoizedDataPanel = memo(InnerFormBasedDataPanel);

View file

@ -8,8 +8,8 @@
import { mount } from 'enzyme';
import React from 'react';
import { BucketNestingEditor } from './bucket_nesting_editor';
import { GenericIndexPatternColumn } from '../indexpattern';
import { IndexPatternField } from '../../types';
import { GenericIndexPatternColumn } from '../form_based';
import { IndexPatternField } from '../../../types';
const fieldMap: Record<string, IndexPatternField> = {
a: { displayName: 'a' } as IndexPatternField,

View file

@ -8,10 +8,10 @@
import React from 'react';
import { i18n } from '@kbn/i18n';
import { EuiFormRow, EuiSwitch, EuiSelect } from '@elastic/eui';
import { IndexPatternLayer } from '../types';
import { FormBasedLayer } from '../types';
import { hasField } from '../pure_utils';
import { GenericIndexPatternColumn } from '../operations';
import { IndexPatternField } from '../../types';
import { IndexPatternField } from '../../../types';
function nestColumn(columnOrder: string[], outer: string, inner: string) {
const result = columnOrder.filter((c) => c !== inner);
@ -38,7 +38,7 @@ export function BucketNestingEditor({
getFieldByName,
}: {
columnId: string;
layer: IndexPatternLayer;
layer: FormBasedLayer;
setColumns: (columns: string[]) => void;
getFieldByName: (name: string) => IndexPatternField | undefined;
}) {

View file

@ -27,9 +27,9 @@ import {
EuiButtonIcon,
} from '@elastic/eui';
import ReactDOM from 'react-dom';
import type { IndexPatternDimensionEditorProps } from './dimension_panel';
import type { FormBasedDimensionEditorProps } from './dimension_panel';
import type { OperationSupportMatrix } from './operation_support';
import { deleteColumn, GenericIndexPatternColumn } from '../indexpattern';
import { deleteColumn, GenericIndexPatternColumn } from '../form_based';
import {
operationDefinitionMap,
getOperationDisplay,
@ -46,7 +46,7 @@ import { mergeLayer } from '../state_helpers';
import { getReferencedField, hasField } from '../pure_utils';
import { fieldIsInvalid } from '../utils';
import { BucketNestingEditor } from './bucket_nesting_editor';
import type { IndexPatternLayer } from '../types';
import type { FormBasedLayer } from '../types';
import { FormatSelector } from './format_selector';
import { ReferenceEditor } from './reference_editor';
import { TimeScaling } from './time_scaling';
@ -54,8 +54,8 @@ import { Filtering } from './filtering';
import { ReducedTimeRange } from './reduced_time_range';
import { AdvancedOptions } from './advanced_options';
import { TimeShift } from './time_shift';
import type { LayerType } from '../../../common';
import { DOCUMENT_FIELD_NAME } from '../../../common';
import type { LayerType } from '../../../../common';
import { DOCUMENT_FIELD_NAME } from '../../../../common';
import {
quickFunctionsName,
staticValueOperationName,
@ -68,15 +68,15 @@ import {
} from './dimensions_editor_helpers';
import type { TemporaryState } from './dimensions_editor_helpers';
import { FieldInput } from './field_input';
import { NameInput } from '../../shared_components';
import { NameInput } from '../../../shared_components';
import { ParamEditorProps } from '../operations/definitions';
import { WrappingHelpPopover } from '../help_popover';
import { isColumn } from '../operations/definitions/helpers';
import type { FieldChoiceWithOperationType } from './field_select';
import type { IndexPattern, IndexPatternField } from '../../types';
import type { IndexPattern, IndexPatternField } from '../../../types';
import { documentField } from '../document_field';
export interface DimensionEditorProps extends IndexPatternDimensionEditorProps {
export interface DimensionEditorProps extends FormBasedDimensionEditorProps {
selectedColumn?: GenericIndexPatternColumn;
layerType: LayerType;
operationSupportMatrix: OperationSupportMatrix;
@ -142,13 +142,13 @@ export function DimensionEditor(props: DimensionEditorProps) {
const setStateWrapper = useCallback(
(
setter:
| IndexPatternLayer
| ((prevLayer: IndexPatternLayer) => IndexPatternLayer)
| FormBasedLayer
| ((prevLayer: FormBasedLayer) => FormBasedLayer)
| GenericIndexPatternColumn,
options: { forceRender?: boolean } = {}
) => {
const layer = state.layers[layerId];
let hypotethicalLayer: IndexPatternLayer;
let hypotethicalLayer: FormBasedLayer;
if (isColumn(setter)) {
hypotethicalLayer = {
...layer,
@ -164,7 +164,7 @@ export function DimensionEditor(props: DimensionEditorProps) {
setState(
(prevState) => {
let outputLayer: IndexPatternLayer;
let outputLayer: FormBasedLayer;
const prevLayer = prevState.layers[layerId];
if (isColumn(setter)) {
outputLayer = {
@ -250,8 +250,8 @@ export function DimensionEditor(props: DimensionEditorProps) {
// TODO: revisit this once we get rid of updateDatasourceAsync upstream
const moveDefinetelyToStaticValueAndUpdate = (
setter:
| IndexPatternLayer
| ((prevLayer: IndexPatternLayer) => IndexPatternLayer)
| FormBasedLayer
| ((prevLayer: FormBasedLayer) => FormBasedLayer)
| GenericIndexPatternColumn
) => {
if (temporaryStaticValue) {
@ -501,7 +501,7 @@ export function DimensionEditor(props: DimensionEditorProps) {
} else if (!selectedColumn || !compatibleWithCurrentField) {
const possibleFields = fieldByOperation[operationType] || new Set();
let newLayer: IndexPatternLayer;
let newLayer: FormBasedLayer;
if (possibleFields.size === 1) {
newLayer = insertOrReplaceColumn({
layer: props.state.layers[props.layerId],
@ -585,9 +585,7 @@ export function DimensionEditor(props: DimensionEditorProps) {
const paramEditorProps: ParamEditorProps<
GenericIndexPatternColumn,
| IndexPatternLayer
| ((prevLayer: IndexPatternLayer) => IndexPatternLayer)
| GenericIndexPatternColumn
FormBasedLayer | ((prevLayer: FormBasedLayer) => FormBasedLayer) | GenericIndexPatternColumn
> = {
layer: state.layers[layerId],
layerId,
@ -769,11 +767,11 @@ export function DimensionEditor(props: DimensionEditorProps) {
}}
paramEditorUpdater={(
setter:
| IndexPatternLayer
| ((prevLayer: IndexPatternLayer) => IndexPatternLayer)
| FormBasedLayer
| ((prevLayer: FormBasedLayer) => FormBasedLayer)
| GenericIndexPatternColumn
) => {
let newLayer: IndexPatternLayer;
let newLayer: FormBasedLayer;
if (typeof setter === 'function') {
newLayer = setter(layer);
} else if (isColumn(setter)) {

View file

@ -21,8 +21,8 @@ import { dataViewPluginMocks } from '@kbn/data-views-plugin/public/mocks';
import { DataPublicPluginStart } from '@kbn/data-plugin/public';
import { fieldFormatsServiceMock } from '@kbn/field-formats-plugin/public/mocks';
import {
IndexPatternDimensionEditorComponent,
IndexPatternDimensionEditorProps,
FormBasedDimensionEditorComponent,
FormBasedDimensionEditorProps,
} from './dimension_panel';
import { mountWithIntl as mount, shallowWithIntl as shallow } from '@kbn/test-jest-helpers';
import {
@ -32,9 +32,9 @@ import {
CoreStart,
} from '@kbn/core/public';
import { IStorageWrapper } from '@kbn/kibana-utils-plugin/public';
import { generateId } from '../../../id_generator';
import { FormBasedPrivateState } from '../types';
import { LayerTypes } from '@kbn/expression-xy-plugin/public';
import { generateId } from '../../id_generator';
import { IndexPatternPrivateState } from '../types';
import {
FiltersIndexPatternColumn,
GenericIndexPatternColumn,
@ -42,7 +42,7 @@ import {
TermsIndexPatternColumn,
} from '../operations';
import { documentField } from '../document_field';
import { OperationMetadata } from '../../types';
import { OperationMetadata } from '../../../types';
import { DateHistogramIndexPatternColumn } from '../operations/definitions/date_histogram';
import { getFieldByNameFactory } from '../pure_helpers';
import { Filtering, setFilter } from './filtering';
@ -69,7 +69,7 @@ jest.mock('lodash', () => {
debounce: (fn: unknown) => fn,
};
});
jest.mock('../../id_generator');
jest.mock('../../../id_generator');
// Mock the Monaco Editor component
jest.mock('../operations/definitions/formula/editor/formula_editor', () => {
return {
@ -148,10 +148,10 @@ const bytesColumn: GenericIndexPatternColumn = {
* - Dimension trigger: Not tested here
* - Dimension editor component: First half of the tests
*/
describe('IndexPatternDimensionEditorPanel', () => {
let state: IndexPatternPrivateState;
describe('FormBasedDimensionEditor', () => {
let state: FormBasedPrivateState;
let setState: jest.Mock;
let defaultProps: IndexPatternDimensionEditorProps;
let defaultProps: FormBasedDimensionEditorProps;
function getStateWithColumns(columns: Record<string, GenericIndexPatternColumn>) {
return {
@ -265,14 +265,14 @@ describe('IndexPatternDimensionEditorPanel', () => {
const filterOperations = jest.fn().mockReturnValue(true);
wrapper = shallow(
<IndexPatternDimensionEditorComponent {...defaultProps} filterOperations={filterOperations} />
<FormBasedDimensionEditorComponent {...defaultProps} filterOperations={filterOperations} />
);
expect(filterOperations).toBeCalled();
});
it('should show field select', () => {
wrapper = mount(<IndexPatternDimensionEditorComponent {...defaultProps} />);
wrapper = mount(<FormBasedDimensionEditorComponent {...defaultProps} />);
expect(
wrapper.find(EuiComboBox).filter('[data-test-subj="indexPattern-dimension-field"]')
@ -281,7 +281,7 @@ describe('IndexPatternDimensionEditorPanel', () => {
it('should not show field select on fieldless operation', () => {
wrapper = mount(
<IndexPatternDimensionEditorComponent
<FormBasedDimensionEditorComponent
{...defaultProps}
state={getStateWithColumns({
col1: {
@ -304,7 +304,7 @@ describe('IndexPatternDimensionEditorPanel', () => {
it('should not show any choices if the filter returns false', () => {
wrapper = mount(
<IndexPatternDimensionEditorComponent
<FormBasedDimensionEditorComponent
{...defaultProps}
columnId={'col2'}
filterOperations={() => false}
@ -320,7 +320,7 @@ describe('IndexPatternDimensionEditorPanel', () => {
});
it('should list all field names and document as a whole in prioritized order', () => {
wrapper = mount(<IndexPatternDimensionEditorComponent {...defaultProps} />);
wrapper = mount(<FormBasedDimensionEditorComponent {...defaultProps} />);
const options = wrapper
.find(EuiComboBox)
@ -348,7 +348,7 @@ describe('IndexPatternDimensionEditorPanel', () => {
},
},
};
wrapper = mount(<IndexPatternDimensionEditorComponent {...props} />);
wrapper = mount(<FormBasedDimensionEditorComponent {...props} />);
const options = wrapper
.find(EuiComboBox)
@ -360,7 +360,7 @@ describe('IndexPatternDimensionEditorPanel', () => {
it('should indicate fields which are incompatible for the operation of the current column', () => {
wrapper = mount(
<IndexPatternDimensionEditorComponent
<FormBasedDimensionEditorComponent
{...defaultProps}
state={getStateWithColumns({ col1: bytesColumn })}
/>
@ -383,7 +383,7 @@ describe('IndexPatternDimensionEditorPanel', () => {
it('should indicate operations which are incompatible for the field of the current column', () => {
wrapper = mount(
<IndexPatternDimensionEditorComponent
<FormBasedDimensionEditorComponent
{...defaultProps}
state={getStateWithColumns({ col1: bytesColumn })}
/>
@ -407,7 +407,7 @@ describe('IndexPatternDimensionEditorPanel', () => {
it('should indicate when a transition is invalid due to filterOperations', () => {
wrapper = mount(
<IndexPatternDimensionEditorComponent
<FormBasedDimensionEditorComponent
{...defaultProps}
state={getStateWithColumns({
col1: {
@ -431,7 +431,7 @@ describe('IndexPatternDimensionEditorPanel', () => {
});
it('should not display hidden operation types', () => {
wrapper = mount(<IndexPatternDimensionEditorComponent {...defaultProps} />);
wrapper = mount(<FormBasedDimensionEditorComponent {...defaultProps} />);
const items: EuiListGroupItemProps[] = wrapper.find(EuiListGroup).prop('listItems') || [];
@ -442,7 +442,7 @@ describe('IndexPatternDimensionEditorPanel', () => {
it('should indicate that reference-based operations are not compatible when they are incomplete', () => {
wrapper = mount(
<IndexPatternDimensionEditorComponent
<FormBasedDimensionEditorComponent
{...defaultProps}
state={getStateWithColumns({
date: {
@ -479,7 +479,7 @@ describe('IndexPatternDimensionEditorPanel', () => {
it('should indicate that reference-based operations are compatible sometimes', () => {
wrapper = mount(
<IndexPatternDimensionEditorComponent
<FormBasedDimensionEditorComponent
{...defaultProps}
state={getStateWithColumns({
date: {
@ -523,11 +523,9 @@ describe('IndexPatternDimensionEditorPanel', () => {
});
it('should keep the operation when switching to another field compatible with this operation', () => {
const initialState: IndexPatternPrivateState = getStateWithColumns({ col1: bytesColumn });
const initialState: FormBasedPrivateState = getStateWithColumns({ col1: bytesColumn });
wrapper = mount(
<IndexPatternDimensionEditorComponent {...defaultProps} state={initialState} />
);
wrapper = mount(<FormBasedDimensionEditorComponent {...defaultProps} state={initialState} />);
const comboBox = wrapper
.find(EuiComboBox)
@ -562,7 +560,7 @@ describe('IndexPatternDimensionEditorPanel', () => {
});
it('should switch operations when selecting a field that requires another operation', () => {
wrapper = mount(<IndexPatternDimensionEditorComponent {...defaultProps} />);
wrapper = mount(<FormBasedDimensionEditorComponent {...defaultProps} />);
const comboBox = wrapper
.find(EuiComboBox)
@ -597,7 +595,7 @@ describe('IndexPatternDimensionEditorPanel', () => {
it('should keep the field when switching to another operation compatible for this field', () => {
wrapper = mount(
<IndexPatternDimensionEditorComponent
<FormBasedDimensionEditorComponent
{...defaultProps}
state={getStateWithColumns({ col1: bytesColumn })}
/>
@ -628,7 +626,7 @@ describe('IndexPatternDimensionEditorPanel', () => {
});
it('should not set the state if selecting the currently active operation', () => {
wrapper = mount(<IndexPatternDimensionEditorComponent {...defaultProps} />);
wrapper = mount(<FormBasedDimensionEditorComponent {...defaultProps} />);
act(() => {
wrapper
@ -640,7 +638,7 @@ describe('IndexPatternDimensionEditorPanel', () => {
});
it('should update label and custom label flag on label input changes', () => {
wrapper = mount(<IndexPatternDimensionEditorComponent {...defaultProps} />);
wrapper = mount(<FormBasedDimensionEditorComponent {...defaultProps} />);
act(() => {
wrapper
@ -669,7 +667,7 @@ describe('IndexPatternDimensionEditorPanel', () => {
it('should not keep the label as long as it is the default label', () => {
wrapper = mount(
<IndexPatternDimensionEditorComponent
<FormBasedDimensionEditorComponent
{...defaultProps}
state={getStateWithColumns({ col1: bytesColumn })}
/>
@ -698,7 +696,7 @@ describe('IndexPatternDimensionEditorPanel', () => {
it('should keep the label on operation change if it is custom', () => {
wrapper = mount(
<IndexPatternDimensionEditorComponent
<FormBasedDimensionEditorComponent
{...defaultProps}
state={getStateWithColumns({
col1: {
@ -734,7 +732,7 @@ describe('IndexPatternDimensionEditorPanel', () => {
it('should remove customLabel flag if label is set to default', () => {
wrapper = mount(
<IndexPatternDimensionEditorComponent
<FormBasedDimensionEditorComponent
{...defaultProps}
state={getStateWithColumns({
col1: {
@ -773,7 +771,7 @@ describe('IndexPatternDimensionEditorPanel', () => {
describe('transient invalid state', () => {
it('should set the state if selecting an operation incompatible with the current field', () => {
wrapper = mount(<IndexPatternDimensionEditorComponent {...defaultProps} />);
wrapper = mount(<FormBasedDimensionEditorComponent {...defaultProps} />);
act(() => {
wrapper
@ -799,7 +797,7 @@ describe('IndexPatternDimensionEditorPanel', () => {
});
it('should show error message in invalid state', () => {
wrapper = mount(<IndexPatternDimensionEditorComponent {...defaultProps} />);
wrapper = mount(<FormBasedDimensionEditorComponent {...defaultProps} />);
wrapper
.find('button[data-test-subj="lns-indexPatternDimension-terms incompatible"]')
@ -811,7 +809,7 @@ describe('IndexPatternDimensionEditorPanel', () => {
});
it('should leave error state if a compatible operation is selected', () => {
wrapper = mount(<IndexPatternDimensionEditorComponent {...defaultProps} />);
wrapper = mount(<FormBasedDimensionEditorComponent {...defaultProps} />);
wrapper
.find('button[data-test-subj="lns-indexPatternDimension-terms incompatible"]')
@ -825,7 +823,7 @@ describe('IndexPatternDimensionEditorPanel', () => {
});
it('should leave error state if the original operation is re-selected', () => {
wrapper = mount(<IndexPatternDimensionEditorComponent {...defaultProps} />);
wrapper = mount(<FormBasedDimensionEditorComponent {...defaultProps} />);
wrapper
.find('button[data-test-subj="lns-indexPatternDimension-terms incompatible"]')
@ -841,7 +839,7 @@ describe('IndexPatternDimensionEditorPanel', () => {
it('should leave error state when switching from incomplete state to fieldless operation', () => {
// @ts-expect-error
window['__react-beautiful-dnd-disable-dev-warnings'] = true; // issue with enzyme & react-beautiful-dnd throwing errors: https://github.com/atlassian/react-beautiful-dnd/issues/1593
wrapper = mount(<IndexPatternDimensionEditorComponent {...defaultProps} />);
wrapper = mount(<FormBasedDimensionEditorComponent {...defaultProps} />);
wrapper
.find('button[data-test-subj="lns-indexPatternDimension-terms incompatible"]')
@ -854,7 +852,7 @@ describe('IndexPatternDimensionEditorPanel', () => {
it('should leave error state when re-selecting the original fieldless function', () => {
wrapper = mount(
<IndexPatternDimensionEditorComponent
<FormBasedDimensionEditorComponent
{...defaultProps}
state={getStateWithColumns({
col1: {
@ -879,7 +877,7 @@ describe('IndexPatternDimensionEditorPanel', () => {
});
it('should indicate fields compatible with selected operation', () => {
wrapper = mount(<IndexPatternDimensionEditorComponent {...defaultProps} />);
wrapper = mount(<FormBasedDimensionEditorComponent {...defaultProps} />);
wrapper
.find('button[data-test-subj="lns-indexPatternDimension-terms incompatible"]')
@ -901,7 +899,7 @@ describe('IndexPatternDimensionEditorPanel', () => {
});
it('should select compatible operation if field not compatible with selected operation', () => {
wrapper = mount(<IndexPatternDimensionEditorComponent {...defaultProps} columnId={'col2'} />);
wrapper = mount(<FormBasedDimensionEditorComponent {...defaultProps} columnId={'col2'} />);
wrapper.find('button[data-test-subj="lns-indexPatternDimension-average"]').simulate('click');
@ -962,11 +960,7 @@ describe('IndexPatternDimensionEditorPanel', () => {
},
});
wrapper = mount(
<IndexPatternDimensionEditorComponent
{...defaultProps}
state={baseState}
columnId={'col2'}
/>
<FormBasedDimensionEditorComponent {...defaultProps} state={baseState} columnId={'col2'} />
);
// Transition to a field operation (incompatible)
@ -991,7 +985,7 @@ describe('IndexPatternDimensionEditorPanel', () => {
it('should select the Records field when count is selected on non-existing column', () => {
wrapper = mount(
<IndexPatternDimensionEditorComponent
<FormBasedDimensionEditorComponent
{...defaultProps}
state={getStateWithColumns({})}
columnId="col2"
@ -1007,7 +1001,7 @@ describe('IndexPatternDimensionEditorPanel', () => {
it('should indicate document and field compatibility with selected document operation', () => {
wrapper = mount(
<IndexPatternDimensionEditorComponent
<FormBasedDimensionEditorComponent
{...defaultProps}
state={getStateWithColumns({
col2: {
@ -1042,7 +1036,7 @@ describe('IndexPatternDimensionEditorPanel', () => {
});
it('should set datasource state if compatible field is selected for operation', () => {
wrapper = mount(<IndexPatternDimensionEditorComponent {...defaultProps} />);
wrapper = mount(<FormBasedDimensionEditorComponent {...defaultProps} />);
wrapper
.find('button[data-test-subj="lns-indexPatternDimension-terms incompatible"]')
@ -1110,7 +1104,7 @@ describe('IndexPatternDimensionEditorPanel', () => {
}
it('should default to None if time scaling is not set', () => {
wrapper = mount(<IndexPatternDimensionEditorComponent {...getProps({})} />);
wrapper = mount(<FormBasedDimensionEditorComponent {...getProps({})} />);
findTestSubject(wrapper, 'indexPattern-advanced-accordion').simulate('click');
expect(wrapper.find('[data-test-subj="indexPattern-time-scaling-enable"]')).toHaveLength(1);
expect(
@ -1122,7 +1116,7 @@ describe('IndexPatternDimensionEditorPanel', () => {
});
it('should show current time scaling if set', () => {
wrapper = mount(<IndexPatternDimensionEditorComponent {...getProps({ timeScale: 'd' })} />);
wrapper = mount(<FormBasedDimensionEditorComponent {...getProps({ timeScale: 'd' })} />);
findTestSubject(wrapper, 'indexPattern-advanced-accordion').simulate('click');
expect(
wrapper
@ -1134,7 +1128,7 @@ describe('IndexPatternDimensionEditorPanel', () => {
it('should allow to set time scaling initially', () => {
const props = getProps({});
wrapper = mount(<IndexPatternDimensionEditorComponent {...props} />);
wrapper = mount(<FormBasedDimensionEditorComponent {...props} />);
findTestSubject(wrapper, 'indexPattern-advanced-accordion').simulate('click');
wrapper
.find('[data-test-subj="indexPattern-time-scaling-unit"]')
@ -1167,7 +1161,7 @@ describe('IndexPatternDimensionEditorPanel', () => {
operationType: 'sum',
label: 'Sum of bytes per hour',
});
wrapper = mount(<IndexPatternDimensionEditorComponent {...props} />);
wrapper = mount(<FormBasedDimensionEditorComponent {...props} />);
wrapper.find('button[data-test-subj="lns-indexPatternDimension-count"]').simulate('click');
expect(setState.mock.calls[0]).toEqual([expect.any(Function), { isDimensionComplete: true }]);
expect(setState.mock.calls[0][0](props.state)).toEqual({
@ -1194,7 +1188,7 @@ describe('IndexPatternDimensionEditorPanel', () => {
operationType: 'sum',
label: 'Sum of bytes per hour',
});
wrapper = mount(<IndexPatternDimensionEditorComponent {...props} />);
wrapper = mount(<FormBasedDimensionEditorComponent {...props} />);
wrapper.find('button[data-test-subj="lns-indexPatternDimension-average"]').simulate('click');
expect(setState.mock.calls[0]).toEqual([expect.any(Function), { isDimensionComplete: true }]);
expect(setState.mock.calls[0][0](props.state)).toEqual({
@ -1216,7 +1210,7 @@ describe('IndexPatternDimensionEditorPanel', () => {
it('should allow to change time scaling', () => {
const props = getProps({ timeScale: 's', label: 'Count of records per second' });
wrapper = mount(<IndexPatternDimensionEditorComponent {...props} />);
wrapper = mount(<FormBasedDimensionEditorComponent {...props} />);
findTestSubject(wrapper, 'indexPattern-advanced-accordion').simulate('click');
wrapper.find('[data-test-subj="indexPattern-time-scaling-unit"] select').simulate('change', {
@ -1243,7 +1237,7 @@ describe('IndexPatternDimensionEditorPanel', () => {
it('should not adjust label if it is custom', () => {
const props = getProps({ timeScale: 's', customLabel: true, label: 'My label' });
wrapper = mount(<IndexPatternDimensionEditorComponent {...props} />);
wrapper = mount(<FormBasedDimensionEditorComponent {...props} />);
wrapper.find('[data-test-subj="indexPattern-time-scaling-unit"] select').simulate('change', {
target: { value: 'h' },
});
@ -1309,7 +1303,7 @@ describe('IndexPatternDimensionEditorPanel', () => {
}),
columnId: 'col2',
};
wrapper = mount(<IndexPatternDimensionEditorComponent {...props} />);
wrapper = mount(<FormBasedDimensionEditorComponent {...props} />);
findTestSubject(wrapper, 'indexPattern-advanced-accordion').simulate('click');
expect(
wrapper.find('[data-test-subj="indexPattern-dimension-reducedTimeRange-row"]')
@ -1318,7 +1312,7 @@ describe('IndexPatternDimensionEditorPanel', () => {
it('should show current reduced time range if set', () => {
wrapper = mount(
<IndexPatternDimensionEditorComponent {...getProps({ reducedTimeRange: '5m' })} />
<FormBasedDimensionEditorComponent {...getProps({ reducedTimeRange: '5m' })} />
);
expect(
wrapper.find(ReducedTimeRange).find(EuiComboBox).prop('selectedOptions')[0].value
@ -1327,7 +1321,7 @@ describe('IndexPatternDimensionEditorPanel', () => {
it('should allow to set reduced time range initially', () => {
const props = getProps({});
wrapper = mount(<IndexPatternDimensionEditorComponent {...props} />);
wrapper = mount(<FormBasedDimensionEditorComponent {...props} />);
findTestSubject(wrapper, 'indexPattern-advanced-accordion').simulate('click');
wrapper.find(ReducedTimeRange).find(EuiComboBox).prop('onChange')!([
{ value: '1h', label: '' },
@ -1355,7 +1349,7 @@ describe('IndexPatternDimensionEditorPanel', () => {
operationType: 'sum',
label: 'Sum of bytes per hour',
});
wrapper = mount(<IndexPatternDimensionEditorComponent {...props} />);
wrapper = mount(<FormBasedDimensionEditorComponent {...props} />);
wrapper.find('button[data-test-subj="lns-indexPatternDimension-count"]').simulate('click');
expect((props.setState as jest.Mock).mock.calls[0][0](props.state)).toEqual({
...props.state,
@ -1377,7 +1371,7 @@ describe('IndexPatternDimensionEditorPanel', () => {
const props = getProps({
timeShift: '1d',
});
wrapper = mount(<IndexPatternDimensionEditorComponent {...props} />);
wrapper = mount(<FormBasedDimensionEditorComponent {...props} />);
wrapper.find(ReducedTimeRange).find(EuiComboBox).prop('onCreateOption')!('7m', []);
expect((props.setState as jest.Mock).mock.calls[0][0](props.state)).toEqual({
...props.state,
@ -1399,7 +1393,7 @@ describe('IndexPatternDimensionEditorPanel', () => {
const props = getProps({
reducedTimeRange: '5 months',
});
wrapper = mount(<IndexPatternDimensionEditorComponent {...props} />);
wrapper = mount(<FormBasedDimensionEditorComponent {...props} />);
expect(wrapper.find(ReducedTimeRange).find(EuiComboBox).prop('isInvalid')).toBeTruthy();
@ -1457,7 +1451,7 @@ describe('IndexPatternDimensionEditorPanel', () => {
columnId: 'col2',
};
wrapper = mount(
<IndexPatternDimensionEditorComponent
<FormBasedDimensionEditorComponent
{...props}
indexPatterns={{
'1': {
@ -1473,7 +1467,7 @@ describe('IndexPatternDimensionEditorPanel', () => {
});
it('should show custom options if time shift is available', () => {
wrapper = shallow(<IndexPatternDimensionEditorComponent {...getProps({})} />);
wrapper = shallow(<FormBasedDimensionEditorComponent {...getProps({})} />);
expect(
wrapper
.find(DimensionEditor)
@ -1485,7 +1479,7 @@ describe('IndexPatternDimensionEditorPanel', () => {
});
it('should show current time shift if set', () => {
wrapper = mount(<IndexPatternDimensionEditorComponent {...getProps({ timeShift: '1d' })} />);
wrapper = mount(<FormBasedDimensionEditorComponent {...getProps({ timeShift: '1d' })} />);
expect(wrapper.find(TimeShift).find(EuiComboBox).prop('selectedOptions')[0].value).toEqual(
'1d'
);
@ -1493,7 +1487,7 @@ describe('IndexPatternDimensionEditorPanel', () => {
it('should allow to set time shift initially', () => {
const props = getProps({});
wrapper = mount(<IndexPatternDimensionEditorComponent {...props} />);
wrapper = mount(<FormBasedDimensionEditorComponent {...props} />);
findTestSubject(wrapper, 'indexPattern-advanced-accordion').simulate('click');
wrapper.find(TimeShift).find(EuiComboBox).prop('onChange')!([{ value: '1h', label: '' }]);
expect((props.setState as jest.Mock).mock.calls[0][0](props.state)).toEqual({
@ -1519,7 +1513,7 @@ describe('IndexPatternDimensionEditorPanel', () => {
operationType: 'sum',
label: 'Sum of bytes per hour',
});
wrapper = mount(<IndexPatternDimensionEditorComponent {...props} />);
wrapper = mount(<FormBasedDimensionEditorComponent {...props} />);
wrapper.find('button[data-test-subj="lns-indexPatternDimension-count"]').simulate('click');
expect((props.setState as jest.Mock).mock.calls[0][0](props.state)).toEqual({
...props.state,
@ -1541,7 +1535,7 @@ describe('IndexPatternDimensionEditorPanel', () => {
const props = getProps({
timeShift: '1d',
});
wrapper = mount(<IndexPatternDimensionEditorComponent {...props} />);
wrapper = mount(<FormBasedDimensionEditorComponent {...props} />);
wrapper.find(TimeShift).find(EuiComboBox).prop('onCreateOption')!('1h', []);
expect((props.setState as jest.Mock).mock.calls[0][0](props.state)).toEqual({
...props.state,
@ -1563,7 +1557,7 @@ describe('IndexPatternDimensionEditorPanel', () => {
const props = getProps({
timeShift: '5 months',
});
wrapper = mount(<IndexPatternDimensionEditorComponent {...props} />);
wrapper = mount(<FormBasedDimensionEditorComponent {...props} />);
expect(wrapper.find(TimeShift).find(EuiComboBox).prop('isInvalid')).toBeTruthy();
@ -1608,7 +1602,7 @@ describe('IndexPatternDimensionEditorPanel', () => {
it('should not show custom options if time scaling is not available', () => {
wrapper = mount(
<IndexPatternDimensionEditorComponent
<FormBasedDimensionEditorComponent
{...getProps({
operationType: 'terms',
sourceField: 'bytes',
@ -1626,7 +1620,7 @@ describe('IndexPatternDimensionEditorPanel', () => {
});
it('should show custom options if filtering is available', () => {
wrapper = mount(<IndexPatternDimensionEditorComponent {...getProps({})} />);
wrapper = mount(<FormBasedDimensionEditorComponent {...getProps({})} />);
findTestSubject(wrapper, 'indexPattern-advanced-accordion').simulate('click');
expect(
wrapper.find('[data-test-subj="indexPattern-filter-by-enable"]').hostNodes()
@ -1635,7 +1629,7 @@ describe('IndexPatternDimensionEditorPanel', () => {
it('should show current filter if set', () => {
wrapper = mount(
<IndexPatternDimensionEditorComponent
<FormBasedDimensionEditorComponent
{...getProps({ filter: { language: 'kuery', query: 'a: b' } })}
/>
);
@ -1655,7 +1649,7 @@ describe('IndexPatternDimensionEditorPanel', () => {
operationType: 'sum',
label: 'Sum of bytes per hour',
});
wrapper = mount(<IndexPatternDimensionEditorComponent {...props} />);
wrapper = mount(<FormBasedDimensionEditorComponent {...props} />);
wrapper.find('button[data-test-subj="lns-indexPatternDimension-count"]').simulate('click');
expect(setState.mock.calls[0]).toEqual([expect.any(Function), { isDimensionComplete: true }]);
expect(setState.mock.calls[0][0](props.state)).toEqual({
@ -1679,7 +1673,7 @@ describe('IndexPatternDimensionEditorPanel', () => {
filter: { language: 'kuery', query: 'a: b' },
});
wrapper = mount(<IndexPatternDimensionEditorComponent {...props} />);
wrapper = mount(<FormBasedDimensionEditorComponent {...props} />);
act(() => {
const { updateLayer, columnId, layer } = wrapper.find(Filtering).props();
@ -1707,7 +1701,7 @@ describe('IndexPatternDimensionEditorPanel', () => {
it('should render invalid field if field reference is broken', () => {
wrapper = mount(
<IndexPatternDimensionEditorComponent
<FormBasedDimensionEditorComponent
{...defaultProps}
state={{
...defaultProps.state,
@ -1735,7 +1729,7 @@ describe('IndexPatternDimensionEditorPanel', () => {
});
it('should support selecting the operation before the field', () => {
wrapper = mount(<IndexPatternDimensionEditorComponent {...defaultProps} columnId={'col2'} />);
wrapper = mount(<FormBasedDimensionEditorComponent {...defaultProps} columnId={'col2'} />);
wrapper.find('button[data-test-subj="lns-indexPatternDimension-average"]').simulate('click');
@ -1784,7 +1778,7 @@ describe('IndexPatternDimensionEditorPanel', () => {
it('should select operation directly if only one field is possible', () => {
wrapper = mount(
<IndexPatternDimensionEditorComponent
<FormBasedDimensionEditorComponent
{...defaultProps}
columnId={'col2'}
indexPatterns={{
@ -1821,7 +1815,7 @@ describe('IndexPatternDimensionEditorPanel', () => {
});
it('should select operation directly if only document is possible', () => {
wrapper = mount(<IndexPatternDimensionEditorComponent {...defaultProps} columnId={'col2'} />);
wrapper = mount(<FormBasedDimensionEditorComponent {...defaultProps} columnId={'col2'} />);
wrapper.find('button[data-test-subj="lns-indexPatternDimension-count"]').simulate('click');
@ -1845,7 +1839,7 @@ describe('IndexPatternDimensionEditorPanel', () => {
});
it('should indicate compatible fields when selecting the operation first', () => {
wrapper = mount(<IndexPatternDimensionEditorComponent {...defaultProps} columnId={'col2'} />);
wrapper = mount(<FormBasedDimensionEditorComponent {...defaultProps} columnId={'col2'} />);
act(() => {
wrapper.find('button[data-test-subj="lns-indexPatternDimension-average"]').simulate('click');
@ -1871,7 +1865,7 @@ describe('IndexPatternDimensionEditorPanel', () => {
it('should indicate document compatibility when document operation is selected', () => {
wrapper = mount(
<IndexPatternDimensionEditorComponent
<FormBasedDimensionEditorComponent
{...defaultProps}
state={getStateWithColumns({
col2: {
@ -1895,7 +1889,7 @@ describe('IndexPatternDimensionEditorPanel', () => {
});
it('should not update when selecting the current field again', () => {
wrapper = mount(<IndexPatternDimensionEditorComponent {...defaultProps} />);
wrapper = mount(<FormBasedDimensionEditorComponent {...defaultProps} />);
const comboBox = wrapper
.find(EuiComboBox)
@ -1914,7 +1908,7 @@ describe('IndexPatternDimensionEditorPanel', () => {
it('should show all operations that are not filtered out', () => {
wrapper = mount(
<IndexPatternDimensionEditorComponent
<FormBasedDimensionEditorComponent
{...defaultProps}
filterOperations={(op: OperationMetadata) => !op.isBucketed && op.dataType === 'number'}
/>
@ -1946,7 +1940,7 @@ describe('IndexPatternDimensionEditorPanel', () => {
// Prevents field format from being loaded
setState.mockImplementation(() => {});
wrapper = mount(<IndexPatternDimensionEditorComponent {...defaultProps} columnId={'col2'} />);
wrapper = mount(<FormBasedDimensionEditorComponent {...defaultProps} columnId={'col2'} />);
const comboBox = wrapper
.find(EuiComboBox)
@ -1981,12 +1975,10 @@ describe('IndexPatternDimensionEditorPanel', () => {
});
it('should use helper function when changing the function', () => {
const initialState: IndexPatternPrivateState = getStateWithColumns({
const initialState: FormBasedPrivateState = getStateWithColumns({
col1: bytesColumn,
});
wrapper = mount(
<IndexPatternDimensionEditorComponent {...defaultProps} state={initialState} />
);
wrapper = mount(<FormBasedDimensionEditorComponent {...defaultProps} state={initialState} />);
act(() => {
wrapper
.find('button[data-test-subj="lns-indexPatternDimension-min"]')
@ -2004,7 +1996,7 @@ describe('IndexPatternDimensionEditorPanel', () => {
});
it('should keep the latest valid dimension when removing the selection in field combobox', () => {
wrapper = mount(<IndexPatternDimensionEditorComponent {...defaultProps} />);
wrapper = mount(<FormBasedDimensionEditorComponent {...defaultProps} />);
act(() => {
wrapper
@ -2017,7 +2009,7 @@ describe('IndexPatternDimensionEditorPanel', () => {
});
it('allows custom format', () => {
const stateWithNumberCol: IndexPatternPrivateState = getStateWithColumns({
const stateWithNumberCol: FormBasedPrivateState = getStateWithColumns({
col1: {
label: 'Average of memory',
dataType: 'number',
@ -2029,7 +2021,7 @@ describe('IndexPatternDimensionEditorPanel', () => {
});
wrapper = mount(
<IndexPatternDimensionEditorComponent {...defaultProps} state={stateWithNumberCol} />
<FormBasedDimensionEditorComponent {...defaultProps} state={stateWithNumberCol} />
);
act(() => {
@ -2059,7 +2051,7 @@ describe('IndexPatternDimensionEditorPanel', () => {
});
it('keeps decimal places while switching', () => {
const stateWithNumberCol: IndexPatternPrivateState = getStateWithColumns({
const stateWithNumberCol: FormBasedPrivateState = getStateWithColumns({
col1: {
label: 'Average of memory',
dataType: 'number',
@ -2073,7 +2065,7 @@ describe('IndexPatternDimensionEditorPanel', () => {
},
});
wrapper = mount(
<IndexPatternDimensionEditorComponent {...defaultProps} state={stateWithNumberCol} />
<FormBasedDimensionEditorComponent {...defaultProps} state={stateWithNumberCol} />
);
act(() => {
@ -2099,7 +2091,7 @@ describe('IndexPatternDimensionEditorPanel', () => {
});
it('allows custom format with number of decimal places', () => {
const stateWithNumberCol: IndexPatternPrivateState = getStateWithColumns({
const stateWithNumberCol: FormBasedPrivateState = getStateWithColumns({
col1: {
label: 'Average of memory',
dataType: 'number',
@ -2114,7 +2106,7 @@ describe('IndexPatternDimensionEditorPanel', () => {
});
wrapper = mount(
<IndexPatternDimensionEditorComponent {...defaultProps} state={stateWithNumberCol} />
<FormBasedDimensionEditorComponent {...defaultProps} state={stateWithNumberCol} />
);
act(() => {
@ -2145,7 +2137,7 @@ describe('IndexPatternDimensionEditorPanel', () => {
it('should hide the top level field selector when switching from non-reference to reference', () => {
(generateId as jest.Mock).mockReturnValue(`second`);
wrapper = mount(<IndexPatternDimensionEditorComponent {...defaultProps} />);
wrapper = mount(<FormBasedDimensionEditorComponent {...defaultProps} />);
expect(wrapper.find('ReferenceEditor')).toHaveLength(0);
@ -2157,7 +2149,7 @@ describe('IndexPatternDimensionEditorPanel', () => {
});
it('should hide the reference editors when switching from reference to non-reference', () => {
const stateWithReferences: IndexPatternPrivateState = getStateWithColumns({
const stateWithReferences: FormBasedPrivateState = getStateWithColumns({
col1: {
label: 'Differences of (incomplete)',
dataType: 'number',
@ -2169,7 +2161,7 @@ describe('IndexPatternDimensionEditorPanel', () => {
});
wrapper = mount(
<IndexPatternDimensionEditorComponent {...defaultProps} state={stateWithReferences} />
<FormBasedDimensionEditorComponent {...defaultProps} state={stateWithReferences} />
);
expect(wrapper.find('ReferenceEditor')).toHaveLength(1);
@ -2182,7 +2174,7 @@ describe('IndexPatternDimensionEditorPanel', () => {
});
it('should show a warning when the current dimension is no longer configurable', () => {
const stateWithInvalidCol: IndexPatternPrivateState = getStateWithColumns({
const stateWithInvalidCol: FormBasedPrivateState = getStateWithColumns({
col1: {
label: 'Invalid differences',
dataType: 'number',
@ -2193,7 +2185,7 @@ describe('IndexPatternDimensionEditorPanel', () => {
});
wrapper = mount(
<IndexPatternDimensionEditorComponent {...defaultProps} state={stateWithInvalidCol} />
<FormBasedDimensionEditorComponent {...defaultProps} state={stateWithInvalidCol} />
);
expect(
@ -2205,7 +2197,7 @@ describe('IndexPatternDimensionEditorPanel', () => {
});
it('should remove options to select references when there are no time fields', () => {
const stateWithoutTime: IndexPatternPrivateState = {
const stateWithoutTime: FormBasedPrivateState = {
...getStateWithColumns({
col1: {
label: 'Avg',
@ -2218,7 +2210,7 @@ describe('IndexPatternDimensionEditorPanel', () => {
};
wrapper = mount(
<IndexPatternDimensionEditorComponent
<FormBasedDimensionEditorComponent
{...defaultProps}
state={stateWithoutTime}
indexPatterns={{
@ -2257,7 +2249,7 @@ describe('IndexPatternDimensionEditorPanel', () => {
});
it('should not show tabs when formula and static_value operations are not available', () => {
const stateWithInvalidCol: IndexPatternPrivateState = getStateWithColumns({
const stateWithInvalidCol: FormBasedPrivateState = getStateWithColumns({
col1: {
label: 'Average of memory',
dataType: 'number',
@ -2279,15 +2271,13 @@ describe('IndexPatternDimensionEditorPanel', () => {
}),
};
wrapper = mount(
<IndexPatternDimensionEditorComponent {...props} state={stateWithInvalidCol} />
);
wrapper = mount(<FormBasedDimensionEditorComponent {...props} state={stateWithInvalidCol} />);
expect(wrapper.find('[data-test-subj="lens-dimensionTabs"]').exists()).toBeFalsy();
});
it('should show the formula tab when supported', () => {
const stateWithFormulaColumn: IndexPatternPrivateState = getStateWithColumns({
const stateWithFormulaColumn: FormBasedPrivateState = getStateWithColumns({
col1: {
label: 'Formula',
dataType: 'number',
@ -2299,7 +2289,7 @@ describe('IndexPatternDimensionEditorPanel', () => {
});
wrapper = mount(
<IndexPatternDimensionEditorComponent {...defaultProps} state={stateWithFormulaColumn} />
<FormBasedDimensionEditorComponent {...defaultProps} state={stateWithFormulaColumn} />
);
expect(
@ -2308,7 +2298,7 @@ describe('IndexPatternDimensionEditorPanel', () => {
});
it('should not show the static_value tab when not supported', () => {
const stateWithFormulaColumn: IndexPatternPrivateState = getStateWithColumns({
const stateWithFormulaColumn: FormBasedPrivateState = getStateWithColumns({
col1: {
label: 'Formula',
dataType: 'number',
@ -2320,14 +2310,14 @@ describe('IndexPatternDimensionEditorPanel', () => {
});
wrapper = mount(
<IndexPatternDimensionEditorComponent {...defaultProps} state={stateWithFormulaColumn} />
<FormBasedDimensionEditorComponent {...defaultProps} state={stateWithFormulaColumn} />
);
expect(wrapper.find('[data-test-subj="lens-dimensionTabs-static_value"]').exists()).toBeFalsy();
});
it('should show the static value tab when supported', () => {
const staticWithFormulaColumn: IndexPatternPrivateState = getStateWithColumns({
const staticWithFormulaColumn: FormBasedPrivateState = getStateWithColumns({
col1: {
label: 'Formula',
dataType: 'number',
@ -2339,7 +2329,7 @@ describe('IndexPatternDimensionEditorPanel', () => {
});
wrapper = mount(
<IndexPatternDimensionEditorComponent
<FormBasedDimensionEditorComponent
{...defaultProps}
supportStaticValue
state={staticWithFormulaColumn}
@ -2352,10 +2342,10 @@ describe('IndexPatternDimensionEditorPanel', () => {
});
it('should select the quick function tab by default', () => {
const stateWithNoColumn: IndexPatternPrivateState = getStateWithColumns({});
const stateWithNoColumn: FormBasedPrivateState = getStateWithColumns({});
wrapper = mount(
<IndexPatternDimensionEditorComponent {...defaultProps} state={stateWithNoColumn} />
<FormBasedDimensionEditorComponent {...defaultProps} state={stateWithNoColumn} />
);
expect(
@ -2367,10 +2357,10 @@ describe('IndexPatternDimensionEditorPanel', () => {
});
it('should select the static value tab when supported by default', () => {
const stateWithNoColumn: IndexPatternPrivateState = getStateWithColumns({});
const stateWithNoColumn: FormBasedPrivateState = getStateWithColumns({});
wrapper = mount(
<IndexPatternDimensionEditorComponent
<FormBasedDimensionEditorComponent
{...defaultProps}
supportStaticValue
state={stateWithNoColumn}
@ -2383,7 +2373,7 @@ describe('IndexPatternDimensionEditorPanel', () => {
});
it('should not show any tab when formula is in full screen mode', () => {
const stateWithFormulaColumn: IndexPatternPrivateState = getStateWithColumns({
const stateWithFormulaColumn: FormBasedPrivateState = getStateWithColumns({
col1: {
label: 'Formula',
dataType: 'number',
@ -2395,7 +2385,7 @@ describe('IndexPatternDimensionEditorPanel', () => {
});
wrapper = mount(
<IndexPatternDimensionEditorComponent
<FormBasedDimensionEditorComponent
{...defaultProps}
state={stateWithFormulaColumn}
supportStaticValue

View file

@ -13,22 +13,22 @@ import { LayerTypes } from '@kbn/expression-xy-plugin/public';
import type { UnifiedSearchPublicPluginStart } from '@kbn/unified-search-plugin/public';
import type { FieldFormatsStart } from '@kbn/field-formats-plugin/public';
import type { DataViewsPublicPluginStart } from '@kbn/data-views-plugin/public';
import type { DatasourceDimensionTriggerProps, DatasourceDimensionEditorProps } from '../../types';
import type { GenericIndexPatternColumn } from '../indexpattern';
import { DatasourceDimensionTriggerProps, DatasourceDimensionEditorProps } from '../../../types';
import { GenericIndexPatternColumn } from '../form_based';
import { isColumnInvalid } from '../utils';
import type { IndexPatternPrivateState } from '../types';
import { FormBasedPrivateState } from '../types';
import { DimensionEditor } from './dimension_editor';
import type { DateRange } from '../../../common';
import { DateRange } from '../../../../common';
import { getOperationSupportMatrix } from './operation_support';
import { DimensionTrigger } from '../../shared_components/dimension_trigger';
import { DimensionTrigger } from '../../../shared_components/dimension_trigger';
export type IndexPatternDimensionTriggerProps =
DatasourceDimensionTriggerProps<IndexPatternPrivateState> & {
export type FormBasedDimensionTriggerProps =
DatasourceDimensionTriggerProps<FormBasedPrivateState> & {
uniqueLabel: string;
};
export type IndexPatternDimensionEditorProps =
DatasourceDimensionEditorProps<IndexPatternPrivateState> & {
export type FormBasedDimensionEditorProps =
DatasourceDimensionEditorProps<FormBasedPrivateState> & {
uiSettings: IUiSettingsClient;
storage: IStorageWrapper;
savedObjectsClient: SavedObjectsClientContract;
@ -49,8 +49,8 @@ function wrapOnDot(str?: string) {
return str ? str.replace(/\./g, '.\u200B') : '';
}
export const IndexPatternDimensionTriggerComponent = function IndexPatternDimensionTrigger(
props: IndexPatternDimensionTriggerProps
export const FormBasedDimensionTriggerComponent = function FormBasedDimensionTrigger(
props: FormBasedDimensionTriggerProps
) {
const layerId = props.layerId;
const layer = props.state.layers[layerId];
@ -80,8 +80,8 @@ export const IndexPatternDimensionTriggerComponent = function IndexPatternDimens
);
};
export const IndexPatternDimensionEditorComponent = function IndexPatternDimensionPanel(
props: IndexPatternDimensionEditorProps
export const FormBasedDimensionEditorComponent = function FormBasedDimensionPanel(
props: FormBasedDimensionEditorProps
) {
const layerId = props.layerId;
const currentIndexPattern = props.indexPatterns[props.state.layers[layerId]?.indexPatternId];
@ -103,5 +103,5 @@ export const IndexPatternDimensionEditorComponent = function IndexPatternDimensi
);
};
export const IndexPatternDimensionTrigger = memo(IndexPatternDimensionTriggerComponent);
export const IndexPatternDimensionEditor = memo(IndexPatternDimensionEditorComponent);
export const FormBasedDimensionTrigger = memo(FormBasedDimensionTriggerComponent);
export const FormBasedDimensionEditor = memo(FormBasedDimensionEditorComponent);

View file

@ -5,7 +5,7 @@
* 2.0.
*/
import { DragDropOperation, OperationMetadata } from '../../../types';
import { DragDropOperation, OperationMetadata } from '../../../../types';
import { TermsIndexPatternColumn } from '../../operations';
import { getDropProps } from './get_drop_props';
import {
@ -15,7 +15,7 @@ import {
mockedDndOperations,
mockedColumns,
} from './mocks';
import { generateId } from '../../../id_generator';
import { generateId } from '../../../../id_generator';
const getDefaultProps = () => ({
indexPatterns: mockDataViews(),
@ -27,7 +27,7 @@ const getDefaultProps = () => ({
source: mockedDndOperations.bucket,
});
describe('IndexPatternDimensionEditorPanel#getDropProps', () => {
describe('FormBasedDimensionEditorPanel#getDropProps', () => {
describe('not dragging', () => {
it('returns undefined if no drag is happening', () => {
expect(getDropProps({ ...getDefaultProps(), source: undefined })).toBe(undefined);

View file

@ -12,22 +12,22 @@ import {
IndexPattern,
IndexPatternMap,
IndexPatternField,
} from '../../../types';
} from '../../../../types';
import {
getCurrentFieldsForOperation,
getOperationDisplay,
hasOperationSupportForMultipleFields,
} from '../../operations';
import { isDraggedDataViewField, isOperationFromTheSameGroup } from '../../../utils';
import { isDraggedDataViewField, isOperationFromTheSameGroup } from '../../../../utils';
import { hasField } from '../../pure_utils';
import { DragContextState } from '../../../drag_drop/providers';
import { OperationMetadata, DraggedField } from '../../../types';
import { DragContextState } from '../../../../drag_drop/providers';
import { OperationMetadata, DraggedField } from '../../../../types';
import { getOperationTypesForField } from '../../operations';
import { GenericIndexPatternColumn } from '../../indexpattern';
import { IndexPatternPrivateState, DataViewDragDropOperation } from '../../types';
import { GenericIndexPatternColumn } from '../../form_based';
import { FormBasedPrivateState, DataViewDragDropOperation } from '../../types';
interface GetDropPropsArgs {
state: IndexPatternPrivateState;
state: FormBasedPrivateState;
source?: DragContextState['dragging'];
target: DragDropOperation;
indexPatterns: IndexPatternMap;

View file

@ -5,9 +5,9 @@
* 2.0.
*/
import { IndexPatternLayer } from '../../types';
import { FormBasedLayer } from '../../types';
import { documentField } from '../../document_field';
import { IndexPatternMap, OperationMetadata } from '../../../types';
import { IndexPatternMap, OperationMetadata } from '../../../../types';
import {
DateHistogramIndexPatternColumn,
GenericIndexPatternColumn,
@ -15,7 +15,7 @@ import {
TermsIndexPatternColumn,
} from '../../operations';
import { getFieldByNameFactory } from '../../pure_helpers';
jest.mock('../../../id_generator');
jest.mock('../../../../id_generator');
export const mockDataViews = (): IndexPatternMap => {
const fields = [
@ -191,7 +191,7 @@ export const mockedColumns: Record<string, GenericIndexPatternColumn> = {
} as GenericIndexPatternColumn,
};
export const mockedLayers: Record<string, (...args: string[]) => IndexPatternLayer> = {
export const mockedLayers: Record<string, (...args: string[]) => FormBasedLayer> = {
singleColumnLayer: (id = 'col1') => ({
indexPatternId: 'first',
columnOrder: [id],

View file

@ -6,10 +6,14 @@
*/
import { onDrop } from './on_drop_handler';
import { IndexPatternPrivateState } from '../../types';
import { OperationMetadata, DropType, DatasourceDimensionDropHandlerProps } from '../../../types';
import { FormBasedPrivateState } from '../../types';
import {
OperationMetadata,
DropType,
DatasourceDimensionDropHandlerProps,
} from '../../../../types';
import { FormulaIndexPatternColumn, MedianIndexPatternColumn } from '../../operations';
import { generateId } from '../../../id_generator';
import { generateId } from '../../../../id_generator';
import {
mockDataViews,
mockedLayers,
@ -18,7 +22,7 @@ import {
mockedColumns,
} from './mocks';
jest.mock('../../../id_generator');
jest.mock('../../../../id_generator');
const dimensionGroups = [
{
@ -47,7 +51,7 @@ const dimensionGroups = [
},
];
function getStateWithMultiFieldColumn(state: IndexPatternPrivateState) {
function getStateWithMultiFieldColumn(state: FormBasedPrivateState) {
return {
...state,
layers: {
@ -62,10 +66,10 @@ function getStateWithMultiFieldColumn(state: IndexPatternPrivateState) {
};
}
describe('IndexPatternDimensionEditorPanel: onDrop', () => {
let state: IndexPatternPrivateState;
describe('FormBasedDimensionEditorPanel: onDrop', () => {
let state: FormBasedPrivateState;
let setState: jest.Mock;
let defaultProps: DatasourceDimensionDropHandlerProps<IndexPatternPrivateState>;
let defaultProps: DatasourceDimensionDropHandlerProps<FormBasedPrivateState>;
beforeEach(() => {
state = {
@ -347,7 +351,7 @@ describe('IndexPatternDimensionEditorPanel: onDrop', () => {
describe('dropping a dimension', () => {
it('sets correct order in group for metric and bucket columns when duplicating a column in group', () => {
const testState: IndexPatternPrivateState = {
const testState: FormBasedPrivateState = {
...state,
layers: {
...state.layers,
@ -439,7 +443,7 @@ describe('IndexPatternDimensionEditorPanel: onDrop', () => {
it('when duplicating fullReference column, the referenced columns get duplicated too', () => {
(generateId as jest.Mock).mockReturnValue(`ref1Copy`);
const testState: IndexPatternPrivateState = {
const testState: FormBasedPrivateState = {
...state,
layers: {
...state.layers,
@ -501,7 +505,7 @@ describe('IndexPatternDimensionEditorPanel: onDrop', () => {
it('when duplicating fullReference column, the multiple referenced columns get duplicated too', () => {
(generateId as jest.Mock).mockReturnValueOnce(`ref1Copy`);
(generateId as jest.Mock).mockReturnValueOnce(`ref2Copy`);
const testState: IndexPatternPrivateState = {
const testState: FormBasedPrivateState = {
...state,
layers: {
...state.layers,
@ -566,7 +570,7 @@ describe('IndexPatternDimensionEditorPanel: onDrop', () => {
it('when duplicating fullReference column, the referenced columns get duplicated', () => {
(generateId as jest.Mock).mockReturnValueOnce(`ref1Copy`);
(generateId as jest.Mock).mockReturnValueOnce(`ref2Copy`);
const testState: IndexPatternPrivateState = {
const testState: FormBasedPrivateState = {
...state,
layers: {
...state.layers,
@ -854,7 +858,7 @@ describe('IndexPatternDimensionEditorPanel: onDrop', () => {
});
describe('dimension group aware ordering and copying', () => {
let testState: IndexPatternPrivateState;
let testState: FormBasedPrivateState;
beforeEach(() => {
testState = { ...state };
testState.layers.first = { ...mockedLayers.multipleColumnsLayer() };
@ -1541,7 +1545,7 @@ describe('IndexPatternDimensionEditorPanel: onDrop', () => {
},
];
describe('simple operations', () => {
let props: DatasourceDimensionDropHandlerProps<IndexPatternPrivateState>;
let props: DatasourceDimensionDropHandlerProps<FormBasedPrivateState>;
beforeEach(() => {
setState = jest.fn();
@ -2087,7 +2091,7 @@ describe('IndexPatternDimensionEditorPanel: onDrop', () => {
});
});
describe('references', () => {
let props: DatasourceDimensionDropHandlerProps<IndexPatternPrivateState>;
let props: DatasourceDimensionDropHandlerProps<FormBasedPrivateState>;
beforeEach(() => {
props = {
dimensionGroups: defaultDimensionGroups,

View file

@ -4,7 +4,7 @@
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import { isDraggedDataViewField } from '../../../utils';
import { isDraggedDataViewField } from '../../../../utils';
import {
DatasourceDimensionDropHandlerProps,
DragDropOperation,
@ -14,7 +14,7 @@ import {
StateSetter,
VisualizationDimensionGroupConfig,
DraggedField,
} from '../../../types';
} from '../../../../types';
import {
insertOrReplaceColumn,
deleteColumn,
@ -28,12 +28,12 @@ import {
} from '../../operations';
import { mergeLayer, mergeLayers } from '../../state_helpers';
import { getNewOperation, getField } from './get_drop_props';
import { IndexPatternPrivateState, DataViewDragDropOperation } from '../../types';
import { FormBasedPrivateState, DataViewDragDropOperation } from '../../types';
interface DropHandlerProps<T = DataViewDragDropOperation> {
state: IndexPatternPrivateState;
state: FormBasedPrivateState;
setState: StateSetter<
IndexPatternPrivateState,
FormBasedPrivateState,
{
isDimensionComplete?: boolean;
forceRender?: boolean;
@ -46,7 +46,7 @@ interface DropHandlerProps<T = DataViewDragDropOperation> {
indexPatterns: IndexPatternMap;
}
export function onDrop(props: DatasourceDimensionDropHandlerProps<IndexPatternPrivateState>) {
export function onDrop(props: DatasourceDimensionDropHandlerProps<FormBasedPrivateState>) {
const { target, source, dropType, state, indexPatterns } = props;
if (isDraggedDataViewField(source) && isFieldDropType(dropType)) {

View file

@ -21,7 +21,7 @@ import {
import { FieldInput, getErrorMessage } from './field_input';
import { createMockedIndexPattern } from '../mocks';
import { getOperationSupportMatrix } from '.';
import { GenericIndexPatternColumn, IndexPatternLayer, IndexPatternPrivateState } from '../types';
import { GenericIndexPatternColumn, FormBasedLayer, FormBasedPrivateState } from '../types';
import { ReferenceBasedIndexPatternColumn } from '../operations/definitions/column_types';
jest.mock('../operations/layer_helpers', () => {
@ -30,7 +30,7 @@ jest.mock('../operations/layer_helpers', () => {
return {
...original,
insertOrReplaceColumn: () => {
return {} as IndexPatternLayer;
return {} as FormBasedLayer;
},
};
});
@ -113,14 +113,14 @@ function getLayer(col1: GenericIndexPatternColumn = getStringBasedOperationColum
};
}
function getDefaultOperationSupportMatrix(
layer: IndexPatternLayer,
layer: FormBasedLayer,
columnId: string,
existingFields: Record<string, Record<string, boolean>>
) {
return getOperationSupportMatrix({
state: {
layers: { layer1: layer },
} as unknown as IndexPatternPrivateState,
} as unknown as FormBasedPrivateState,
layerId: 'layer1',
filterOperations: () => true,
columnId,

View file

@ -10,11 +10,15 @@ import { partition } from 'lodash';
import React, { useMemo } from 'react';
import { i18n } from '@kbn/i18n';
import { EuiComboBoxOptionOption, EuiComboBoxProps } from '@elastic/eui';
import type { OperationType } from '../indexpattern';
import type { OperationType } from '../form_based';
import type { OperationSupportMatrix } from './operation_support';
import { FieldOption, FieldOptionValue, FieldPicker } from '../../shared_components/field_picker';
import { fieldContainsData } from '../../shared_components';
import type { ExistingFieldsMap, IndexPattern } from '../../types';
import {
FieldOption,
FieldOptionValue,
FieldPicker,
} from '../../../shared_components/field_picker';
import { fieldContainsData } from '../../../shared_components';
import type { ExistingFieldsMap, IndexPattern } from '../../../types';
import { getFieldType } from '../pure_utils';
export type FieldChoiceWithOperationType = FieldOptionValue & {

View file

@ -8,11 +8,11 @@ import React, { useCallback } from 'react';
import { isEqual } from 'lodash';
import type { Query } from '@kbn/es-query';
import { GenericIndexPatternColumn, operationDefinitionMap } from '../operations';
import type { IndexPatternLayer } from '../types';
import { validateQuery, FilterQueryInput } from '../../shared_components';
import type { IndexPattern } from '../../types';
import type { FormBasedLayer } from '../types';
import { validateQuery, FilterQueryInput } from '../../../shared_components';
import type { IndexPattern } from '../../../types';
export function setFilter(columnId: string, layer: IndexPatternLayer, query: Query | undefined) {
export function setFilter(columnId: string, layer: FormBasedLayer, query: Query | undefined) {
return {
...layer,
columns: {
@ -36,8 +36,8 @@ export function Filtering({
selectedColumn: GenericIndexPatternColumn;
indexPattern: IndexPattern;
columnId: string;
layer: IndexPatternLayer;
updateLayer: (newLayer: IndexPatternLayer) => void;
layer: FormBasedLayer;
updateLayer: (newLayer: FormBasedLayer) => void;
helpMessage: string | null;
}) {
const inputFilter = selectedColumn.filter;

View file

@ -9,7 +9,7 @@ import React from 'react';
import { mount, shallow } from 'enzyme';
import { FormatSelector } from './format_selector';
import { act } from 'react-dom/test-utils';
import { GenericIndexPatternColumn } from '../..';
import { GenericIndexPatternColumn } from '../../..';
jest.mock('lodash', () => {
const original = jest.requireActual('lodash');

View file

@ -8,9 +8,9 @@
import React, { useCallback, useMemo, useState } from 'react';
import { i18n } from '@kbn/i18n';
import { EuiFormRow, EuiComboBox, EuiSpacer, EuiRange, EuiFieldText } from '@elastic/eui';
import { GenericIndexPatternColumn } from '../indexpattern';
import { GenericIndexPatternColumn } from '../form_based';
import { isColumnFormatted } from '../operations/definitions/helpers';
import { useDebouncedValue } from '../../shared_components';
import { useDebouncedValue } from '../../../shared_components';
const supportedFormats: Record<string, { title: string; defaultDecimals?: number }> = {
number: {

View file

@ -6,10 +6,10 @@
*/
import memoizeOne from 'memoize-one';
import { DatasourceDimensionDropProps, IndexPatternMap, OperationMetadata } from '../../types';
import { OperationType } from '../indexpattern';
import { DatasourceDimensionDropProps, IndexPatternMap, OperationMetadata } from '../../../types';
import { OperationType } from '../form_based';
import { memoizedGetAvailableOperationsByMetadata, OperationFieldTuple } from '../operations';
import { IndexPatternPrivateState } from '../types';
import { FormBasedPrivateState } from '../types';
export interface OperationSupportMatrix {
operationByField: Partial<Record<string, Set<OperationType>>>;
@ -18,9 +18,9 @@ export interface OperationSupportMatrix {
}
type Props = Pick<
DatasourceDimensionDropProps<IndexPatternPrivateState>['target'],
DatasourceDimensionDropProps<FormBasedPrivateState>['target'],
'layerId' | 'columnId' | 'filterOperations'
> & { state: IndexPatternPrivateState; indexPatterns: IndexPatternMap };
> & { state: FormBasedPrivateState; indexPatterns: IndexPatternMap };
function computeOperationMatrix(
operationsByMetadata: Array<{

View file

@ -17,13 +17,13 @@ import {
GenericIndexPatternColumn,
operationDefinitionMap,
} from '../operations';
import type { IndexPatternLayer } from '../types';
import type { IndexPattern } from '../../types';
import type { FormBasedLayer } from '../types';
import type { IndexPattern } from '../../../types';
import { reducedTimeRangeOptions } from '../reduced_time_range_utils';
export function setReducedTimeRange(
columnId: string,
layer: IndexPatternLayer,
layer: FormBasedLayer,
reducedTimeRange: string | undefined,
skipLabelUpdate?: boolean
) {
@ -69,8 +69,8 @@ export function ReducedTimeRange({
}: {
selectedColumn: GenericIndexPatternColumn;
columnId: string;
layer: IndexPatternLayer;
updateLayer: (newLayer: IndexPatternLayer) => void;
layer: FormBasedLayer;
updateLayer: (newLayer: FormBasedLayer) => void;
indexPattern: IndexPattern;
helpMessage: string | null;
skipLabelUpdate?: boolean;

View file

@ -16,7 +16,7 @@ import { fieldFormatsServiceMock } from '@kbn/field-formats-plugin/public/mocks'
import type { IUiSettingsClient, SavedObjectsClientContract, HttpSetup } from '@kbn/core/public';
import { IStorageWrapper } from '@kbn/kibana-utils-plugin/public';
import type { DataPublicPluginStart } from '@kbn/data-plugin/public';
import { OperationMetadata } from '../../types';
import { OperationMetadata } from '../../../types';
import { createMockedIndexPattern, createMockedIndexPatternWithoutType } from '../mocks';
import { ReferenceEditor, ReferenceEditorProps } from './reference_editor';
import {
@ -26,7 +26,7 @@ import {
TermsIndexPatternColumn,
} from '../operations';
import { FieldSelect } from './field_select';
import { IndexPatternLayer } from '../types';
import { FormBasedLayer } from '../types';
jest.mock('../operations');
@ -148,7 +148,7 @@ describe('reference editor', () => {
sourceField: 'bytes',
},
},
} as IndexPatternLayer;
} as FormBasedLayer;
wrapper = mount(
<ReferenceEditor
{...getDefaultArgs()}
@ -187,7 +187,7 @@ describe('reference editor', () => {
sourceField: 'dest',
},
},
} as IndexPatternLayer;
} as FormBasedLayer;
wrapper = mount(
<ReferenceEditor
{...getDefaultArgs()}
@ -223,7 +223,7 @@ describe('reference editor', () => {
sourceField: 'bytes',
},
},
} as IndexPatternLayer;
} as FormBasedLayer;
wrapper = mount(
<ReferenceEditor
{...getDefaultArgs()}
@ -261,7 +261,7 @@ describe('reference editor', () => {
sourceField: 'bytes',
},
},
} as IndexPatternLayer;
} as FormBasedLayer;
wrapper = mount(
<ReferenceEditor
{...getDefaultArgs()}
@ -305,7 +305,7 @@ describe('reference editor', () => {
sourceField: 'dest',
},
},
} as IndexPatternLayer;
} as FormBasedLayer;
const onChooseFunction = jest.fn();
wrapper = mount(
<ReferenceEditor
@ -346,7 +346,7 @@ describe('reference editor', () => {
sourceField: 'bytes',
},
},
} as IndexPatternLayer;
} as FormBasedLayer;
wrapper = mount(
<ReferenceEditor
{...getDefaultArgs()}
@ -438,7 +438,7 @@ describe('reference editor', () => {
incompleteColumns: {
ref: { operationType: 'max' },
},
} as IndexPatternLayer;
} as FormBasedLayer;
wrapper = mount(
<ReferenceEditor
{...getDefaultArgs()}
@ -476,7 +476,7 @@ describe('reference editor', () => {
incompleteColumns: {
ref: { sourceField: 'timestamp' },
},
} as IndexPatternLayer;
} as FormBasedLayer;
wrapper = mount(
<ReferenceEditor
{...getDefaultArgs()}
@ -531,7 +531,7 @@ describe('reference editor', () => {
sourceField: 'missing',
},
},
} as IndexPatternLayer;
} as FormBasedLayer;
wrapper = mount(
<ReferenceEditor
{...getDefaultArgs()}

View file

@ -15,9 +15,9 @@ import type { DataViewsPublicPluginStart } from '@kbn/data-views-plugin/public';
import type { FieldFormatsStart } from '@kbn/field-formats-plugin/public';
import { IStorageWrapper } from '@kbn/kibana-utils-plugin/public';
import type { DataPublicPluginStart } from '@kbn/data-plugin/public';
import type { DateRange } from '../../../common';
import type { DateRange } from '../../../../common';
import type { OperationSupportMatrix } from './operation_support';
import type { GenericIndexPatternColumn, OperationType } from '../indexpattern';
import type { GenericIndexPatternColumn, OperationType } from '../form_based';
import {
getOperationDisplay,
isOperationAllowedAsReference,
@ -28,14 +28,14 @@ import {
} from '../operations';
import { FieldChoiceWithOperationType, FieldSelect } from './field_select';
import { hasField } from '../pure_utils';
import type { IndexPatternLayer } from '../types';
import type { FormBasedLayer } from '../types';
import type {
ExistingFieldsMap,
IndexPattern,
IndexPatternField,
ParamEditorCustomProps,
} from '../../types';
import type { IndexPatternDimensionEditorProps } from './dimension_panel';
} from '../../../types';
import type { FormBasedDimensionEditorProps } from './dimension_panel';
import { FormRow } from '../operations/definitions/shared_components';
const operationDisplay = getOperationDisplay();
@ -70,9 +70,9 @@ const getFunctionOptions = (
};
export interface ReferenceEditorProps {
layer: IndexPatternLayer;
layer: FormBasedLayer;
layerId: string;
activeData?: IndexPatternDimensionEditorProps['activeData'];
activeData?: FormBasedDimensionEditorProps['activeData'];
selectionStyle: 'full' | 'field' | 'hidden';
validation: RequiredReference;
columnId: string;
@ -92,8 +92,8 @@ export interface ReferenceEditorProps {
paramEditorCustomProps?: ParamEditorCustomProps;
paramEditorUpdater: (
setter:
| IndexPatternLayer
| ((prevLayer: IndexPatternLayer) => IndexPatternLayer)
| FormBasedLayer
| ((prevLayer: FormBasedLayer) => FormBasedLayer)
| GenericIndexPatternColumn
) => void;
onChooseField: (choice: FieldChoiceWithOperationType) => void;

View file

@ -20,13 +20,13 @@ import {
GenericIndexPatternColumn,
operationDefinitionMap,
} from '../operations';
import type { TimeScaleUnit } from '../../../common/expressions';
import { unitSuffixesLong } from '../../../common/suffix_formatter';
import type { IndexPatternLayer } from '../types';
import type { TimeScaleUnit } from '../../../../common/expressions';
import { unitSuffixesLong } from '../../../../common/suffix_formatter';
import type { FormBasedLayer } from '../types';
export function setTimeScaling(
columnId: string,
layer: IndexPatternLayer,
layer: FormBasedLayer,
timeScale: TimeScaleUnit | undefined
) {
const currentColumn = layer.columns[columnId];
@ -62,8 +62,8 @@ export function TimeScaling({
}: {
selectedColumn: GenericIndexPatternColumn;
columnId: string;
layer: IndexPatternLayer;
updateLayer: (newLayer: IndexPatternLayer) => void;
layer: FormBasedLayer;
updateLayer: (newLayer: FormBasedLayer) => void;
}) {
const selectedOperation = operationDefinitionMap[selectedColumn.operationType];

View file

@ -15,18 +15,18 @@ import {
GenericIndexPatternColumn,
operationDefinitionMap,
} from '../operations';
import type { IndexPatternLayer } from '../types';
import type { IndexPatternDimensionEditorProps } from './dimension_panel';
import type { FormBasedLayer } from '../types';
import type { FormBasedDimensionEditorProps } from './dimension_panel';
import {
getDateHistogramInterval,
getLayerTimeShiftChecks,
timeShiftOptions,
} from '../time_shift_utils';
import type { IndexPattern } from '../../types';
import type { IndexPattern } from '../../../types';
export function setTimeShift(
columnId: string,
layer: IndexPatternLayer,
layer: FormBasedLayer,
timeShift: string | undefined
) {
const trimmedTimeShift = timeShift?.trim();
@ -69,9 +69,9 @@ export function TimeShift({
selectedColumn: GenericIndexPatternColumn;
indexPattern: IndexPattern;
columnId: string;
layer: IndexPatternLayer;
updateLayer: (newLayer: IndexPatternLayer) => void;
activeData: IndexPatternDimensionEditorProps['activeData'];
layer: FormBasedLayer;
updateLayer: (newLayer: FormBasedLayer) => void;
activeData: FormBasedDimensionEditorProps['activeData'];
layerId: string;
}) {
const [localValue, setLocalValue] = useState(selectedColumn.timeShift);

View file

@ -6,8 +6,8 @@
*/
import { i18n } from '@kbn/i18n';
import { DOCUMENT_FIELD_NAME } from '../../common';
import type { IndexPatternField } from '../types';
import { DOCUMENT_FIELD_NAME } from '../../../common';
import type { IndexPatternField } from '../../types';
const customLabel = i18n.translate('xpack.lens.indexPattern.records', {
defaultMessage: 'Records',

View file

@ -1,4 +1,4 @@
@import '../mixins';
@import '../../mixins';
.lnsFieldItem {
width: 100%;

View file

@ -15,7 +15,7 @@ import { coreMock } from '@kbn/core/public/mocks';
import { mountWithIntl } from '@kbn/test-jest-helpers';
import { findTestSubject } from '@elastic/eui/lib/test';
import { fieldFormatsServiceMock } from '@kbn/field-formats-plugin/public/mocks';
import { IndexPattern } from '../types';
import { IndexPattern } from '../../types';
import { chartPluginMock } from '@kbn/charts-plugin/public/mocks';
import { documentField } from './document_field';
import { uiActionsPluginMock } from '@kbn/ui-actions-plugin/public/mocks';
@ -25,9 +25,9 @@ import { dataPluginMock } from '@kbn/data-plugin/public/mocks';
import { dataViewPluginMocks } from '@kbn/data-views-plugin/public/mocks';
import { DataView, DataViewField } from '@kbn/data-views-plugin/common';
import { loadFieldStats } from '@kbn/unified-field-list-plugin/public/services/field_stats';
import { DOCUMENT_FIELD_NAME } from '../../../common';
import { LensFieldIcon } from '../../shared_components';
import { FieldStats, FieldVisualizeButton } from '@kbn/unified-field-list-plugin/public';
import { DOCUMENT_FIELD_NAME } from '../../common';
import { LensFieldIcon } from '../shared_components';
jest.mock('@kbn/unified-field-list-plugin/public/services/field_stats', () => ({
loadFieldStats: jest.fn().mockResolvedValue({}),

View file

@ -26,16 +26,16 @@ import {
FieldPopoverVisualize,
} from '@kbn/unified-field-list-plugin/public';
import { generateFilters, getEsQueryConfig } from '@kbn/data-plugin/public';
import { APP_ID } from '../../common/constants';
import { DragDrop } from '../drag_drop';
import { DatasourceDataPanelProps, DataType } from '../types';
import { DOCUMENT_FIELD_NAME } from '../../common';
import type { IndexPattern, IndexPatternField } from '../types';
import { LensFieldIcon } from '../shared_components/field_picker/lens_field_icon';
import type { LensAppServices } from '../app_plugin/types';
import { debouncedComponent } from '../debounced_component';
import { DragDrop } from '../../drag_drop';
import { DatasourceDataPanelProps, DataType } from '../../types';
import { DOCUMENT_FIELD_NAME } from '../../../common';
import type { IndexPattern, IndexPatternField } from '../../types';
import { LensFieldIcon } from '../../shared_components/field_picker/lens_field_icon';
import type { LensAppServices } from '../../app_plugin/types';
import { debouncedComponent } from '../../debounced_component';
import { APP_ID } from '../../../common/constants';
import { getFieldType } from './pure_utils';
import { combineQueryAndFilters } from '../app_plugin/show_underlying_data';
import { combineQueryAndFilters } from '../../app_plugin/show_underlying_data';
export interface FieldItemProps {
core: DatasourceDataPanelProps['core'];

View file

@ -13,7 +13,7 @@ import { UiActionsStart } from '@kbn/ui-actions-plugin/public';
import { FieldItem } from './field_item';
import { NoFieldsCallout } from './no_fields_callout';
import { FieldItemSharedProps, FieldsAccordion } from './fields_accordion';
import type { DatasourceDataPanelProps, IndexPatternField } from '../types';
import type { DatasourceDataPanelProps, IndexPatternField } from '../../types';
const PAGINATION_SIZE = 50;
export type FieldGroups = Record<

View file

@ -10,7 +10,7 @@ import { EuiLoadingSpinner, EuiNotificationBadge } from '@elastic/eui';
import { coreMock } from '@kbn/core/public/mocks';
import { mountWithIntl, shallowWithIntl } from '@kbn/test-jest-helpers';
import { fieldFormatsServiceMock } from '@kbn/field-formats-plugin/public/mocks';
import { IndexPattern } from '../types';
import { IndexPattern } from '../../types';
import { FieldItem } from './field_item';
import { FieldsAccordion, FieldsAccordionProps, FieldItemSharedProps } from './fields_accordion';
import { chartPluginMock } from '@kbn/charts-plugin/public/mocks';

View file

@ -23,7 +23,7 @@ import type { Query } from '@kbn/es-query';
import { ChartsPluginSetup } from '@kbn/charts-plugin/public';
import { UiActionsStart } from '@kbn/ui-actions-plugin/public';
import { FieldItem } from './field_item';
import type { DatasourceDataPanelProps, IndexPattern, IndexPatternField } from '../types';
import type { DatasourceDataPanelProps, IndexPattern, IndexPatternField } from '../../types';
export interface FieldItemSharedProps {
core: DatasourceDataPanelProps['core'];

View file

@ -10,7 +10,7 @@ import { SavedObjectReference } from '@kbn/core/public';
import { isFragment } from 'react-is';
import { coreMock } from '@kbn/core/public/mocks';
import { IStorageWrapper } from '@kbn/kibana-utils-plugin/public';
import { IndexPatternPersistedState, IndexPatternPrivateState } from './types';
import { FormBasedPersistedState, FormBasedPrivateState } from './types';
import { unifiedSearchPluginMock } from '@kbn/unified-search-plugin/public/mocks';
import { dataPluginMock } from '@kbn/data-plugin/public/mocks';
import { dataViewPluginMocks } from '@kbn/data-views-plugin/public/mocks';
@ -20,8 +20,8 @@ import { indexPatternFieldEditorPluginMock } from '@kbn/data-view-field-editor-p
import { uiActionsPluginMock } from '@kbn/ui-actions-plugin/public/mocks';
import { fieldFormatsServiceMock } from '@kbn/field-formats-plugin/public/mocks';
import { TinymathAST } from '@kbn/tinymath';
import { getIndexPatternDatasource, GenericIndexPatternColumn } from './indexpattern';
import { DatasourcePublicAPI, Datasource, FramePublicAPI, OperationDescriptor } from '../types';
import { getFormBasedDatasource, GenericIndexPatternColumn } from './form_based';
import { DatasourcePublicAPI, Datasource, FramePublicAPI, OperationDescriptor } from '../../types';
import { getFieldByNameFactory } from './pure_helpers';
import {
operationDefinitionMap,
@ -42,10 +42,10 @@ import {
import { createMockedFullReference } from './operations/mocks';
import { cloneDeep } from 'lodash';
import { DatatableColumn } from '@kbn/expressions-plugin/common';
import { createMockFramePublicAPI } from '../mocks';
import { createMockFramePublicAPI } from '../../mocks';
jest.mock('./loader');
jest.mock('../id_generator');
jest.mock('../../id_generator');
jest.mock('./operations');
jest.mock('./dimension_panel/reference_editor', () => ({
ReferenceEditor: () => null,
@ -178,11 +178,11 @@ const expectedIndexPatterns = {
const indexPatterns = expectedIndexPatterns;
describe('IndexPattern Data Source', () => {
let baseState: IndexPatternPrivateState;
let indexPatternDatasource: Datasource<IndexPatternPrivateState, IndexPatternPersistedState>;
let baseState: FormBasedPrivateState;
let FormBasedDatasource: Datasource<FormBasedPrivateState, FormBasedPersistedState>;
beforeEach(() => {
indexPatternDatasource = getIndexPatternDatasource({
FormBasedDatasource = getFormBasedDatasource({
unifiedSearch: unifiedSearchPluginMock.createStartContract(),
storage: {} as IStorageWrapper,
core: coreMock.createStart(),
@ -230,7 +230,7 @@ describe('IndexPattern Data Source', () => {
operationType: 'count',
sourceField: '___records___',
};
const map = indexPatternDatasource.uniqueLabels({
const map = FormBasedDatasource.uniqueLabels({
layers: {
a: {
columnOrder: ['a', 'b'],
@ -252,7 +252,7 @@ describe('IndexPattern Data Source', () => {
indexPatternId: 'foo',
},
},
} as unknown as IndexPatternPrivateState);
} as unknown as FormBasedPrivateState);
expect(map).toMatchInlineSnapshot(`
Object {
@ -267,7 +267,7 @@ describe('IndexPattern Data Source', () => {
describe('#getPersistedState', () => {
it('should persist from saved state', async () => {
expect(indexPatternDatasource.getPersistableState(baseState)).toEqual({
expect(FormBasedDatasource.getPersistableState(baseState)).toEqual({
state: {
layers: {
first: {
@ -300,12 +300,12 @@ describe('IndexPattern Data Source', () => {
describe('#toExpression', () => {
it('should generate an empty expression when no columns are selected', async () => {
const state = indexPatternDatasource.initialize();
expect(indexPatternDatasource.toExpression(state, 'first', indexPatterns)).toEqual(null);
const state = FormBasedDatasource.initialize();
expect(FormBasedDatasource.toExpression(state, 'first', indexPatterns)).toEqual(null);
});
it('should create a table when there is a formula without aggs', async () => {
const queryBaseState: IndexPatternPrivateState = {
const queryBaseState: FormBasedPrivateState = {
currentIndexPatternId: '1',
layers: {
first: {
@ -324,7 +324,7 @@ describe('IndexPattern Data Source', () => {
},
},
};
expect(indexPatternDatasource.toExpression(queryBaseState, 'first', indexPatterns)).toEqual({
expect(FormBasedDatasource.toExpression(queryBaseState, 'first', indexPatterns)).toEqual({
chain: [
{
function: 'createTable',
@ -342,7 +342,7 @@ describe('IndexPattern Data Source', () => {
});
it('should generate an expression for an aggregated query', async () => {
const queryBaseState: IndexPatternPrivateState = {
const queryBaseState: FormBasedPrivateState = {
currentIndexPatternId: '1',
layers: {
first: {
@ -371,7 +371,7 @@ describe('IndexPattern Data Source', () => {
},
};
expect(indexPatternDatasource.toExpression(queryBaseState, 'first', indexPatterns))
expect(FormBasedDatasource.toExpression(queryBaseState, 'first', indexPatterns))
.toMatchInlineSnapshot(`
Object {
"chain": Array [
@ -496,7 +496,7 @@ describe('IndexPattern Data Source', () => {
});
it('should put all time fields used in date_histograms to the esaggs timeFields parameter if not ignoring global time range', async () => {
const queryBaseState: IndexPatternPrivateState = {
const queryBaseState: FormBasedPrivateState = {
currentIndexPatternId: '1',
layers: {
first: {
@ -546,16 +546,12 @@ describe('IndexPattern Data Source', () => {
},
};
const ast = indexPatternDatasource.toExpression(
queryBaseState,
'first',
indexPatterns
) as Ast;
const ast = FormBasedDatasource.toExpression(queryBaseState, 'first', indexPatterns) as Ast;
expect(ast.chain[1].arguments.timeFields).toEqual(['timestamp', 'another_datefield']);
});
it('should pass time shift parameter to metric agg functions', async () => {
const queryBaseState: IndexPatternPrivateState = {
const queryBaseState: FormBasedPrivateState = {
currentIndexPatternId: '1',
layers: {
first: {
@ -585,11 +581,7 @@ describe('IndexPattern Data Source', () => {
},
};
const ast = indexPatternDatasource.toExpression(
queryBaseState,
'first',
indexPatterns
) as Ast;
const ast = FormBasedDatasource.toExpression(queryBaseState, 'first', indexPatterns) as Ast;
expect((ast.chain[1].arguments.aggs[1] as Ast).chain[0].arguments.timeShift).toEqual(['1d']);
});
@ -609,7 +601,7 @@ describe('IndexPattern Data Source', () => {
* The sum has its own shift and does not respected the shift from the moving average
* The differences has a filter which is inherited to the median, but not the average as it has its own filter
*/
const queryBaseState: IndexPatternPrivateState = {
const queryBaseState: FormBasedPrivateState = {
currentIndexPatternId: '1',
layers: {
first: {
@ -796,11 +788,7 @@ describe('IndexPattern Data Source', () => {
},
};
const ast = indexPatternDatasource.toExpression(
queryBaseState,
'first',
indexPatterns
) as Ast;
const ast = FormBasedDatasource.toExpression(queryBaseState, 'first', indexPatterns) as Ast;
const count = (ast.chain[1].arguments.aggs[1] as Ast).chain[0];
const sum = (ast.chain[1].arguments.aggs[2] as Ast).chain[0];
const average = (ast.chain[1].arguments.aggs[3] as Ast).chain[0];
@ -822,7 +810,7 @@ describe('IndexPattern Data Source', () => {
});
it('should wrap filtered metrics in filtered metric aggregation', async () => {
const queryBaseState: IndexPatternPrivateState = {
const queryBaseState: FormBasedPrivateState = {
currentIndexPatternId: '1',
layers: {
first: {
@ -864,11 +852,7 @@ describe('IndexPattern Data Source', () => {
},
};
const ast = indexPatternDatasource.toExpression(
queryBaseState,
'first',
indexPatterns
) as Ast;
const ast = FormBasedDatasource.toExpression(queryBaseState, 'first', indexPatterns) as Ast;
expect(ast.chain[1].arguments.aggs[0]).toMatchInlineSnapshot(`
Object {
"chain": Array [
@ -954,7 +938,7 @@ describe('IndexPattern Data Source', () => {
});
it('should add time_scale and format function if time scale is set and supported', async () => {
const queryBaseState: IndexPatternPrivateState = {
const queryBaseState: FormBasedPrivateState = {
currentIndexPatternId: '1',
layers: {
first: {
@ -992,11 +976,7 @@ describe('IndexPattern Data Source', () => {
},
};
const ast = indexPatternDatasource.toExpression(
queryBaseState,
'first',
indexPatterns
) as Ast;
const ast = FormBasedDatasource.toExpression(queryBaseState, 'first', indexPatterns) as Ast;
const timeScaleCalls = ast.chain.filter((fn) => fn.function === 'lens_time_scale');
const formatCalls = ast.chain.filter((fn) => fn.function === 'lens_format_column');
expect(timeScaleCalls).toHaveLength(1);
@ -1040,7 +1020,7 @@ describe('IndexPattern Data Source', () => {
});
it('should not add time shift to nested count metric', async () => {
const queryBaseState: IndexPatternPrivateState = {
const queryBaseState: FormBasedPrivateState = {
currentIndexPatternId: '1',
layers: {
first: {
@ -1061,11 +1041,7 @@ describe('IndexPattern Data Source', () => {
},
};
const ast = indexPatternDatasource.toExpression(
queryBaseState,
'first',
indexPatterns
) as Ast;
const ast = FormBasedDatasource.toExpression(queryBaseState, 'first', indexPatterns) as Ast;
const filteredMetricAgg = (ast.chain[1].arguments.aggs[0] as Ast).chain[0].arguments;
const metricAgg = (filteredMetricAgg.customMetric[0] as Ast).chain[0].arguments;
const bucketAgg = (filteredMetricAgg.customBucket[0] as Ast).chain[0].arguments;
@ -1076,7 +1052,7 @@ describe('IndexPattern Data Source', () => {
});
it('should put column formatters after calculated columns', async () => {
const queryBaseState: IndexPatternPrivateState = {
const queryBaseState: FormBasedPrivateState = {
currentIndexPatternId: '1',
layers: {
first: {
@ -1116,18 +1092,14 @@ describe('IndexPattern Data Source', () => {
},
};
const ast = indexPatternDatasource.toExpression(
queryBaseState,
'first',
indexPatterns
) as Ast;
const ast = FormBasedDatasource.toExpression(queryBaseState, 'first', indexPatterns) as Ast;
const formatIndex = ast.chain.findIndex((fn) => fn.function === 'lens_format_column');
const calculationIndex = ast.chain.findIndex((fn) => fn.function === 'moving_average');
expect(calculationIndex).toBeLessThan(formatIndex);
});
it('should rename the output from esaggs when using flat query', () => {
const queryBaseState: IndexPatternPrivateState = {
const queryBaseState: FormBasedPrivateState = {
currentIndexPatternId: '1',
layers: {
first: {
@ -1168,11 +1140,7 @@ describe('IndexPattern Data Source', () => {
},
};
const ast = indexPatternDatasource.toExpression(
queryBaseState,
'first',
indexPatterns
) as Ast;
const ast = FormBasedDatasource.toExpression(queryBaseState, 'first', indexPatterns) as Ast;
expect(ast.chain[1].arguments.metricsAtAllLevels).toEqual([false]);
expect(JSON.parse(ast.chain[2].arguments.idMap[0] as string)).toEqual({
'col-0-0': [expect.objectContaining({ id: 'bucket1' })],
@ -1182,7 +1150,7 @@ describe('IndexPattern Data Source', () => {
});
it('should not put date fields used outside date_histograms to the esaggs timeFields parameter', async () => {
const queryBaseState: IndexPatternPrivateState = {
const queryBaseState: FormBasedPrivateState = {
currentIndexPatternId: '1',
layers: {
first: {
@ -1211,18 +1179,14 @@ describe('IndexPattern Data Source', () => {
},
};
const ast = indexPatternDatasource.toExpression(
queryBaseState,
'first',
indexPatterns
) as Ast;
const ast = FormBasedDatasource.toExpression(queryBaseState, 'first', indexPatterns) as Ast;
expect(ast.chain[1].arguments.timeFields).toEqual(['timestamp']);
expect(ast.chain[1].arguments.timeFields).not.toContain('timefield');
});
describe('optimizations', () => {
it('should call optimizeEsAggs once per operation for which it is available', () => {
const queryBaseState: IndexPatternPrivateState = {
const queryBaseState: FormBasedPrivateState = {
currentIndexPatternId: '1',
layers: {
first: {
@ -1272,7 +1236,7 @@ describe('IndexPattern Data Source', () => {
const optimizeMock = jest.spyOn(operationDefinitionMap.percentile, 'optimizeEsAggs');
indexPatternDatasource.toExpression(queryBaseState, 'first', indexPatterns);
FormBasedDatasource.toExpression(queryBaseState, 'first', indexPatterns);
expect(operationDefinitionMap.percentile.optimizeEsAggs).toHaveBeenCalledTimes(1);
@ -1280,7 +1244,7 @@ describe('IndexPattern Data Source', () => {
});
it('should update anticipated esAggs column IDs based on the order of the optimized agg expression builders', () => {
const queryBaseState: IndexPatternPrivateState = {
const queryBaseState: FormBasedPrivateState = {
currentIndexPatternId: '1',
layers: {
first: {
@ -1340,11 +1304,7 @@ describe('IndexPattern Data Source', () => {
return { aggs: aggs.reverse(), esAggsIdMap };
});
const ast = indexPatternDatasource.toExpression(
queryBaseState,
'first',
indexPatterns
) as Ast;
const ast = FormBasedDatasource.toExpression(queryBaseState, 'first', indexPatterns) as Ast;
expect(operationDefinitionMap.percentile.optimizeEsAggs).toHaveBeenCalledTimes(1);
@ -1356,7 +1316,7 @@ describe('IndexPattern Data Source', () => {
});
it('should deduplicate aggs for supported operations', () => {
const queryBaseState: IndexPatternPrivateState = {
const queryBaseState: FormBasedPrivateState = {
currentIndexPatternId: '1',
layers: {
first: {
@ -1408,11 +1368,7 @@ describe('IndexPattern Data Source', () => {
},
};
const ast = indexPatternDatasource.toExpression(
queryBaseState,
'first',
indexPatterns
) as Ast;
const ast = FormBasedDatasource.toExpression(queryBaseState, 'first', indexPatterns) as Ast;
const idMap = JSON.parse(ast.chain[2].arguments.idMap as unknown as string);
@ -1491,7 +1447,7 @@ describe('IndexPattern Data Source', () => {
});
it('should collect expression references and append them', async () => {
const queryBaseState: IndexPatternPrivateState = {
const queryBaseState: FormBasedPrivateState = {
currentIndexPatternId: '1',
layers: {
first: {
@ -1517,18 +1473,14 @@ describe('IndexPattern Data Source', () => {
},
};
const ast = indexPatternDatasource.toExpression(
queryBaseState,
'first',
indexPatterns
) as Ast;
const ast = FormBasedDatasource.toExpression(queryBaseState, 'first', indexPatterns) as Ast;
// @ts-expect-error we can't isolate just the reference type
expect(operationDefinitionMap.testReference.toExpression).toHaveBeenCalled();
expect(ast.chain[3]).toEqual('mock');
});
it('should keep correct column mapping keys with reference columns present', async () => {
const queryBaseState: IndexPatternPrivateState = {
const queryBaseState: FormBasedPrivateState = {
currentIndexPatternId: '1',
layers: {
first: {
@ -1554,11 +1506,7 @@ describe('IndexPattern Data Source', () => {
},
};
const ast = indexPatternDatasource.toExpression(
queryBaseState,
'first',
indexPatterns
) as Ast;
const ast = FormBasedDatasource.toExpression(queryBaseState, 'first', indexPatterns) as Ast;
expect(JSON.parse(ast.chain[2].arguments.idMap[0] as string)).toEqual({
'col-0-0': [
@ -1571,7 +1519,7 @@ describe('IndexPattern Data Source', () => {
it('should topologically sort references', () => {
// This is a real example of count() + count()
const queryBaseState: IndexPatternPrivateState = {
const queryBaseState: FormBasedPrivateState = {
currentIndexPatternId: '1',
layers: {
first: {
@ -1645,11 +1593,7 @@ describe('IndexPattern Data Source', () => {
},
};
const ast = indexPatternDatasource.toExpression(
queryBaseState,
'first',
indexPatterns
) as Ast;
const ast = FormBasedDatasource.toExpression(queryBaseState, 'first', indexPatterns) as Ast;
const chainLength = ast.chain.length;
expect(ast.chain[chainLength - 2].arguments.name).toEqual(['math']);
expect(ast.chain[chainLength - 1].arguments.id).toEqual(['formula']);
@ -1674,7 +1618,7 @@ describe('IndexPattern Data Source', () => {
},
currentIndexPatternId: '1',
};
expect(indexPatternDatasource.insertLayer(state, 'newLayer')).toEqual({
expect(FormBasedDatasource.insertLayer(state, 'newLayer')).toEqual({
...state,
layers: {
...state.layers,
@ -1705,7 +1649,7 @@ describe('IndexPattern Data Source', () => {
},
currentIndexPatternId: '1',
};
expect(indexPatternDatasource.removeLayer(state, 'first')).toEqual({
expect(FormBasedDatasource.removeLayer(state, 'first')).toEqual({
...state,
layers: {
second: {
@ -1720,7 +1664,7 @@ describe('IndexPattern Data Source', () => {
describe('#createEmptyLayer', () => {
it('creates state with empty layers', () => {
expect(indexPatternDatasource.createEmptyLayer('index-pattern-id')).toEqual({
expect(FormBasedDatasource.createEmptyLayer('index-pattern-id')).toEqual({
currentIndexPatternId: 'index-pattern-id',
layers: {},
});
@ -1730,7 +1674,7 @@ describe('IndexPattern Data Source', () => {
describe('#getLayers', () => {
it('should list the current layers', () => {
expect(
indexPatternDatasource.getLayers({
FormBasedDatasource.getLayers({
layers: {
first: {
indexPatternId: '1',
@ -1753,7 +1697,7 @@ describe('IndexPattern Data Source', () => {
let publicAPI: DatasourcePublicAPI;
beforeEach(async () => {
publicAPI = indexPatternDatasource.getPublicAPI({
publicAPI = FormBasedDatasource.getPublicAPI({
state: baseState,
layerId: 'first',
indexPatterns,
@ -1770,7 +1714,7 @@ describe('IndexPattern Data Source', () => {
});
it('should skip columns that are being referenced', () => {
publicAPI = indexPatternDatasource.getPublicAPI({
publicAPI = FormBasedDatasource.getPublicAPI({
state: {
...baseState,
layers: {
@ -1808,7 +1752,7 @@ describe('IndexPattern Data Source', () => {
});
it('should collect all fields (also from referenced columns)', () => {
publicAPI = indexPatternDatasource.getPublicAPI({
publicAPI = FormBasedDatasource.getPublicAPI({
state: {
...baseState,
layers: {
@ -1847,7 +1791,7 @@ describe('IndexPattern Data Source', () => {
});
it('should collect and organize fields per visible column', () => {
publicAPI = indexPatternDatasource.getPublicAPI({
publicAPI = FormBasedDatasource.getPublicAPI({
state: {
...baseState,
layers: {
@ -1917,7 +1861,7 @@ describe('IndexPattern Data Source', () => {
});
it('should return null for referenced columns', () => {
publicAPI = indexPatternDatasource.getPublicAPI({
publicAPI = FormBasedDatasource.getPublicAPI({
state: {
...baseState,
layers: {
@ -1962,7 +1906,7 @@ describe('IndexPattern Data Source', () => {
describe('getFilters', () => {
it('should return all filters in metrics, grouped by language', () => {
publicAPI = indexPatternDatasource.getPublicAPI({
publicAPI = FormBasedDatasource.getPublicAPI({
state: {
...baseState,
layers: {
@ -2004,7 +1948,7 @@ describe('IndexPattern Data Source', () => {
});
});
it('should ignore empty filtered metrics', () => {
publicAPI = indexPatternDatasource.getPublicAPI({
publicAPI = FormBasedDatasource.getPublicAPI({
state: {
...baseState,
layers: {
@ -2034,7 +1978,7 @@ describe('IndexPattern Data Source', () => {
});
});
it('shuold collect top values fields as kuery existence filters if no data is provided', () => {
publicAPI = indexPatternDatasource.getPublicAPI({
publicAPI = FormBasedDatasource.getPublicAPI({
state: {
...baseState,
layers: {
@ -2089,7 +2033,7 @@ describe('IndexPattern Data Source', () => {
});
});
it('shuold collect top values fields and terms as kuery filters if data is provided', () => {
publicAPI = indexPatternDatasource.getPublicAPI({
publicAPI = FormBasedDatasource.getPublicAPI({
state: {
...baseState,
layers: {
@ -2160,7 +2104,7 @@ describe('IndexPattern Data Source', () => {
});
});
it('shuold collect top values fields and terms and carefully handle empty string values', () => {
publicAPI = indexPatternDatasource.getPublicAPI({
publicAPI = FormBasedDatasource.getPublicAPI({
state: {
...baseState,
layers: {
@ -2231,7 +2175,7 @@ describe('IndexPattern Data Source', () => {
});
});
it('should ignore top values fields if other/missing option is enabled', () => {
publicAPI = indexPatternDatasource.getPublicAPI({
publicAPI = FormBasedDatasource.getPublicAPI({
state: {
...baseState,
layers: {
@ -2278,7 +2222,7 @@ describe('IndexPattern Data Source', () => {
});
});
it('should collect custom ranges as kuery filters', () => {
publicAPI = indexPatternDatasource.getPublicAPI({
publicAPI = FormBasedDatasource.getPublicAPI({
state: {
...baseState,
layers: {
@ -2333,7 +2277,7 @@ describe('IndexPattern Data Source', () => {
});
});
it('should collect custom ranges as kuery filters as partial', () => {
publicAPI = indexPatternDatasource.getPublicAPI({
publicAPI = FormBasedDatasource.getPublicAPI({
state: {
...baseState,
layers: {
@ -2393,7 +2337,7 @@ describe('IndexPattern Data Source', () => {
});
});
it('should collect filters within filters operation grouped by language', () => {
publicAPI = indexPatternDatasource.getPublicAPI({
publicAPI = FormBasedDatasource.getPublicAPI({
state: {
...baseState,
layers: {
@ -2464,7 +2408,7 @@ describe('IndexPattern Data Source', () => {
});
});
it('should ignore filtered metrics if at least one metric is unfiltered', () => {
publicAPI = indexPatternDatasource.getPublicAPI({
publicAPI = FormBasedDatasource.getPublicAPI({
state: {
...baseState,
layers: {
@ -2502,7 +2446,7 @@ describe('IndexPattern Data Source', () => {
});
});
it('should ignore filtered metrics if at least one metric is unfiltered in formula', () => {
publicAPI = indexPatternDatasource.getPublicAPI({
publicAPI = FormBasedDatasource.getPublicAPI({
state: {
...baseState,
layers: {
@ -2575,7 +2519,7 @@ describe('IndexPattern Data Source', () => {
});
});
it('should support complete scenarios', () => {
publicAPI = indexPatternDatasource.getPublicAPI({
publicAPI = FormBasedDatasource.getPublicAPI({
state: {
...baseState,
layers: {
@ -2662,7 +2606,7 @@ describe('IndexPattern Data Source', () => {
});
it('should avoid duplicate filters when formula has a global filter', () => {
publicAPI = indexPatternDatasource.getPublicAPI({
publicAPI = FormBasedDatasource.getPublicAPI({
state: {
...baseState,
layers: {
@ -2770,7 +2714,7 @@ describe('IndexPattern Data Source', () => {
it('should use the results of getErrorMessages directly when single layer', () => {
(getErrorMessages as jest.Mock).mockClear();
(getErrorMessages as jest.Mock).mockReturnValueOnce(['error 1', 'error 2']);
const state: IndexPatternPrivateState = {
const state: FormBasedPrivateState = {
layers: {
first: {
indexPatternId: '1',
@ -2780,7 +2724,7 @@ describe('IndexPattern Data Source', () => {
},
currentIndexPatternId: '1',
};
expect(indexPatternDatasource.getErrorMessages(state, indexPatterns)).toEqual([
expect(FormBasedDatasource.getErrorMessages(state, indexPatterns)).toEqual([
{ longMessage: 'error 1', shortMessage: '' },
{ longMessage: 'error 2', shortMessage: '' },
]);
@ -2790,7 +2734,7 @@ describe('IndexPattern Data Source', () => {
it('should prepend each error with its layer number on multi-layer chart', () => {
(getErrorMessages as jest.Mock).mockClear();
(getErrorMessages as jest.Mock).mockReturnValueOnce(['error 1', 'error 2']);
const state: IndexPatternPrivateState = {
const state: FormBasedPrivateState = {
layers: {
first: {
indexPatternId: '1',
@ -2805,7 +2749,7 @@ describe('IndexPattern Data Source', () => {
},
currentIndexPatternId: '1',
};
expect(indexPatternDatasource.getErrorMessages(state, indexPatterns)).toEqual([
expect(FormBasedDatasource.getErrorMessages(state, indexPatterns)).toEqual([
{ longMessage: 'Layer 1 error: error 1', shortMessage: '' },
{ longMessage: 'Layer 1 error: error 2', shortMessage: '' },
]);
@ -2814,7 +2758,7 @@ describe('IndexPattern Data Source', () => {
});
describe('#getWarningMessages', () => {
let state: IndexPatternPrivateState;
let state: FormBasedPrivateState;
let framePublicAPI: FramePublicAPI;
beforeEach(() => {
@ -2948,12 +2892,7 @@ describe('IndexPattern Data Source', () => {
);
it('should return mismatched time shifts', () => {
const warnings = indexPatternDatasource.getWarningMessages!(
state,
framePublicAPI,
{},
() => {}
);
const warnings = FormBasedDatasource.getWarningMessages!(state, framePublicAPI, {}, () => {});
expect(extractTranslationIdsFromWarnings(warnings)).toMatchInlineSnapshot(`
Array [
@ -2966,12 +2905,7 @@ describe('IndexPattern Data Source', () => {
it('should show different types of warning messages', () => {
framePublicAPI.activeData!.first.columns[1].meta.sourceParams!.hasPrecisionError = true;
const warnings = indexPatternDatasource.getWarningMessages!(
state,
framePublicAPI,
{},
() => {}
);
const warnings = FormBasedDatasource.getWarningMessages!(state, framePublicAPI, {}, () => {});
expect(extractTranslationIdsFromWarnings(warnings)).toMatchInlineSnapshot(`
Array [
@ -3002,7 +2936,7 @@ describe('IndexPattern Data Source', () => {
currentIndexPatternId: '1',
};
expect(indexPatternDatasource.getErrorMessages(state, indexPatterns)).toEqual([
expect(FormBasedDatasource.getErrorMessages(state, indexPatterns)).toEqual([
{ longMessage: 'Layer 1 error: error 1', shortMessage: '' },
{ longMessage: 'Layer 1 error: error 2', shortMessage: '' },
]);
@ -3013,7 +2947,7 @@ describe('IndexPattern Data Source', () => {
describe('#updateStateOnCloseDimension', () => {
it('should not update when there are no incomplete columns', () => {
expect(
indexPatternDatasource.updateStateOnCloseDimension!({
FormBasedDatasource.updateStateOnCloseDimension!({
state: {
layers: {
first: {
@ -3055,7 +2989,7 @@ describe('IndexPattern Data Source', () => {
currentIndexPatternId: '1',
};
expect(
indexPatternDatasource.updateStateOnCloseDimension!({
FormBasedDatasource.updateStateOnCloseDimension!({
state,
layerId: 'first',
columnId: 'col1',
@ -3127,9 +3061,9 @@ describe('IndexPattern Data Source', () => {
},
},
},
} as IndexPatternPrivateState;
} as FormBasedPrivateState;
expect(
indexPatternDatasource.isTimeBased(state, {
FormBasedDatasource.isTimeBased(state, {
...indexPatterns,
'1': { ...indexPatterns['1'], timeFieldName: undefined },
})
@ -3189,9 +3123,9 @@ describe('IndexPattern Data Source', () => {
},
},
},
} as IndexPatternPrivateState;
} as FormBasedPrivateState;
expect(
indexPatternDatasource.isTimeBased(state, {
FormBasedDatasource.isTimeBased(state, {
...indexPatterns,
'1': { ...indexPatterns['1'], timeFieldName: undefined },
})
@ -3215,9 +3149,9 @@ describe('IndexPattern Data Source', () => {
},
},
},
} as IndexPatternPrivateState;
} as FormBasedPrivateState;
expect(
indexPatternDatasource.isTimeBased(state, {
FormBasedDatasource.isTimeBased(state, {
...indexPatterns,
'1': { ...indexPatterns['1'], timeFieldName: undefined },
})
@ -3241,8 +3175,8 @@ describe('IndexPattern Data Source', () => {
},
},
},
} as IndexPatternPrivateState;
expect(indexPatternDatasource.isTimeBased(state, indexPatterns)).toEqual(true);
} as FormBasedPrivateState;
expect(FormBasedDatasource.isTimeBased(state, indexPatterns)).toEqual(true);
});
});
@ -3265,9 +3199,9 @@ describe('IndexPattern Data Source', () => {
},
},
},
} as IndexPatternPrivateState;
} as FormBasedPrivateState;
expect(
indexPatternDatasource.initializeDimension!(state, 'first', indexPatterns, {
FormBasedDatasource.initializeDimension!(state, 'first', indexPatterns, {
columnId: 'newStatic',
groupId: 'a',
})
@ -3292,9 +3226,9 @@ describe('IndexPattern Data Source', () => {
},
},
},
} as IndexPatternPrivateState;
} as FormBasedPrivateState;
expect(
indexPatternDatasource.initializeDimension!(state, 'first', indexPatterns, {
FormBasedDatasource.initializeDimension!(state, 'first', indexPatterns, {
columnId: 'newStatic',
groupId: 'a',
staticValue: 0, // use a falsy value to check also this corner case
@ -3329,7 +3263,7 @@ describe('IndexPattern Data Source', () => {
describe('#isEqual', () => {
const layerId = '8bd66b66-aba3-49fb-9ff2-4bf83f2be08e';
const persistableState: IndexPatternPersistedState = {
const persistableState: FormBasedPersistedState = {
layers: {
[layerId]: {
columns: {
@ -3366,7 +3300,7 @@ describe('IndexPattern Data Source', () => {
it('should be false if datasource states are using different data views', () => {
expect(
indexPatternDatasource.isEqual(persistableState, references1, persistableState, references2)
FormBasedDatasource.isEqual(persistableState, references1, persistableState, references2)
).toBe(false);
});
@ -3375,7 +3309,7 @@ describe('IndexPattern Data Source', () => {
differentPersistableState.layers[layerId].columnOrder = ['something else'];
expect(
indexPatternDatasource.isEqual(
FormBasedDatasource.isEqual(
persistableState,
references1,
differentPersistableState,
@ -3386,7 +3320,7 @@ describe('IndexPattern Data Source', () => {
it('should be true if datasource states are identical and they refer to the same data view', () => {
expect(
indexPatternDatasource.isEqual(persistableState, references1, persistableState, references1)
FormBasedDatasource.isEqual(persistableState, references1, persistableState, references1)
).toBe(true);
});
});

View file

@ -36,7 +36,7 @@ import type {
IndexPatternField,
IndexPattern,
IndexPatternRef,
} from '../types';
} from '../../types';
import {
changeIndexPattern,
changeLayerIndexPattern,
@ -49,18 +49,18 @@ import {
} from './loader';
import { toExpression } from './to_expression';
import {
IndexPatternDimensionTrigger,
IndexPatternDimensionEditor,
FormBasedDimensionTrigger,
FormBasedDimensionEditor,
getDropProps,
onDrop,
} from './dimension_panel';
import { IndexPatternDataPanel } from './datapanel';
import { FormBasedDataPanel } from './datapanel';
import {
getDatasourceSuggestionsForField,
getDatasourceSuggestionsFromCurrentState,
getDatasourceSuggestionsForVisualizeField,
getDatasourceSuggestionsForVisualizeCharts,
} from './indexpattern_suggestions';
} from './form_based_suggestions';
import {
getFiltersInLayer,
@ -69,7 +69,7 @@ import {
isColumnInvalid,
cloneLayer,
} from './utils';
import { isDraggedDataViewField } from '../utils';
import { isDraggedDataViewField } from '../../utils';
import { normalizeOperationDataType } from './pure_utils';
import { LayerPanel } from './layerpanel';
import {
@ -81,15 +81,15 @@ import {
TermsIndexPatternColumn,
} from './operations';
import { getReferenceRoot } from './operations/layer_helpers';
import { IndexPatternPrivateState, IndexPatternPersistedState } from './types';
import { FormBasedPrivateState, FormBasedPersistedState } from './types';
import { mergeLayer } from './state_helpers';
import { Datasource, VisualizeEditorContext } from '../types';
import { Datasource, VisualizeEditorContext } from '../../types';
import { deleteColumn, isReferenced } from './operations';
import { GeoFieldWorkspacePanel } from '../editor_frame_service/editor_frame/workspace_panel/geo_field_workspace_panel';
import { DraggingIdentifier } from '../drag_drop';
import { GeoFieldWorkspacePanel } from '../../editor_frame_service/editor_frame/workspace_panel/geo_field_workspace_panel';
import { DraggingIdentifier } from '../../drag_drop';
import { getStateTimeShiftWarningMessages } from './time_shift_utils';
import { getPrecisionErrorWarningMessages } from './utils';
import { DOCUMENT_FIELD_NAME } from '../../common/constants';
import { DOCUMENT_FIELD_NAME } from '../../../common/constants';
import { isColumnOfType } from './operations/definitions/helpers';
export type { OperationType, GenericIndexPatternColumn } from './operations';
export { deleteColumn } from './operations';
@ -119,15 +119,15 @@ export function columnToOperation(
};
}
export type { FormatColumnArgs, TimeScaleArgs, CounterRateArgs } from '../../common/expressions';
export type { FormatColumnArgs, TimeScaleArgs, CounterRateArgs } from '../../../common/expressions';
export {
getSuffixFormatter,
unitSuffixesLong,
suffixFormatterId,
} from '../../common/suffix_formatter';
} from '../../../common/suffix_formatter';
export function getIndexPatternDatasource({
export function getFormBasedDatasource({
core,
storage,
data,
@ -152,14 +152,14 @@ export function getIndexPatternDatasource({
}) {
const uiSettings = core.uiSettings;
const DATASOURCE_ID = 'indexpattern';
const DATASOURCE_ID = 'formBased';
// Not stateful. State is persisted to the frame
const indexPatternDatasource: Datasource<IndexPatternPrivateState, IndexPatternPersistedState> = {
const formBasedDatasource: Datasource<FormBasedPrivateState, FormBasedPersistedState> = {
id: DATASOURCE_ID,
initialize(
persistedState?: IndexPatternPersistedState,
persistedState?: FormBasedPersistedState,
references?: SavedObjectReference[],
initialContext?: VisualizeFieldContext | VisualizeEditorContext,
indexPatternRefs?: IndexPatternRef[],
@ -176,11 +176,11 @@ export function getIndexPatternDatasource({
});
},
getPersistableState(state: IndexPatternPrivateState) {
getPersistableState(state: FormBasedPrivateState) {
return extractReferences(state);
},
insertLayer(state: IndexPatternPrivateState, newLayerId: string) {
insertLayer(state: FormBasedPrivateState, newLayerId: string) {
return {
...state,
layers: {
@ -204,7 +204,7 @@ export function getIndexPatternDatasource({
};
},
removeLayer(state: IndexPatternPrivateState, layerId: string) {
removeLayer(state: FormBasedPrivateState, layerId: string) {
const newLayers = { ...state.layers };
delete newLayers[layerId];
@ -214,7 +214,7 @@ export function getIndexPatternDatasource({
};
},
clearLayer(state: IndexPatternPrivateState, layerId: string) {
clearLayer(state: FormBasedPrivateState, layerId: string) {
return {
...state,
layers: {
@ -224,7 +224,7 @@ export function getIndexPatternDatasource({
};
},
getLayers(state: IndexPatternPrivateState) {
getLayers(state: FormBasedPrivateState) {
return Object.keys(state?.layers);
},
@ -266,10 +266,7 @@ export function getIndexPatternDatasource({
toExpression: (state, layerId, indexPatterns) =>
toExpression(state, layerId, indexPatterns, uiSettings),
renderDataPanel(
domElement: Element,
props: DatasourceDataPanelProps<IndexPatternPrivateState>
) {
renderDataPanel(domElement: Element, props: DatasourceDataPanelProps<FormBasedPrivateState>) {
const { onChangeIndexPattern, ...otherProps } = props;
render(
<KibanaThemeProvider theme$={core.theme.theme$}>
@ -285,7 +282,7 @@ export function getIndexPatternDatasource({
discover,
}}
>
<IndexPatternDataPanel
<FormBasedDataPanel
data={data}
dataViews={dataViews}
fieldFormats={fieldFormats}
@ -303,7 +300,7 @@ export function getIndexPatternDatasource({
);
},
uniqueLabels(state: IndexPatternPrivateState) {
uniqueLabels(state: FormBasedPrivateState) {
const layers = state.layers;
const columnLabelMap = {} as Record<string, string>;
const counts = {} as Record<string, number>;
@ -342,9 +339,9 @@ export function getIndexPatternDatasource({
renderDimensionTrigger: (
domElement: Element,
props: DatasourceDimensionTriggerProps<IndexPatternPrivateState>
props: DatasourceDimensionTriggerProps<FormBasedPrivateState>
) => {
const columnLabelMap = indexPatternDatasource.uniqueLabels(props.state);
const columnLabelMap = formBasedDatasource.uniqueLabels(props.state);
render(
<KibanaThemeProvider theme$={core.theme.theme$}>
@ -361,10 +358,7 @@ export function getIndexPatternDatasource({
unifiedSearch,
}}
>
<IndexPatternDimensionTrigger
uniqueLabel={columnLabelMap[props.columnId]}
{...props}
/>
<FormBasedDimensionTrigger uniqueLabel={columnLabelMap[props.columnId]} {...props} />
</KibanaContextProvider>
</I18nProvider>
</KibanaThemeProvider>,
@ -374,9 +368,9 @@ export function getIndexPatternDatasource({
renderDimensionEditor: (
domElement: Element,
props: DatasourceDimensionEditorProps<IndexPatternPrivateState>
props: DatasourceDimensionEditorProps<FormBasedPrivateState>
) => {
const columnLabelMap = indexPatternDatasource.uniqueLabels(props.state);
const columnLabelMap = formBasedDatasource.uniqueLabels(props.state);
render(
<KibanaThemeProvider theme$={core.theme.theme$}>
@ -394,7 +388,7 @@ export function getIndexPatternDatasource({
unifiedSearch,
}}
>
<IndexPatternDimensionEditor
<FormBasedDimensionEditor
uiSettings={uiSettings}
storage={storage}
fieldFormats={fieldFormats}
@ -415,7 +409,7 @@ export function getIndexPatternDatasource({
renderLayerPanel: (
domElement: Element,
props: DatasourceLayerPanelProps<IndexPatternPrivateState>
props: DatasourceLayerPanelProps<FormBasedPrivateState>
) => {
const { onChangeIndexPattern, ...otherProps } = props;
render(
@ -445,7 +439,7 @@ export function getIndexPatternDatasource({
onDrop,
getCustomWorkspaceRenderer: (
state: IndexPatternPrivateState,
state: FormBasedPrivateState,
dragging: DraggingIdentifier,
indexPatterns: Record<string, IndexPattern>
) => {
@ -501,7 +495,7 @@ export function getIndexPatternDatasource({
onIndexPatternRename: (state, oldIndexPatternId, newIndexPatternId) => {
return renameIndexPattern({ state, oldIndexPatternId, newIndexPatternId });
},
getRenderEventCounters(state: IndexPatternPrivateState): string[] {
getRenderEventCounters(state: FormBasedPrivateState): string[] {
const additionalEvents = {
time_shift: false,
filter: false,
@ -545,8 +539,8 @@ export function getIndexPatternDatasource({
});
},
getPublicAPI({ state, layerId, indexPatterns }: PublicAPIProps<IndexPatternPrivateState>) {
const columnLabelMap = indexPatternDatasource.uniqueLabels(state);
getPublicAPI({ state, layerId, indexPatterns }: PublicAPIProps<FormBasedPrivateState>) {
const columnLabelMap = formBasedDatasource.uniqueLabels(state);
const layer = state.layers[layerId];
const visibleColumnIds = layer.columnOrder.filter((colId) => !isReferenced(layer, colId));
@ -766,16 +760,16 @@ export function getIndexPatternDatasource({
);
},
isEqual: (
persistableState1: IndexPatternPersistedState,
persistableState1: FormBasedPersistedState,
references1: SavedObjectReference[],
persistableState2: IndexPatternPersistedState,
persistableState2: FormBasedPersistedState,
references2: SavedObjectReference[]
) =>
isEqual(
injectReferences(persistableState1, references1),
injectReferences(persistableState2, references2)
),
getUsedDataView: (state: IndexPatternPrivateState, layerId?: string) => {
getUsedDataView: (state: FormBasedPrivateState, layerId?: string) => {
if (!layerId) {
return state.currentIndexPatternId;
}
@ -786,7 +780,7 @@ export function getIndexPatternDatasource({
},
};
return indexPatternDatasource;
return formBasedDatasource;
}
function blankLayer(indexPatternId: string) {

View file

@ -12,16 +12,16 @@ import type {
StaticValueColumn,
CountColumn,
} from '@kbn/visualizations-plugin/common/convert_to_lens';
import { DatasourceSuggestion } from '../types';
import { generateId } from '../id_generator';
import type { IndexPatternPrivateState } from './types';
import { DatasourceSuggestion } from '../../types';
import { generateId } from '../../id_generator';
import type { FormBasedPrivateState } from './types';
import {
getDatasourceSuggestionsForField,
getDatasourceSuggestionsFromCurrentState,
getDatasourceSuggestionsForVisualizeField,
getDatasourceSuggestionsForVisualizeCharts,
IndexPatternSuggestion,
} from './indexpattern_suggestions';
} from './form_based_suggestions';
import { documentField } from './document_field';
import { getFieldByNameFactory } from './pure_helpers';
import { isEqual } from 'lodash';
@ -33,7 +33,7 @@ import {
} from './operations/definitions';
jest.mock('./loader');
jest.mock('../id_generator');
jest.mock('../../id_generator');
const fieldsOne = [
{
@ -171,7 +171,7 @@ const expectedIndexPatterns = {
},
};
function testInitialState(): IndexPatternPrivateState {
function testInitialState(): FormBasedPrivateState {
return {
currentIndexPatternId: '1',
layers: {
@ -206,7 +206,7 @@ function getSuggestionSubset(
): Array<Omit<IndexPatternSuggestion, 'state'>> {
return suggestions.map((s) => {
const newSuggestion = { ...s } as Omit<IndexPatternSuggestion, 'state'> & {
state?: IndexPatternPrivateState;
state?: FormBasedPrivateState;
};
delete newSuggestion.state;
return newSuggestion;
@ -385,7 +385,7 @@ describe('IndexPattern Data Source suggestions', () => {
});
it('should make a metric suggestion for a number field if there is no time field', async () => {
const state: IndexPatternPrivateState = {
const state: FormBasedPrivateState = {
currentIndexPatternId: '1',
layers: {
first: {
@ -628,7 +628,7 @@ describe('IndexPattern Data Source suggestions', () => {
});
it('should make a metric suggestion for a number field if there is no time field', async () => {
const state: IndexPatternPrivateState = {
const state: FormBasedPrivateState = {
currentIndexPatternId: '1',
layers: {
previousLayer: {
@ -764,7 +764,7 @@ describe('IndexPattern Data Source suggestions', () => {
});
describe('suggesting extensions to non-empty tables', () => {
function stateWithNonEmptyTables(): IndexPatternPrivateState {
function stateWithNonEmptyTables(): FormBasedPrivateState {
const state = testInitialState();
return {
@ -1036,7 +1036,7 @@ describe('IndexPattern Data Source suggestions', () => {
it('adds a metric column on a number field if no other metrics set', () => {
(generateId as jest.Mock).mockReturnValue('newid');
const initialState = stateWithNonEmptyTables();
const modifiedState: IndexPatternPrivateState = {
const modifiedState: FormBasedPrivateState = {
...initialState,
layers: {
...initialState.layers,
@ -1138,7 +1138,7 @@ describe('IndexPattern Data Source suggestions', () => {
it('skips duplicates when the document-specific field is already in use', () => {
const initialState = stateWithNonEmptyTables();
const modifiedState: IndexPatternPrivateState = {
const modifiedState: FormBasedPrivateState = {
...initialState,
layers: {
...initialState.layers,
@ -1170,7 +1170,7 @@ describe('IndexPattern Data Source suggestions', () => {
it('hides any referenced metrics when adding new metrics', () => {
(generateId as jest.Mock).mockReturnValue('newid');
const initialState = stateWithNonEmptyTables();
const modifiedState: IndexPatternPrivateState = {
const modifiedState: FormBasedPrivateState = {
...initialState,
layers: {
currentLayer: {
@ -1239,7 +1239,7 @@ describe('IndexPattern Data Source suggestions', () => {
it('makes a suggestion to extending from an invalid state with a new metric', () => {
(generateId as jest.Mock).mockReturnValue('newid');
const initialState = stateWithNonEmptyTables();
const modifiedState: IndexPatternPrivateState = {
const modifiedState: FormBasedPrivateState = {
...initialState,
layers: {
currentLayer: {
@ -1306,7 +1306,7 @@ describe('IndexPattern Data Source suggestions', () => {
(generateId as jest.Mock).mockReturnValue('newid');
const initialState = stateWithNonEmptyTables();
const modifiedState: IndexPatternPrivateState = {
const modifiedState: FormBasedPrivateState = {
...initialState,
layers: {
referenceLineLayer: {
@ -1394,7 +1394,7 @@ describe('IndexPattern Data Source suggestions', () => {
});
describe('finding the layer that is using the current index pattern', () => {
function stateWithCurrentIndexPattern(): IndexPatternPrivateState {
function stateWithCurrentIndexPattern(): FormBasedPrivateState {
const state = testInitialState();
return {
@ -2140,7 +2140,7 @@ describe('IndexPattern Data Source suggestions', () => {
it('returns a single suggestion containing the current columns for each layer', async () => {
const initialState = testInitialState();
const state: IndexPatternPrivateState = {
const state: FormBasedPrivateState = {
...initialState,
layers: {
...initialState.layers,
@ -2233,7 +2233,7 @@ describe('IndexPattern Data Source suggestions', () => {
it('returns a metric over time for single metric tables', async () => {
const initialState = testInitialState();
const state: IndexPatternPrivateState = {
const state: FormBasedPrivateState = {
...initialState,
layers: {
first: {
@ -2296,7 +2296,7 @@ describe('IndexPattern Data Source suggestions', () => {
it('adds date histogram over default time field for tables without time dimension', async () => {
const initialState = testInitialState();
const state: IndexPatternPrivateState = {
const state: FormBasedPrivateState = {
...initialState,
layers: {
first: {
@ -2385,7 +2385,7 @@ describe('IndexPattern Data Source suggestions', () => {
it('adds date histogram over default time field for tables without time dimension and a referenceLine', async () => {
const initialState = testInitialState();
const state: IndexPatternPrivateState = {
const state: FormBasedPrivateState = {
...initialState,
layers: {
first: {
@ -2495,7 +2495,7 @@ describe('IndexPattern Data Source suggestions', () => {
it('does not create an over time suggestion if tables with numeric buckets with time dimension', async () => {
const initialState = testInitialState();
const state: IndexPatternPrivateState = {
const state: FormBasedPrivateState = {
...initialState,
layers: {
first: {
@ -2543,7 +2543,7 @@ describe('IndexPattern Data Source suggestions', () => {
it('adds date histogram over default time field for custom range intervals', async () => {
const initialState = testInitialState();
const state: IndexPatternPrivateState = {
const state: FormBasedPrivateState = {
...initialState,
layers: {
first: {
@ -2630,7 +2630,7 @@ describe('IndexPattern Data Source suggestions', () => {
it('does not create an over time suggestion if there is no default time field', async () => {
const initialState = testInitialState();
const state: IndexPatternPrivateState = {
const state: FormBasedPrivateState = {
...initialState,
layers: {
first: {
@ -2667,7 +2667,7 @@ describe('IndexPattern Data Source suggestions', () => {
it('should not propose an over time suggestion if there are multiple bucket dimensions', () => {
const initialState = testInitialState();
const state: IndexPatternPrivateState = {
const state: FormBasedPrivateState = {
...initialState,
layers: {
first: {
@ -2751,7 +2751,7 @@ describe('IndexPattern Data Source suggestions', () => {
searchable: true,
},
];
const state: IndexPatternPrivateState = {
const state: FormBasedPrivateState = {
currentIndexPatternId: '1',
layers: {
first: {
@ -2858,7 +2858,7 @@ describe('IndexPattern Data Source suggestions', () => {
it('returns an only metric version of a given table, but does not include current state as reduced', () => {
const initialState = testInitialState();
const state: IndexPatternPrivateState = {
const state: FormBasedPrivateState = {
currentIndexPatternId: '1',
layers: {
first: {
@ -2966,7 +2966,7 @@ describe('IndexPattern Data Source suggestions', () => {
it('returns an alternative metric for an only-metric table', () => {
const initialState = testInitialState();
const state: IndexPatternPrivateState = {
const state: FormBasedPrivateState = {
currentIndexPatternId: '1',
layers: {
first: {
@ -3032,7 +3032,7 @@ describe('IndexPattern Data Source suggestions', () => {
it('contains a reordering suggestion when there are exactly 2 buckets', () => {
const initialState = testInitialState();
const state: IndexPatternPrivateState = {
const state: FormBasedPrivateState = {
currentIndexPatternId: '1',
layers: {
first: {
@ -3084,7 +3084,7 @@ describe('IndexPattern Data Source suggestions', () => {
it('will generate suggestions even if there are errors from missing fields', () => {
const initialState = testInitialState();
const state: IndexPatternPrivateState = {
const state: FormBasedPrivateState = {
currentIndexPatternId: '1',
layers: {
first: {
@ -3148,7 +3148,7 @@ describe('IndexPattern Data Source suggestions', () => {
describe('references', () => {
it('will extend the table with a date when starting in an invalid state', () => {
const initialState = testInitialState();
const state: IndexPatternPrivateState = {
const state: FormBasedPrivateState = {
...initialState,
layers: {
...initialState.layers,
@ -3237,7 +3237,7 @@ describe('IndexPattern Data Source suggestions', () => {
it('will make an unchanged suggestion including incomplete references', () => {
const initialState = testInitialState();
const state: IndexPatternPrivateState = {
const state: FormBasedPrivateState = {
...initialState,
layers: {
...initialState.layers,
@ -3327,7 +3327,7 @@ describe('IndexPattern Data Source suggestions', () => {
it('will create reduced suggestions with all referenced children when handling references', () => {
const initialState = testInitialState();
const state: IndexPatternPrivateState = {
const state: FormBasedPrivateState = {
...initialState,
layers: {
...initialState.layers,
@ -3473,7 +3473,7 @@ describe('IndexPattern Data Source suggestions', () => {
it('will leave dangling references in place', () => {
const initialState = testInitialState();
const state: IndexPatternPrivateState = {
const state: FormBasedPrivateState = {
...initialState,
layers: {
...initialState.layers,
@ -3521,7 +3521,7 @@ describe('IndexPattern Data Source suggestions', () => {
it('will not suggest reduced tables if there is just a referenced top level metric', () => {
const initialState = testInitialState();
const state: IndexPatternPrivateState = {
const state: FormBasedPrivateState = {
...initialState,
layers: {
...initialState.layers,
@ -3566,7 +3566,7 @@ describe('IndexPattern Data Source suggestions', () => {
});
function isTableWithBucketColumns(
suggestion: DatasourceSuggestion<IndexPatternPrivateState>,
suggestion: DatasourceSuggestion<FormBasedPrivateState>,
columnIds: string[],
numBuckets: number
) {
@ -3577,7 +3577,7 @@ function isTableWithBucketColumns(
}
function isTableWithMetricColumns(
suggestion: DatasourceSuggestion<IndexPatternPrivateState>,
suggestion: DatasourceSuggestion<FormBasedPrivateState>,
columnIds: string[]
) {
expect(suggestion.table.isMultiRow).toEqual(false);

View file

@ -14,7 +14,7 @@ import type {
AnyColumnWithSourceField,
TermsColumn,
} from '@kbn/visualizations-plugin/common/convert_to_lens';
import { generateId } from '../id_generator';
import { generateId } from '../../id_generator';
import type {
DatasourceSuggestion,
IndexPattern,
@ -22,8 +22,8 @@ import type {
IndexPatternMap,
TableChangeType,
VisualizationDimensionGroupConfig,
} from '../types';
import { columnToOperation } from './indexpattern';
} from '../../types';
import { columnToOperation } from './form_based';
import {
insertNewColumn,
replaceColumn,
@ -41,12 +41,12 @@ import {
ColumnAdvancedParams,
} from './operations';
import { hasField } from './pure_utils';
import type { IndexPatternPrivateState, IndexPatternLayer } from './types';
import type { FormBasedPrivateState, FormBasedLayer } from './types';
import { documentField } from './document_field';
import { OperationDefinition } from './operations/definitions';
import { insertOrReplaceFormulaColumn } from './operations/definitions/formula';
export type IndexPatternSuggestion = DatasourceSuggestion<IndexPatternPrivateState>;
export type IndexPatternSuggestion = DatasourceSuggestion<FormBasedPrivateState>;
interface ColumnChange {
op: OperationType;
@ -67,12 +67,12 @@ function buildSuggestion({
label,
changeType,
}: {
state: IndexPatternPrivateState;
state: FormBasedPrivateState;
layerId: string;
changeType: TableChangeType;
updatedLayer?: IndexPatternLayer;
updatedLayer?: FormBasedLayer;
label?: string;
}): DatasourceSuggestion<IndexPatternPrivateState> {
}): DatasourceSuggestion<FormBasedPrivateState> {
const updatedState = updatedLayer
? {
...state,
@ -120,7 +120,7 @@ function buildSuggestion({
}
export function getDatasourceSuggestionsForField(
state: IndexPatternPrivateState,
state: FormBasedPrivateState,
indexPatternId: string,
field: IndexPatternField,
indexPatterns: IndexPatternMap,
@ -176,7 +176,7 @@ export function getDatasourceSuggestionsForField(
// Called when the user navigates from Visualize editor to Lens
export function getDatasourceSuggestionsForVisualizeCharts(
state: IndexPatternPrivateState,
state: FormBasedPrivateState,
contextLayers: Layer[],
indexPatterns: IndexPatternMap
): IndexPatternSuggestion[] {
@ -184,7 +184,7 @@ export function getDatasourceSuggestionsForVisualizeCharts(
}
function getEmptyLayersSuggestionsForVisualizeCharts(
state: IndexPatternPrivateState,
state: FormBasedPrivateState,
contextLayers: Layer[],
indexPatterns: IndexPatternMap
): IndexPatternSuggestion[] {
@ -280,7 +280,7 @@ function convertToColumnChange(columns: Layer['columns'], indexPattern: IndexPat
) {
const orderColumn = column.params.orderAgg;
const operationDefinition = operationDefinitionMap[orderColumn.operationType];
const layer: IndexPatternLayer = {
const layer: FormBasedLayer = {
indexPatternId: indexPattern.id,
columns: {},
columnOrder: [],
@ -311,7 +311,7 @@ function createNewLayerWithMetricAggregationFromVizEditor(
layer: Layer
) {
const columns = convertToColumnChange(layer.columns, indexPattern);
let newLayer: IndexPatternLayer = {
let newLayer: FormBasedLayer = {
indexPatternId: indexPattern.id,
columns: {},
columnOrder: [],
@ -360,7 +360,7 @@ function createNewLayerWithMetricAggregationFromVizEditor(
// Called when the user navigates from Discover to Lens (Visualize button)
export function getDatasourceSuggestionsForVisualizeField(
state: IndexPatternPrivateState,
state: FormBasedPrivateState,
indexPatternId: string,
fieldName: string,
indexPatterns: IndexPatternMap
@ -400,7 +400,7 @@ function getBucketOperation(field: IndexPatternField) {
}
function getExistingLayerSuggestionsForField(
state: IndexPatternPrivateState,
state: FormBasedPrivateState,
layerId: string,
field: IndexPatternField,
indexPatterns: IndexPatternMap
@ -514,14 +514,14 @@ function getExistingLayerSuggestionsForField(
}
function getEmptyLayerSuggestionsForField(
state: IndexPatternPrivateState,
state: FormBasedPrivateState,
layerId: string,
indexPatternId: string,
field: IndexPatternField,
indexPatterns: IndexPatternMap
): IndexPatternSuggestion[] {
const indexPattern = indexPatterns[indexPatternId];
let newLayer: IndexPatternLayer | undefined;
let newLayer: FormBasedLayer | undefined;
const bucketOperation = getBucketOperation(field);
if (bucketOperation) {
newLayer = createNewLayerWithBucketAggregation(indexPattern, field, bucketOperation);
@ -549,7 +549,7 @@ function createNewLayerWithBucketAggregation(
indexPattern: IndexPattern,
field: IndexPatternField,
operation: OperationType
): IndexPatternLayer {
): FormBasedLayer {
return insertNewColumn({
op: operation,
layer: insertNewColumn({
@ -570,7 +570,7 @@ function createNewLayerWithBucketAggregation(
function createNewLayerWithMetricAggregation(
indexPattern: IndexPattern,
field: IndexPatternField
): IndexPatternLayer | undefined {
): FormBasedLayer | undefined {
const dateField = indexPattern.getFieldByName(indexPattern.timeFieldName!);
const [metricOperation] = getMetricOperationTypes(field);
if (!metricOperation) {
@ -595,10 +595,10 @@ function createNewLayerWithMetricAggregation(
}
export function getDatasourceSuggestionsFromCurrentState(
state: IndexPatternPrivateState,
state: FormBasedPrivateState,
indexPatterns: IndexPatternMap,
filterLayers: (layerId: string) => boolean = () => true
): Array<DatasourceSuggestion<IndexPatternPrivateState>> {
): Array<DatasourceSuggestion<FormBasedPrivateState>> {
const layers = Object.entries(state.layers || {}).filter(([layerId]) => filterLayers(layerId));
if (layers.length > 1) {
@ -658,7 +658,7 @@ export function getDatasourceSuggestionsFromCurrentState(
buckets.length === 1 &&
buckets.some((columnId) => layer.columns[columnId].dataType === 'number');
const suggestions: Array<DatasourceSuggestion<IndexPatternPrivateState>> = [];
const suggestions: Array<DatasourceSuggestion<FormBasedPrivateState>> = [];
// Always suggest an unchanged table, including during invalid states
suggestions.push(
@ -708,7 +708,7 @@ export function getDatasourceSuggestionsFromCurrentState(
}
function createChangedNestingSuggestion(
state: IndexPatternPrivateState,
state: FormBasedPrivateState,
layerId: string,
indexPatterns: IndexPatternMap
) {
@ -739,7 +739,7 @@ function createChangedNestingSuggestion(
function createMetricSuggestion(
indexPattern: IndexPattern,
layerId: string,
state: IndexPatternPrivateState,
state: FormBasedPrivateState,
field: IndexPatternField
) {
const [operation] = getMetricOperationTypes(field);
@ -781,10 +781,10 @@ function getNestedTitle([outerBucketLabel, innerBucketLabel]: string[]) {
function createAlternativeMetricSuggestions(
indexPattern: IndexPattern,
layerId: string,
state: IndexPatternPrivateState
state: FormBasedPrivateState
) {
const layer = state.layers[layerId];
const suggestions: Array<DatasourceSuggestion<IndexPatternPrivateState>> = [];
const suggestions: Array<DatasourceSuggestion<FormBasedPrivateState>> = [];
const topLevelMetricColumns = layer.columnOrder.filter(
(columnId) => !isReferenced(layer, columnId)
);
@ -826,7 +826,7 @@ function createAlternativeMetricSuggestions(
}
function createSuggestionWithDefaultDateHistogram(
state: IndexPatternPrivateState,
state: FormBasedPrivateState,
layerId: string,
timeField: IndexPatternField,
indexPatterns: IndexPatternMap
@ -852,7 +852,7 @@ function createSuggestionWithDefaultDateHistogram(
});
}
function createSimplifiedTableSuggestions(state: IndexPatternPrivateState, layerId: string) {
function createSimplifiedTableSuggestions(state: FormBasedPrivateState, layerId: string) {
const layer = state.layers[layerId];
const [availableBucketedColumns, availableMetricColumns] = partition(
@ -916,7 +916,7 @@ function createSimplifiedTableSuggestions(state: IndexPatternPrivateState, layer
});
}
function getMetricSuggestionTitle(layer: IndexPatternLayer, onlySimpleMetric: boolean) {
function getMetricSuggestionTitle(layer: FormBasedLayer, onlySimpleMetric: boolean) {
const { operationType, label } = layer.columns[layer.columnOrder[0]];
return i18n.translate('xpack.lens.indexpattern.suggestions.overallLabel', {
defaultMessage: '{operation} overall',

View file

@ -16,11 +16,11 @@ import type { IndexPatternFieldEditorStart } from '@kbn/data-view-field-editor-p
import type { DataPublicPluginSetup, DataPublicPluginStart } from '@kbn/data-plugin/public';
import type { UiActionsStart } from '@kbn/ui-actions-plugin/public';
import type { FieldFormatsStart, FieldFormatsSetup } from '@kbn/field-formats-plugin/public';
import type { EditorFrameSetup } from '../types';
import type { EditorFrameSetup } from '../../types';
export type { PersistedIndexPatternLayer, FormulaPublicApi } from './types';
export interface IndexPatternDatasourceSetupPlugins {
export interface FormBasedDatasourceSetupPlugins {
expressions: ExpressionsSetup;
fieldFormats: FieldFormatsSetup;
data: DataPublicPluginSetup;
@ -28,7 +28,7 @@ export interface IndexPatternDatasourceSetupPlugins {
charts: ChartsPluginSetup;
}
export interface IndexPatternDatasourceStartPlugins {
export interface FormBasedDatasourceStartPlugins {
data: DataPublicPluginStart;
unifiedSearch: UnifiedSearchPublicPluginStart;
discover?: DiscoverStart;
@ -38,19 +38,19 @@ export interface IndexPatternDatasourceStartPlugins {
uiActions: UiActionsStart;
}
export class IndexPatternDatasource {
export class FormBasedDatasource {
setup(
core: CoreSetup<IndexPatternDatasourceStartPlugins>,
core: CoreSetup<FormBasedDatasourceStartPlugins>,
{
fieldFormats: fieldFormatsSetup,
expressions,
editorFrame,
charts,
}: IndexPatternDatasourceSetupPlugins
}: FormBasedDatasourceSetupPlugins
) {
editorFrame.registerDatasource(async () => {
const { getIndexPatternDatasource, getSuffixFormatter, suffixFormatterId } = await import(
'../async_services'
const { getFormBasedDatasource, getSuffixFormatter, suffixFormatterId } = await import(
'../../async_services'
);
if (!fieldFormatsSetup.has(suffixFormatterId)) {
@ -67,7 +67,7 @@ export class IndexPatternDatasource {
{ dataViewFieldEditor, uiActions, data, fieldFormats, dataViews, unifiedSearch, discover },
] = await core.getStartServices();
return getIndexPatternDatasource({
return getFormBasedDatasource({
core: coreStart,
fieldFormats,
storage: new Storage(localStorage),

View file

@ -6,13 +6,13 @@
*/
import React, { MouseEvent } from 'react';
import { IndexPatternPrivateState } from './types';
import { IndexPatternLayerPanelProps, LayerPanel } from './layerpanel';
import { FormBasedPrivateState } from './types';
import { FormBasedLayerPanelProps, LayerPanel } from './layerpanel';
import { shallowWithIntl as shallow } from '@kbn/test-jest-helpers';
import { ShallowWrapper } from 'enzyme';
import { EuiSelectable } from '@elastic/eui';
import { DataViewsList } from '@kbn/unified-search-plugin/public';
import { ChangeIndexPattern } from '../shared_components/dataview_picker/dataview_picker';
import { ChangeIndexPattern } from '../../shared_components/dataview_picker/dataview_picker';
import { getFieldByNameFactory } from './pure_helpers';
import { TermsIndexPatternColumn } from './operations';
@ -135,7 +135,7 @@ const fieldsThree = [
},
];
const initialState: IndexPatternPrivateState = {
const initialState: FormBasedPrivateState = {
currentIndexPatternId: '1',
layers: {
first: {
@ -168,7 +168,7 @@ const initialState: IndexPatternPrivateState = {
},
};
describe('Layer Data Panel', () => {
let defaultProps: IndexPatternLayerPanelProps;
let defaultProps: FormBasedLayerPanelProps;
beforeEach(() => {
defaultProps = {

View file

@ -8,13 +8,12 @@
import React from 'react';
import { I18nProvider } from '@kbn/i18n-react';
import { i18n } from '@kbn/i18n';
import { DatasourceLayerPanelProps } from '../types';
import { IndexPatternPrivateState } from './types';
import { ChangeIndexPattern } from '../shared_components/dataview_picker/dataview_picker';
import { DatasourceLayerPanelProps } from '../../types';
import { FormBasedPrivateState } from './types';
import { ChangeIndexPattern } from '../../shared_components/dataview_picker/dataview_picker';
export interface IndexPatternLayerPanelProps
extends DatasourceLayerPanelProps<IndexPatternPrivateState> {
state: IndexPatternPrivateState;
export interface FormBasedLayerPanelProps extends DatasourceLayerPanelProps<FormBasedPrivateState> {
state: FormBasedPrivateState;
onChangeIndexPattern: (newId: string) => void;
}
@ -23,7 +22,7 @@ export function LayerPanel({
layerId,
onChangeIndexPattern,
dataViews,
}: IndexPatternLayerPanelProps) {
}: FormBasedLayerPanelProps) {
const layer = state.layers[layerId];
const indexPattern = dataViews.indexPatterns[layer.indexPatternId];

View file

@ -12,9 +12,9 @@ import {
extractReferences,
injectReferences,
} from './loader';
import { IndexPatternPersistedState, IndexPatternPrivateState } from './types';
import { FormBasedPersistedState, FormBasedPrivateState } from './types';
import { DateHistogramIndexPatternColumn, TermsIndexPatternColumn } from './operations';
import { sampleIndexPatterns } from '../data_views_service/mocks';
import { sampleIndexPatterns } from '../../data_views_service/mocks';
const createMockStorage = (lastData?: Record<string, string>) => {
return {
@ -141,7 +141,7 @@ describe('loader', () => {
});
it('should initialize all the embeddable references without local storage', () => {
const savedState: IndexPatternPersistedState = {
const savedState: FormBasedPersistedState = {
layers: {
layerb: {
columnOrder: ['col1', 'col2'],
@ -189,7 +189,7 @@ describe('loader', () => {
});
it('should initialize from saved state', () => {
const savedState: IndexPatternPersistedState = {
const savedState: FormBasedPersistedState = {
layers: {
layerb: {
columnOrder: ['col1', 'col2'],
@ -242,7 +242,7 @@ describe('loader', () => {
});
describe('saved object references', () => {
const state: IndexPatternPrivateState = {
const state: FormBasedPrivateState = {
currentIndexPatternId: 'b',
layers: {
a: {
@ -300,7 +300,7 @@ describe('loader', () => {
describe('changeIndexPattern', () => {
it('sets the given indexpattern as current', () => {
const state: IndexPatternPrivateState = {
const state: FormBasedPrivateState = {
currentIndexPatternId: '2',
layers: {},
};
@ -324,7 +324,7 @@ describe('loader', () => {
});
it('should update an empty layer on indexpattern change', () => {
const state: IndexPatternPrivateState = {
const state: FormBasedPrivateState = {
currentIndexPatternId: '2',
layers: { layerId: { columnOrder: [], columns: {}, indexPatternId: '2' } },
};
@ -345,7 +345,7 @@ describe('loader', () => {
});
it('should keep layer indexpattern on change if not empty', () => {
const state: IndexPatternPrivateState = {
const state: FormBasedPrivateState = {
currentIndexPatternId: '2',
layers: {
layerId: {
@ -402,7 +402,7 @@ describe('loader', () => {
describe('changeLayerIndexPattern', () => {
it('loads the index pattern and then changes the specified layer', async () => {
const state: IndexPatternPrivateState = {
const state: FormBasedPrivateState = {
currentIndexPatternId: '1',
layers: {
l0: {

View file

@ -17,12 +17,12 @@ import {
UiActionsStart,
VisualizeFieldContext,
} from '@kbn/ui-actions-plugin/public';
import type { VisualizeEditorContext } from '../types';
import { IndexPatternPersistedState, IndexPatternPrivateState, IndexPatternLayer } from './types';
import type { VisualizeEditorContext } from '../../types';
import { FormBasedPersistedState, FormBasedPrivateState, FormBasedLayer } from './types';
import { memoizedGetAvailableOperationsByMetadata, updateLayerIndexPattern } from './operations';
import { readFromStorage, writeToStorage } from '../settings_storage';
import type { IndexPattern, IndexPatternRef } from '../types';
import { readFromStorage, writeToStorage } from '../../settings_storage';
import type { IndexPattern, IndexPatternRef } from '../../types';
export function onRefreshIndexPattern() {
if (memoizedGetAvailableOperationsByMetadata.cache.clear) {
@ -47,9 +47,9 @@ function getLayerReferenceName(layerId: string) {
return `indexpattern-datasource-layer-${layerId}`;
}
export function extractReferences({ layers }: IndexPatternPrivateState) {
export function extractReferences({ layers }: FormBasedPrivateState) {
const savedObjectReferences: SavedObjectReference[] = [];
const persistableState: IndexPatternPersistedState = {
const persistableState: FormBasedPersistedState = {
layers: {},
};
Object.entries(layers).forEach(([layerId, { indexPatternId, ...persistableLayer }]) => {
@ -64,10 +64,10 @@ export function extractReferences({ layers }: IndexPatternPrivateState) {
}
export function injectReferences(
state: IndexPatternPersistedState,
state: FormBasedPersistedState,
references: SavedObjectReference[]
) {
const layers: Record<string, IndexPatternLayer> = {};
const layers: Record<string, FormBasedLayer> = {};
Object.entries(state.layers).forEach(([layerId, persistedLayer]) => {
layers[layerId] = {
...persistedLayer,
@ -83,7 +83,7 @@ function createStateFromPersisted({
persistedState,
references,
}: {
persistedState?: IndexPatternPersistedState;
persistedState?: FormBasedPersistedState;
references?: SavedObjectReference[];
}) {
return persistedState && references ? injectReferences(persistedState, references) : undefined;
@ -97,7 +97,7 @@ function getUsedIndexPatterns({
defaultIndexPatternId,
}: {
state?: {
layers: Record<string, IndexPatternLayer>;
layers: Record<string, FormBasedLayer>;
};
defaultIndexPatternId?: string;
storage: IStorageWrapper;
@ -139,14 +139,14 @@ export function loadInitialState({
indexPatternRefs = [],
indexPatterns = {},
}: {
persistedState?: IndexPatternPersistedState;
persistedState?: FormBasedPersistedState;
references?: SavedObjectReference[];
defaultIndexPatternId?: string;
storage: IStorageWrapper;
initialContext?: VisualizeFieldContext | VisualizeEditorContext;
indexPatternRefs?: IndexPatternRef[];
indexPatterns?: Record<string, IndexPattern>;
}): IndexPatternPrivateState {
}): FormBasedPrivateState {
const state = createStateFromPersisted({ persistedState, references });
const { usedPatterns, allIndexPatternIds: indexPatternIds } = getUsedIndexPatterns({
state,
@ -186,7 +186,7 @@ export function changeIndexPattern({
indexPatterns,
}: {
indexPatternId: string;
state: IndexPatternPrivateState;
state: FormBasedPrivateState;
storage: IStorageWrapper;
indexPatterns: Record<string, IndexPattern>;
}) {
@ -209,7 +209,7 @@ export function renameIndexPattern({
}: {
oldIndexPatternId: string;
newIndexPatternId: string;
state: IndexPatternPrivateState;
state: FormBasedPrivateState;
}) {
return {
...state,
@ -231,7 +231,7 @@ export function triggerActionOnIndexPatternChange({
}: {
indexPatternId: string;
layerId: string;
state: IndexPatternPrivateState;
state: FormBasedPrivateState;
uiActions: UiActionsStart;
}) {
const fromDataView = state.layers[layerId]?.indexPatternId;
@ -260,7 +260,7 @@ export function changeLayerIndexPattern({
}: {
indexPatternId: string;
layerId: string;
state: IndexPatternPrivateState;
state: FormBasedPrivateState;
replaceIfPossible?: boolean;
storage: IStorageWrapper;
indexPatterns: Record<string, IndexPattern>;
@ -276,7 +276,7 @@ export function changeLayerIndexPattern({
};
}
function isSingleEmptyLayer(layerMap: IndexPatternPrivateState['layers']) {
function isSingleEmptyLayer(layerMap: FormBasedPrivateState['layers']) {
const layers = Object.values(layerMap);
return layers.length === 1 && layers[0].columnOrder.length === 0;
}

View file

@ -5,9 +5,9 @@
* 2.0.
*/
import { DragContextState } from '../drag_drop';
import { DragContextState } from '../../drag_drop';
import { getFieldByNameFactory } from './pure_helpers';
import type { IndexPattern, IndexPatternField } from '../types';
import type { IndexPattern, IndexPatternField } from '../../types';
export const createMockedIndexPattern = (someProps?: Partial<IndexPattern>): IndexPattern => {
const fields = [

View file

@ -18,8 +18,8 @@ import {
} from './definitions';
import { getFieldByNameFactory } from '../pure_helpers';
import { documentField } from '../document_field';
import { IndexPatternLayer } from '../types';
import { IndexPattern, IndexPatternField } from '../../types';
import { FormBasedLayer } from '../types';
import { IndexPattern, IndexPatternField } from '../../../types';
import { GenericIndexPatternColumn } from '.';
import { DateHistogramIndexPatternColumn } from './definitions/date_histogram';
@ -83,7 +83,7 @@ const indexPattern = {
const baseColumnArgs: {
previousColumn: GenericIndexPatternColumn;
indexPattern: IndexPattern;
layer: IndexPatternLayer;
layer: FormBasedLayer;
field: IndexPatternField;
} = {
previousColumn: {
@ -105,7 +105,7 @@ const baseColumnArgs: {
field: indexPattern.fields[2],
};
const layer: IndexPatternLayer = {
const layer: FormBasedLayer = {
indexPatternId: '1',
columnOrder: ['date', 'metric', 'ref'],
columns: {

View file

@ -7,7 +7,7 @@
import { i18n } from '@kbn/i18n';
import { FormattedIndexPatternColumn, ReferenceBasedIndexPatternColumn } from '../column_types';
import { IndexPatternLayer } from '../../../types';
import { FormBasedLayer } from '../../../types';
import {
buildLabelFunction,
getErrorsForDateReference,
@ -106,7 +106,7 @@ export const counterRateOperation: OperationDefinition<
isTransferable: (column, newIndexPattern) => {
return hasDateField(newIndexPattern);
},
getErrorMessage: (layer: IndexPatternLayer, columnId: string) => {
getErrorMessage: (layer: FormBasedLayer, columnId: string) => {
return combineErrorMessages([
getErrorsForDateReference(
layer,

View file

@ -7,7 +7,7 @@
import { i18n } from '@kbn/i18n';
import { FormattedIndexPatternColumn, ReferenceBasedIndexPatternColumn } from '../column_types';
import { IndexPatternLayer } from '../../../types';
import { FormBasedLayer } from '../../../types';
import {
checkForDateHistogram,
getErrorsForDateReference,
@ -19,7 +19,7 @@ import {
import { OperationDefinition } from '..';
import { getFormatFromPreviousColumn, getFilter, combineErrorMessages } from '../helpers';
import { getDisallowedPreviousShiftMessage } from '../../../time_shift_utils';
import { DOCUMENT_FIELD_NAME } from '../../../../../common';
import { DOCUMENT_FIELD_NAME } from '../../../../../../common';
const ofName = buildLabelFunction((name?: string) => {
return i18n.translate('xpack.lens.indexPattern.cumulativeSumOf', {
@ -106,7 +106,7 @@ export const cumulativeSumOperation: OperationDefinition<
isTransferable: () => {
return true;
},
getErrorMessage: (layer: IndexPatternLayer, columnId: string) => {
getErrorMessage: (layer: FormBasedLayer, columnId: string) => {
return combineErrorMessages([
getErrorsForDateReference(
layer,

View file

@ -7,7 +7,7 @@
import { i18n } from '@kbn/i18n';
import { FormattedIndexPatternColumn, ReferenceBasedIndexPatternColumn } from '../column_types';
import { IndexPatternLayer } from '../../../types';
import { FormBasedLayer } from '../../../types';
import {
buildLabelFunction,
checkForDateHistogram,
@ -92,7 +92,7 @@ export const derivativeOperation: OperationDefinition<
isTransferable: (column, newIndexPattern) => {
return hasDateField(newIndexPattern);
},
getErrorMessage: (layer: IndexPatternLayer, columnId: string) => {
getErrorMessage: (layer: FormBasedLayer, columnId: string) => {
return combineErrorMessages([
getErrorsForDateReference(
layer,

View file

@ -9,9 +9,9 @@ import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n-react';
import React, { useState } from 'react';
import { EuiFieldNumber, EuiFormRow } from '@elastic/eui';
import { useDebounceWithOptions } from '../../../../shared_components';
import { useDebounceWithOptions } from '../../../../../shared_components';
import { FormattedIndexPatternColumn, ReferenceBasedIndexPatternColumn } from '../column_types';
import { IndexPatternLayer } from '../../../types';
import { FormBasedLayer } from '../../../types';
import {
buildLabelFunction,
checkForDateHistogram,
@ -114,7 +114,7 @@ export const movingAverageOperation: OperationDefinition<
isTransferable: (column, newIndexPattern) => {
return hasDateField(newIndexPattern);
},
getErrorMessage: (layer: IndexPatternLayer, columnId: string) => {
getErrorMessage: (layer: FormBasedLayer, columnId: string) => {
return combineErrorMessages([
getErrorsForDateReference(
layer,

View file

@ -6,7 +6,7 @@
*/
import { createMockedIndexPattern } from '../../../mocks';
import type { IndexPatternLayer } from '../../../types';
import type { FormBasedLayer } from '../../../types';
import {
overallAverageOperation,
overallMaxOperation,
@ -16,7 +16,7 @@ import {
describe('overall_metric', () => {
const indexPattern = createMockedIndexPattern();
let layer: IndexPatternLayer;
let layer: FormBasedLayer;
beforeEach(() => {
layer = {

View file

@ -13,7 +13,7 @@ import type {
import { getErrorsForDateReference } from './utils';
import type { OperationDefinition } from '..';
import { combineErrorMessages, getFormatFromPreviousColumn } from '../helpers';
import { IndexPatternLayer } from '../../../types';
import { FormBasedLayer } from '../../../types';
import { getDisallowedPreviousShiftMessage } from '../../../time_shift_utils';
type OverallMetricIndexPatternColumn<T extends string> = FormattedIndexPatternColumn &
@ -101,7 +101,7 @@ export const timeScaleOperation: OperationDefinition<TimeScaleIndexPatternColumn
isTransferable: () => {
return true;
},
getErrorMessage: (layer: IndexPatternLayer, columnId: string) => {
getErrorMessage: (layer: FormBasedLayer, columnId: string) => {
return combineErrorMessages([
getErrorsForDateReference(
layer,

View file

@ -9,10 +9,10 @@ import { i18n } from '@kbn/i18n';
import type { AstFunction } from '@kbn/interpreter';
import memoizeOne from 'memoize-one';
import { LayerTypes } from '@kbn/expression-xy-plugin/public';
import type { IndexPattern } from '../../../../types';
import type { LayerType } from '../../../../../common';
import type { TimeScaleUnit } from '../../../../../common/expressions';
import type { IndexPatternLayer } from '../../../types';
import type { IndexPattern } from '../../../../../types';
import { LayerType } from '../../../../../../common';
import type { TimeScaleUnit } from '../../../../../../common/expressions';
import type { FormBasedLayer } from '../../../types';
import { adjustTimeScaleLabelSuffix } from '../../time_scale_utils';
import type { ReferenceBasedIndexPatternColumn } from '../column_types';
import { getManagedColumnsFrom, isColumnValidAsReference } from '../../layer_helpers';
@ -49,7 +49,7 @@ export function checkForDataLayerType(layerType: LayerType, name: string) {
/**
* Checks whether the current layer includes a date histogram and returns an error otherwise
*/
export function checkForDateHistogram(layer: IndexPatternLayer, name: string) {
export function checkForDateHistogram(layer: FormBasedLayer, name: string) {
const buckets = layer.columnOrder.filter((colId) => layer.columns[colId].isBucketed);
const hasDateHistogram = buckets.some(
(colId) => layer.columns[colId].operationType === 'date_histogram'
@ -68,7 +68,7 @@ export function checkForDateHistogram(layer: IndexPatternLayer, name: string) {
];
}
const getFullyManagedColumnIds = memoizeOne((layer: IndexPatternLayer) => {
const getFullyManagedColumnIds = memoizeOne((layer: FormBasedLayer) => {
const managedColumnIds = new Set<string>();
Object.entries(layer.columns).forEach(([id, column]) => {
if (
@ -85,7 +85,7 @@ const getFullyManagedColumnIds = memoizeOne((layer: IndexPatternLayer) => {
return managedColumnIds;
});
export function checkReferences(layer: IndexPatternLayer, columnId: string) {
export function checkReferences(layer: FormBasedLayer, columnId: string) {
const column = layer.columns[columnId] as ReferenceBasedIndexPatternColumn;
const errors: string[] = [];
@ -128,11 +128,7 @@ export function checkReferences(layer: IndexPatternLayer, columnId: string) {
return errors.length ? errors : undefined;
}
export function getErrorsForDateReference(
layer: IndexPatternLayer,
columnId: string,
name: string
) {
export function getErrorsForDateReference(layer: FormBasedLayer, columnId: string, name: string) {
const dateErrors = checkForDateHistogram(layer, name) ?? [];
const referenceErrors = checkReferences(layer, columnId) ?? [];
if (dateErrors.length || referenceErrors.length) {
@ -149,7 +145,7 @@ export function hasDateField(indexPattern: IndexPattern) {
* Creates an expression ast for a date based operation (cumulative sum, derivative, moving average, counter rate)
*/
export function dateBasedOperationToExpression(
layer: IndexPatternLayer,
layer: FormBasedLayer,
columnId: string,
functionName: string,
additionalArgs: Record<string, unknown[]> = {}
@ -180,7 +176,7 @@ export function dateBasedOperationToExpression(
* Creates an expression ast for a date based operation (cumulative sum, derivative, moving average, counter rate)
*/
export function optionallHistogramBasedOperationToExpression(
layer: IndexPatternLayer,
layer: FormBasedLayer,
columnId: string,
functionName: string,
additionalArgs: Record<string, unknown[]> = {}

View file

@ -6,8 +6,8 @@
*/
import type { Query } from '@kbn/es-query';
import type { Operation } from '../../../types';
import type { TimeScaleUnit } from '../../../../common/expressions';
import type { Operation } from '../../../../types';
import type { TimeScaleUnit } from '../../../../../common/expressions';
import type { OperationType } from '.';
export interface BaseIndexPatternColumn extends Operation {

View file

@ -11,10 +11,10 @@ import { euiThemeVars } from '@kbn/ui-theme';
import { EuiSwitch, EuiText } from '@elastic/eui';
import { AggFunctionsMapping } from '@kbn/data-plugin/public';
import { buildExpressionFunction } from '@kbn/expressions-plugin/public';
import type { TimeScaleUnit } from '../../../../common/expressions';
import type { OperationDefinition, ParamEditorProps } from '.';
import type { FieldBasedIndexPatternColumn, ValueFormatConfig } from './column_types';
import type { IndexPatternField } from '../../../types';
import { TimeScaleUnit } from '../../../../../common/expressions';
import { OperationDefinition, ParamEditorProps } from '.';
import { FieldBasedIndexPatternColumn, ValueFormatConfig } from './column_types';
import type { IndexPatternField } from '../../../../types';
import {
getInvalidFieldMessage,
getFilter,

View file

@ -18,8 +18,8 @@ import type { IStorageWrapper } from '@kbn/kibana-utils-plugin/public';
import { UI_SETTINGS } from '@kbn/data-plugin/public';
import { dataPluginMock, getCalculateAutoTimeExpression } from '@kbn/data-plugin/public/mocks';
import { createMockedIndexPattern } from '../../mocks';
import type { IndexPatternLayer } from '../../types';
import type { IndexPattern } from '../../../types';
import type { FormBasedLayer } from '../../types';
import type { IndexPattern } from '../../../../types';
import { getFieldByNameFactory } from '../../pure_helpers';
import { act } from 'react-dom/test-utils';
@ -124,7 +124,7 @@ const defaultOptions = {
};
describe('date_histogram', () => {
let layer: IndexPatternLayer;
let layer: FormBasedLayer;
const InlineOptions = dateHistogramOperation.paramEditor!;
beforeEach(() => {
@ -160,7 +160,7 @@ describe('date_histogram', () => {
},
},
},
} as unknown as IndexPatternLayer;
} as unknown as FormBasedLayer;
}
describe('buildColumn', () => {
@ -339,7 +339,7 @@ describe('date_histogram', () => {
it('should render current value for other index pattern', () => {
const updateLayerSpy = jest.fn();
const secondLayer: IndexPatternLayer = {
const secondLayer: FormBasedLayer = {
indexPatternId: '2',
columnOrder: ['col2'],
columns: {
@ -374,7 +374,7 @@ describe('date_histogram', () => {
});
it('should render time interval control set to auto for auto interval', () => {
const thirdLayer: IndexPatternLayer = {
const thirdLayer: FormBasedLayer = {
indexPatternId: '1',
columnOrder: ['col1'],
columns: {
@ -409,7 +409,7 @@ describe('date_histogram', () => {
});
it('should allow switching to manual interval', () => {
const thirdLayer: IndexPatternLayer = {
const thirdLayer: FormBasedLayer = {
indexPatternId: '1',
columnOrder: ['col1'],
columns: {
@ -451,7 +451,7 @@ describe('date_histogram', () => {
});
it('should allow turning off time range sync', () => {
const thirdLayer: IndexPatternLayer = {
const thirdLayer: FormBasedLayer = {
indexPatternId: '1',
columnOrder: ['col1'],
columns: {
@ -493,7 +493,7 @@ describe('date_histogram', () => {
});
it('turns off time range ignore on switching to auto interval', () => {
const thirdLayer: IndexPatternLayer = {
const thirdLayer: FormBasedLayer = {
indexPatternId: '1',
columnOrder: ['col1'],
columns: {
@ -535,7 +535,7 @@ describe('date_histogram', () => {
});
it('turns off drop partial bucket on tuning off time range ignore', () => {
const thirdLayer: IndexPatternLayer = {
const thirdLayer: FormBasedLayer = {
indexPatternId: '1',
columnOrder: ['col1'],
columns: {
@ -735,7 +735,7 @@ describe('date_histogram', () => {
});
it('should allow the drop of partial buckets', () => {
const thirdLayer: IndexPatternLayer = {
const thirdLayer: FormBasedLayer = {
indexPatternId: '1',
columnOrder: ['col1'],
columns: {

View file

@ -33,8 +33,8 @@ import { updateColumnParam } from '../layer_helpers';
import { OperationDefinition, ParamEditorProps } from '.';
import { FieldBasedIndexPatternColumn } from './column_types';
import { getInvalidFieldMessage, getSafeName } from './helpers';
import { IndexPatternLayer } from '../../types';
import { TooltipWrapper } from '../../../shared_components';
import { FormBasedLayer } from '../../types';
import { TooltipWrapper } from '../../../../shared_components';
const { isValidInterval } = search.aggs;
const autoInterval = 'auto';
@ -50,7 +50,7 @@ export interface DateHistogramIndexPatternColumn extends FieldBasedIndexPatternC
};
}
function getMultipleDateHistogramsErrorMessage(layer: IndexPatternLayer, columnId: string) {
function getMultipleDateHistogramsErrorMessage(layer: FormBasedLayer, columnId: string) {
const usesTimeShift = Object.values(layer.columns).some(
(col) => col.timeShift && col.timeShift !== ''
);

View file

@ -13,7 +13,7 @@ import { createMockedIndexPattern } from '../../../mocks';
import { FilterPopover } from './filter_popover';
import { LabelInput } from '../shared_components';
import { QueryStringInput } from '@kbn/unified-search-plugin/public';
import { QueryInput } from '../../../../shared_components';
import { QueryInput } from '../../../../../shared_components';
jest.mock('.', () => ({
isQueryValid: () => true,

View file

@ -12,8 +12,8 @@ import { EuiPopover, EuiSpacer } from '@elastic/eui';
import type { Query } from '@kbn/es-query';
// Need to keep it separate to make it work Jest mocks in dimension_panel tests
// import { QueryInput } from '../../../../shared_components/query_input';
import { isQueryValid, QueryInput } from '../../../../shared_components';
import { IndexPattern } from '../../../../types';
import { isQueryValid, QueryInput } from '../../../../../shared_components';
import { IndexPattern } from '../../../../../types';
import { FilterValue, defaultLabel } from '.';
import { LabelInput } from '../shared_components';

View file

@ -16,7 +16,7 @@ import { dataPluginMock } from '@kbn/data-plugin/public/mocks';
import { dataViewPluginMocks } from '@kbn/data-views-plugin/public/mocks';
import type { FiltersIndexPatternColumn } from '.';
import { filtersOperation } from '..';
import type { IndexPatternLayer } from '../../../types';
import type { FormBasedLayer } from '../../../types';
import { createMockedIndexPattern } from '../../../mocks';
import { FilterPopover } from './filter_popover';
@ -62,7 +62,7 @@ jest.mock('@elastic/eui', () => {
});
describe('filters', () => {
let layer: IndexPatternLayer;
let layer: FormBasedLayer;
const InlineOptions = filtersOperation.paramEditor!;
beforeEach(() => {

View file

@ -19,8 +19,8 @@ import {
DraggableBucketContainer,
isQueryValid,
NewBucketButton,
} from '../../../../shared_components';
import { IndexPattern } from '../../../../types';
} from '../../../../../shared_components';
import { IndexPattern } from '../../../../../types';
import { updateColumnParam } from '../../layer_helpers';
import type { OperationDefinition } from '..';
import type { BaseIndexPatternColumn } from '../column_types';

View file

@ -27,7 +27,7 @@ import { monaco } from '@kbn/monaco';
import classNames from 'classnames';
import { CodeEditor } from '@kbn/kibana-react-plugin/public';
import type { CodeEditorProps } from '@kbn/kibana-react-plugin/public';
import { TooltipWrapper, useDebounceWithOptions } from '../../../../../shared_components';
import { TooltipWrapper, useDebounceWithOptions } from '../../../../../../shared_components';
import { ParamEditorProps } from '../..';
import { getManagedColumnsFrom } from '../../../layer_helpers';
import { ErrorWrapper, runASTValidation, tryToParse } from '../validation';

View file

@ -21,7 +21,7 @@ import {
EuiSpacer,
} from '@elastic/eui';
import { Markdown } from '@kbn/kibana-react-plugin/public';
import type { IndexPattern } from '../../../../../types';
import type { IndexPattern } from '../../../../../../types';
import { tinymathFunctions } from '../util';
import { getPossibleFunctions } from './math_completion';
import { hasFunctionFieldArgument } from '../validation';

Some files were not shown because too many files have changed in this diff Show more