Skip to content

Commit 101fb18

Browse files
Merge branch 'master' into fix/ftr-fails-to-clear-session-storage
2 parents 86b237d + 583500e commit 101fb18

File tree

161 files changed

+7743
-1764
lines changed

Some content is hidden

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

161 files changed

+7743
-1764
lines changed

.eslintrc.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -214,13 +214,6 @@ module.exports = {
214214
'jsx-a11y/click-events-have-key-events': 'off',
215215
},
216216
},
217-
{
218-
files: ['x-pack/legacy/plugins/siem/**/*.{js,ts,tsx}'],
219-
rules: {
220-
'react-hooks/exhaustive-deps': 'off',
221-
'react-hooks/rules-of-hooks': 'off',
222-
},
223-
},
224217
{
225218
files: ['x-pack/legacy/plugins/snapshot_restore/**/*.{js,ts,tsx}'],
226219
rules: {
@@ -839,6 +832,8 @@ module.exports = {
839832
// might be introduced after the other warns are fixed
840833
// 'react/jsx-sort-props': 'error',
841834
'react/jsx-tag-spacing': 'error',
835+
// might be introduced after the other warns are fixed
836+
'react-hooks/exhaustive-deps': 'off',
842837
'require-atomic-updates': 'error',
843838
'rest-spread-spacing': ['error', 'never'],
844839
'symbol-description': 'error',

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

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ const CHILD_ELEMENT_PREFIX = 'historyReq';
4545
export function ConsoleHistory({ close }: Props) {
4646
const {
4747
services: { history },
48-
ResizeChecker,
4948
} = useAppContext();
5049

5150
const dispatch = useEditorActionContext();
@@ -200,7 +199,6 @@ export function ConsoleHistory({ close }: Props) {
200199
<HistoryViewer
201200
settings={readOnlySettings}
202201
req={viewingReq}
203-
ResizeChecker={ResizeChecker}
204202
/>
205203
</div>
206204

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,9 @@ import { applyCurrentSettings } from '../console_editor/apply_editor_settings';
3131
interface Props {
3232
settings: DevToolsSettings;
3333
req: any | null;
34-
ResizeChecker: any;
3534
}
3635

37-
export function HistoryViewer({ settings, ResizeChecker, req }: Props) {
36+
export function HistoryViewer({ settings, req }: Props) {
3837
const divRef = useRef<HTMLDivElement | null>(null);
3938
const viewerRef = useRef<any | null>(null);
4039

@@ -43,7 +42,7 @@ export function HistoryViewer({ settings, ResizeChecker, req }: Props) {
4342
viewerRef.current = viewer;
4443
viewer.renderer.setShowPrintMargin(false);
4544
viewer.$blockScrolling = Infinity;
46-
const unsubscribe = subscribeResizeChecker(ResizeChecker, divRef.current!, viewer);
45+
const unsubscribe = subscribeResizeChecker(divRef.current!, viewer);
4746
return () => unsubscribe();
4847
}, []);
4948

0 commit comments

Comments
 (0)