Skip to content

Commit

Permalink
Index pattern save => Index pattern service (#76706)
Browse files Browse the repository at this point in the history
* Index pattern save => Index pattern service
  • Loading branch information
mattkime committed Sep 8, 2020
1 parent 8bc6898 commit 842bcf4
Show file tree
Hide file tree
Showing 25 changed files with 366 additions and 338 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ Constructs a new instance of the `IndexPattern` class
<b>Signature:</b>

```typescript
constructor(id: string | undefined, { savedObjectsClient, apiClient, patternCache, fieldFormats, onNotification, onError, shortDotsEnable, metaFields, }: IndexPatternDeps);
constructor(id: string | undefined, { savedObjectsClient, apiClient, patternCache, fieldFormats, indexPatternsService, onNotification, onError, shortDotsEnable, metaFields, }: IndexPatternDeps);
```

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| id | <code>string &#124; undefined</code> | |
| { savedObjectsClient, apiClient, patternCache, fieldFormats, onNotification, onError, shortDotsEnable, metaFields, } | <code>IndexPatternDeps</code> | |
| { savedObjectsClient, apiClient, patternCache, fieldFormats, indexPatternsService, onNotification, onError, shortDotsEnable, metaFields, } | <code>IndexPatternDeps</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, { savedObjectsClient, apiClient, patternCache, fieldFormats, onNotification, onError, shortDotsEnable, metaFields, })](./kibana-plugin-plugins-data-public.indexpattern._constructor_.md) | | Constructs a new instance of the <code>IndexPattern</code> class |
| [(constructor)(id, { savedObjectsClient, apiClient, patternCache, fieldFormats, indexPatternsService, onNotification, onError, shortDotsEnable, metaFields, })](./kibana-plugin-plugins-data-public.indexpattern._constructor_.md) | | Constructs a new instance of the <code>IndexPattern</code> class |
## Properties
Expand All @@ -29,11 +29,13 @@ export declare class IndexPattern implements IIndexPattern
| [id](./kibana-plugin-plugins-data-public.indexpattern.id.md) | | <code>string</code> | |
| [intervalName](./kibana-plugin-plugins-data-public.indexpattern.intervalname.md) | | <code>string &#124; undefined</code> | |
| [metaFields](./kibana-plugin-plugins-data-public.indexpattern.metafields.md) | | <code>string[]</code> | |
| [originalBody](./kibana-plugin-plugins-data-public.indexpattern.originalbody.md) | | <code>{</code><br/><code> [key: string]: any;</code><br/><code> }</code> | |
| [sourceFilters](./kibana-plugin-plugins-data-public.indexpattern.sourcefilters.md) | | <code>SourceFilter[]</code> | |
| [timeFieldName](./kibana-plugin-plugins-data-public.indexpattern.timefieldname.md) | | <code>string &#124; undefined</code> | |
| [title](./kibana-plugin-plugins-data-public.indexpattern.title.md) | | <code>string</code> | |
| [type](./kibana-plugin-plugins-data-public.indexpattern.type.md) | | <code>string &#124; undefined</code> | |
| [typeMeta](./kibana-plugin-plugins-data-public.indexpattern.typemeta.md) | | <code>TypeMeta</code> | |
| [version](./kibana-plugin-plugins-data-public.indexpattern.version.md) | | <code>string &#124; undefined</code> | |
## Methods
Expand All @@ -60,6 +62,5 @@ export declare class IndexPattern implements IIndexPattern
| [prepBody()](./kibana-plugin-plugins-data-public.indexpattern.prepbody.md) | | |
| [refreshFields()](./kibana-plugin-plugins-data-public.indexpattern.refreshfields.md) | | |
| [removeScriptedField(fieldName)](./kibana-plugin-plugins-data-public.indexpattern.removescriptedfield.md) | | |
| [save(saveAttempts)](./kibana-plugin-plugins-data-public.indexpattern.save.md) | | |
| [toSpec()](./kibana-plugin-plugins-data-public.indexpattern.tospec.md) | | |
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!-- 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; [IndexPattern](./kibana-plugin-plugins-data-public.indexpattern.md) &gt; [originalBody](./kibana-plugin-plugins-data-public.indexpattern.originalbody.md)

## IndexPattern.originalBody property

<b>Signature:</b>

```typescript
originalBody: {
[key: string]: any;
};
```
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<b>Signature:</b>

```typescript
removeScriptedField(fieldName: string): Promise<void | Error>;
removeScriptedField(fieldName: string): void;
```

