Skip to content

Commit

Permalink
Merge branch 'master' into fix/siem-initial-kibana-search-filters
Browse files Browse the repository at this point in the history
  • Loading branch information
elasticmachine authored Aug 18, 2020
2 parents d42a73e + 196cb7f commit a74b6d2
Show file tree
Hide file tree
Showing 197 changed files with 2,800 additions and 1,888 deletions.
5 changes: 3 additions & 2 deletions docs/developer/architecture/code-exploration.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -313,9 +313,10 @@ To access an elasticsearch instance that has live data you have two options:
WARNING: Missing README.
- {kib-repo}blob/{branch}/x-pack/plugins/beats_management[beats_management]
- {kib-repo}blob/{branch}/x-pack/plugins/beats_management/readme.md[beatsManagement]
WARNING: Missing README.
Notes:
Failure to have auth enabled in Kibana will make for a broken UI. UI-based errors not yet in place
- {kib-repo}blob/{branch}/x-pack/plugins/canvas/README.md[canvas]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,5 +96,6 @@ readonly links: {
readonly dateMath: string;
};
readonly management: Record<string, string>;
readonly visualize: Record<string, string>;
};
```
13 changes: 13 additions & 0 deletions packages/kbn-monaco/src/xjson/grammar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,19 @@ export enum AnnoTypes {
warning = 'warning',
}

export type Parser = ReturnType<typeof createParser>;

export interface Annotation {
name?: string;
type: AnnoTypes;
text: string;
at: number;
}

export interface ParseResult {
annotations: Annotation[];
}

/* eslint-disable */

export const createParser = () => {
Expand Down
8 changes: 5 additions & 3 deletions packages/kbn-monaco/src/xjson/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@
* under the License.
*/

import { registerGrammarChecker } from './language';

/**
* This import registers the XJSON monaco language contribution
*/
import './language';
import { ID } from './constants';

export const XJsonLang = { registerGrammarChecker, ID };
export const XJsonLang = { ID };
45 changes: 27 additions & 18 deletions packages/kbn-monaco/src/xjson/language.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,16 @@ const wps = new WorkerProxyService();
registerLexerRules(monaco);

// In future we will need to make this map languages to workers using "id" and/or "label" values
// that get passed in.
// that get passed in. Also this should not live inside the "xjson" dir directly. We can update this
// once we have another worker.
// @ts-ignore
window.MonacoEnvironment = {
getWorker: (id: any, label: any) => {
// In kibana we will probably build this once and then load with raw-loader
const blob = new Blob([workerSrc], { type: 'application/javascript' });
return new Worker(URL.createObjectURL(blob));
getWorker: (module: string, languageId: string) => {
if (languageId === ID) {
// In kibana we will probably build this once and then load with raw-loader
const blob = new Blob([workerSrc], { type: 'application/javascript' });
return new Worker(URL.createObjectURL(blob));
}
},
};

Expand All @@ -47,15 +50,19 @@ monaco.languages.onLanguage(ID, async () => {
});

const OWNER = 'XJSON_GRAMMAR_CHECKER';
export const registerGrammarChecker = (editor: monaco.editor.IEditor) => {

export const registerGrammarChecker = () => {
const allDisposables: monaco.IDisposable[] = [];

const updateAnnos = async () => {
const { annotations } = await wps.getAnnos();
const model = editor.getModel() as monaco.editor.ITextModel | null;
if (!model) {
const updateAnnotations = async (model: monaco.editor.IModel): Promise<void> => {
if (model.isDisposed()) {
return;
}
const parseResult = await wps.getAnnos(model.uri);
if (!parseResult) {
return;
}
const { annotations } = parseResult;
monaco.editor.setModelMarkers(
model,
OWNER,
Expand All @@ -74,19 +81,21 @@ export const registerGrammarChecker = (editor: monaco.editor.IEditor) => {
};

const onModelAdd = (model: monaco.editor.IModel) => {
allDisposables.push(
model.onDidChangeContent(async () => {
updateAnnos();
})
);
if (model.getModeId() === ID) {
allDisposables.push(
model.onDidChangeContent(async () => {
updateAnnotations(model);
})
);

updateAnnos();
updateAnnotations(model);
}
};

allDisposables.push(monaco.editor.onDidCreateModel(onModelAdd));
monaco.editor.getModels().forEach(onModelAdd);
return () => {
wps.stop();
allDisposables.forEach((d) => d.dispose());
};
};

registerGrammarChecker();
12 changes: 7 additions & 5 deletions packages/kbn-monaco/src/xjson/worker/xjson_worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,19 @@

/* eslint-disable-next-line @kbn/eslint/module_migration */
import * as monaco from 'monaco-editor/esm/vs/editor/editor.api';
import { createParser } from '../grammar';
import { createParser, Parser, ParseResult } from '../grammar';

export class XJsonWorker {
constructor(private ctx: monaco.worker.IWorkerContext) {}
private parser: any;
private parser: Parser | undefined;

async parse() {
async parse(modelUri: string): Promise<ParseResult | undefined> {
if (!this.parser) {
this.parser = createParser();
}
const [model] = this.ctx.getMirrorModels();
return this.parser(model.getValue());
const model = this.ctx.getMirrorModels().find((m) => m.uri.toString() === modelUri);
if (model) {
return this.parser(model.getValue());
}
}
}
19 changes: 4 additions & 15 deletions packages/kbn-monaco/src/xjson/worker_proxy_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,32 +17,21 @@
* under the License.
*/

import { AnnoTypes } from './grammar';
import { ParseResult } from './grammar';
import { monaco } from '../monaco';
import { XJsonWorker } from './worker';
import { ID } from './constants';

export interface Annotation {
name?: string;
type: AnnoTypes;
text: string;
at: number;
}

export interface AnnotationsResponse {
annotations: Annotation[];
}

export class WorkerProxyService {
private worker: monaco.editor.MonacoWebWorker<XJsonWorker> | undefined;

public async getAnnos(): Promise<AnnotationsResponse> {
public async getAnnos(modelUri: monaco.Uri): Promise<ParseResult | undefined> {
if (!this.worker) {
throw new Error('Worker Proxy Service has not been setup!');
}
await this.worker.withSyncedResources(monaco.editor.getModels().map(({ uri }) => uri));
await this.worker.withSyncedResources([modelUri]);
const proxy = await this.worker.getProxy();
return proxy.parse();
return proxy.parse(modelUri.toString());
}

public setup() {
Expand Down
14 changes: 7 additions & 7 deletions src/core/public/application/application_service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,15 +117,15 @@ describe('#setup()', () => {
expect.objectContaining({
id: 'app1',
legacy: false,
navLinkStatus: AppNavLinkStatus.default,
navLinkStatus: AppNavLinkStatus.visible,
status: AppStatus.accessible,
})
);
expect(applications.get('app2')).toEqual(
expect.objectContaining({
id: 'app2',
legacy: false,
navLinkStatus: AppNavLinkStatus.default,
navLinkStatus: AppNavLinkStatus.visible,
status: AppStatus.accessible,
})
);
Expand All @@ -142,7 +142,7 @@ describe('#setup()', () => {
expect.objectContaining({
id: 'app1',
legacy: false,
navLinkStatus: AppNavLinkStatus.default,
navLinkStatus: AppNavLinkStatus.hidden,
status: AppStatus.inaccessible,
defaultPath: 'foo/bar',
tooltip: 'App inaccessible due to reason',
Expand All @@ -152,7 +152,7 @@ describe('#setup()', () => {
expect.objectContaining({
id: 'app2',
legacy: false,
navLinkStatus: AppNavLinkStatus.default,
navLinkStatus: AppNavLinkStatus.visible,
status: AppStatus.accessible,
})
);
Expand Down Expand Up @@ -268,7 +268,7 @@ describe('#setup()', () => {
expect.objectContaining({
id: 'app2',
legacy: false,
navLinkStatus: AppNavLinkStatus.default,
navLinkStatus: AppNavLinkStatus.visible,
status: AppStatus.accessible,
tooltip: 'App accessible',
})
Expand Down Expand Up @@ -523,7 +523,7 @@ describe('#start()', () => {
appRoute: '/app/app1',
id: 'app1',
legacy: false,
navLinkStatus: AppNavLinkStatus.default,
navLinkStatus: AppNavLinkStatus.visible,
status: AppStatus.accessible,
})
);
Expand All @@ -532,7 +532,7 @@ describe('#start()', () => {
appUrl: '/my-url',
id: 'app2',
legacy: true,
navLinkStatus: AppNavLinkStatus.default,
navLinkStatus: AppNavLinkStatus.visible,
status: AppStatus.accessible,
})
);
Expand Down
39 changes: 33 additions & 6 deletions src/core/public/application/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@
*/

import { of } from 'rxjs';
import { LegacyApp, App, AppStatus, AppNavLinkStatus } from './types';
import { App, AppNavLinkStatus, AppStatus, LegacyApp } from './types';
import { BasePath } from '../http/base_path';
import {
removeSlashes,
appendAppPath,
getAppInfo,
isLegacyApp,
relativeToAbsolute,
parseAppUrl,
getAppInfo,
relativeToAbsolute,
removeSlashes,
} from './utils';

describe('removeSlashes', () => {
Expand Down Expand Up @@ -494,7 +494,7 @@ describe('getAppInfo', () => {
id: 'some-id',
title: 'some-title',
status: AppStatus.accessible,
navLinkStatus: AppNavLinkStatus.default,
navLinkStatus: AppNavLinkStatus.visible,
appRoute: `/app/some-id`,
legacy: false,
});
Expand All @@ -509,8 +509,35 @@ describe('getAppInfo', () => {
id: 'some-id',
title: 'some-title',
status: AppStatus.accessible,
navLinkStatus: AppNavLinkStatus.default,
navLinkStatus: AppNavLinkStatus.visible,
legacy: true,
});
});

it('computes the navLinkStatus depending on the app status', () => {
expect(
getAppInfo(
createApp({
navLinkStatus: AppNavLinkStatus.default,
status: AppStatus.inaccessible,
})
)
).toEqual(
expect.objectContaining({
navLinkStatus: AppNavLinkStatus.hidden,
})
);
expect(
getAppInfo(
createApp({
navLinkStatus: AppNavLinkStatus.default,
status: AppStatus.accessible,
})
)
).toEqual(
expect.objectContaining({
navLinkStatus: AppNavLinkStatus.visible,
})
);
});
});
20 changes: 17 additions & 3 deletions src/core/public/application/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,15 @@
*/

import { IBasePath } from '../http';
import { App, LegacyApp, PublicAppInfo, PublicLegacyAppInfo, ParsedAppUrl } from './types';
import {
App,
AppNavLinkStatus,
AppStatus,
LegacyApp,
ParsedAppUrl,
PublicAppInfo,
PublicLegacyAppInfo,
} from './types';

/**
* Utility to remove trailing, leading or duplicate slashes.
Expand Down Expand Up @@ -116,20 +124,26 @@ const removeBasePath = (url: string, basePath: IBasePath, origin: string): strin
};

export function getAppInfo(app: App<unknown> | LegacyApp): PublicAppInfo | PublicLegacyAppInfo {
const navLinkStatus =
app.navLinkStatus === AppNavLinkStatus.default
? app.status === AppStatus.inaccessible
? AppNavLinkStatus.hidden
: AppNavLinkStatus.visible
: app.navLinkStatus!;
if (isLegacyApp(app)) {
const { updater$, ...infos } = app;
return {
...infos,
status: app.status!,
navLinkStatus: app.navLinkStatus!,
navLinkStatus,
legacy: true,
};
} else {
const { updater$, mount, ...infos } = app;
return {
...infos,
status: app.status!,
navLinkStatus: app.navLinkStatus!,
navLinkStatus,
appRoute: app.appRoute!,
legacy: false,
};
Expand Down
5 changes: 5 additions & 0 deletions src/core/public/doc_links/doc_links_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@ export class DocLinksService {
kibanaSearchSettings: `${ELASTIC_WEBSITE_URL}guide/en/kibana/${DOC_LINK_VERSION}/advanced-options.html#kibana-search-settings`,
dashboardSettings: `${ELASTIC_WEBSITE_URL}guide/en/kibana/${DOC_LINK_VERSION}/advanced-options.html#kibana-dashboard-settings`,
},
visualize: {
guide: `${ELASTIC_WEBSITE_URL}guide/en/kibana/${DOC_LINK_VERSION}/visualize.html`,
timelionDeprecation: `${ELASTIC_WEBSITE_URL}guide/en/kibana/${DOC_LINK_VERSION}/timelion.html#timelion-deprecation`,
},
},
});
}
Expand Down Expand Up @@ -225,5 +229,6 @@ export interface DocLinksStart {
readonly dateMath: string;
};
readonly management: Record<string, string>;
readonly visualize: Record<string, string>;
};
}
1 change: 1 addition & 0 deletions src/core/public/public.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,7 @@ export interface DocLinksStart {
readonly dateMath: string;
};
readonly management: Record<string, string>;
readonly visualize: Record<string, string>;
};
}

Expand Down
Loading

0 comments on commit a74b6d2

Please sign in to comment.