Skip to content

Commit a396eb4

Browse files
Merge branch 'master' into fix/spriteloading
2 parents ae41ba1 + 2166044 commit a396eb4

File tree

89 files changed

+7270
-1242
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

89 files changed

+7270
-1242
lines changed

docs/development/core/server/kibana-plugin-server.httpservicesetup.createrouter.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Each route can have only one handler function, which is executed when the route
2121

2222
```ts
2323
const router = createRouter();
24-
// handler is called when '${my-plugin-id}/path' resource is requested with `GET` method
24+
// handler is called when '/path' resource is requested with `GET` method
2525
router.get({ path: '/path', validate: false }, (context, req, res) => res.ok({ content: 'ok' }));
2626

2727
```

docs/development/core/server/kibana-plugin-server.httpservicesetup.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export interface HttpServiceSetup
2727

2828
## Example
2929

30-
To handle an incoming request in your plugin you should: - Create a `Router` instance. Router is already configured to use `plugin-id` to prefix path segment for your routes.
30+
To handle an incoming request in your plugin you should: - Create a `Router` instance.
3131

3232
```ts
3333
const router = httpSetup.createRouter();
@@ -61,7 +61,7 @@ const handler = async (context: RequestHandlerContext, request: KibanaRequest, r
6161
}
6262

6363
```
64-
- Register route handler for GET request to 'my-app/path/<!-- -->{<!-- -->id<!-- -->}<!-- -->' path
64+
- Register route handler for GET request to 'path/<!-- -->{<!-- -->id<!-- -->}<!-- -->' path
6565

6666
```ts
6767
import { schema, TypeOf } from '@kbn/config-schema';

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,7 @@
327327
"@types/pngjs": "^3.3.2",
328328
"@types/podium": "^1.0.0",
329329
"@types/prop-types": "^15.5.3",
330+
"@types/reach__router": "^1.2.6",
330331
"@types/react": "^16.8.0",
331332
"@types/react-dom": "^16.8.0",
332333
"@types/react-redux": "^6.0.6",

renovate.json5

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,14 @@
513513
'@types/podium',
514514
],
515515
},
516+
{
517+
groupSlug: '@reach/router',
518+
groupName: '@reach/router related packages',
519+
packageNames: [
520+
'@reach/router',
521+
'@types/reach__router',
522+
],
523+
},
516524
{
517525
groupSlug: 'request',
518526
groupName: 'request related packages',

src/core/server/config/config_service.test.ts

Lines changed: 77 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ test('throws if config at path does not match schema', async () => {
5555
await expect(
5656
configService.setSchema('key', schema.string())
5757
).rejects.toThrowErrorMatchingInlineSnapshot(
58-
`"[key]: expected value of type [string] but got [number]"`
58+
`"[config validation of [key]]: expected value of type [string] but got [number]"`
5959
);
6060
});
6161

@@ -78,11 +78,11 @@ test('re-validate config when updated', async () => {
7878
config$.next(new ObjectToConfigAdapter({ key: 123 }));
7979

8080
await expect(valuesReceived).toMatchInlineSnapshot(`
81-
Array [
82-
"value",
83-
[Error: [key]: expected value of type [string] but got [number]],
84-
]
85-
`);
81+
Array [
82+
"value",
83+
[Error: [config validation of [key]]: expected value of type [string] but got [number]],
84+
]
85+
`);
8686
});
8787

