Skip to content

Commit

Permalink
Merge branch 'add-get-delete-api' into add-stable-id-option
Browse files Browse the repository at this point in the history
  • Loading branch information
FrankHassanabad committed Oct 14, 2019
2 parents 93e888e + a5eaab1 commit 688da79
Show file tree
Hide file tree
Showing 302 changed files with 7,403 additions and 12,530 deletions.
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
# Platform
/src/core/ @elastic/kibana-platform
/src/legacy/server/saved_objects/ @elastic/kibana-platform
/src/legacy/ui/public/saved_objects @elastic/kibana-platform
/config/kibana.yml @elastic/kibana-platform
/x-pack/plugins/features/ @elastic/kibana-platform

Expand All @@ -56,6 +55,7 @@
/x-pack/legacy/plugins/encrypted_saved_objects/ @elastic/kibana-security
/src/legacy/server/csp/ @elastic/kibana-security
/x-pack/plugins/security/ @elastic/kibana-security
/x-pack/test/api_integration/apis/security/ @elastic/kibana-security

# Kibana Stack Services
/packages/kbn-analytics/ @elastic/kibana-stack-services
Expand Down
10 changes: 10 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,8 @@ IntelliJ | Settings » Languages & Frameworks » JavaScript » Code Quality To

Another tool we use for enforcing consistent coding style is EditorConfig, which can be set up by installing a plugin in your editor that dynamically updates its configuration. Take a look at the [EditorConfig](http://editorconfig.org/#download) site to find a plugin for your editor, and browse our [`.editorconfig`](https://github.com/elastic/kibana/blob/master/.editorconfig) file to see what config rules we set up.

#### Setup Guide for VS Code Users

Note that for VSCode, to enable "live" linting of TypeScript (and other) file types, you will need to modify your local settings, as shown below. The default for the ESLint extension is to only lint JavaScript file types.

```json
Expand All @@ -317,6 +319,14 @@ Note that for VSCode, to enable "live" linting of TypeScript (and other) file ty
]
```

`eslint` can automatically fix trivial lint errors when you save a file by adding this line in your setting.

```json
"eslint.autoFixOnSave": true,
```

It is **not** recommended to use `prettier` plugin on Kibana project. Because settings are in `eslintrc.js` file and it is applied to too many files that shouldn't be prettier-ized.

### Internationalization

All user-facing labels and info texts in Kibana should be internationalized. Please take a look at the [readme](packages/kbn-i18n/README.md) and the [guideline](packages/kbn-i18n/GUIDELINE.md) of the i18n package on how to do so.
Expand Down
2 changes: 1 addition & 1 deletion docs/management/dashboard_only_mode/index.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
[[xpack-dashboard-only-mode]]
== Dashboard-only mode

deprecated[7.4.0, Using the `kibana_dashboard_only_user` role is deprecated. Use <<kibana-feature-privileges,feature privileges>> instead.]
deprecated[7.4.0, "Using the `kibana_dashboard_only_user` role is deprecated. Use <<kibana-feature-privileges,feature privileges>> instead."]

In dashboard-only mode, users have access to only the *Dashboard* app.
Users can view and filter the dashboards, but cannot create, edit, or delete
Expand Down
6 changes: 6 additions & 0 deletions docs/settings/code-settings.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ Whitelist of protocols for git clone address. Defaults to `[ 'https', 'git', 'ss
`xpack.code.security.enableGitCertCheck`::
Whether enable HTTPS certificate check when clone from HTTPS URL.

`xpack.code.security.enableJavaSecurityManager`::
Whether enable Java security manager for Java langserver. Defaults to `true`.

`xpack.code.security.extraJavaRepositoryWhitelist`::
Whitelist of extra repository to download dependencies for Java language. Defaults to `[]`.

`xpack.code.maxWorkspace`::
Maximal number of workspaces each language server allows to span. Defaults to `5`.

Expand Down
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@
"@babel/register": "^7.5.5",
"@elastic/charts": "^13.5.1",
"@elastic/datemath": "5.0.2",
"@elastic/ems-client": "^1.0.2",
"@elastic/eui": "14.4.0",
"@elastic/filesaver": "1.1.2",
"@elastic/good": "8.1.1-kibana2",
Expand Down Expand Up @@ -171,7 +172,7 @@
"hapi": "^17.5.3",
"hapi-auth-cookie": "^9.0.0",
"history": "^4.9.0",
"hjson": "3.1.2",
"hjson": "3.2.0",
"hoek": "^5.0.4",
"http-proxy-agent": "^2.1.0",
"https-proxy-agent": "^2.2.2",
Expand Down Expand Up @@ -358,7 +359,7 @@
"babel-jest": "^24.9.0",
"babel-plugin-dynamic-import-node": "^2.3.0",
"babel-plugin-istanbul": "^5.2.0",
"backport": "4.7.1",
"backport": "4.7.3",
"chai": "3.5.0",
"chance": "1.0.18",
"cheerio": "0.22.0",
Expand Down Expand Up @@ -446,7 +447,7 @@
"strip-ansi": "^3.0.1",
"supertest": "^3.1.0",
"supertest-as-promised": "^4.0.2",
"tree-kill": "^1.1.0",
"tree-kill": "^1.2.1",
"typescript": "3.5.3",
"typings-tester": "^0.3.2",
"vinyl-fs": "^3.0.3",
Expand Down
32 changes: 20 additions & 12 deletions packages/kbn-babel-preset/common_preset.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,28 @@
* under the License.
*/

const plugins = [
require.resolve('babel-plugin-add-module-exports'),

// The class properties proposal was merged with the private fields proposal
// into the "class fields" proposal. Babel doesn't support this combined
// proposal yet, which includes private field, so this transform is
// TECHNICALLY stage 2, but for all intents and purposes it's stage 3
//
// See https://github.com/babel/proposals/issues/12 for progress
require.resolve('@babel/plugin-proposal-class-properties'),
];

module.exports = {
presets: [require.resolve('@babel/preset-typescript'), require.resolve('@babel/preset-react')],
plugins: [
require.resolve('@kbn/elastic-idx/babel'),
require.resolve('babel-plugin-add-module-exports'),

// The class properties proposal was merged with the private fields proposal
// into the "class fields" proposal. Babel doesn't support this combined
// proposal yet, which includes private field, so this transform is
// TECHNICALLY stage 2, but for all intents and purposes it's stage 3
//
// See https://github.com/babel/proposals/issues/12 for progress
require.resolve('@babel/plugin-proposal-class-properties'),
],
plugins: plugins.concat(require.resolve('@kbn/elastic-idx/babel')),
// Do not use the idx plugin in the test environment because it causes
// causes conflicts with Jest's coverage mapping.
env: {
test: {
plugins,
},
},
overrides: [
{
// Babel 7 don't support the namespace feature on typescript code.
Expand Down
2 changes: 1 addition & 1 deletion packages/kbn-dev-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"getopts": "^2.2.5",
"moment": "^2.20.1",
"rxjs": "^6.2.1",
"tree-kill": "^1.2.0",
"tree-kill": "^1.2.1",
"tslib": "^1.9.3"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/kbn-dev-utils/src/proc_runner/proc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import chalk from 'chalk';

import treeKill from 'tree-kill';
import { promisify } from 'util';
const treeKillAsync = promisify(treeKill);
const treeKillAsync = promisify((...args: [number, string, any]) => treeKill(...args));

import { ToolingLog } from '../tooling_log';
import { observeLines } from './observe_lines';
Expand Down
2 changes: 1 addition & 1 deletion packages/kbn-es/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"node-fetch": "^2.6.0",
"simple-git": "^1.91.0",
"tar-fs": "^1.16.3",
"tree-kill": "^1.1.0",
"tree-kill": "^1.2.1",
"yauzl": "^2.10.0"
}
}
8 changes: 4 additions & 4 deletions src/fixtures/fake_row.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
* under the License.
*/

import _ from 'lodash';
const longString = Array(200).join('_');

export function getFakeRowVals(type, id, mapping) {
return _.mapValues(mapping, function (f, c) {
return c + '_' + type + '_' + id + longString;
});
return mapping.reduce((collector, field) => {
collector[field.name] = `${field.name}_${type}_${id}_${longString}`;
return collector;
}, {});
}

export function getFakeRow(id, mapping) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import { Filter, RangeFilter, FILTERS, isRangeFilter, isScriptedRangeFilter } from '@kbn/es-query';
import { get, has } from 'lodash';
import { SavedObjectNotFound } from '../../../../../../../plugins/kibana_utils/public';
import { IndexPatterns, IndexPattern } from '../../../index_patterns';
import { IndexPatterns, IndexPattern, Field } from '../../../index_patterns';

const getFirstRangeKey = (filter: RangeFilter) => filter.range && Object.keys(filter.range)[0];
const getRangeByKey = (filter: RangeFilter, key: string) => get(filter, ['range', key]);
Expand All @@ -44,9 +44,8 @@ function getParams(filter: RangeFilter, indexPattern?: IndexPattern) {
// for example a user might manually edit the url or the index pattern's ID might change due to
// external factors e.g. a reindex. We only need the index in order to grab the field formatter, so we fallback
// on displaying the raw value if the index is invalid.
if (key && indexPattern && indexPattern.fields.byName[key]) {
const convert = indexPattern.fields.byName[key].format.getConverterFor('text');

if (key && indexPattern && indexPattern.fields.getByName(key)) {
const convert = (indexPattern.fields.getByName(key) as Field).format.getConverterFor('text');
value = `${convert(left)} to ${convert(right)}`;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export class StubIndexPatterns {
async get(index: string) {
return {
fields: {
byName: {},
getByName: () => undefined,
},
};
}
Expand Down
1 change: 1 addition & 0 deletions src/legacy/core_plugins/data/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export { FilterBar, ApplyFiltersPopover } from './filter';
export {
Field,
FieldType,
FieldListInterface,
IndexPattern,
IndexPatterns,
StaticIndexPattern,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,69 @@
* under the License.
*/

import { IndexedArray } from 'ui/indexed_array';
import { NotificationsSetup } from 'kibana/public';
import { findIndex } from 'lodash';
import { IndexPattern } from '../index_patterns';
import { Field, FieldSpec } from './field';
import { Field, FieldType, FieldSpec } from './field';

export class FieldList extends IndexedArray<Field> {
type FieldMap = Map<Field['name'], Field>;

export interface FieldListInterface extends Array<Field> {
getByName(name: Field['name']): Field | undefined;
getByType(type: Field['type']): Field[];
add(field: FieldSpec): void;
remove(field: FieldType): void;
}

export class FieldList extends Array<Field> implements FieldListInterface {
private byName: FieldMap = new Map();
private groups: Map<Field['type'], FieldMap> = new Map();
private indexPattern: IndexPattern;
private shortDotsEnable: boolean;
private notifications: NotificationsSetup;
private setByName = (field: Field) => this.byName.set(field.name, field);
private setByGroup = (field: Field) => {
if (typeof this.groups.get(field.type) === 'undefined') {
this.groups.set(field.type, new Map());
}
this.groups.get(field.type)!.set(field.name, field);
};
private removeByGroup = (field: FieldType) => this.groups.get(field.type)!.delete(field.name);
constructor(
indexPattern: IndexPattern,
specs: FieldSpec[],
specs: FieldSpec[] = [],
shortDotsEnable = false,
notifications: NotificationsSetup
) {
super({
index: ['name'],
group: ['type'],
initialSet: specs.map(function(field) {
return new Field(indexPattern, field, shortDotsEnable, notifications);
}),
});
super();
this.indexPattern = indexPattern;
this.shortDotsEnable = shortDotsEnable;
this.notifications = notifications;
specs.map(field => this.add(field));
}

getByName = (name: Field['name']) => this.byName.get(name);
getByType = (type: Field['type']) => [...(this.groups.get(type) || new Map()).values()];
add = (field: FieldSpec) => {
const newField = new Field(this.indexPattern, field, this.shortDotsEnable, this.notifications);
this.push(newField);
this.setByName(newField);
this.setByGroup(newField);
};

remove = (field: FieldType) => {
this.removeByGroup(field);
this.byName.delete(field.name);

const fieldIndex = findIndex(this, { name: field.name });
this.splice(fieldIndex, 1);
};

update = (field: Field) => {
const index = this.findIndex(f => f.name === field.name);
this.splice(index, 1, field);
this.setByName(field);
this.removeByGroup(field);
this.setByGroup(field);
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,15 @@ function flattenHit(indexPattern: IndexPattern, hit: Record<string, any>, deep:
const flat = {} as Record<string, any>;

// recursively merge _source
const fields = indexPattern.fields.byName;
const fields = indexPattern.fields.getByName;
(function flatten(obj, keyPrefix = '') {
keyPrefix = keyPrefix ? keyPrefix + '.' : '';
_.forOwn(obj, function(val, key) {
key = keyPrefix + key;

if (deep) {
const isNestedField = fields[key] && fields[key].type === 'nested';
const field = fields(key);
const isNestedField = field && field.type === 'nested';
const isArrayOfObjects = Array.isArray(val) && _.isPlainObject(_.first(val));
if (isArrayOfObjects && !isNestedField) {
_.each(val, v => flatten(v, key));
Expand All @@ -44,7 +45,8 @@ function flattenHit(indexPattern: IndexPattern, hit: Record<string, any>, deep:
return;
}

const hasValidMapping = fields[key] && fields[key].type !== 'conflict';
const field = fields(key);
const hasValidMapping = field && field.type !== 'conflict';
const isValue = !_.isPlainObject(val);

if (hasValidMapping || isValue) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const partialFormattedCache = new WeakMap();
// returns a formatted version
export function formatHitProvider(indexPattern: IndexPattern, defaultFormat: any) {
function convert(hit: Record<string, any>, val: any, fieldName: string, type: string = 'html') {
const field = indexPattern.fields.byName[fieldName];
const field = indexPattern.fields.getByName(fieldName);
if (!field) return defaultFormat.convert(val, type);
const parsedUrl = {
origin: window.location.origin,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
*/

import { defaults, pluck, last, get } from 'lodash';
import { IndexedArray } from 'ui/indexed_array';
import { IndexPattern } from './index_pattern';

import { DuplicateField } from '../../../../../../plugins/kibana_utils/public';
Expand Down Expand Up @@ -170,7 +169,6 @@ describe('IndexPattern', () => {
test('should append the found fields', () => {
expect(savedObjectsClient.get).toHaveBeenCalled();
expect(indexPattern.fields).toHaveLength(mockLogStashFields().length);
expect(indexPattern.fields).toBeInstanceOf(IndexedArray);
});
});

Expand Down Expand Up @@ -295,7 +293,9 @@ describe('IndexPattern', () => {
const scriptedFields = indexPattern.getScriptedFields();
// expect(saveSpy.callCount).to.equal(1);
expect(scriptedFields).toHaveLength(oldCount + 1);
expect(indexPattern.fields.byName[scriptedField.name].name).toEqual(scriptedField.name);
expect((indexPattern.fields.getByName(scriptedField.name) as Field).name).toEqual(
scriptedField.name
);
});

test('should remove scripted field, by name', async () => {
Expand All @@ -304,11 +304,11 @@ describe('IndexPattern', () => {
const oldCount = scriptedFields.length;
const scriptedField = last(scriptedFields);

await indexPattern.removeScriptedField(scriptedField.name);
await indexPattern.removeScriptedField(scriptedField);

// expect(saveSpy.callCount).to.equal(1);
expect(indexPattern.getScriptedFields().length).toEqual(oldCount - 1);
expect(indexPattern.fields.byName[scriptedField.name]).toEqual(undefined);
expect(indexPattern.fields.getByName(scriptedField.name)).toEqual(undefined);
});

test('should not allow duplicate names', async () => {
Expand Down
Loading

0 comments on commit 688da79

Please sign in to comment.