-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Cases] Add Lens markdown plugin (#96703)
- Loading branch information
1 parent
d2d1ad9
commit 5968a2c
Showing
77 changed files
with
2,305 additions
and
344 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
...ibana-plugin-plugins-embeddable-public.embeddableeditorstate.originatingpath.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
||
[Home](./index.md) > [kibana-plugin-plugins-embeddable-public](./kibana-plugin-plugins-embeddable-public.md) > [EmbeddableEditorState](./kibana-plugin-plugins-embeddable-public.embeddableeditorstate.md) > [originatingPath](./kibana-plugin-plugins-embeddable-public.embeddableeditorstate.originatingpath.md) | ||
|
||
## EmbeddableEditorState.originatingPath property | ||
|
||
<b>Signature:</b> | ||
|
||
```typescript | ||
originatingPath?: string; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
x-pack/plugins/cases/common/utils/markdown_plugins/lens/constants.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
export const LENS_ID = 'lens'; |
10 changes: 10 additions & 0 deletions
10
x-pack/plugins/cases/common/utils/markdown_plugins/lens/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
export * from './constants'; | ||
export * from './parser'; | ||
export * from './serializer'; |
77 changes: 77 additions & 0 deletions
77
x-pack/plugins/cases/common/utils/markdown_plugins/lens/parser.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { Plugin } from 'unified'; | ||
import { RemarkTokenizer } from '@elastic/eui'; | ||
import { LENS_ID } from './constants'; | ||
|
||
export const LensParser: Plugin = function () { | ||
const Parser = this.Parser; | ||
const tokenizers = Parser.prototype.blockTokenizers; | ||
const methods = Parser.prototype.blockMethods; | ||
|
||
const tokenizeLens: RemarkTokenizer = function (eat, value, silent) { | ||
if (value.startsWith(`!{${LENS_ID}`) === false) return true; | ||
|
||
const nextChar = value[6]; | ||
|
||
if (nextChar !== '{' && nextChar !== '}') return false; // this isn't actually a lens | ||
|
||
if (silent) { | ||
return true; | ||
} | ||
|
||
// is there a configuration? | ||
const hasConfiguration = nextChar === '{'; | ||
|
||
let match = `!{${LENS_ID}`; | ||
let configuration = {}; | ||
|
||
if (hasConfiguration) { | ||
let configurationString = ''; | ||
|
||
let openObjects = 0; | ||
|
||
for (let i = 6; i < value.length; i++) { | ||
const char = value[i]; | ||
if (char === '{') { | ||
openObjects++; | ||
configurationString += char; | ||
} else if (char === '}') { | ||
openObjects--; | ||
if (openObjects === -1) { | ||
break; | ||
} | ||
configurationString += char; | ||
} else { | ||
configurationString += char; | ||
} | ||
} | ||
|
||
match += configurationString; | ||
try { | ||
configuration = JSON.parse(configurationString); | ||
} catch (e) { | ||
const now = eat.now(); | ||
this.file.fail(`Unable to parse lens JSON configuration: ${e}`, { | ||
line: now.line, | ||
column: now.column + 6, | ||
}); | ||
} | ||
} | ||
|
||
match += '}'; | ||
|
||
return eat(match)({ | ||
type: LENS_ID, | ||
...configuration, | ||
}); | ||
}; | ||
|
||
tokenizers.lens = tokenizeLens; | ||
methods.splice(methods.indexOf('text'), 0, LENS_ID); | ||
}; |
20 changes: 20 additions & 0 deletions
20
x-pack/plugins/cases/common/utils/markdown_plugins/lens/serializer.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import type { TimeRange } from 'src/plugins/data/common'; | ||
import { LENS_ID } from './constants'; | ||
|
||
export interface LensSerializerProps { | ||
attributes: Record<string, unknown>; | ||
timeRange: TimeRange; | ||
} | ||
|
||
export const LensSerializer = ({ timeRange, attributes }: LensSerializerProps) => | ||
`!{${LENS_ID}${JSON.stringify({ | ||
timeRange, | ||
attributes, | ||
})}}`; |
9 changes: 9 additions & 0 deletions
9
x-pack/plugins/cases/common/utils/markdown_plugins/timeline/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
export * from './parser'; | ||
export * from './serializer'; |
83 changes: 83 additions & 0 deletions
83
x-pack/plugins/cases/common/utils/markdown_plugins/timeline/parser.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { Plugin } from 'unified'; | ||
import { RemarkTokenizer } from '@elastic/eui'; | ||
import * as i18n from './translations'; | ||
|
||
export const ID = 'timeline'; | ||
const PREFIX = '['; | ||
|
||
export const TimelineParser: Plugin = function () { | ||
const Parser = this.Parser; | ||
const tokenizers = Parser.prototype.blockTokenizers; | ||
const methods = Parser.prototype.blockMethods; | ||
|
||
const tokenizeTimeline: RemarkTokenizer = function (eat, value, silent) { | ||
if ( | ||
value.startsWith(PREFIX) === false || | ||
(value.startsWith(PREFIX) === true && !value.includes('timelines?timeline=(id')) | ||
) { | ||
return false; | ||
} | ||
|
||
let index = 0; | ||
const nextChar = value[index]; | ||
|
||
if (nextChar !== PREFIX) { | ||
return false; | ||
} | ||
|
||
if (silent) { | ||
return true; | ||
} | ||
|
||
function readArg(open: string, close: string) { | ||
if (value[index] !== open) { | ||
throw new Error(i18n.NO_PARENTHESES); | ||
} | ||
|
||
index++; | ||
|
||
let body = ''; | ||
let openBrackets = 0; | ||
|
||
for (; index < value.length; index++) { | ||
const char = value[index]; | ||
|
||
if (char === close && openBrackets === 0) { | ||
index++; | ||
return body; | ||
} else if (char === close) { | ||
openBrackets--; | ||
} else if (char === open) { | ||
openBrackets++; | ||
} | ||
|
||
body += char; | ||
} | ||
|
||
return ''; | ||
} | ||
|
||
const timelineTitle = readArg(PREFIX, ']'); | ||
const timelineUrl = readArg('(', ')'); | ||
const match = `[${timelineTitle}](${timelineUrl})`; | ||
|
||
return eat(match)({ | ||
type: ID, | ||
match, | ||
}); | ||
}; | ||
|
||
tokenizeTimeline.locator = (value: string, fromIndex: number) => { | ||
return value.indexOf(PREFIX, fromIndex); | ||
}; | ||
|
||
tokenizers.timeline = tokenizeTimeline; | ||
methods.splice(methods.indexOf('url'), 0, ID); | ||
}; |
12 changes: 12 additions & 0 deletions
12
x-pack/plugins/cases/common/utils/markdown_plugins/timeline/serializer.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
export interface TimelineSerializerProps { | ||
match: string; | ||
} | ||
|
||
export const TimelineSerializer = ({ match }: TimelineSerializerProps) => match; |
15 changes: 15 additions & 0 deletions
15
x-pack/plugins/cases/common/utils/markdown_plugins/timeline/translations.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { i18n } from '@kbn/i18n'; | ||
|
||
export const NO_PARENTHESES = i18n.translate( | ||
'xpack.cases.markdownEditor.plugins.timeline.noParenthesesErrorMsg', | ||
{ | ||
defaultMessage: 'Expected left parentheses', | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.