8888
test("returns undefined if fetching optional config at a path that doesn't exist", async () => {
@@ -143,7 +143,7 @@ test("throws error if 'schema' is not defined for a key", async () => {
143143
const configs = configService.atPath('key');
144144

145145
await expect(configs.pipe(first()).toPromise()).rejects.toMatchInlineSnapshot(
146-
`[Error: No validation schema has been defined for key]`
146+
`[Error: No validation schema has been defined for [key]]`
147147
);
148148
});
149149

@@ -153,7 +153,7 @@ test("throws error if 'setSchema' called several times for the same key", async
153153
const addSchema = async () => await configService.setSchema('key', schema.string());
154154
await addSchema();
155155
await expect(addSchema()).rejects.toMatchInlineSnapshot(
156-
`[Error: Validation schema for key was already registered.]`
156+
`[Error: Validation schema for [key] was already registered.]`
157157
);
158158
});
159159

@@ -280,6 +280,33 @@ test('handles disabled path and marks config as used', async () => {
280280
expect(unusedPaths).toEqual([]);
281281
});
282282

283+
test('does not throw if schema does not define "enabled" schema', async () => {
284+
const initialConfig = {
285+
pid: {
286+
file: '/some/file.pid',
287+
},
288+
};
289+
290+
const config$ = new BehaviorSubject(new ObjectToConfigAdapter(initialConfig));
291+
const configService = new ConfigService(config$, defaultEnv, logger);
292+
expect(
293+
configService.setSchema(
294+
'pid',
295+
schema.object({
296+
file: schema.string(),
297+
})
298+
)
299+
).resolves.toBeUndefined();
300+
301+
const value$ = configService.atPath('pid');
302+
const value: any = await value$.pipe(first()).toPromise();
303+
expect(value.enabled).toBe(undefined);
304+
305+
const valueOptional$ = configService.optionalAtPath('pid');
306+
const valueOptional: any = await valueOptional$.pipe(first()).toPromise();
307+
expect(valueOptional.enabled).toBe(undefined);
308+
});
309+
283310
test('treats config as enabled if config path is not present in config', async () => {
284311
const initialConfig = {};
285312

@@ -292,3 +319,45 @@ test('treats config as enabled if config path is not present in config', async (
292319
const unusedPaths = await configService.getUnusedPaths();
293320
expect(unusedPaths).toEqual([]);
294321
});
322+
323+
test('read "enabled" even if its schema is not present', async () => {
324+
const initialConfig = {
325+
foo: {
326+
enabled: true,
327+
},
328+
};
329+
330+
const config$ = new BehaviorSubject(new ObjectToConfigAdapter(initialConfig));
331+
const configService = new ConfigService(config$, defaultEnv, logger);
332+
333+
const isEnabled = await configService.isEnabledAtPath('foo');
334+
expect(isEnabled).toBe(true);
335+
});
336+
337+
test('allows plugins to specify "enabled" flag via validation schema', async () => {
338+
const initialConfig = {};
339+
340+
const config$ = new BehaviorSubject(new ObjectToConfigAdapter(initialConfig));
341+
const configService = new ConfigService(config$, defaultEnv, logger);
342+
343+
await configService.setSchema(
344+
'foo',
345+
schema.object({ enabled: schema.boolean({ defaultValue: false }) })
346+
);
347+
348+
expect(await configService.isEnabledAtPath('foo')).toBe(false);
349+
350+
await configService.setSchema(
351+
'bar',
352+
schema.object({ enabled: schema.boolean({ defaultValue: true }) })
353+
);
354+
355+
expect(await configService.isEnabledAtPath('bar')).toBe(true);
356+
357+
await configService.setSchema(
358+
'baz',
359+
schema.object({ different: schema.boolean({ defaultValue: true }) })
360+
);
361+
362+
expect(await configService.isEnabledAtPath('baz')).toBe(true);
363+
});

src/core/server/config/config_service.ts

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export class ConfigService {
5454
public async setSchema(path: ConfigPath, schema: Type<unknown>) {
5555
const namespace = pathToString(path);
5656
if (this.schemas.has(namespace)) {
57-
throw new Error(`Validation schema for ${path} was already registered.`);
57+
throw new Error(`Validation schema for [${path}] was already registered.`);
5858
}
5959

6060
this.schemas.set(namespace, schema);
@@ -98,14 +98,28 @@ export class ConfigService {
9898
}
9999

100100
public async isEnabledAtPath(path: ConfigPath) {
101-
const enabledPath = createPluginEnabledPath(path);
101+
const namespace = pathToString(path);
102+
103+
const validatedConfig = this.schemas.has(namespace)
104+
? await this.atPath<{ enabled?: boolean }>(path)
105+
.pipe(first())
106+
.toPromise()
107+
: undefined;
102108

109+
const enabledPath = createPluginEnabledPath(path);
103110
const config = await this.config$.pipe(first()).toPromise();
104-
if (!config.has(enabledPath)) {
111+
112+
// if plugin hasn't got a config schema, we try to read "enabled" directly
113+
const isEnabled =
114+
validatedConfig && validatedConfig.enabled !== undefined
115+
? validatedConfig.enabled
116+
: config.get(enabledPath);
117+
118+
// not declared. consider that plugin is enabled by default
119+
if (isEnabled === undefined) {
105120
return true;
106121
}
107122

108-
const isEnabled = config.get(enabledPath);
109123
if (isEnabled === false) {
110124
// If the plugin is _not_ enabled, we mark the entire plugin path as
111125
// handled, as it's expected that it won't be used.
@@ -138,7 +152,7 @@ export class ConfigService {
138152
const namespace = pathToString(path);
139153
const schema = this.schemas.get(namespace);
140154
if (!schema) {
141-
throw new Error(`No validation schema has been defined for ${namespace}`);
155+
throw new Error(`No validation schema has been defined for [${namespace}]`);
142156
}
143157
return schema.validate(
144158
config,
@@ -147,7 +161,7 @@ export class ConfigService {
147161
prod: this.env.mode.prod,
148162
...this.env.packageInfo,
149163
},
150-
namespace
164+
`config validation of [${namespace}]`
151165
);
152166
}
153167

src/core/server/http/types.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export type RequestHandlerContextProvider<
5252
*
5353
* @example
5454
* To handle an incoming request in your plugin you should:
55-
* - Create a `Router` instance. Router is already configured to use `plugin-id` to prefix path segment for your routes.
55+
* - Create a `Router` instance.
5656
* ```ts
5757
* const router = httpSetup.createRouter();
5858
* ```
@@ -87,7 +87,7 @@ export type RequestHandlerContextProvider<
8787
* }
8888
* ```
8989
*
90-
* - Register route handler for GET request to 'my-app/path/{id}' path
90+
* - Register route handler for GET request to 'path/{id}' path
9191
* ```ts
9292
* import { schema, TypeOf } from '@kbn/config-schema';
9393
* const router = httpSetup.createRouter();
@@ -184,7 +184,7 @@ export interface HttpServiceSetup {
184184
* @example
185185
* ```ts
186186
* const router = createRouter();
187-
* // handler is called when '${my-plugin-id}/path' resource is requested with `GET` method
187+
* // handler is called when '/path' resource is requested with `GET` method
188188
* router.get({ path: '/path', validate: false }, (context, req, res) => res.ok({ content: 'ok' }));
189189
* ```
190190
* @public

src/legacy/core_plugins/console/np_ready/public/application/containers/editor/legacy/console_editor/editor.test.tsx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,6 @@ describe('Legacy (Ace) Console Editor Component Smoke Test', () => {
6262
updateCurrentState: () => {},
6363
},
6464
},
65-
// eslint-disable-next-line
66-
ResizeChecker: function() {
67-
return { on: () => {} };
68-
},
6965
docLinkVersion: 'NA',
7066
};
7167
editor = mount(

src/legacy/core_plugins/console/np_ready/public/application/containers/editor/legacy/console_editor/editor.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ const DEFAULT_INPUT_VALUE = `GET _search
6363
function _Editor({ previousStateLocation = 'stored' }: EditorProps) {
6464
const {
6565
services: { history, notifications },
66-
ResizeChecker,
6766
docLinkVersion,
6867
} = useAppContext();
6968

@@ -130,7 +129,6 @@ function _Editor({ previousStateLocation = 'stored' }: EditorProps) {
130129
mappings.retrieveAutoCompleteInfo();
131130

132131
const unsubscribeResizer = subscribeResizeChecker(
133-
ResizeChecker,
134132
editorRef.current!,
135133
editorInstanceRef.current
136134
);

src/legacy/core_plugins/console/np_ready/public/application/containers/editor/legacy/console_editor/editor_output.tsx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ function _EditorOuput() {
3131
const editorInstanceRef = useRef<null | any>(null);
3232
const {
3333
services: { settings },
34-
ResizeChecker,
3534
} = useAppContext();
3635

3736
const dispatch = useEditorActionContext();
@@ -42,11 +41,7 @@ function _EditorOuput() {
4241
const editor$ = $(editorRef.current!);
4342
editorInstanceRef.current = initializeOutput(editor$, settings);
4443
editorInstanceRef.current.update('');
45-
const unsubscribe = subscribeResizeChecker(
46-
ResizeChecker,
47-
editorRef.current!,
48-
editorInstanceRef.current
49-
);
44+
const unsubscribe = subscribeResizeChecker(editorRef.current!, editorInstanceRef.current);
5045

5146
dispatch({ type: 'setOutputEditor', value: editorInstanceRef.current });
5247

0 commit comments

Comments
 (0)