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 save => Index pattern service #76706

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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">>
Copy link
Contributor

Choose a reason for hiding this comment

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

do you have the same problem with latest master? #76890

Copy link
Contributor

@mshustov mshustov Sep 8, 2020

Choose a reason for hiding this comment

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

note that this type in the current form doesn't provide a lot of value and it's better to declare it explicitly microsoft/rushstack#1958 (comment) instead of relying on an inferred type

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I changed export const QueryStringInput = withKibana(QueryStringInputUI); to export const QueryStringInput = withKibana<Props>(QueryStringInputUI); with no change in the resulting docs.

Copy link
Contributor

@mshustov mshustov Sep 9, 2020

Choose a reason for hiding this comment

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

Right, because withKibana is inferring the result type with Omit.
Before:

const QueryStringInput: React.FC<Pick<Pick<Props, "query" | "prepend" ....>

After:

const QueryStringInput: React.FC<Pick<Props, "query" | "prepend" ....>

The main point that the generated document doesn't provide any useful information about the inferred interface. It's hard to say what is a type of query property, for example.
For comparison: the output with an explicit QueryStringInputProps interface #77054

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, right right.

```
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