## Parameters
Expand All @@ -18,5 +18,5 @@ removeScriptedField(fieldName: string): Promise<void | Error>;

<b>Returns:</b>

`Promise<void | Error>`
`void`

This file was deleted.

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; [IndexPattern](./kibana-plugin-plugins-data-public.indexpattern.md) &gt; [version](./kibana-plugin-plugins-data-public.indexpattern.version.md)

## IndexPattern.version property

<b>Signature:</b>

```typescript
version: string | undefined;
```
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
<b>Signature:</b>

```typescript
QueryStringInput: React.FC<Pick<Props, "query" | "prepend" | "size" | "placeholder" | "onChange" | "onBlur" | "onSubmit" | "indexPatterns" | "dataTestSubj" | "screenTitle" | "disableAutoFocus" | "persistedLog" | "bubbleSubmitEvent" | "languageSwitcherPopoverAnchorPosition" | "onChangeQueryInputFocus">>
QueryStringInput: React.FC<Pick<Props, "query" | "prepend" | "size" | "className" | "placeholder" | "onChange" | "onBlur" | "onSubmit" | "indexPatterns" | "dataTestSubj" | "screenTitle" | "disableAutoFocus" | "persistedLog" | "bubbleSubmitEvent" | "languageSwitcherPopoverAnchorPosition" | "onChangeQueryInputFocus">>
```
1 change: 1 addition & 0 deletions src/fixtures/stubbed_saved_object_index_pattern.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export function stubbedSavedObjectIndexPattern(id: string | null = null) {
timeFieldName: 'timestamp',
customFormats: '{}',
fields: mockLogstashFields,
title: 'title',
},
version: 2,
};
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import { defaults, map, last, get } from 'lodash';
import { defaults, map, last } from 'lodash';

import { IndexPattern } from './index_pattern';

Expand All @@ -29,7 +29,7 @@ import { stubbedSavedObjectIndexPattern } from '../../../../../fixtures/stubbed_
import { IndexPatternField } from '../fields';

import { fieldFormatsMock } from '../../field_formats/mocks';
import { FieldFormat } from '../..';
import { FieldFormat, IndexPatternsService } from '../..';

class MockFieldFormatter {}

Expand Down Expand Up @@ -116,6 +116,7 @@ function create(id: string, payload?: any): Promise<IndexPattern> {
apiClient,
patternCache,
fieldFormats: fieldFormatsMock,
indexPatternsService: {} as IndexPatternsService,
onNotification: () => {},
onError: () => {},
shortDotsEnable: false,
Expand Down Expand Up @@ -151,7 +152,6 @@ describe('IndexPattern', () => {
expect(indexPattern).toHaveProperty('getNonScriptedFields');
expect(indexPattern).toHaveProperty('addScriptedField');
expect(indexPattern).toHaveProperty('removeScriptedField');
expect(indexPattern).toHaveProperty('save');

// properties
expect(indexPattern).toHaveProperty('fields');
Expand Down Expand Up @@ -389,60 +389,4 @@ describe('IndexPattern', () => {
});
});
});

test('should handle version conflicts', async () => {
setDocsourcePayload(null, {
id: 'foo',
version: 'foo',
attributes: {
title: 'something',
},
});
// Create a normal index pattern
const pattern = new IndexPattern('foo', {
savedObjectsClient: savedObjectsClient as any,
apiClient,
patternCache,
fieldFormats: fieldFormatsMock,
onNotification: () => {},
onError: () => {},
shortDotsEnable: false,
metaFields: [],
});
await pattern.init();

expect(get(pattern, 'version')).toBe('fooa');

// Create the same one - we're going to handle concurrency
const samePattern = new IndexPattern('foo', {
savedObjectsClient: savedObjectsClient as any,
apiClient,
patternCache,
fieldFormats: fieldFormatsMock,
onNotification: () => {},
onError: () => {},
shortDotsEnable: false,
metaFields: [],
});
await samePattern.init();

expect(get(samePattern, 'version')).toBe('fooaa');

// This will conflict because samePattern did a save (from refreshFields)
// but the resave should work fine
pattern.title = 'foo2';
await pattern.save();

// This should not be able to recover
samePattern.title = 'foo3';

let result;
try {
await samePattern.save();
} catch (err) {
result = err;
}

expect(result.res.status).toBe(409);
});
});
Loading

0 comments on commit 842bcf4

Please sign in to comment.