diff --git a/x-pack/plugins/code/public/components/codeblock/codeblock.tsx b/x-pack/plugins/code/public/components/codeblock/codeblock.tsx index b38e26f56699..5f3a721d45e5 100644 --- a/x-pack/plugins/code/public/components/codeblock/codeblock.tsx +++ b/x-pack/plugins/code/public/components/codeblock/codeblock.tsx @@ -4,23 +4,16 @@ * you may not use this file except in compliance with the Elastic License. */ -import { EuiPanel, EuiText } from '@elastic/eui'; -import { EuiSpacer } from '@elastic/eui'; -import theme from '@elastic/eui/dist/eui_theme_light.json'; +import { EuiPanel } from '@elastic/eui'; import { editor, IPosition, IRange } from 'monaco-editor'; import React from 'react'; -import styled from 'styled-components'; import { ResizeChecker } from 'ui/resize_checker'; import { monaco } from '../../monaco/monaco'; import { registerEditor } from '../../monaco/single_selection_helper'; -const U = styled.u` - color: ${theme.euiCodeBlockTagColor}; -`; - interface Props { code: string; - file?: string; + fileComponent?: React.ReactNode; startLine?: number; language?: string; highlightRanges?: IRange[]; @@ -130,14 +123,7 @@ export class CodeBlock extends React.PureComponent { const linesCount = this.props.code.split('\n').length; return ( - {this.props.file && ( - - - {this.props.file} - - - - )} + {this.props.fileComponent}
(this.el = r)} style={{ height: linesCount * 18 }} /> ); diff --git a/x-pack/plugins/code/public/components/editor/references_panel.tsx b/x-pack/plugins/code/public/components/editor/references_panel.tsx index fcf3dd090202..376e1a2613f2 100644 --- a/x-pack/plugins/code/public/components/editor/references_panel.tsx +++ b/x-pack/plugins/code/public/components/editor/references_panel.tsx @@ -4,7 +4,15 @@ * you may not use this file except in compliance with the Elastic License. */ -import { EuiAccordion, EuiButtonIcon, EuiLoadingKibana, EuiPanel, EuiTitle } from '@elastic/eui'; +import { + EuiAccordion, + EuiButtonIcon, + EuiLoadingKibana, + EuiPanel, + EuiSpacer, + EuiText, + EuiTitle, +} from '@elastic/eui'; import { IPosition } from 'monaco-editor'; import queryString from 'querystring'; import React from 'react'; @@ -114,36 +122,47 @@ export class ReferencesPanel extends React.Component { const lineNumberFn = (l: number) => { return file.lineNumbers[l - 1]; }; + const fileComponent = ( + + + {file.file} + + + + ); + return ( ); } private onCodeClick(lineNumbers: string[], url: string, pos: IPosition) { - const { uri } = parseSchema(url)!; const line = parseInt(lineNumbers[pos.lineNumber - 1], 10); - if (!isNaN(line)) { - let search = history.location.search; - if (search.startsWith('?')) { - search = search.substring(1); - } - const queries = queryString.parse(search); - const query = queryString.stringify({ - ...queries, - tab: 'references', - refUrl: this.props.refUrl, - }); - history.push(`${uri}!L${line}:0?${query}`); + history.push(this.computeUrl(url, line)); + } + + private computeUrl(url: string, line?: number) { + const { uri } = parseSchema(url)!; + let search = history.location.search; + if (search.startsWith('?')) { + search = search.substring(1); } + const queries = queryString.parse(search); + const query = queryString.stringify({ + ...queries, + tab: 'references', + refUrl: this.props.refUrl, + }); + return line !== undefined ? `${uri}!L${line}:0?${query}` : `${uri}?${query}`; } }