Skip to content

Commit

Permalink
[7.x] Index pattern public api => common (#68289) (#68863)
Browse files Browse the repository at this point in the history
* Index pattern public api => common (#68289)
  • Loading branch information
mattkime authored Jun 11, 2020
1 parent 6c1f977 commit 5d55413
Show file tree
Hide file tree
Showing 68 changed files with 531 additions and 281 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) &gt; [expandShorthand](./kibana-plugin-plugins-data-public.expandshorthand.md)

## expandShorthand variable


<b>Signature:</b>

```typescript
expandShorthand: (sh: Record<string, ShorthandFieldMapObject>) => Record<string, FieldMappingSpec>
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) &gt; [FieldMappingSpec](./kibana-plugin-plugins-data-public.fieldmappingspec.md) &gt; [\_deserialize](./kibana-plugin-plugins-data-public.fieldmappingspec._deserialize.md)

## FieldMappingSpec.\_deserialize property

<b>Signature:</b>

```typescript
_deserialize?: (mapping: string) => any | undefined;
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) &gt; [FieldMappingSpec](./kibana-plugin-plugins-data-public.fieldmappingspec.md) &gt; [\_serialize](./kibana-plugin-plugins-data-public.fieldmappingspec._serialize.md)

## FieldMappingSpec.\_serialize property

<b>Signature:</b>

