forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Cases] Fix add Lens markdown plugin UX (elastic#109178)
# Conflicts: # package.json
- Loading branch information
1 parent
6f7562b
commit 4ca70e5
Showing
26 changed files
with
1,139 additions
and
460 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
56 changes: 56 additions & 0 deletions
56
x-pack/plugins/cases/common/utils/markdown_plugins/utils.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,56 @@ | ||
/* | ||
* 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 { filter } from 'lodash'; | ||
import type { Node } from 'unist'; | ||
import markdown from 'remark-parse'; | ||
import remarkStringify from 'remark-stringify'; | ||
import unified from 'unified'; | ||
|
||
import { TimeRange } from 'src/plugins/data/server'; | ||
import { SerializableRecord } from '@kbn/utility-types'; | ||
import { LENS_ID, LensParser, LensSerializer } from './lens'; | ||
import { TimelineSerializer, TimelineParser } from './timeline'; | ||
|
||
interface LensMarkdownNode extends Node { | ||
timeRange: TimeRange; | ||
attributes: SerializableRecord; | ||
type: string; | ||
id: string; | ||
} | ||
|
||
interface LensMarkdownParent extends Node { | ||
children: Array<LensMarkdownNode | Node>; | ||
} | ||
|
||
export const getLensVisualizations = (parsedComment?: Array<LensMarkdownNode | Node>) => | ||
(parsedComment?.length ? filter(parsedComment, { type: LENS_ID }) : []) as LensMarkdownNode[]; | ||
|
||
export const parseCommentString = (comment: string) => { | ||
const processor = unified().use([[markdown, {}], LensParser, TimelineParser]); | ||
return processor.parse(comment) as LensMarkdownParent; | ||
}; | ||
|
||
export const stringifyComment = (comment: LensMarkdownParent) => | ||
unified() | ||
.use([ | ||
[ | ||
remarkStringify, | ||
{ | ||
allowDangerousHtml: true, | ||
handlers: { | ||
/* | ||
because we're using rison in the timeline url we need | ||
to make sure that markdown parser doesn't modify the url | ||
*/ | ||
timeline: TimelineSerializer, | ||
lens: LensSerializer, | ||
}, | ||
}, | ||
], | ||
]) | ||
.stringify(comment); |
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
Oops, something went wrong.