Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Index pattern public api => common #68289

Merged
merged 33 commits into from
Jun 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
a2da8d3
partial progress
mattkime Jun 4, 2020
3a40208
front end code should be working again
mattkime Jun 5, 2020
cb9e775
restore unknown field toast
mattkime Jun 5, 2020
5de1b21
fix jest test mock
mattkime Jun 5, 2020
2683b7a
Revert "fix jest test mock"
mattkime Jun 5, 2020
2913835
fix jest test mock
mattkime Jun 5, 2020
5cfaee5
add onError callback, remove comments
mattkime Jun 5, 2020
f963496
Merge branch 'master' into index_pattern_server_api_2
mattkime Jun 5, 2020
ec2f0c6
better define fieldFormats common start service
mattkime Jun 5, 2020
ebc56d8
dependency cleanup
mattkime Jun 5, 2020
c994a1f
Revert "dependency cleanup"
mattkime Jun 5, 2020
f097b31
update api docs
mattkime Jun 6, 2020
6998499
remove commented lines
mattkime Jun 6, 2020
01e6e2f
typefix
mattkime Jun 6, 2020
f75873f
refactor core usage
mattkime Jun 6, 2020
49a06d7
Merge branch 'master' into index_pattern_server_api_2
elasticmachine Jun 8, 2020
ba4d131
Merge branch 'master' into index_pattern_server_api_2
mattkime Jun 8, 2020
30bf1e0
more specific dependencies
mattkime Jun 8, 2020
8e0f3b8
Merge branch 'master' into index_pattern_server_api_2
elasticmachine Jun 8, 2020
bce0d2e
Revert "more specific dependencies"
mattkime Jun 8, 2020
90a8695
more specific core usage
mattkime Jun 8, 2020
240371a
Merge branch 'index_pattern_server_api_2' of github.com:mattkime/kiba…
mattkime Jun 8, 2020
d8b1999
more specific core usage
mattkime Jun 9, 2020
6c30c28
move field_mapping code from kibana_utils to data
mattkime Jun 9, 2020
f96d3c3
fix jest test mock
mattkime Jun 9, 2020
5beadc0
Merge branch 'master' into index_pattern_server_api_2
elasticmachine Jun 9, 2020
7aeb8f2
remove fields index file, was only re-exporting from common
mattkime Jun 9, 2020
ace29ae
Merge branch 'index_pattern_server_api_2' of github.com:mattkime/kiba…
mattkime Jun 9, 2020
e3a16b3
remove index pattern lib dir which just re-exports from common
mattkime Jun 9, 2020
0b7f84f
remove re-export
mattkime Jun 10, 2020
885c8ce
remove re-export
mattkime Jun 10, 2020
03e849d
Revert "remove re-export"
mattkime Jun 10, 2020
985e90a
Revert "remove re-export"
mattkime Jun 10, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
```

## Parameters
Expand All @@ -21,4 +21,7 @@ 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> | |

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)](./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 @@ -53,6 +53,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 @@ -100,6 +101,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 @@ -140,6 +142,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' });
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what if we throw here and let the caller handle the exception. instead of passing onNotification in they can wrap code in try/cache

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is good idea but I'd prefer to address it in another ticket as this PR aims to be a minimal set of changes required to provide a common api. I think I'd need to examine all places where index patterns are used to ensure errors are being caught. I've added a ticket to #67920

}

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