Skip to content

Commit

Permalink
Merge branch 'master' of github.com:elastic/kibana into implement/plu…
Browse files Browse the repository at this point in the history
…gin-helpers-kp-support
  • Loading branch information
spalger committed Aug 27, 2020
2 parents b3db5f9 + 12f4f6d commit eefa5b1
Show file tree
Hide file tree
Showing 19 changed files with 183 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Constructs a new instance of the `FieldList` class
<b>Signature:</b>

```typescript
constructor(indexPattern: IndexPattern, specs?: FieldSpec[], shortDotsEnable?: boolean, onNotification?: () => void);
constructor(indexPattern: IndexPattern, specs?: FieldSpec[], shortDotsEnable?: boolean, onNotification?: OnNotification);
```

## Parameters
Expand All @@ -19,5 +19,5 @@ constructor(indexPattern: IndexPattern, specs?: FieldSpec[], shortDotsEnable?: b
| indexPattern | <code>IndexPattern</code> | |
| specs | <code>FieldSpec[]</code> | |
| shortDotsEnable | <code>boolean</code> | |
| onNotification | <code>() =&gt; void</code> | |
| onNotification | <code>OnNotification</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; [IndexPattern](./kibana-plugin-plugins-data-public.indexpattern.md) &gt; [intervalName](./kibana-plugin-plugins-data-public.indexpattern.intervalname.md)

## IndexPattern.intervalName property

<b>Signature:</b>

```typescript
intervalName: string | undefined;
```
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,12 @@ export declare class IndexPattern implements IIndexPattern
| [formatField](./kibana-plugin-plugins-data-public.indexpattern.formatfield.md) | | <code>any</code> | |
| [formatHit](./kibana-plugin-plugins-data-public.indexpattern.formathit.md) | | <code>any</code> | |
| [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> | |
| [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> | |
## Methods
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,26 @@

```typescript
prepBody(): {
[key: string]: any;
title: string;
timeFieldName: string | undefined;
intervalName: string | undefined;
sourceFilters: string | undefined;
fields: string | undefined;
fieldFormatMap: string | undefined;
type: string | undefined;
typeMeta: string | undefined;
};
```
<b>Returns:</b>

`{
[key: string]: any;
title: string;
timeFieldName: string | undefined;
intervalName: string | undefined;
sourceFilters: string | undefined;
fields: string | undefined;
fieldFormatMap: string | undefined;
type: string | undefined;
typeMeta: string | 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; [IndexPattern](./kibana-plugin-plugins-data-public.indexpattern.md) &gt; [sourceFilters](./kibana-plugin-plugins-data-public.indexpattern.sourcefilters.md)

## IndexPattern.sourceFilters property

<b>Signature:</b>

```typescript
sourceFilters?: SourceFilter[];
```
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; [type](./kibana-plugin-plugins-data-public.indexpattern.type.md)

## IndexPattern.type property

<b>Signature:</b>

```typescript
type: string | undefined;
```
2 changes: 1 addition & 1 deletion docs/setup/settings.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,7 @@ The `server.xsrf.whitelist` setting requires the following format:
[cols="2*<"]
|===

| [[settings-xsrf-disableProtection]] `status.xsrf.disableProtection:`
| [[settings-xsrf-disableProtection]] `server.xsrf.disableProtection:`
| Setting this to `true` will completely disable Cross-site request forgery protection in Kibana. This is not recommended. *Default: `false`*

| `status.allowAnonymous:`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export class FieldList extends Array<IndexPatternField> implements IIndexPattern
indexPattern: IndexPattern,
specs: FieldSpec[] = [],
shortDotsEnable = false,
onNotification = () => {}
onNotification: OnNotification = () => {}
) {
super();
this.indexPattern = indexPattern;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,21 @@ jest.mock('../../field_mapping', () => {
id: true,
title: true,
fieldFormatMap: {
_serialize: jest.fn().mockImplementation(() => {}),
_deserialize: jest.fn().mockImplementation(() => []),
},
fields: {
_serialize: jest.fn().mockImplementation(() => {}),
_deserialize: jest.fn().mockImplementation((fields) => fields),
},
sourceFilters: {
_serialize: jest.fn().mockImplementation(() => {}),
_deserialize: jest.fn().mockImplementation(() => undefined),
},
typeMeta: {
_serialize: jest.fn().mockImplementation(() => {}),
_deserialize: jest.fn().mockImplementation(() => undefined),
},
})),
};
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,14 @@ interface IndexPatternDeps {
}

export class IndexPattern implements IIndexPattern {
[key: string]: any;

public id?: string;
public title: string = '';
public fieldFormatMap: any;
public typeMeta?: TypeMeta;
public fields: IIndexPatternFieldList & { toSpec: () => FieldSpec[] };
public timeFieldName: string | undefined;
public intervalName: string | undefined;
public type: string | undefined;
public formatHit: any;
public formatField: any;
public flattenHit: any;
Expand All @@ -72,7 +72,7 @@ export class IndexPattern implements IIndexPattern {
private version: string | undefined;
private savedObjectsClient: SavedObjectsClientCommon;
private patternCache: PatternCache;
private sourceFilters?: SourceFilter[];
public sourceFilters?: SourceFilter[];
private originalBody: { [key: string]: any } = {};
public fieldsFetcher: any; // probably want to factor out any direct usage and change to private
private shortDotsEnable: boolean = false;
Expand Down Expand Up @@ -126,7 +126,7 @@ export class IndexPattern implements IIndexPattern {
this.shortDotsEnable = shortDotsEnable;
this.metaFields = metaFields;

this.fields = new FieldList(this, [], this.shortDotsEnable, this.onUnknownType);
this.fields = new FieldList(this, [], this.shortDotsEnable, this.onNotification);

this.apiClient = apiClient;
this.fieldsFetcher = createFieldsFetcher(this, apiClient, metaFields);
Expand Down Expand Up @@ -226,10 +226,13 @@ export class IndexPattern implements IIndexPattern {
response[name] = fieldMapping._deserialize(response[name]);
});

// give index pattern all of the values
const fieldList = this.fields;
_.assign(this, response);
this.fields = fieldList;
this.title = response.title;
this.timeFieldName = response.timeFieldName;
this.intervalName = response.intervalName;
this.sourceFilters = response.sourceFilters;
this.fieldFormatMap = response.fieldFormatMap;
this.type = response.type;
this.typeMeta = response.typeMeta;

if (!this.title && this.id) {
this.title = this.id;
Expand Down Expand Up @@ -430,18 +433,16 @@ export class IndexPattern implements IIndexPattern {
}

prepBody() {
const body: { [key: string]: any } = {};

// serialize json fields
_.forOwn(this.mapping, (fieldMapping, fieldName) => {
if (!fieldName || this[fieldName] == null) return;

body[fieldName] = fieldMapping._serialize
? fieldMapping._serialize(this[fieldName])
: this[fieldName];
});

return body;
return {
title: this.title,
timeFieldName: this.timeFieldName,
intervalName: this.intervalName,
sourceFilters: this.mapping.sourceFilters._serialize!(this.sourceFilters),
fields: this.mapping.fields._serialize!(this.fields),
fieldFormatMap: this.mapping.fieldFormatMap._serialize!(this.fieldFormatMap),
type: this.type,
typeMeta: this.mapping.typeMeta._serialize!(this.mapping),
};
}

getFormatterForField(field: IndexPatternField | IndexPatternField['spec']): FieldFormat {
Expand Down Expand Up @@ -485,10 +486,14 @@ export class IndexPattern implements IIndexPattern {
async save(saveAttempts: number = 0): Promise<void | Error> {
if (!this.id) return;
const body = this.prepBody();
// What keys changed since they last pulled the index pattern
const originalChangedKeys = Object.keys(body).filter(
(key) => body[key] !== this.originalBody[key]
);

const originalChangedKeys: string[] = [];
Object.entries(body).forEach(([key, value]) => {
if (value !== this.originalBody[key]) {
originalChangedKeys.push(key);
}
});

return this.savedObjectsClient
.update(savedObjectType, this.id, body, { version: this.version })
.then((resp) => {
Expand Down Expand Up @@ -519,8 +524,12 @@ export class IndexPattern implements IIndexPattern {
// and ensure we ignore the key if the server response
// is the same as the original response (since that is expected
// if we made a change in that key)
const serverChangedKeys = Object.keys(updatedBody).filter((key) => {
return updatedBody[key] !== body[key] && this.originalBody[key] !== updatedBody[key];

const serverChangedKeys: string[] = [];
Object.entries(updatedBody).forEach(([key, value]) => {
if (value !== (body as any)[key] && value !== this.originalBody[key]) {
serverChangedKeys.push(key);
}
});

let unresolvedCollision = false;
Expand All @@ -545,7 +554,7 @@ export class IndexPattern implements IIndexPattern {

// Set the updated response on this object
serverChangedKeys.forEach((key) => {
this[key] = samePattern[key];
(this as any)[key] = (samePattern as any)[key];
});
this.version = samePattern.version;

Expand Down
23 changes: 18 additions & 5 deletions src/plugins/data/public/public.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,8 @@ export type FieldFormatsGetConfigFn = GetConfigFn;
// @public (undocumented)
export class FieldList extends Array<IndexPatternField> implements IIndexPatternFieldList {
// Warning: (ae-forgotten-export) The symbol "FieldSpec" needs to be exported by the entry point index.d.ts
constructor(indexPattern: IndexPattern, specs?: FieldSpec[], shortDotsEnable?: boolean, onNotification?: () => void);
// Warning: (ae-forgotten-export) The symbol "OnNotification" needs to be exported by the entry point index.d.ts
constructor(indexPattern: IndexPattern, specs?: FieldSpec[], shortDotsEnable?: boolean, onNotification?: OnNotification);
// (undocumented)
readonly add: (field: FieldSpec) => void;
// (undocumented)
Expand Down Expand Up @@ -946,8 +947,6 @@ export class IndexPattern implements IIndexPattern {
// Warning: (ae-forgotten-export) The symbol "IndexPatternDeps" needs to be exported by the entry point index.d.ts
constructor(id: string | undefined, { savedObjectsClient, apiClient, patternCache, fieldFormats, onNotification, onError, shortDotsEnable, metaFields, }: IndexPatternDeps);
// (undocumented)
[key: string]: any;
// (undocumented)
addScriptedField(name: string, script: string, fieldType: string | undefined, lang: string): Promise<void>;
// (undocumented)
create(allowOverride?: boolean): Promise<string | false>;
Expand Down Expand Up @@ -1008,6 +1007,8 @@ export class IndexPattern implements IIndexPattern {
// (undocumented)
initFromSpec(spec: IndexPatternSpec): this;
// (undocumented)
intervalName: string | undefined;
// (undocumented)
isTimeBased(): boolean;
// (undocumented)
isTimeBasedWildcard(): boolean;
Expand All @@ -1021,14 +1022,25 @@ export class IndexPattern implements IIndexPattern {
popularizeField(fieldName: string, unit?: number): Promise<void>;
// (undocumented)
prepBody(): {
[key: string]: any;
title: string;
timeFieldName: string | undefined;
intervalName: string | undefined;
sourceFilters: string | undefined;
fields: string | undefined;
fieldFormatMap: string | undefined;
type: string | undefined;
typeMeta: string | undefined;
};
// (undocumented)
refreshFields(): Promise<void | Error | never[] | undefined>;
// (undocumented)
removeScriptedField(fieldName: string): Promise<void | Error>;
// (undocumented)
save(saveAttempts?: number): Promise<void | Error>;
// Warning: (ae-forgotten-export) The symbol "SourceFilter" needs to be exported by the entry point index.d.ts
//
// (undocumented)
sourceFilters?: SourceFilter[];
// (undocumented)
timeFieldName: string | undefined;
// (undocumented)
Expand All @@ -1040,6 +1052,8 @@ export class IndexPattern implements IIndexPattern {
// (undocumented)
toString(): string;
// (undocumented)
type: string | undefined;
// (undocumented)
typeMeta?: IndexPatternTypeMeta;
}

Expand Down Expand Up @@ -1081,7 +1095,6 @@ export interface IndexPatternAttributes {
//
// @public (undocumented)
export class IndexPatternField implements IFieldType {
// Warning: (ae-forgotten-export) The symbol "OnNotification" needs to be exported by the entry point index.d.ts
constructor(indexPattern: IndexPattern, spec: FieldSpec, displayName: string, onNotification: OnNotification);
// (undocumented)
get aggregatable(): boolean;
Expand Down
21 changes: 20 additions & 1 deletion x-pack/plugins/maps/public/routing/maps_router.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,14 @@
import React from 'react';
import { render, unmountComponentAtNode } from 'react-dom';
import { Router, Switch, Route, Redirect } from 'react-router-dom';
import { getCoreI18n, getToasts, getEmbeddableService } from '../kibana_services';
import { i18n } from '@kbn/i18n';
import {
getCoreChrome,
getCoreI18n,
getMapsCapabilities,
getToasts,
getEmbeddableService,
} from '../kibana_services';
import {
createKbnUrlStateStorage,
withNotifyOnErrors,
Expand Down Expand Up @@ -44,6 +51,18 @@ const App = ({ history, appBasePath, onAppLeave }) => {
const { originatingApp } =
stateTransfer?.getIncomingEditorState({ keysToRemoveAfterFetch: ['originatingApp'] }) || {};

if (!getMapsCapabilities().save) {
getCoreChrome().setBadge({
text: i18n.translate('xpack.maps.badge.readOnly.text', {
defaultMessage: 'Read only',
}),
tooltip: i18n.translate('xpack.maps.badge.readOnly.tooltip', {
defaultMessage: 'Unable to save maps',
}),
iconType: 'glasses',
});
}

return (
<I18nContext>
<Provider store={store}>
Expand Down
6 changes: 6 additions & 0 deletions x-pack/test/functional/apps/maps/add_layer_panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,23 @@ import expect from '@kbn/expect';
export default function ({ getService, getPageObjects }) {
const testSubjects = getService('testSubjects');
const PageObjects = getPageObjects(['maps']);
const security = getService('security');

describe('Add layer panel', () => {
const LAYER_NAME = 'World Countries';

before(async () => {
await security.testUser.setRoles(['global_maps_all']);
await PageObjects.maps.openNewMap();
await PageObjects.maps.clickAddLayer();
await PageObjects.maps.selectEMSBoundariesSource();
await PageObjects.maps.selectVectorLayer(LAYER_NAME);
});

after(async () => {
await security.testUser.restoreDefaults();
});

it('should show unsaved layer in layer TOC', async () => {
const vectorLayerExists = await PageObjects.maps.doesLayerExist(LAYER_NAME);
expect(vectorLayerExists).to.be(true);
Expand Down
Loading

0 comments on commit eefa5b1

Please sign in to comment.