From d16a7daa28acb282c2fd543dd2cd6f1b796d206c Mon Sep 17 00:00:00 2001 From: Lukas Olson Date: Tue, 10 May 2022 12:47:44 -0700 Subject: [PATCH 01/10] Tmp commit --- packages/kbn-es-query/src/es_query/types.ts | 9 ++++---- .../data_views/persistable_state.test.ts | 14 ++++++++++++ .../common/data_views/persistable_state.ts | 22 +++++++++++++++++++ .../common/fields/persistable_state.test.ts | 14 ++++++++++++ .../common/fields/persistable_state.ts | 22 +++++++++++++++++++ .../common/persistable_state/types.ts | 2 +- 6 files changed, 78 insertions(+), 5 deletions(-) create mode 100644 src/plugins/data_views/common/data_views/persistable_state.test.ts create mode 100644 src/plugins/data_views/common/data_views/persistable_state.ts create mode 100644 src/plugins/data_views/common/fields/persistable_state.test.ts create mode 100644 src/plugins/data_views/common/fields/persistable_state.ts diff --git a/packages/kbn-es-query/src/es_query/types.ts b/packages/kbn-es-query/src/es_query/types.ts index f746e652d2183f..df06309a9dae45 100644 --- a/packages/kbn-es-query/src/es_query/types.ts +++ b/packages/kbn-es-query/src/es_query/types.ts @@ -7,6 +7,7 @@ */ import * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; +import { SerializableRecord } from '@kbn/utility-types'; /** * A field's sub type @@ -14,7 +15,7 @@ import * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; */ export type IFieldSubType = IFieldSubTypeMultiOptional | IFieldSubTypeNestedOptional; -export interface IFieldSubTypeMultiOptional { +export interface IFieldSubTypeMultiOptional extends SerializableRecord { multi?: { parent: string }; } @@ -22,7 +23,7 @@ export interface IFieldSubTypeMulti { multi: { parent: string }; } -export interface IFieldSubTypeNestedOptional { +export interface IFieldSubTypeNestedOptional extends SerializableRecord { nested?: { path: string }; } @@ -34,7 +35,7 @@ export interface IFieldSubTypeNested { * A base interface for an index pattern field * @public */ -export interface DataViewFieldBase { +export interface DataViewFieldBase extends SerializableRecord { name: string; /** * Kibana field type @@ -57,7 +58,7 @@ export interface DataViewFieldBase { * A base interface for an index pattern * @public */ -export interface DataViewBase { +export interface DataViewBase extends SerializableRecord { fields: DataViewFieldBase[]; id?: string; title: string; diff --git a/src/plugins/data_views/common/data_views/persistable_state.test.ts b/src/plugins/data_views/common/data_views/persistable_state.test.ts new file mode 100644 index 00000000000000..da7b176d3cc8f7 --- /dev/null +++ b/src/plugins/data_views/common/data_views/persistable_state.test.ts @@ -0,0 +1,14 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +// import { DataViewPersistableStateService } from './persistable_state'; + +describe('filter manager persistable state tests', () => { + describe('reference injection', () => {}); + describe('reference extraction', () => {}); +}); diff --git a/src/plugins/data_views/common/data_views/persistable_state.ts b/src/plugins/data_views/common/data_views/persistable_state.ts new file mode 100644 index 00000000000000..9f97d38762dd25 --- /dev/null +++ b/src/plugins/data_views/common/data_views/persistable_state.ts @@ -0,0 +1,22 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +import { DataViewBase } from '@kbn/es-query'; +import { PersistableStateService } from '@kbn/kibana-utils-plugin/common'; + +export const DataViewPersistableStateService: PersistableStateService = { + inject: (state, references) => { + return state; + }, + extract: (state) => { + return { state, references: [] }; + }, + getAllMigrations: () => ({}), + migrateToLatest: ({ state }) => state, + telemetry: () => ({}), +}; diff --git a/src/plugins/data_views/common/fields/persistable_state.test.ts b/src/plugins/data_views/common/fields/persistable_state.test.ts new file mode 100644 index 00000000000000..da7b176d3cc8f7 --- /dev/null +++ b/src/plugins/data_views/common/fields/persistable_state.test.ts @@ -0,0 +1,14 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +// import { DataViewPersistableStateService } from './persistable_state'; + +describe('filter manager persistable state tests', () => { + describe('reference injection', () => {}); + describe('reference extraction', () => {}); +}); diff --git a/src/plugins/data_views/common/fields/persistable_state.ts b/src/plugins/data_views/common/fields/persistable_state.ts new file mode 100644 index 00000000000000..a5655a4cee7616 --- /dev/null +++ b/src/plugins/data_views/common/fields/persistable_state.ts @@ -0,0 +1,22 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +import { DataViewFieldBase } from '@kbn/es-query'; +import { PersistableStateService } from '@kbn/kibana-utils-plugin/common'; + +export const DataViewPersistableStateService: PersistableStateService = { + inject: (state, references) => { + return state; + }, + extract: (state) => { + return { state, references: [] }; + }, + getAllMigrations: () => ({}), + migrateToLatest: ({ state }) => state, + telemetry: () => ({}), +}; diff --git a/src/plugins/kibana_utils/common/persistable_state/types.ts b/src/plugins/kibana_utils/common/persistable_state/types.ts index 4db588d15741f4..31234ca5c18dab 100644 --- a/src/plugins/kibana_utils/common/persistable_state/types.ts +++ b/src/plugins/kibana_utils/common/persistable_state/types.ts @@ -159,7 +159,7 @@ export interface PersistableStateService

* @param version Current semver version of the `state`. * @returns A serializable state object migrated to the latest state. */ - migrateToLatest?: (state: VersionedState) => P; + migrateToLatest?: (state: VersionedState

) => P; /** * returns all registered migrations From d2d36e2621a9272cd90f0e02a5fea35d28792570 Mon Sep 17 00:00:00 2001 From: Lukas Olson Date: Wed, 25 May 2022 10:21:18 -0700 Subject: [PATCH 02/10] Use serializable version --- packages/kbn-es-query/src/es_query/index.ts | 2 ++ packages/kbn-es-query/src/es_query/types.ts | 8 ++++-- packages/kbn-es-query/src/index.ts | 2 ++ .../common/data_views/persistable_state.ts | 4 +-- .../common/fields/persistable_state.ts | 25 ++++++++++--------- 5 files changed, 25 insertions(+), 16 deletions(-) diff --git a/packages/kbn-es-query/src/es_query/index.ts b/packages/kbn-es-query/src/es_query/index.ts index 399df50e350587..15dac6e3621ef8 100644 --- a/packages/kbn-es-query/src/es_query/index.ts +++ b/packages/kbn-es-query/src/es_query/index.ts @@ -16,7 +16,9 @@ export type { IFieldSubType, BoolQuery, DataViewBase, + DataViewBaseSerializable, DataViewFieldBase, + DataViewFieldBaseSerializable, IFieldSubTypeMulti, IFieldSubTypeNested, } from './types'; diff --git a/packages/kbn-es-query/src/es_query/types.ts b/packages/kbn-es-query/src/es_query/types.ts index df06309a9dae45..baf7a8a376e3aa 100644 --- a/packages/kbn-es-query/src/es_query/types.ts +++ b/packages/kbn-es-query/src/es_query/types.ts @@ -35,7 +35,7 @@ export interface IFieldSubTypeNested { * A base interface for an index pattern field * @public */ -export interface DataViewFieldBase extends SerializableRecord { +export interface DataViewFieldBase { name: string; /** * Kibana field type @@ -54,16 +54,20 @@ export interface DataViewFieldBase extends SerializableRecord { scripted?: boolean; } +export type DataViewFieldBaseSerializable = SerializableRecord & DataViewFieldBase; + /** * A base interface for an index pattern * @public */ -export interface DataViewBase extends SerializableRecord { +export interface DataViewBase { fields: DataViewFieldBase[]; id?: string; title: string; } +export type DataViewBaseSerializable = SerializableRecord & DataViewBase; + export interface BoolQuery { must: estypes.QueryDslQueryContainer[]; must_not: estypes.QueryDslQueryContainer[]; diff --git a/packages/kbn-es-query/src/index.ts b/packages/kbn-es-query/src/index.ts index 02d54df9951761..7585d1de8c2a4c 100644 --- a/packages/kbn-es-query/src/index.ts +++ b/packages/kbn-es-query/src/index.ts @@ -9,7 +9,9 @@ export type { BoolQuery, DataViewBase, + DataViewBaseSerializable, DataViewFieldBase, + DataViewFieldBaseSerializable, EsQueryConfig, IFieldSubType, IFieldSubTypeMulti, diff --git a/src/plugins/data_views/common/data_views/persistable_state.ts b/src/plugins/data_views/common/data_views/persistable_state.ts index 9f97d38762dd25..da160677686284 100644 --- a/src/plugins/data_views/common/data_views/persistable_state.ts +++ b/src/plugins/data_views/common/data_views/persistable_state.ts @@ -6,10 +6,10 @@ * Side Public License, v 1. */ -import { DataViewBase } from '@kbn/es-query'; +import { DataViewBaseSerializable } from '@kbn/es-query'; import { PersistableStateService } from '@kbn/kibana-utils-plugin/common'; -export const DataViewPersistableStateService: PersistableStateService = { +export const DataViewPersistableStateService: PersistableStateService = { inject: (state, references) => { return state; }, diff --git a/src/plugins/data_views/common/fields/persistable_state.ts b/src/plugins/data_views/common/fields/persistable_state.ts index a5655a4cee7616..ed04b72217ca9d 100644 --- a/src/plugins/data_views/common/fields/persistable_state.ts +++ b/src/plugins/data_views/common/fields/persistable_state.ts @@ -6,17 +6,18 @@ * Side Public License, v 1. */ -import { DataViewFieldBase } from '@kbn/es-query'; +import { DataViewFieldBaseSerializable } from '@kbn/es-query'; import { PersistableStateService } from '@kbn/kibana-utils-plugin/common'; -export const DataViewPersistableStateService: PersistableStateService = { - inject: (state, references) => { - return state; - }, - extract: (state) => { - return { state, references: [] }; - }, - getAllMigrations: () => ({}), - migrateToLatest: ({ state }) => state, - telemetry: () => ({}), -}; +export const DataViewPersistableStateService: PersistableStateService = + { + inject: (state, references) => { + return state; + }, + extract: (state) => { + return { state, references: [] }; + }, + getAllMigrations: () => ({}), + migrateToLatest: ({ state }) => state, + telemetry: () => ({}), + }; From cf34478b5315e07b49c72c9e4ebd67f82e7c262f Mon Sep 17 00:00:00 2001 From: Lukas Olson Date: Wed, 25 May 2022 10:35:12 -0700 Subject: [PATCH 03/10] Update tests --- .../data_views/persistable_state.test.ts | 32 +++++++++++++++++-- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/src/plugins/data_views/common/data_views/persistable_state.test.ts b/src/plugins/data_views/common/data_views/persistable_state.test.ts index da7b176d3cc8f7..238c3e8034976e 100644 --- a/src/plugins/data_views/common/data_views/persistable_state.test.ts +++ b/src/plugins/data_views/common/data_views/persistable_state.test.ts @@ -6,9 +6,35 @@ * Side Public License, v 1. */ -// import { DataViewPersistableStateService } from './persistable_state'; +import { DataViewBaseSerializable } from '@kbn/es-query'; +import { DataViewPersistableStateService } from './persistable_state'; +import { SavedObjectReference } from '@kbn/core/types'; +const { inject, extract } = DataViewPersistableStateService; describe('filter manager persistable state tests', () => { - describe('reference injection', () => {}); - describe('reference extraction', () => {}); + test('inject references', () => { + const state: DataViewBaseSerializable = { + id: 'my-id', + title: 'my-title', + fields: [], + }; + const references: SavedObjectReference[] = []; + + const result = inject(state, references); + + expect(result).toBe(state); + }); + + test('extract references', () => { + const state: DataViewBaseSerializable = { + id: 'my-id', + title: 'my-title', + fields: [], + }; + + const result = extract(state); + + expect(result.state).toBe(state); + expect(result.references).toEqual([]); + }); }); From 8ac389a819e4792312c7cfced8abb6e360d52218 Mon Sep 17 00:00:00 2001 From: Lukas Olson Date: Wed, 25 May 2022 10:41:03 -0700 Subject: [PATCH 04/10] Add test for fields --- .../data_views/persistable_state.test.ts | 2 +- .../common/fields/persistable_state.test.ts | 32 ++++++++++++++++--- .../common/fields/persistable_state.ts | 2 +- 3 files changed, 30 insertions(+), 6 deletions(-) diff --git a/src/plugins/data_views/common/data_views/persistable_state.test.ts b/src/plugins/data_views/common/data_views/persistable_state.test.ts index 238c3e8034976e..5970ae2ae5a3c8 100644 --- a/src/plugins/data_views/common/data_views/persistable_state.test.ts +++ b/src/plugins/data_views/common/data_views/persistable_state.test.ts @@ -11,7 +11,7 @@ import { DataViewPersistableStateService } from './persistable_state'; import { SavedObjectReference } from '@kbn/core/types'; const { inject, extract } = DataViewPersistableStateService; -describe('filter manager persistable state tests', () => { +describe('data view persistable state tests', () => { test('inject references', () => { const state: DataViewBaseSerializable = { id: 'my-id', diff --git a/src/plugins/data_views/common/fields/persistable_state.test.ts b/src/plugins/data_views/common/fields/persistable_state.test.ts index da7b176d3cc8f7..29e01ef9f63d7a 100644 --- a/src/plugins/data_views/common/fields/persistable_state.test.ts +++ b/src/plugins/data_views/common/fields/persistable_state.test.ts @@ -6,9 +6,33 @@ * Side Public License, v 1. */ -// import { DataViewPersistableStateService } from './persistable_state'; +import { DataViewFieldBaseSerializable } from '@kbn/es-query'; +import { DataViewFieldPersistableStateService } from './persistable_state'; +import { SavedObjectReference } from '@kbn/core/types'; +const { inject, extract } = DataViewFieldPersistableStateService; -describe('filter manager persistable state tests', () => { - describe('reference injection', () => {}); - describe('reference extraction', () => {}); +describe('data view field persistable state tests', () => { + test('inject references', () => { + const state: DataViewFieldBaseSerializable = { + name: 'my-name', + type: 'my-type', + }; + const references: SavedObjectReference[] = []; + + const result = inject(state, references); + + expect(result).toBe(state); + }); + + test('extract references', () => { + const state: DataViewFieldBaseSerializable = { + name: 'my-name', + type: 'my-type', + }; + + const result = extract(state); + + expect(result.state).toBe(state); + expect(result.references).toEqual([]); + }); }); diff --git a/src/plugins/data_views/common/fields/persistable_state.ts b/src/plugins/data_views/common/fields/persistable_state.ts index ed04b72217ca9d..6091014fb99eb2 100644 --- a/src/plugins/data_views/common/fields/persistable_state.ts +++ b/src/plugins/data_views/common/fields/persistable_state.ts @@ -9,7 +9,7 @@ import { DataViewFieldBaseSerializable } from '@kbn/es-query'; import { PersistableStateService } from '@kbn/kibana-utils-plugin/common'; -export const DataViewPersistableStateService: PersistableStateService = +export const DataViewFieldPersistableStateService: PersistableStateService = { inject: (state, references) => { return state; From ece074faf23dab560adf8a3bbd02a60d1e08309d Mon Sep 17 00:00:00 2001 From: Lukas Olson Date: Thu, 2 Jun 2022 13:43:42 -0700 Subject: [PATCH 05/10] Use spec instead of base --- packages/kbn-es-query/src/es_query/index.ts | 2 - packages/kbn-es-query/src/es_query/types.ts | 14 +++---- packages/kbn-es-query/src/index.ts | 2 - .../common/types/expression_renderers.ts | 4 +- .../public/helpers/data_layers.tsx | 9 +---- .../data/common/search/aggs/agg_config.ts | 5 +-- .../data/common/search/aggs/agg_type.ts | 3 +- .../search/aggs/utils/get_aggs_formats.ts | 13 +++---- .../field_format_editor/editors/date/date.tsx | 2 +- .../editors/date_nanos/date_nanos.tsx | 2 +- .../editors/duration/duration.tsx | 2 +- .../editors/number/number.tsx | 2 +- .../field_format_editor/editors/url/url.tsx | 2 +- .../data_views/persistable_state.test.ts | 10 ++--- .../common/data_views/persistable_state.ts | 4 +- .../common/fields/persistable_state.test.ts | 38 ------------------- .../common/fields/persistable_state.ts | 23 ----------- src/plugins/data_views/common/types.ts | 38 +++++++++++-------- .../rest_api_routes/fields/update_fields.ts | 4 +- .../field_formats/common/field_format.ts | 2 +- src/plugins/field_formats/common/types.ts | 20 ++++++---- .../vis_types/pie/public/types/types.ts | 2 +- .../visualizations/common/utils/accessors.ts | 4 +- .../components/table_basic.test.tsx | 20 ++++------ 24 files changed, 80 insertions(+), 147 deletions(-) delete mode 100644 src/plugins/data_views/common/fields/persistable_state.test.ts delete mode 100644 src/plugins/data_views/common/fields/persistable_state.ts diff --git a/packages/kbn-es-query/src/es_query/index.ts b/packages/kbn-es-query/src/es_query/index.ts index 15dac6e3621ef8..399df50e350587 100644 --- a/packages/kbn-es-query/src/es_query/index.ts +++ b/packages/kbn-es-query/src/es_query/index.ts @@ -16,9 +16,7 @@ export type { IFieldSubType, BoolQuery, DataViewBase, - DataViewBaseSerializable, DataViewFieldBase, - DataViewFieldBaseSerializable, IFieldSubTypeMulti, IFieldSubTypeNested, } from './types'; diff --git a/packages/kbn-es-query/src/es_query/types.ts b/packages/kbn-es-query/src/es_query/types.ts index baf7a8a376e3aa..41cc025fddadee 100644 --- a/packages/kbn-es-query/src/es_query/types.ts +++ b/packages/kbn-es-query/src/es_query/types.ts @@ -35,7 +35,8 @@ export interface IFieldSubTypeNested { * A base interface for an index pattern field * @public */ -export interface DataViewFieldBase { +// eslint-disable-next-line @typescript-eslint/consistent-type-definitions +export type DataViewFieldBase = { name: string; /** * Kibana field type @@ -52,21 +53,18 @@ export interface DataViewFieldBase { */ lang?: estypes.ScriptLanguage; scripted?: boolean; -} - -export type DataViewFieldBaseSerializable = SerializableRecord & DataViewFieldBase; +}; /** * A base interface for an index pattern * @public */ -export interface DataViewBase { +// eslint-disable-next-line @typescript-eslint/consistent-type-definitions +export type DataViewBase = { fields: DataViewFieldBase[]; id?: string; title: string; -} - -export type DataViewBaseSerializable = SerializableRecord & DataViewBase; +}; export interface BoolQuery { must: estypes.QueryDslQueryContainer[]; diff --git a/packages/kbn-es-query/src/index.ts b/packages/kbn-es-query/src/index.ts index abc4d777b63048..bde089d12e39b6 100644 --- a/packages/kbn-es-query/src/index.ts +++ b/packages/kbn-es-query/src/index.ts @@ -9,9 +9,7 @@ export type { BoolQuery, DataViewBase, - DataViewBaseSerializable, DataViewFieldBase, - DataViewFieldBaseSerializable, EsQueryConfig, IFieldSubType, IFieldSubTypeMulti, diff --git a/src/plugins/chart_expressions/expression_partition_vis/common/types/expression_renderers.ts b/src/plugins/chart_expressions/expression_partition_vis/common/types/expression_renderers.ts index 89a242fe26de17..93f93659875530 100644 --- a/src/plugins/chart_expressions/expression_partition_vis/common/types/expression_renderers.ts +++ b/src/plugins/chart_expressions/expression_partition_vis/common/types/expression_renderers.ts @@ -24,7 +24,7 @@ export interface Dimension { accessor: number; format: { id?: string; - params?: SerializedFieldFormat; + params?: SerializedFieldFormat; }; } @@ -129,7 +129,7 @@ export enum LegendDisplay { export interface BucketColumns extends DatatableColumn { format?: { id?: string; - params?: SerializedFieldFormat; + params?: SerializedFieldFormat; }; } diff --git a/src/plugins/chart_expressions/expression_xy/public/helpers/data_layers.tsx b/src/plugins/chart_expressions/expression_xy/public/helpers/data_layers.tsx index d4216545edd664..25314572529b42 100644 --- a/src/plugins/chart_expressions/expression_xy/public/helpers/data_layers.tsx +++ b/src/plugins/chart_expressions/expression_xy/public/helpers/data_layers.tsx @@ -18,12 +18,7 @@ import { XYChartSeriesIdentifier, } from '@elastic/charts'; import { i18n } from '@kbn/i18n'; -import { - FieldFormat, - FieldFormatParams, - IFieldFormat, - SerializedFieldFormat, -} from '@kbn/field-formats-plugin/common'; +import { FieldFormat, IFieldFormat, SerializedFieldFormat } from '@kbn/field-formats-plugin/common'; import { Datatable } from '@kbn/expressions-plugin'; import { getFormatByAccessor, @@ -64,7 +59,7 @@ type GetSeriesNameFn = ( config: { splitColumnId?: string; accessorsCount: number; - splitHint: SerializedFieldFormat | undefined; + splitHint: SerializedFieldFormat | undefined; splitFormatter: FieldFormat; alreadyFormattedColumns: Record; columnToLabelMap: Record; diff --git a/src/plugins/data/common/search/aggs/agg_config.ts b/src/plugins/data/common/search/aggs/agg_config.ts index f78452d99ededb..c80c4d4d4b4570 100644 --- a/src/plugins/data/common/search/aggs/agg_config.ts +++ b/src/plugins/data/common/search/aggs/agg_config.ts @@ -14,6 +14,7 @@ import { Assign, Ensure } from '@kbn/utility-types'; import { ExpressionAstExpression, ExpressionAstArgument } from '@kbn/expressions-plugin/common'; import type { SerializedFieldFormat } from '@kbn/field-formats-plugin/common'; +import { FieldFormatParams } from '@kbn/field-formats-plugin/common'; // eslint-disable-next-line @kbn/eslint/no-restricted-paths import { ISearchOptions, ISearchSource } from '../../../public'; @@ -323,9 +324,7 @@ export class AggConfig { * * @public */ - toSerializedFieldFormat(): - | {} - | Ensure, SerializableRecord> { + toSerializedFieldFormat(): SerializedFieldFormat { return this.type ? this.type.getSerializedFormat(this) : {}; } diff --git a/src/plugins/data/common/search/aggs/agg_type.ts b/src/plugins/data/common/search/aggs/agg_type.ts index 633bd00dd9a35a..b7be15cd703c22 100644 --- a/src/plugins/data/common/search/aggs/agg_type.ts +++ b/src/plugins/data/common/search/aggs/agg_type.ts @@ -15,6 +15,7 @@ import type { SerializedFieldFormat } from '@kbn/field-formats-plugin/common'; import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; // eslint-disable-next-line @kbn/eslint/no-restricted-paths +import { FieldFormatParams } from '@kbn/field-formats-plugin/common'; import { ISearchSource } from '../../../public'; import { initParams } from './agg_params'; import { AggConfig } from './agg_config'; @@ -208,7 +209,7 @@ export class AggType< * @param {agg} agg - the agg to pick a format for * @return {SerializedFieldFormat} */ - getSerializedFormat: (agg: TAggConfig) => SerializedFieldFormat; + getSerializedFormat: (agg: TAggConfig) => SerializedFieldFormat; getValue: (agg: TAggConfig, bucket: any) => any; diff --git a/src/plugins/data/common/search/aggs/utils/get_aggs_formats.ts b/src/plugins/data/common/search/aggs/utils/get_aggs_formats.ts index 61b61d70f13751..42ef726d04026b 100644 --- a/src/plugins/data/common/search/aggs/utils/get_aggs_formats.ts +++ b/src/plugins/data/common/search/aggs/utils/get_aggs_formats.ts @@ -12,7 +12,6 @@ import { i18n } from '@kbn/i18n'; import { FieldFormat, FieldFormatInstanceType, - FieldFormatParams, FieldFormatsContentType, IFieldFormat, SerializedFieldFormat, @@ -129,13 +128,13 @@ export function getAggsFormats(getFieldFormat: GetFieldFormat): FieldFormatInsta convert = (val: string, type: FieldFormatsContentType) => { const params = this._params; - const format = getFieldFormat({ id: params.id, params }); + const format = getFieldFormat({ id: `${params.id}`, params }); if (val === '__other__') { - return params.otherBucketLabel; + return `${params.otherBucketLabel}`; } if (val === '__missing__') { - return params.missingBucketLabel; + return `${params.missingBucketLabel}`; } return format.convert(val, type); @@ -146,7 +145,7 @@ export function getAggsFormats(getFieldFormat: GetFieldFormat): FieldFormatInsta static id = 'multi_terms'; static hidden = true; - private formatCache: Map, FieldFormat> = new Map(); + private formatCache: Map = new Map(); convert = (val: unknown, type: FieldFormatsContentType) => { const params = this._params; @@ -160,10 +159,10 @@ export function getAggsFormats(getFieldFormat: GetFieldFormat): FieldFormatInsta }); if (String(val) === '__other__') { - return params.otherBucketLabel; + return `${params.otherBucketLabel}`; } - const joinTemplate = params.separator ?? ' › '; + const joinTemplate = `${params.separator}` ?? ' › '; return (val as MultiFieldKey).keys .map((valPart, i) => formats[i].convert(valPart, type)) diff --git a/src/plugins/data_view_field_editor/public/components/field_format_editor/editors/date/date.tsx b/src/plugins/data_view_field_editor/public/components/field_format_editor/editors/date/date.tsx index 73ab4b58bbcb05..fdf0291f0fa4dc 100644 --- a/src/plugins/data_view_field_editor/public/components/field_format_editor/editors/date/date.tsx +++ b/src/plugins/data_view_field_editor/public/components/field_format_editor/editors/date/date.tsx @@ -35,7 +35,7 @@ export class DateFormatEditor extends DefaultFormatEditor diff --git a/src/plugins/data_view_field_editor/public/components/field_format_editor/editors/date_nanos/date_nanos.tsx b/src/plugins/data_view_field_editor/public/components/field_format_editor/editors/date_nanos/date_nanos.tsx index 8a82caa1e7f03d..468263fcdfc38d 100644 --- a/src/plugins/data_view_field_editor/public/components/field_format_editor/editors/date_nanos/date_nanos.tsx +++ b/src/plugins/data_view_field_editor/public/components/field_format_editor/editors/date_nanos/date_nanos.tsx @@ -34,7 +34,7 @@ export class DateNanosFormatEditor extends DefaultFormatEditor diff --git a/src/plugins/data_view_field_editor/public/components/field_format_editor/editors/duration/duration.tsx b/src/plugins/data_view_field_editor/public/components/field_format_editor/editors/duration/duration.tsx index e18c9664cacabc..8b8864622ffc2e 100644 --- a/src/plugins/data_view_field_editor/public/components/field_format_editor/editors/duration/duration.tsx +++ b/src/plugins/data_view_field_editor/public/components/field_format_editor/editors/duration/duration.tsx @@ -86,7 +86,7 @@ export class DurationFormatEditor extends DefaultFormatEditor< const { error, samples, hasDecimalError } = this.state; const formatParams: DurationFormatEditorFormatParams = { - includeSpaceWithSuffix: format.getParamDefaults().includeSpaceWithSuffix, + includeSpaceWithSuffix: format.getParamDefaults().includeSpaceWithSuffix as boolean, ...this.props.formatParams, }; diff --git a/src/plugins/data_view_field_editor/public/components/field_format_editor/editors/number/number.tsx b/src/plugins/data_view_field_editor/public/components/field_format_editor/editors/number/number.tsx index 65793583d8bf35..5d9f2e0c875956 100644 --- a/src/plugins/data_view_field_editor/public/components/field_format_editor/editors/number/number.tsx +++ b/src/plugins/data_view_field_editor/public/components/field_format_editor/editors/number/number.tsx @@ -34,7 +34,7 @@ export class NumberFormatEditor extends DefaultFormatEditor diff --git a/src/plugins/data_view_field_editor/public/components/field_format_editor/editors/url/url.tsx b/src/plugins/data_view_field_editor/public/components/field_format_editor/editors/url/url.tsx index d7f76e07ef4470..ed458f7a040ffb 100644 --- a/src/plugins/data_view_field_editor/public/components/field_format_editor/editors/url/url.tsx +++ b/src/plugins/data_view_field_editor/public/components/field_format_editor/editors/url/url.tsx @@ -148,7 +148,7 @@ export class UrlFormatEditor extends DefaultFormatEditor< const { formatParams, format } = this.props; const { error, samples, sampleConverterType } = this.state; - const urlType = formatParams.type ?? format.getParamDefaults().type; + const urlType = formatParams.type ?? `${format.getParamDefaults().type}`; return ( { test('inject references', () => { - const state: DataViewBaseSerializable = { + const state: DataViewSpec = { id: 'my-id', title: 'my-title', - fields: [], + fields: {}, }; const references: SavedObjectReference[] = []; @@ -26,10 +26,10 @@ describe('data view persistable state tests', () => { }); test('extract references', () => { - const state: DataViewBaseSerializable = { + const state: DataViewSpec = { id: 'my-id', title: 'my-title', - fields: [], + fields: {}, }; const result = extract(state); diff --git a/src/plugins/data_views/common/data_views/persistable_state.ts b/src/plugins/data_views/common/data_views/persistable_state.ts index da160677686284..604cc3777deaad 100644 --- a/src/plugins/data_views/common/data_views/persistable_state.ts +++ b/src/plugins/data_views/common/data_views/persistable_state.ts @@ -6,10 +6,10 @@ * Side Public License, v 1. */ -import { DataViewBaseSerializable } from '@kbn/es-query'; import { PersistableStateService } from '@kbn/kibana-utils-plugin/common'; +import { DataViewSpec } from '../types'; -export const DataViewPersistableStateService: PersistableStateService = { +export const DataViewPersistableStateService: PersistableStateService = { inject: (state, references) => { return state; }, diff --git a/src/plugins/data_views/common/fields/persistable_state.test.ts b/src/plugins/data_views/common/fields/persistable_state.test.ts deleted file mode 100644 index 29e01ef9f63d7a..00000000000000 --- a/src/plugins/data_views/common/fields/persistable_state.test.ts +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ - -import { DataViewFieldBaseSerializable } from '@kbn/es-query'; -import { DataViewFieldPersistableStateService } from './persistable_state'; -import { SavedObjectReference } from '@kbn/core/types'; -const { inject, extract } = DataViewFieldPersistableStateService; - -describe('data view field persistable state tests', () => { - test('inject references', () => { - const state: DataViewFieldBaseSerializable = { - name: 'my-name', - type: 'my-type', - }; - const references: SavedObjectReference[] = []; - - const result = inject(state, references); - - expect(result).toBe(state); - }); - - test('extract references', () => { - const state: DataViewFieldBaseSerializable = { - name: 'my-name', - type: 'my-type', - }; - - const result = extract(state); - - expect(result.state).toBe(state); - expect(result.references).toEqual([]); - }); -}); diff --git a/src/plugins/data_views/common/fields/persistable_state.ts b/src/plugins/data_views/common/fields/persistable_state.ts deleted file mode 100644 index 6091014fb99eb2..00000000000000 --- a/src/plugins/data_views/common/fields/persistable_state.ts +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ - -import { DataViewFieldBaseSerializable } from '@kbn/es-query'; -import { PersistableStateService } from '@kbn/kibana-utils-plugin/common'; - -export const DataViewFieldPersistableStateService: PersistableStateService = - { - inject: (state, references) => { - return state; - }, - extract: (state) => { - return { state, references: [] }; - }, - getAllMigrations: () => ({}), - migrateToLatest: ({ state }) => state, - telemetry: () => ({}), - }; diff --git a/src/plugins/data_views/common/types.ts b/src/plugins/data_views/common/types.ts index 628a98d89e68d3..1a8aa0afbd6502 100644 --- a/src/plugins/data_views/common/types.ts +++ b/src/plugins/data_views/common/types.ts @@ -36,7 +36,8 @@ export type RuntimeTypeExceptComposite = Exclude; * Runtime field definition * @public */ -export interface RuntimeFieldBase { +// eslint-disable-next-line @typescript-eslint/consistent-type-definitions +export type RuntimeFieldBase = { /** * Type of runtime field */ @@ -50,12 +51,12 @@ export interface RuntimeFieldBase { */ source: string; }; -} +}; /** * The RuntimeField that will be sent in the ES Query "runtime_mappings" object */ -export interface RuntimeFieldSpec extends RuntimeFieldBase { +export type RuntimeFieldSpec = RuntimeFieldBase & { fields?: Record< string, { @@ -63,7 +64,7 @@ export interface RuntimeFieldSpec extends RuntimeFieldBase { type: RuntimeTypeExceptComposite; } >; -} +}; /** * Field attributes that are user configurable @@ -159,15 +160,17 @@ export interface DataViewAttributes { * @public * Storage of field attributes. Necessary since the field list isn't saved. */ -export interface FieldAttrs { +// eslint-disable-next-line @typescript-eslint/consistent-type-definitions +export type FieldAttrs = { [key: string]: FieldAttrSet; -} +}; /** * Field attributes that are stored on the data view * @public */ -export interface FieldAttrSet { +// eslint-disable-next-line @typescript-eslint/consistent-type-definitions +export type FieldAttrSet = { /** * Custom field label */ @@ -176,7 +179,7 @@ export interface FieldAttrSet { * Popularity count - used for discover */ count?: number; -} +}; /** * Handler for data view notifications @@ -328,7 +331,8 @@ export type AggregationRestrictions = Record< /** * Interface for metadata about rollup indices */ -export interface TypeMeta { +// eslint-disable-next-line @typescript-eslint/consistent-type-definitions +export type TypeMeta = { /** * Aggregation restrictions for rollup fields */ @@ -342,7 +346,7 @@ export interface TypeMeta { */ rollup_index: string; }; -} +}; /** * Data View type. Default or rollup @@ -366,7 +370,7 @@ export type FieldSpecConflictDescriptions = Record; * Serialized version of DataViewField * @public */ -export interface FieldSpec extends DataViewFieldBase { +export type FieldSpec = DataViewFieldBase & { /** * Popularity count is used by discover */ @@ -418,7 +422,7 @@ export interface FieldSpec extends DataViewFieldBase { * Is this field in the mapping? False if a scripted or runtime field defined on the data view. */ isMapped?: boolean; -} +}; export type DataViewFieldMap = Record; @@ -426,7 +430,8 @@ export type DataViewFieldMap = Record; * Static data view format * Serialized data object, representing data view attributes and state */ -export interface DataViewSpec { +// eslint-disable-next-line @typescript-eslint/consistent-type-definitions +export type DataViewSpec = { /** * Saved object id */ @@ -479,11 +484,12 @@ export interface DataViewSpec { * Array of namespace ids */ namespaces?: string[]; -} +}; -export interface SourceFilter { +// eslint-disable-next-line @typescript-eslint/consistent-type-definitions +export type SourceFilter = { value: string; -} +}; export interface HasDataService { hasESData: () => Promise; diff --git a/src/plugins/data_views/server/rest_api_routes/fields/update_fields.ts b/src/plugins/data_views/server/rest_api_routes/fields/update_fields.ts index d99aa67c7f1537..1695f28675188d 100644 --- a/src/plugins/data_views/server/rest_api_routes/fields/update_fields.ts +++ b/src/plugins/data_views/server/rest_api_routes/fields/update_fields.ts @@ -9,7 +9,7 @@ import { UsageCounter } from '@kbn/usage-collection-plugin/server'; import { schema } from '@kbn/config-schema'; import { IRouter, StartServicesAccessor } from '@kbn/core/server'; -import { FieldFormatParams, SerializedFieldFormat } from '@kbn/field-formats-plugin/common'; +import { SerializedFieldFormat } from '@kbn/field-formats-plugin/common'; import { DataViewsService } from '../../../common'; import { handleErrors } from '../util/handle_errors'; import { serializedFieldFormatSchema } from '../util/schemas'; @@ -83,7 +83,7 @@ export const updateFields = async ({ interface FieldUpdateType { customLabel?: string | null; count?: number | null; - format?: SerializedFieldFormat | null; + format?: SerializedFieldFormat | null; } const fieldUpdateSchema = schema.object({ diff --git a/src/plugins/field_formats/common/field_format.ts b/src/plugins/field_formats/common/field_format.ts index 05b376ddf3272f..9b783b244e868d 100644 --- a/src/plugins/field_formats/common/field_format.ts +++ b/src/plugins/field_formats/common/field_format.ts @@ -192,7 +192,7 @@ export abstract class FieldFormat { const params = transform( this._params, - (uniqParams: FieldFormatParams & FieldFormatMetaParams, val: unknown, param: string) => { + (uniqParams: FieldFormatParams & FieldFormatMetaParams, val, param: string) => { if (param === 'parsedUrl') return; if (param && val !== get(defaultsParams, param)) { uniqParams[param] = val; diff --git a/src/plugins/field_formats/common/types.ts b/src/plugins/field_formats/common/types.ts index 55db21ffa74ea4..d2be3416721b80 100644 --- a/src/plugins/field_formats/common/types.ts +++ b/src/plugins/field_formats/common/types.ts @@ -6,6 +6,7 @@ * Side Public License, v 1. */ +import { Serializable, SerializableRecord } from '@kbn/utility-types'; import { FieldFormat } from './field_format'; import { FieldFormatsRegistry } from './field_formats_registry'; @@ -74,11 +75,12 @@ export enum FIELD_FORMAT_IDS { } /** @public */ -export interface FieldFormatConfig { +// eslint-disable-next-line @typescript-eslint/consistent-type-definitions +export type FieldFormatConfig = { id: FieldFormatId; params: FieldFormatParams; es?: boolean; -} +}; /** * If a service is being shared on both the client and the server, and @@ -92,7 +94,10 @@ export interface FieldFormatConfig { * @public */ -export type FieldFormatsGetConfigFn = (key: string, defaultOverride?: T) => T; +export type FieldFormatsGetConfigFn = ( + key: string, + defaultOverride?: T +) => T; export type IFieldFormat = FieldFormat; @@ -123,9 +128,7 @@ export type FieldFormatInstanceType = (new ( * TODO: support strict typing for params depending on format type * https://github.com/elastic/kibana/issues/108158 */ -export interface FieldFormatParams { - [param: string]: any; -} +export type FieldFormatParams = SerializableRecord; /** * Params provided by the registry to every field formatter @@ -149,9 +152,10 @@ export type FieldFormatsStartCommon = Omit { +// eslint-disable-next-line @typescript-eslint/consistent-type-definitions +export type SerializedFieldFormat = { id?: string; params?: TParams; -} +}; export type FormatFactory = (mapping?: SerializedFieldFormat) => IFieldFormat; diff --git a/src/plugins/vis_types/pie/public/types/types.ts b/src/plugins/vis_types/pie/public/types/types.ts index de8151bffbfcb8..968e04fd590752 100644 --- a/src/plugins/vis_types/pie/public/types/types.ts +++ b/src/plugins/vis_types/pie/public/types/types.ts @@ -14,7 +14,7 @@ export interface Dimension { accessor: number; format: { id?: string; - params?: SerializedFieldFormat; + params?: SerializedFieldFormat; }; } diff --git a/src/plugins/visualizations/common/utils/accessors.ts b/src/plugins/visualizations/common/utils/accessors.ts index e8146906b036a3..97b47ef7a32678 100644 --- a/src/plugins/visualizations/common/utils/accessors.ts +++ b/src/plugins/visualizations/common/utils/accessors.ts @@ -7,7 +7,7 @@ */ import { i18n } from '@kbn/i18n'; import { Datatable, DatatableColumn } from '@kbn/expressions-plugin/common'; -import { FieldFormatParams, SerializedFieldFormat } from '@kbn/field-formats-plugin/common/types'; +import { SerializedFieldFormat } from '@kbn/field-formats-plugin/common/types'; import { ExpressionValueVisDimension } from '../expression_functions'; const getAccessorByIndex = (accessor: number, columns: Datatable['columns']) => @@ -68,7 +68,7 @@ export function getAccessor(dimension: string | ExpressionValueVisDimension) { export function getFormatByAccessor( dimension: string | ExpressionValueVisDimension, columns: DatatableColumn[], - defaultColumnFormat?: SerializedFieldFormat + defaultColumnFormat?: SerializedFieldFormat ) { return typeof dimension === 'string' ? getColumnByAccessor(dimension, columns)?.meta.params || defaultColumnFormat diff --git a/x-pack/plugins/lens/public/datatable_visualization/components/table_basic.test.tsx b/x-pack/plugins/lens/public/datatable_visualization/components/table_basic.test.tsx index bcf6f50d2bd466..0bdcb22c280b29 100644 --- a/x-pack/plugins/lens/public/datatable_visualization/components/table_basic.test.tsx +++ b/x-pack/plugins/lens/public/datatable_visualization/components/table_basic.test.tsx @@ -11,11 +11,7 @@ import { act } from 'react-dom/test-utils'; import { mountWithIntl } from '@kbn/test-jest-helpers'; import { EuiDataGrid } from '@elastic/eui'; import { IAggType } from '@kbn/data-plugin/public'; -import { - FieldFormatParams, - IFieldFormat, - SerializedFieldFormat, -} from '@kbn/field-formats-plugin/common'; +import { IFieldFormat, SerializedFieldFormat } from '@kbn/field-formats-plugin/common'; import { VisualizationContainer } from '../../visualization_container'; import { EmptyPlaceholder } from '@kbn/charts-plugin/public'; import { LensIconChartDatatable } from '../../assets/chart_datatable'; @@ -110,7 +106,7 @@ describe('DatatableComponent', () => { x as IFieldFormat} + formatFactory={(x) => x as unknown as IFieldFormat} dispatchEvent={onDispatchEvent} getType={jest.fn()} paletteService={chartPluginMock.createPaletteRegistry()} @@ -130,7 +126,7 @@ describe('DatatableComponent', () => { x as IFieldFormat} + formatFactory={(x) => x as unknown as IFieldFormat} dispatchEvent={onDispatchEvent} getType={jest.fn()} rowHasRowClickTriggerActions={[true, true, true]} @@ -151,7 +147,7 @@ describe('DatatableComponent', () => { x as IFieldFormat} + formatFactory={(x) => x as unknown as IFieldFormat} dispatchEvent={onDispatchEvent} getType={jest.fn()} rowHasRowClickTriggerActions={[false, false, false]} @@ -729,7 +725,7 @@ describe('DatatableComponent', () => { x as IFieldFormat} + formatFactory={(x) => x as unknown as IFieldFormat} dispatchEvent={onDispatchEvent} getType={jest.fn()} paletteService={chartPluginMock.createPaletteRegistry()} @@ -764,7 +760,7 @@ describe('DatatableComponent', () => { x as IFieldFormat} + formatFactory={(x) => x as unknown as IFieldFormat} dispatchEvent={onDispatchEvent} getType={jest.fn()} paletteService={chartPluginMock.createPaletteRegistry()} @@ -789,7 +785,7 @@ describe('DatatableComponent', () => { const defaultProps = { data, - formatFactory: (x?: SerializedFieldFormat) => x as IFieldFormat, + formatFactory: (x?: SerializedFieldFormat) => x as unknown as IFieldFormat, dispatchEvent: onDispatchEvent, getType: jest.fn(), paletteService: chartPluginMock.createPaletteRegistry(), @@ -825,7 +821,7 @@ describe('DatatableComponent', () => { x as IFieldFormat} + formatFactory={(x) => x as unknown as IFieldFormat} dispatchEvent={onDispatchEvent} getType={jest.fn()} paletteService={chartPluginMock.createPaletteRegistry()} From b138f1466b77a836f7b150ed29235f0f0e3053d1 Mon Sep 17 00:00:00 2001 From: Lukas Olson Date: Thu, 2 Jun 2022 13:51:54 -0700 Subject: [PATCH 06/10] Update types --- packages/kbn-es-query/src/es_query/types.ts | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/packages/kbn-es-query/src/es_query/types.ts b/packages/kbn-es-query/src/es_query/types.ts index 41cc025fddadee..14e091ed5b7f28 100644 --- a/packages/kbn-es-query/src/es_query/types.ts +++ b/packages/kbn-es-query/src/es_query/types.ts @@ -7,7 +7,6 @@ */ import * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; -import { SerializableRecord } from '@kbn/utility-types'; /** * A field's sub type @@ -15,17 +14,19 @@ import { SerializableRecord } from '@kbn/utility-types'; */ export type IFieldSubType = IFieldSubTypeMultiOptional | IFieldSubTypeNestedOptional; -export interface IFieldSubTypeMultiOptional extends SerializableRecord { +// eslint-disable-next-line @typescript-eslint/consistent-type-definitions +export type IFieldSubTypeMultiOptional = { multi?: { parent: string }; -} +}; export interface IFieldSubTypeMulti { multi: { parent: string }; } -export interface IFieldSubTypeNestedOptional extends SerializableRecord { +// eslint-disable-next-line @typescript-eslint/consistent-type-definitions +export type IFieldSubTypeNestedOptional = { nested?: { path: string }; -} +}; export interface IFieldSubTypeNested { nested: { path: string }; @@ -48,7 +49,7 @@ export type DataViewFieldBase = { */ script?: string; /** - * Scripted field langauge + * Scripted field language * Painless is the only valid scripted field language */ lang?: estypes.ScriptLanguage; From 92fa1b85a328ee22c6f3897bd75236b5fdc86798 Mon Sep 17 00:00:00 2001 From: Lukas Olson Date: Thu, 2 Jun 2022 14:14:04 -0700 Subject: [PATCH 07/10] Fix type errors --- .../components/field_editor/field_editor.tsx | 4 ++-- .../format_column/format_column_fn.ts | 16 ++++++++-------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/plugins/data_view_management/public/components/field_editor/field_editor.tsx b/src/plugins/data_view_management/public/components/field_editor/field_editor.tsx index c9e74ba05448f3..460d0317b2323f 100644 --- a/src/plugins/data_view_management/public/components/field_editor/field_editor.tsx +++ b/src/plugins/data_view_management/public/components/field_editor/field_editor.tsx @@ -33,7 +33,7 @@ import { import { i18n } from '@kbn/i18n'; import { FormattedMessage } from '@kbn/i18n-react'; import { PainlessLang } from '@kbn/monaco'; -import type { FieldFormatInstanceType } from '@kbn/field-formats-plugin/common'; +import type { FieldFormatInstanceType, FieldFormatParams } from '@kbn/field-formats-plugin/common'; import type { FieldFormatsStart } from '@kbn/field-formats-plugin/public'; import { KBN_FIELD_TYPES, ES_FIELD_TYPES } from '@kbn/field-types'; import { DataView, DataViewField, DataViewsPublicPluginStart } from '@kbn/data-views-plugin/public'; @@ -97,7 +97,7 @@ export interface FieldEditorState { fieldTypeFormats: FieldTypeFormat[]; existingFieldNames: string[]; fieldFormatId?: string; - fieldFormatParams: { [key: string]: unknown }; + fieldFormatParams: FieldFormatParams; showScriptingHelp: boolean; showDeleteModal: boolean; hasFormatError: boolean; diff --git a/x-pack/plugins/lens/common/expressions/format_column/format_column_fn.ts b/x-pack/plugins/lens/common/expressions/format_column/format_column_fn.ts index bca56b2dbddbe4..ff6ea3f443dcc2 100644 --- a/x-pack/plugins/lens/common/expressions/format_column/format_column_fn.ts +++ b/x-pack/plugins/lens/common/expressions/format_column/format_column_fn.ts @@ -67,7 +67,7 @@ export const formatColumnFn: FormatColumnExpressionFunction['fn'] = ( }; // Some parent formatters are multi-fields and wrap the custom format into a "paramsPerField" // property. Here the format is passed to this property to make it work properly - if (col.meta.params?.params?.paramsPerField?.length) { + if ((col.meta.params?.params?.paramsPerField as SerializedFieldFormat[])?.length) { return withParams(col, { id: parentFormatId, params: { @@ -77,13 +77,13 @@ export const formatColumnFn: FormatColumnExpressionFunction['fn'] = ( // some wrapper formatters require params to be flatten out (i.e. terms) while others // require them to be in the params property (i.e. ranges) // so for now duplicate - paramsPerField: col.meta.params?.params?.paramsPerField.map( - (f: { id: string | undefined; params: Record | undefined }) => ({ - ...f, - params: { ...f.params, ...customParams }, - ...customParams, - }) - ), + paramsPerField: ( + col.meta.params?.params?.paramsPerField as SerializedFieldFormat[] + ).map((f) => ({ + ...f, + params: { ...f.params, ...customParams }, + ...customParams, + })), }, }); } From 9501327e06af0ac90509a2879f83eb87f07feaa5 Mon Sep 17 00:00:00 2001 From: Lukas Olson Date: Thu, 2 Jun 2022 16:10:03 -0700 Subject: [PATCH 08/10] Fix tests & types --- .../common/search/aggs/utils/get_aggs_formats.ts | 2 +- .../components/shared/exploratory_view/types.ts | 12 ++++++------ .../observability_data_views.ts | 6 +++--- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/plugins/data/common/search/aggs/utils/get_aggs_formats.ts b/src/plugins/data/common/search/aggs/utils/get_aggs_formats.ts index 42ef726d04026b..5e36fbb791e28f 100644 --- a/src/plugins/data/common/search/aggs/utils/get_aggs_formats.ts +++ b/src/plugins/data/common/search/aggs/utils/get_aggs_formats.ts @@ -162,7 +162,7 @@ export function getAggsFormats(getFieldFormat: GetFieldFormat): FieldFormatInsta return `${params.otherBucketLabel}`; } - const joinTemplate = `${params.separator}` ?? ' › '; + const joinTemplate = `${params.separator ?? ' › '}`; return (val as MultiFieldKey).keys .map((valPart, i) => formats[i].convert(valPart, type)) diff --git a/x-pack/plugins/observability/public/components/shared/exploratory_view/types.ts b/x-pack/plugins/observability/public/components/shared/exploratory_view/types.ts index 09973e33b0dc25..f0ae7a6dd2a0ae 100644 --- a/x-pack/plugins/observability/public/components/shared/exploratory_view/types.ts +++ b/x-pack/plugins/observability/public/components/shared/exploratory_view/types.ts @@ -18,6 +18,10 @@ import type { import type { PersistableFilter } from '@kbn/lens-plugin/common'; import type { DataView } from '@kbn/data-views-plugin/common'; +import { + FieldFormatParams as BaseFieldFormatParams, + SerializedFieldFormat, +} from '@kbn/field-formats-plugin/common'; export const ReportViewTypes = { dist: 'data-distribution', @@ -121,11 +125,10 @@ export interface ConfigProps { export type AppDataType = 'synthetics' | 'ux' | 'infra_logs' | 'infra_metrics' | 'apm' | 'mobile'; -type FormatType = 'duration' | 'number' | 'bytes' | 'percent'; type InputFormat = 'microseconds' | 'milliseconds' | 'seconds'; type OutputFormat = 'asSeconds' | 'asMilliseconds' | 'humanize' | 'humanizePrecise'; -export interface FieldFormatParams { +export interface FieldFormatParams extends BaseFieldFormatParams { inputFormat?: InputFormat; outputFormat?: OutputFormat; outputPrecision?: number; @@ -135,10 +138,7 @@ export interface FieldFormatParams { export interface FieldFormat { field: string; - format: { - id: FormatType; - params: FieldFormatParams; - }; + format: SerializedFieldFormat; } export interface BuilderItem { diff --git a/x-pack/plugins/observability/public/utils/observability_data_views/observability_data_views.ts b/x-pack/plugins/observability/public/utils/observability_data_views/observability_data_views.ts index bc88769db43bf7..37661c696ea889 100644 --- a/x-pack/plugins/observability/public/utils/observability_data_views/observability_data_views.ts +++ b/x-pack/plugins/observability/public/utils/observability_data_views/observability_data_views.ts @@ -65,15 +65,15 @@ const getAppDataViewId = (app: AppDataType, indices: string) => { return `${dataViewList?.[app] ?? app}_${postfix}`; }; -export function isParamsSame(param1: IFieldFormat['_params'], param2: FieldFormatParams) { +export function isParamsSame(param1: IFieldFormat['_params'], param2?: FieldFormatParams) { const isSame = param1?.inputFormat === param2?.inputFormat && param1?.outputFormat === param2?.outputFormat && param1?.useShortSuffix === param2?.useShortSuffix && param1?.showSuffix === param2?.showSuffix; - if (param2.outputPrecision !== undefined) { - return param2?.outputPrecision === param1?.outputPrecision && isSame; + if (param2?.outputPrecision !== undefined) { + return param2.outputPrecision === param1?.outputPrecision && isSame; } return isSame; From 0f0347e45a7aa2704af11f16ecfa540eb9024d9b Mon Sep 17 00:00:00 2001 From: Lukas Olson Date: Thu, 2 Jun 2022 16:53:16 -0700 Subject: [PATCH 09/10] Update types --- .../application/contexts/kibana/use_field_formatter.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/x-pack/plugins/ml/public/application/contexts/kibana/use_field_formatter.ts b/x-pack/plugins/ml/public/application/contexts/kibana/use_field_formatter.ts index 113d77d7b16da8..7d34615d617589 100644 --- a/x-pack/plugins/ml/public/application/contexts/kibana/use_field_formatter.ts +++ b/x-pack/plugins/ml/public/application/contexts/kibana/use_field_formatter.ts @@ -5,18 +5,18 @@ * 2.0. */ -import { FIELD_FORMAT_IDS } from '@kbn/field-formats-plugin/common'; +import { FIELD_FORMAT_IDS, FieldFormatParams } from '@kbn/field-formats-plugin/common'; import { useMlKibana } from './kibana_context'; /** * Set of reasonable defaults for formatters for the ML app. */ -const defaultParam = { +const defaultParam: Record = { [FIELD_FORMAT_IDS.DURATION]: { inputFormat: 'milliseconds', outputFormat: 'humanizePrecise', }, -} as Record; +}; export function useFieldFormatter(fieldType: FIELD_FORMAT_IDS) { const { From 6dc21c565d0a50717ad4056d018d3c4a8abe8dfb Mon Sep 17 00:00:00 2001 From: Lukas Olson Date: Thu, 2 Jun 2022 22:34:51 -0700 Subject: [PATCH 10/10] Fix lint --- src/plugins/data/common/search/aggs/agg_type.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/data/common/search/aggs/agg_type.ts b/src/plugins/data/common/search/aggs/agg_type.ts index b7be15cd703c22..22055587eb7e8d 100644 --- a/src/plugins/data/common/search/aggs/agg_type.ts +++ b/src/plugins/data/common/search/aggs/agg_type.ts @@ -14,8 +14,8 @@ import type { RequestAdapter } from '@kbn/inspector-plugin/common'; import type { SerializedFieldFormat } from '@kbn/field-formats-plugin/common'; import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; -// eslint-disable-next-line @kbn/eslint/no-restricted-paths import { FieldFormatParams } from '@kbn/field-formats-plugin/common'; +// eslint-disable-next-line @kbn/eslint/no-restricted-paths import { ISearchSource } from '../../../public'; import { initParams } from './agg_params'; import { AggConfig } from './agg_config';