Skip to content

Commit

Permalink
Merge branch 'master' into bump-chromedriver-up-to-80
Browse files Browse the repository at this point in the history
  • Loading branch information
elasticmachine authored Feb 14, 2020
2 parents a130858 + 918c0de commit 2b2d37a
Show file tree
Hide file tree
Showing 184 changed files with 3,362 additions and 2,683 deletions.
5 changes: 5 additions & 0 deletions docs/developer/plugin/development-plugin-resources.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,8 @@ To enable TypeScript support, create a `tsconfig.json` file at the root of your
TypeScript code is automatically converted into JavaScript during development,
but not in the distributable version of Kibana. If you use the
{repo}blob/{branch}/packages/kbn-plugin-helpers[@kbn/plugin-helpers] to build your plugin, then your `.ts` and `.tsx` files will be permanently transpiled before your plugin is archived. If you have your own build process, make sure to run the TypeScript compiler on your source files and ship the compilation output so that your plugin will work with the distributable version of Kibana.

==== {kib} platform migration guide

{repo}blob/{branch}/src/core/MIGRATION.md#migrating-legacy-plugins-to-the-new-platform[This guide]
provides an action plan for moving a legacy plugin to the new platform.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@
"@elastic/charts": "^17.0.2",
"@elastic/datemath": "5.0.2",
"@elastic/ems-client": "7.6.0",
"@elastic/eui": "18.3.0",
"@elastic/eui": "19.0.0",
"@elastic/filesaver": "1.1.2",
"@elastic/good": "8.1.1-kibana2",
"@elastic/numeral": "2.3.5",
Expand Down
6 changes: 3 additions & 3 deletions packages/kbn-config-schema/src/types/duration_type.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ describe('#defaultValue', () => {
source: duration({ defaultValue: 600 }),
target: duration({ defaultValue: siblingRef('source') }),
fromContext: duration({ defaultValue: contextRef('val') }),
}).validate(undefined, { val: momentDuration(700, 'ms') })
}).validate({}, { val: momentDuration(700, 'ms') })
).toMatchInlineSnapshot(`
Object {
"fromContext": "PT0.7S",
Expand All @@ -115,7 +115,7 @@ Object {
source: duration({ defaultValue: '1h' }),
target: duration({ defaultValue: siblingRef('source') }),
fromContext: duration({ defaultValue: contextRef('val') }),
}).validate(undefined, { val: momentDuration(2, 'hour') })
}).validate({}, { val: momentDuration(2, 'hour') })
).toMatchInlineSnapshot(`
Object {
"fromContext": "PT2H",
Expand All @@ -129,7 +129,7 @@ Object {
source: duration({ defaultValue: momentDuration(1, 'hour') }),
target: duration({ defaultValue: siblingRef('source') }),
fromContext: duration({ defaultValue: contextRef('val') }),
}).validate(undefined, { val: momentDuration(2, 'hour') })
}).validate({}, { val: momentDuration(2, 'hour') })
).toMatchInlineSnapshot(`
Object {
"fromContext": "PT2H",
Expand Down
38 changes: 38 additions & 0 deletions packages/kbn-config-schema/src/types/maybe_type.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,41 @@ test('includes namespace in failure', () => {
const type = schema.maybe(schema.string());
expect(() => type.validate(null, {}, 'foo-namespace')).toThrowErrorMatchingSnapshot();
});

describe('maybe + object', () => {
test('returns undefined if undefined object', () => {
const type = schema.maybe(schema.object({}));
expect(type.validate(undefined)).toEqual(undefined);
});

test('returns undefined if undefined object with no defaults', () => {
const type = schema.maybe(
schema.object({
type: schema.string(),
id: schema.string(),
})
);

expect(type.validate(undefined)).toEqual(undefined);
});

test('returns empty object if maybe keys', () => {
const type = schema.object({
name: schema.maybe(schema.string()),
});
expect(type.validate({})).toEqual({});
});

test('returns empty object if maybe nested object', () => {
const type = schema.object({
name: schema.maybe(
schema.object({
type: schema.string(),
id: schema.string(),
})
),
});

expect(type.validate({})).toEqual({});
});
});
2 changes: 1 addition & 1 deletion packages/kbn-config-schema/src/types/maybe_type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export class MaybeType<V> extends Type<V | undefined> {
type
.getSchema()
.optional()
.default()
.default(() => undefined, 'undefined')
);
}
}
22 changes: 21 additions & 1 deletion packages/kbn-config-schema/src/types/object_type.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ test('returns value by default', () => {
expect(type.validate(value)).toEqual({ name: 'test' });
});

test('returns empty object if undefined', () => {
const type = schema.object({});
expect(type.validate(undefined)).toEqual({});
});

test('properly parse the value if input is a string', () => {
const type = schema.object({
name: schema.string(),
Expand Down Expand Up @@ -112,21 +117,36 @@ test('undefined object within object', () => {
}),
});

expect(type.validate(undefined)).toEqual({
foo: {
bar: 'hello world',
},
});

expect(type.validate({})).toEqual({
foo: {
bar: 'hello world',
},
});

expect(type.validate({ foo: {} })).toEqual({
foo: {
bar: 'hello world',
},
});
});

test('object within object with required', () => {
test('object within object with key without defaultValue', () => {
const type = schema.object({
foo: schema.object({
bar: schema.string(),
}),
});
const value = { foo: {} };

expect(() => type.validate(undefined)).toThrowErrorMatchingInlineSnapshot(
`"[foo.bar]: expected value of type [string] but got [undefined]"`
);
expect(() => type.validate(value)).toThrowErrorMatchingInlineSnapshot(
`"[foo.bar]: expected value of type [string] but got [undefined]"`
);
Expand Down
6 changes: 3 additions & 3 deletions packages/kbn-config-schema/src/types/object_type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,23 @@ export type ObjectResultType<P extends Props> = Readonly<{ [K in keyof P]: TypeO
export type ObjectTypeOptions<P extends Props = any> = TypeOptions<
{ [K in keyof P]: TypeOf<P[K]> }
> & {
/** Should uknown keys not be defined in the schema be allowed. Defaults to `false` */
allowUnknowns?: boolean;
};

export class ObjectType<P extends Props = any> extends Type<ObjectResultType<P>> {
private props: Record<string, AnySchema>;

constructor(props: P, options: ObjectTypeOptions<P> = {}) {
constructor(props: P, { allowUnknowns = false, ...typeOptions }: ObjectTypeOptions<P> = {}) {
const schemaKeys = {} as Record<string, AnySchema>;
for (const [key, value] of Object.entries(props)) {
schemaKeys[key] = value.getSchema();
}
const { allowUnknowns, ...typeOptions } = options;
const schema = internals
.object()
.keys(schemaKeys)
.optional()
.default()
.optional()
.unknown(Boolean(allowUnknowns));

super(schema, typeOptions);
Expand Down
2 changes: 1 addition & 1 deletion packages/kbn-ui-shared-deps/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"devDependencies": {
"@elastic/charts": "^17.0.2",
"abort-controller": "^3.0.0",
"@elastic/eui": "18.3.0",
"@elastic/eui": "19.0.0",
"@kbn/dev-utils": "1.0.0",
"@kbn/i18n": "1.0.0",
"@yarnpkg/lockfile": "^1.1.0",
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 @@ -41,7 +41,7 @@ import {
} from '@elastic/charts';

import { i18n } from '@kbn/i18n';
import { EuiChartThemeType } from '@elastic/eui/src/themes/charts/themes';
import { EuiChartThemeType } from '@elastic/eui/dist/eui_charts_theme';
import { Subscription } from 'rxjs';
import { getServices, timezoneProvider } from '../../../kibana_services';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,31 @@ jest.mock('../../../kibana_services', () => {
};
});

// Mocking to prevent errors with React portal.
// Temporary until https://github.com/elastic/kibana/pull/55877 provides other alternatives.
jest.mock('@elastic/eui/lib/components/code/code_block', () => {
const React = require.requireActual('react');
return {
EuiCodeBlock: ({ children }) => (
<div>
<pre>
<code>{children}</code>
</pre>
</div>
),
};
});
jest.mock('@elastic/eui/lib/components/code/code', () => {
const React = require.requireActual('react');
return {
EuiCode: ({ children }) => (
<span>
<code>{children}</code>
</span>
),
};
});

beforeEach(() => {
jest.clearAllMocks();
});
Expand Down
Loading

0 comments on commit 2b2d37a

Please sign in to comment.