diff --git a/src/platform/packages/shared/as-code/data-views-schema/src/schema_data_view.ts b/src/platform/packages/shared/as-code/data-views-schema/src/schema_data_view.ts index daac9edb4bdda..0deeb34206294 100644 --- a/src/platform/packages/shared/as-code/data-views-schema/src/schema_data_view.ts +++ b/src/platform/packages/shared/as-code/data-views-schema/src/schema_data_view.ts @@ -14,14 +14,14 @@ import { runtimeFieldSchema } from './schema_runtime_field'; export const dataViewReferenceSchema = schema.object( { type: schema.literal(AS_CODE_DATA_VIEW_REFERENCE_TYPE), - id: schema.string({ + ref_id: schema.string({ meta: { description: 'The id of the Kibana data view to use as the data source. Example: "my-data-view".', }, }), }, - { meta: { id: 'dataViewReferenceDataSourceTypeSchema' } } + { meta: { id: 'kbn-data-view-reference-schema', title: 'Data view reference' } } ); export const dataViewSpecSchema = schema.object( @@ -43,7 +43,7 @@ export const dataViewSpecSchema = schema.object( ), runtime_fields: schema.maybe(schema.arrayOf(runtimeFieldSchema, { maxSize: 100 })), }, - { meta: { id: 'dataViewSpecDataSourceTypeSchema' } } + { meta: { id: 'kbn-data-view-spec-schema', title: 'Data view inline spec' } } ); export const dataViewSchema = schema.discriminatedUnion('type', [ diff --git a/src/platform/packages/shared/as-code/data-views-schema/src/schema_runtime_field.ts b/src/platform/packages/shared/as-code/data-views-schema/src/schema_runtime_field.ts index 07f7952653e7a..57158b84b86f9 100644 --- a/src/platform/packages/shared/as-code/data-views-schema/src/schema_runtime_field.ts +++ b/src/platform/packages/shared/as-code/data-views-schema/src/schema_runtime_field.ts @@ -28,6 +28,8 @@ const commonRuntimeFieldSchema = { minLength: 1, maxLength: MAX_NAME_LENGTH, meta: { + id: 'kbn-runtime-field-name', + title: 'Name', description: 'The name of the runtime field. Example: "my_runtime_field".', }, }), @@ -39,6 +41,8 @@ const commonRuntimeFieldSchema = { schema.string({ minLength: 1, meta: { + id: 'kbn-runtime-field-script', + title: 'Script', description: "The script that defines the runtime field. This should be a painless script that computes the field value at query time. Runtime fields without a script retrieve values from _source. If the field doesn't exist in _source, a search request returns no value.", }, @@ -57,7 +61,14 @@ const commonFieldSchema = { type: schema.oneOf( PRIMITIVE_RUNTIME_FIELD_TYPES.map((type) => schema.literal(type)) as [ Type<(typeof PRIMITIVE_RUNTIME_FIELD_TYPES)[number]> - ] + ], + { + meta: { + id: 'kbn-runtime-field-type', + title: 'Type', + description: 'The type of the runtime field (e.g., "keyword", "long", "date").', + }, + } ), /** * Optional format definition for the runtime field. The structure depends on the field type and use case. @@ -71,6 +82,8 @@ const commonFieldSchema = { }, { meta: { + id: 'kbn-runtime-field-format', + title: 'Format', description: 'Set your preferred format for displaying the value. Changing the format can affect the value and prevent highlighting in Discover.', }, @@ -81,6 +94,8 @@ const commonFieldSchema = { schema.string({ minLength: 1, meta: { + id: 'kbn-runtime-field-custom-label', + title: 'Custom label', description: 'Create a label to display in place of the field name in Discover, Maps, Lens, Visualize, and TSVB. Useful for shortening a long field name. Queries and filters use the original field name.', }, @@ -90,6 +105,8 @@ const commonFieldSchema = { schema.string({ minLength: 1, meta: { + id: 'kbn-runtime-field-custom-description', + title: 'Custom description', description: "Add a description to the field. It's displayed next to the field on the Discover, Lens, and Data View Management pages.", }, @@ -97,33 +114,39 @@ const commonFieldSchema = { ), }; -export const primitiveRuntimeFieldSchema = schema.object({ - ...commonFieldSchema, - ...commonRuntimeFieldSchema, -}); +export const primitiveRuntimeFieldSchema = schema.object( + { + ...commonFieldSchema, + ...commonRuntimeFieldSchema, + }, + { meta: { id: 'kbn-runtime-field-schema', title: 'Runtime field' } } +); -export const compositeRuntimeFieldSchema = schema.object({ - type: schema.literal(RUNTIME_FIELD_COMPOSITE_TYPE), - fields: schema.arrayOf( - schema.object({ - /** - * The name of the subfield. - * If the name is "field" and this subname is "name" the full name of the subfield will be "field.name". - */ - name: schema.string({ - minLength: 1, - maxLength: MAX_NAME_LENGTH, - meta: { - description: - 'The name of the runtime subfield, it gets appended to the parent field name. Example: "parent_name.my_runtime_subfield".', - }, +export const compositeRuntimeFieldSchema = schema.object( + { + type: schema.literal(RUNTIME_FIELD_COMPOSITE_TYPE), + fields: schema.arrayOf( + schema.object({ + /** + * The name of the subfield. + * If the name is "field" and this subname is "name" the full name of the subfield will be "field.name". + */ + name: schema.string({ + minLength: 1, + maxLength: MAX_NAME_LENGTH, + meta: { + description: + 'The name of the runtime subfield, it gets appended to the parent field name. Example: "parent_name.my_runtime_subfield".', + }, + }), + ...commonFieldSchema, }), - ...commonFieldSchema, - }), - { maxSize: 100 } - ), - ...commonRuntimeFieldSchema, -}); + { maxSize: 100 } + ), + ...commonRuntimeFieldSchema, + }, + { meta: { id: 'kbn-composite-runtime-field-schema', title: 'Composite runtime field' } } +); export const runtimeFieldSchema = schema.discriminatedUnion('type', [ primitiveRuntimeFieldSchema, diff --git a/src/platform/packages/shared/as-code/data-views-transforms/src/from_stored_data_view.ts b/src/platform/packages/shared/as-code/data-views-transforms/src/from_stored_data_view.ts index 3cdff6ea50cfd..588316af1d402 100644 --- a/src/platform/packages/shared/as-code/data-views-transforms/src/from_stored_data_view.ts +++ b/src/platform/packages/shared/as-code/data-views-transforms/src/from_stored_data_view.ts @@ -27,7 +27,7 @@ export function fromStoredDataView( ): AsCodeDataView { if (!index) throw new Error('Cannot derive data view from empty index'); if (typeof index === 'string') { - return { type: AS_CODE_DATA_VIEW_REFERENCE_TYPE, id: index }; + return { type: AS_CODE_DATA_VIEW_REFERENCE_TYPE, ref_id: index }; } if (!index.title) throw new Error('Cannot derive data view without `title` or `id`'); return { diff --git a/src/platform/packages/shared/as-code/data-views-transforms/src/stored_data_source.test.ts b/src/platform/packages/shared/as-code/data-views-transforms/src/to_stored_data_view.test.ts similarity index 98% rename from src/platform/packages/shared/as-code/data-views-transforms/src/stored_data_source.test.ts rename to src/platform/packages/shared/as-code/data-views-transforms/src/to_stored_data_view.test.ts index d3e61ca134981..7a3ec7712439d 100644 --- a/src/platform/packages/shared/as-code/data-views-transforms/src/stored_data_source.test.ts +++ b/src/platform/packages/shared/as-code/data-views-transforms/src/to_stored_data_view.test.ts @@ -19,7 +19,7 @@ describe('toStoredDataView', () => { it('converts data_view_reference data_source to string id', () => { const dataView: AsCodeDataViewReference = { type: AS_CODE_DATA_VIEW_REFERENCE_TYPE, - id: 'my-data-view-id', + ref_id: 'my-data-view-id', }; const result = toStoredDataView(dataView); expect(result).toBe('my-data-view-id'); diff --git a/src/platform/packages/shared/as-code/data-views-transforms/src/to_stored_data_view.ts b/src/platform/packages/shared/as-code/data-views-transforms/src/to_stored_data_view.ts index 39ea77da884e2..69ecfb1a7a218 100644 --- a/src/platform/packages/shared/as-code/data-views-transforms/src/to_stored_data_view.ts +++ b/src/platform/packages/shared/as-code/data-views-transforms/src/to_stored_data_view.ts @@ -26,7 +26,7 @@ import { * @returns Value suitable for `SerializedSearchSourceFields.index` */ export function toStoredDataView(dataView: AsCodeDataView): string | DataViewSpec { - if (dataView.type === AS_CODE_DATA_VIEW_REFERENCE_TYPE) return dataView.id; + if (dataView.type === AS_CODE_DATA_VIEW_REFERENCE_TYPE) return dataView.ref_id; const runtimeFieldMap = toStoredRuntimeFields(dataView.runtime_fields); const fieldFormats = toStoredFieldFormats(dataView.runtime_fields); const fieldAttrs = toStoredFieldAttributes(dataView.runtime_fields); diff --git a/src/platform/plugins/shared/discover/common/embeddable/search_embeddable_transforms.test.ts b/src/platform/plugins/shared/discover/common/embeddable/search_embeddable_transforms.test.ts index c5845e7f1ebfd..d7f27005d159b 100644 --- a/src/platform/plugins/shared/discover/common/embeddable/search_embeddable_transforms.test.ts +++ b/src/platform/plugins/shared/discover/common/embeddable/search_embeddable_transforms.test.ts @@ -139,7 +139,7 @@ describe('searchEmbeddableTransforms', () => { expect(density).toBe(DataGridDensity.COMPACT); expect(dataSource).toEqual({ type: AS_CODE_DATA_VIEW_REFERENCE_TYPE, - id: 'data-view-1', + ref_id: 'data-view-1', }); expect(mockDrilldownTransforms.transformOut).toHaveBeenCalledWith(state, references); }); @@ -243,7 +243,7 @@ describe('searchEmbeddableTransforms', () => { filters: [], rows_per_page: 100, sample_size: 1000, - data_source: { type: AS_CODE_DATA_VIEW_REFERENCE_TYPE, id: 'data-view-1' }, + data_source: { type: AS_CODE_DATA_VIEW_REFERENCE_TYPE, ref_id: 'data-view-1' }, }, ], }; @@ -281,7 +281,7 @@ describe('searchEmbeddableTransforms', () => { row_height: 3, query: { language: 'kuery', query: '' }, filters: [], - data_source: { type: AS_CODE_DATA_VIEW_REFERENCE_TYPE, id: 'data-view-id-123' }, + data_source: { type: AS_CODE_DATA_VIEW_REFERENCE_TYPE, ref_id: 'data-view-id-123' }, }, ], }; diff --git a/src/platform/plugins/shared/discover/common/embeddable/transform_utils.test.ts b/src/platform/plugins/shared/discover/common/embeddable/transform_utils.test.ts index 866d5dc4c52c7..8498e6bb4a69c 100644 --- a/src/platform/plugins/shared/discover/common/embeddable/transform_utils.test.ts +++ b/src/platform/plugins/shared/discover/common/embeddable/transform_utils.test.ts @@ -171,7 +171,7 @@ describe('search embeddable transform utils', () => { expect('tabs' in result && result.tabs).toBeDefined(); expect('tabs' in result && result.tabs?.[0]).toMatchObject({ - data_source: { type: AS_CODE_DATA_VIEW_REFERENCE_TYPE, id: dataViewId }, + data_source: { type: AS_CODE_DATA_VIEW_REFERENCE_TYPE, ref_id: dataViewId }, }); }); }); @@ -213,7 +213,7 @@ describe('search embeddable transform utils', () => { row_height: 'auto', query: { language: 'kuery', query: '' }, filters: [], - data_source: { type: AS_CODE_DATA_VIEW_REFERENCE_TYPE, id: 'data-view-1' }, + data_source: { type: AS_CODE_DATA_VIEW_REFERENCE_TYPE, ref_id: 'data-view-1' }, }, ], }; @@ -298,7 +298,7 @@ describe('search embeddable transform utils', () => { header_row_height: 3, data_source: { type: AS_CODE_DATA_VIEW_REFERENCE_TYPE, - id: 'c7d7a1f5-19da-4ba9-af15-5919e8cd2528', + ref_id: 'c7d7a1f5-19da-4ba9-af15-5919e8cd2528', }, }, ], @@ -474,7 +474,7 @@ describe('search embeddable transform utils', () => { filters: [], rows_per_page: 100, sample_size: 1000, - data_source: { type: AS_CODE_DATA_VIEW_REFERENCE_TYPE, id: 'data-view-1' }, + data_source: { type: AS_CODE_DATA_VIEW_REFERENCE_TYPE, ref_id: 'data-view-1' }, }, ], }; @@ -1000,7 +1000,7 @@ describe('search embeddable transform utils', () => { expect(result.density).toBe(DataGridDensity.COMPACT); expect('data_source' in result && result.data_source).toEqual({ type: AS_CODE_DATA_VIEW_REFERENCE_TYPE, - id: 'data-view-1', + ref_id: 'data-view-1', }); expect('view_mode' in result && result.view_mode).toBe(VIEW_MODE.DOCUMENT_LEVEL); }); @@ -1020,7 +1020,7 @@ describe('search embeddable transform utils', () => { filters: [], rows_per_page: 100, sample_size: 500, - data_source: { type: AS_CODE_DATA_VIEW_REFERENCE_TYPE, id: 'data-view-1' }, + data_source: { type: AS_CODE_DATA_VIEW_REFERENCE_TYPE, ref_id: 'data-view-1' }, }; const { state, references } = toStoredTab(apiTab); expect(references).toContainEqual({ diff --git a/src/platform/plugins/shared/discover/public/embeddable/utils/serialization_utils.test.ts b/src/platform/plugins/shared/discover/public/embeddable/utils/serialization_utils.test.ts index f8080324b6264..a86c56e3b262f 100644 --- a/src/platform/plugins/shared/discover/public/embeddable/utils/serialization_utils.test.ts +++ b/src/platform/plugins/shared/discover/public/embeddable/utils/serialization_utils.test.ts @@ -91,7 +91,7 @@ describe('Serialization utils', () => { filters: [], rows_per_page: 100, sample_size: 100, - data_source: { type: AS_CODE_DATA_VIEW_REFERENCE_TYPE, id: dataViewId }, + data_source: { type: AS_CODE_DATA_VIEW_REFERENCE_TYPE, ref_id: dataViewId }, }, ], }; @@ -345,7 +345,7 @@ describe('Serialization utils', () => { sort: [{ name: 'order_date', direction: 'desc' }], view_mode: VIEW_MODE.DOCUMENT_LEVEL, density: DataGridDensity.COMPACT, - data_source: { type: AS_CODE_DATA_VIEW_REFERENCE_TYPE, id: dataViewId }, + data_source: { type: AS_CODE_DATA_VIEW_REFERENCE_TYPE, ref_id: dataViewId }, }), ], });