```typescript
_serialize?: (mapping: any) => string | undefined;
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) &gt; [FieldMappingSpec](./kibana-plugin-plugins-data-public.fieldmappingspec.md)

## FieldMappingSpec interface


<b>Signature:</b>

```typescript
export interface FieldMappingSpec
```

## Properties

| Property | Type | Description |
| --- | --- | --- |
| [\_deserialize](./kibana-plugin-plugins-data-public.fieldmappingspec._deserialize.md) | <code>(mapping: string) =&gt; any &#124; undefined</code> | |
| [\_serialize](./kibana-plugin-plugins-data-public.fieldmappingspec._serialize.md) | <code>(mapping: any) =&gt; string &#124; undefined</code> | |
| [type](./kibana-plugin-plugins-data-public.fieldmappingspec.type.md) | <code>ES_FIELD_TYPES</code> | |

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) &gt; [FieldMappingSpec](./kibana-plugin-plugins-data-public.fieldmappingspec.md) &gt; [type](./kibana-plugin-plugins-data-public.fieldmappingspec.type.md)

## FieldMappingSpec.type property

<b>Signature:</b>

```typescript
type: ES_FIELD_TYPES;
```
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
<b>Signature:</b>

```typescript
getIndexPatternFieldListCreator: ({ fieldFormats, toastNotifications, }: FieldListDependencies) => CreateIndexPatternFieldList
getIndexPatternFieldListCreator: ({ fieldFormats, onNotification, }: FieldListDependencies) => CreateIndexPatternFieldList
```
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Constructs a new instance of the `IndexPattern` class
<b>Signature:</b>

```typescript
constructor(id: string | undefined, getConfig: any, savedObjectsClient: SavedObjectsClientContract, apiClient: IIndexPatternsApiClient, patternCache: PatternCache);
constructor(id: string | undefined, getConfig: any, savedObjectsClient: SavedObjectsClientContract, apiClient: IIndexPatternsApiClient, patternCache: PatternCache, fieldFormats: FieldFormatsStartCommon, onNotification: OnNotification, onError: OnError, onUnsupportedTimePattern: OnUnsupportedTimePattern);
```

## Parameters
Expand All @@ -21,4 +21,8 @@ constructor(id: string | undefined, getConfig: any, savedObjectsClient: SavedObj
| savedObjectsClient | <code>SavedObjectsClientContract</code> | |
| apiClient | <code>IIndexPatternsApiClient</code> | |
| patternCache | <code>PatternCache</code> | |
| fieldFormats | <code>FieldFormatsStartCommon</code> | |
| onNotification | <code>OnNotification</code> | |
| onError | <code>OnError</code> | |
| onUnsupportedTimePattern | <code>OnUnsupportedTimePattern</code> | |

Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export declare class IndexPattern implements IIndexPattern
| Constructor | Modifiers | Description |
| --- | --- | --- |
| [(constructor)(id, getConfig, savedObjectsClient, apiClient, patternCache)](./kibana-plugin-plugins-data-public.indexpattern._constructor_.md) | | Constructs a new instance of the <code>IndexPattern</code> class |
| [(constructor)(id, getConfig, savedObjectsClient, apiClient, patternCache, fieldFormats, onNotification, onError, onUnsupportedTimePattern)](./kibana-plugin-plugins-data-public.indexpattern._constructor_.md) | | Constructs a new instance of the <code>IndexPattern</code> class |
## Properties
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ Constructs a new instance of the `Field` class
<b>Signature:</b>

```typescript
constructor(indexPattern: IndexPattern, spec: FieldSpec | Field, shortDotsEnable: boolean, { fieldFormats, toastNotifications }: FieldDependencies);
constructor(indexPattern: IIndexPattern, spec: FieldSpec | Field, shortDotsEnable: boolean, { fieldFormats, onNotification }: FieldDependencies);
```

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| indexPattern | <code>IndexPattern</code> | |
| indexPattern | <code>IIndexPattern</code> | |
| spec | <code>FieldSpec &#124; Field</code> | |
| shortDotsEnable | <code>boolean</code> | |
| { fieldFormats, toastNotifications } | <code>FieldDependencies</code> | |
| { fieldFormats, onNotification } | <code>FieldDependencies</code> | |

Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
<b>Signature:</b>

```typescript
indexPattern?: IndexPattern;
indexPattern?: IIndexPattern;
```
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export declare class Field implements IFieldType
| Constructor | Modifiers | Description |
| --- | --- | --- |
| [(constructor)(indexPattern, spec, shortDotsEnable, { fieldFormats, toastNotifications })](./kibana-plugin-plugins-data-public.indexpatternfield._constructor_.md) | | Constructs a new instance of the <code>Field</code> class |
| [(constructor)(indexPattern, spec, shortDotsEnable, { fieldFormats, onNotification })](./kibana-plugin-plugins-data-public.indexpatternfield._constructor_.md) | | Constructs a new instance of the <code>Field</code> class |
## Properties
Expand All @@ -28,7 +28,7 @@ export declare class Field implements IFieldType
| [esTypes](./kibana-plugin-plugins-data-public.indexpatternfield.estypes.md) | | <code>string[]</code> | |
| [filterable](./kibana-plugin-plugins-data-public.indexpatternfield.filterable.md) | | <code>boolean</code> | |
| [format](./kibana-plugin-plugins-data-public.indexpatternfield.format.md) | | <code>any</code> | |
| [indexPattern](./kibana-plugin-plugins-data-public.indexpatternfield.indexpattern.md) | | <code>IndexPattern</code> | |
| [indexPattern](./kibana-plugin-plugins-data-public.indexpatternfield.indexpattern.md) | | <code>IIndexPattern</code> | |
| [lang](./kibana-plugin-plugins-data-public.indexpatternfield.lang.md) | | <code>string</code> | |
| [name](./kibana-plugin-plugins-data-public.indexpatternfield.name.md) | | <code>string</code> | |
| [readFromDocValues](./kibana-plugin-plugins-data-public.indexpatternfield.readfromdocvalues.md) | | <code>boolean</code> | |
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) &gt; [MappingObject](./kibana-plugin-plugins-data-public.mappingobject.md)

## MappingObject type


<b>Signature:</b>

```typescript
export declare type MappingObject = Record<string, FieldMappingSpec>;
```
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
| [EsQueryConfig](./kibana-plugin-plugins-data-public.esqueryconfig.md) | |
| [FetchOptions](./kibana-plugin-plugins-data-public.fetchoptions.md) | |
| [FieldFormatConfig](./kibana-plugin-plugins-data-public.fieldformatconfig.md) | |
| [FieldMappingSpec](./kibana-plugin-plugins-data-public.fieldmappingspec.md) | |
| [Filter](./kibana-plugin-plugins-data-public.filter.md) | |
| [IDataPluginServices](./kibana-plugin-plugins-data-public.idatapluginservices.md) | |
| [IEsSearchRequest](./kibana-plugin-plugins-data-public.iessearchrequest.md) | |
Expand Down Expand Up @@ -101,6 +102,7 @@
| [esFilters](./kibana-plugin-plugins-data-public.esfilters.md) | |
| [esKuery](./kibana-plugin-plugins-data-public.eskuery.md) | |
| [esQuery](./kibana-plugin-plugins-data-public.esquery.md) | |
| [expandShorthand](./kibana-plugin-plugins-data-public.expandshorthand.md) | |
| [extractSearchSourceReferences](./kibana-plugin-plugins-data-public.extractsearchsourcereferences.md) | |
| [fieldFormats](./kibana-plugin-plugins-data-public.fieldformats.md) | |
| [FilterBar](./kibana-plugin-plugins-data-public.filterbar.md) | |
Expand Down Expand Up @@ -141,6 +143,7 @@
| [ISearch](./kibana-plugin-plugins-data-public.isearch.md) | |
| [ISearchGeneric](./kibana-plugin-plugins-data-public.isearchgeneric.md) | |
| [ISearchSource](./kibana-plugin-plugins-data-public.isearchsource.md) | \* |
| [MappingObject](./kibana-plugin-plugins-data-public.mappingobject.md) | |
| [MatchAllFilter](./kibana-plugin-plugins-data-public.matchallfilter.md) | |
| [ParsedInterval](./kibana-plugin-plugins-data-public.parsedinterval.md) | |
| [PhraseFilter](./kibana-plugin-plugins-data-public.phrasefilter.md) | |
Expand Down
1 change: 1 addition & 0 deletions src/plugins/data/common/field_formats/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,5 @@ export {
// Used in data plugin only
FieldFormatInstanceType,
IFieldFormat,
FieldFormatsStartCommon,
} from './types';
3 changes: 3 additions & 0 deletions src/plugins/data/common/field_formats/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
* under the License.
*/
import { FieldFormat } from './field_format';
import { FieldFormatsRegistry } from './field_formats_registry';

/** @public **/
export type FieldFormatsContentType = 'html' | 'text';
Expand Down Expand Up @@ -99,3 +100,5 @@ export interface IFieldFormatMetaParams {
basePath?: string;
};
}

export type FieldFormatsStartCommon = Omit<FieldFormatsRegistry, 'init' & 'register'>;
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

import { expandShorthand } from './mapping_setup';
import { ES_FIELD_TYPES } from '../../../data/public';
import { ES_FIELD_TYPES } from '../../../data/common';

describe('mapping_setup', () => {
it('allows shortcuts for field types by just setting the value to the type name', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import { ES_FIELD_TYPES } from '../../../data/public';
import { ES_FIELD_TYPES } from '../../../data/common';

/** @public */
export interface FieldMappingSpec {
Expand Down
1 change: 1 addition & 0 deletions src/plugins/data/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ export * from './search';
export * from './search/aggs';
export * from './types';
export * from './utils';
export * from './field_mapping';
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@
*/

import { Field } from './field';
import { IndexPattern } from '..';
import { notificationServiceMock } from '../../../../../core/public/mocks';
import { FieldFormatsStart } from '../../field_formats';
import { IndexPattern } from '../index_patterns';
import { FieldFormatsStartCommon } from '../..';
import { KBN_FIELD_TYPES } from '../../../common';

describe('Field', function () {
Expand All @@ -34,8 +33,8 @@ describe('Field', function () {
{ ...fieldValues, ...values },
false,
{
fieldFormats: {} as FieldFormatsStart,
toastNotifications: notificationServiceMock.createStartContract().toasts,
fieldFormats: {} as FieldFormatsStartCommon,
onNotification: () => {},
}
);
}
Expand Down Expand Up @@ -215,8 +214,8 @@ describe('Field', function () {

it('exports the property to JSON', () => {
const field = new Field({ fieldFormatMap: { name: {} } } as IndexPattern, fieldValues, false, {
fieldFormats: {} as FieldFormatsStart,
toastNotifications: notificationServiceMock.createStartContract().toasts,
fieldFormats: {} as FieldFormatsStartCommon,
onNotification: () => {},
});
expect(flatten(field)).toMatchSnapshot();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,24 @@
*/

import { i18n } from '@kbn/i18n';
import { ToastsStart } from 'kibana/public';
// @ts-ignore
import { ObjDefine } from './obj_define';
import { IndexPattern } from '../index_patterns';
import { IIndexPattern } from '../../types';
import {
IFieldType,
getKbnFieldType,
IFieldSubType,
FieldFormat,
shortenDottedString,
} from '../../../common';
import { FieldFormatsStart } from '../../field_formats';
import { OnNotification } from '../types';
import { FieldFormatsStartCommon } from '../../field_formats';

export type FieldSpec = Record<string, any>;

interface FieldDependencies {
fieldFormats: FieldFormatsStart;
toastNotifications: ToastsStart;
fieldFormats: FieldFormatsStartCommon;
onNotification: OnNotification;
}

export class Field implements IFieldType {
Expand All @@ -55,17 +55,17 @@ export class Field implements IFieldType {
scripted?: boolean;
subType?: IFieldSubType;
displayName?: string;
indexPattern?: IndexPattern;
indexPattern?: IIndexPattern;
readFromDocValues?: boolean;
format: any;
$$spec: FieldSpec;
conflictDescriptions?: Record<string, string[]>;

constructor(
indexPattern: IndexPattern,
indexPattern: IIndexPattern,
spec: FieldSpec | Field,
shortDotsEnable: boolean,
{ fieldFormats, toastNotifications }: FieldDependencies
{ fieldFormats, onNotification }: FieldDependencies
) {
// unwrap old instances of Field
if (spec instanceof Field) spec = spec.$$spec;
Expand All @@ -90,11 +90,7 @@ export class Field implements IFieldType {
values: { name: spec.name, title: indexPattern.title },
defaultMessage: 'Field {name} in indexPattern {title} is using an unknown field type.',
});

toastNotifications.addDanger({
title,
text,
});
onNotification({ title, text, color: 'danger', iconType: 'alert' });
}

if (!type) type = getKbnFieldType('unknown');
Expand All @@ -103,7 +99,7 @@ export class Field implements IFieldType {

if (!FieldFormat.isInstanceOfFieldFormat(format)) {
format =
indexPattern.fieldFormatMap[spec.name] ||
(indexPattern.fieldFormatMap && indexPattern.fieldFormatMap[spec.name]) ||
fieldFormats.getDefaultInstance(spec.type, spec.esTypes);
}

Expand Down
Loading

0 comments on commit 5d55413

Please sign in to comment.