Skip to content

Commit 3438a70

Browse files
authoredAug 5, 2021
[Fleet] Replace usages of EuiCodeEditor by CodeEditor (#107434)
1 parent 39bd188 commit 3438a70

File tree

8 files changed

+119
-40
lines changed

8 files changed

+119
-40
lines changed
 

‎src/plugins/kibana_react/public/code_editor/languages/index.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@
99
import { Lang as CssLang } from './css';
1010
import { Lang as HandlebarsLang } from './handlebars';
1111
import { Lang as MarkdownLang } from './markdown';
12+
import { Lang as YamlLang } from './yaml';
1213

13-
export { CssLang, HandlebarsLang, MarkdownLang };
14+
export { CssLang, HandlebarsLang, MarkdownLang, YamlLang };
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0 and the Server Side Public License, v 1; you may not use this file except
5+
* in compliance with, at your election, the Elastic License 2.0 or the Server
6+
* Side Public License, v 1.
7+
*/
8+
9+
export const LANG = 'yaml';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0 and the Server Side Public License, v 1; you may not use this file except
5+
* in compliance with, at your election, the Elastic License 2.0 or the Server
6+
* Side Public License, v 1.
7+
*/
8+
import { LangModuleType } from '@kbn/monaco';
9+
import { languageConfiguration, lexerRules } from './language';
10+
import { LANG } from './constants';
11+
12+
export const Lang: LangModuleType = { ID: LANG, languageConfiguration, lexerRules };
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0 and the Server Side Public License, v 1; you may not use this file except
5+
* in compliance with, at your election, the Elastic License 2.0 or the Server
6+
* Side Public License, v 1.
7+
*/
8+
9+
/* eslint-disable @kbn/eslint/module_migration */
10+
import { conf, language } from 'monaco-editor/esm/vs/basic-languages/yaml/yaml';
11+
12+
export { conf as languageConfiguration, language as lexerRules };

‎src/plugins/kibana_react/public/code_editor/register_languages.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66
* Side Public License, v 1.
77
*/
88
import { registerLanguage } from '@kbn/monaco';
9-
import { CssLang, HandlebarsLang, MarkdownLang } from './languages';
9+
import { CssLang, HandlebarsLang, MarkdownLang, YamlLang } from './languages';
1010

1111
registerLanguage(CssLang);
1212
registerLanguage(HandlebarsLang);
1313
registerLanguage(MarkdownLang);
14+
registerLanguage(YamlLang);

‎typings/index.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,4 @@ declare module 'react-syntax-highlighter/dist/cjs/prism-light';
3737
// Monaco languages support
3838
declare module 'monaco-editor/esm/vs/basic-languages/markdown/markdown';
3939
declare module 'monaco-editor/esm/vs/basic-languages/css/css';
40+
declare module 'monaco-editor/esm/vs/basic-languages/yaml/yaml';

‎x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/package_policy_input_var_field.tsx

+27-20
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,20 @@
77

88
import React, { useState, memo, useMemo } from 'react';
99
import ReactMarkdown from 'react-markdown';
10+
import { i18n } from '@kbn/i18n';
1011
import { FormattedMessage } from '@kbn/i18n/react';
1112
import {
1213
EuiFormRow,
1314
EuiSwitch,
1415
EuiFieldText,
1516
EuiText,
16-
EuiCodeEditor,
17-
EuiTextArea,
1817
EuiFieldPassword,
18+
EuiCodeBlock,
1919
} from '@elastic/eui';
2020

2121
import type { RegistryVarsEntry } from '../../../../types';
22+
import { CodeEditor } from '../../../../../../../../../../src/plugins/kibana_react/public';
2223

23-
import 'brace/mode/yaml';
24-
import 'brace/theme/textmate';
2524
import { MultiTextInput } from './multi_text_input';
2625

2726
export const PackagePolicyInputVarField: React.FunctionComponent<{
@@ -52,26 +51,34 @@ export const PackagePolicyInputVarField: React.FunctionComponent<{
5251
switch (type) {
5352
case 'yaml':
5453
return frozen ? (
55-
<EuiTextArea
56-
className="ace_editor"
57-
disabled
58-
value={value}
59-
style={{ height: '175px', padding: '4px', whiteSpace: 'pre', resize: 'none' }}
60-
/>
54+
<EuiCodeBlock language="yaml" isCopyable={false} paddingSize="s">
55+
<pre>{value}</pre>
56+
</EuiCodeBlock>
6157
) : (
62-
<EuiCodeEditor
58+
<CodeEditor
59+
languageId="yaml"
6360
width="100%"
64-
mode="yaml"
65-
theme="textmate"
66-
setOptions={{
67-
minLines: 10,
68-
maxLines: 30,
61+
height="300px"
62+
value={value}
63+
onChange={onChange}
64+
options={{
65+
minimap: {
66+
enabled: false,
67+
},
68+
ariaLabel: i18n.translate('xpack.fleet.packagePolicyField.yamlCodeEditor', {
69+
defaultMessage: 'YAML Code Editor',
70+
}),
71+
scrollBeyondLastLine: false,
72+
wordWrap: 'off',
73+
wrappingIndent: 'indent',
6974
tabSize: 2,
70-
showGutter: false,
75+
// To avoid left margin
76+
lineNumbers: 'off',
77+
lineNumbersMinChars: 0,
78+
glyphMargin: false,
79+
folding: false,
80+
lineDecorationsWidth: 0,
7181
}}
72-
value={value}
73-
onChange={(newVal) => onChange(newVal)}
74-
onBlur={() => setIsDirty(true)}
7582
/>
7683
);
7784
case 'bool':

‎x-pack/plugins/fleet/public/components/settings_flyout/index.tsx

+54-18
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*/
77

88
import React, { useEffect, useCallback } from 'react';
9+
import styled from 'styled-components';
910
import { i18n } from '@kbn/i18n';
1011
import {
1112
EuiFlyout,
@@ -21,9 +22,9 @@ import {
2122
EuiForm,
2223
EuiFormRow,
2324
EuiCode,
24-
EuiCodeEditor,
2525
EuiLink,
2626
EuiPanel,
27+
EuiTextColor,
2728
} from '@elastic/eui';
2829
import { FormattedMessage } from '@kbn/i18n/react';
2930
import { EuiText } from '@elastic/eui';
@@ -39,13 +40,29 @@ import {
3940
sendPutOutput,
4041
} from '../../hooks';
4142
import { isDiffPathProtocol, normalizeHostsForAgents } from '../../../common';
43+
import { CodeEditor } from '../../../../../../src/plugins/kibana_react/public';
4244

4345
import { SettingsConfirmModal } from './confirm_modal';
4446
import type { SettingsConfirmModalProps } from './confirm_modal';
4547
import { HostsInput } from './hosts_input';
4648

47-
import 'brace/mode/yaml';
48-
import 'brace/theme/textmate';
49+
const CodeEditorContainer = styled.div`
50+
min-height: 0;
51+
position: relative;
52+
height: 250px;
53+
`;
54+
55+
const CodeEditorPlaceholder = styled(EuiTextColor).attrs((props) => ({
56+
color: 'subdued',
57+
size: 'xs',
58+
}))`
59+
position: absolute;
60+
top: 0;
61+
right: 0;
62+
// Matches monaco editor
63+
font-family: Menlo, Monaco, 'Courier New', monospace;
64+
pointer-events: none;
65+
`;
4966

5067
const URL_REGEX = /^(https?):\/\/[^\s$.?#].[^\s]*$/gm;
5168

@@ -361,21 +378,40 @@ export const SettingFlyout: React.FunctionComponent<Props> = ({ onClose }) => {
361378
})}
362379
fullWidth
363380
>
364-
<EuiCodeEditor
365-
width="100%"
366-
mode="yaml"
367-
theme="textmate"
368-
placeholder="# YAML settings here will be added to the Elasticsearch output section of each policy"
369-
setOptions={{
370-
minLines: 10,
371-
maxLines: 30,
372-
tabSize: 2,
373-
showGutter: false,
374-
showPrintMargin: false,
375-
}}
376-
{...inputs.additionalYamlConfig.props}
377-
onChange={inputs.additionalYamlConfig.setValue}
378-
/>
381+
<CodeEditorContainer>
382+
<CodeEditor
383+
languageId="yaml"
384+
width="100%"
385+
height="250px"
386+
value={inputs.additionalYamlConfig.value}
387+
onChange={inputs.additionalYamlConfig.setValue}
388+
options={{
389+
minimap: {
390+
enabled: false,
391+
},
392+
393+
ariaLabel: i18n.translate('xpack.fleet.settings.yamlCodeEditor', {
394+
defaultMessage: 'YAML Code Editor',
395+
}),
396+
scrollBeyondLastLine: false,
397+
wordWrap: 'on',
398+
wrappingIndent: 'indent',
399+
automaticLayout: true,
400+
tabSize: 2,
401+
// To avoid left margin
402+
lineNumbers: 'off',
403+
lineNumbersMinChars: 0,
404+
glyphMargin: false,
405+
folding: false,
406+
lineDecorationsWidth: 0,
407+
}}
408+
/>
409+
{(!inputs.additionalYamlConfig.value || inputs.additionalYamlConfig.value === '') && (
410+
<CodeEditorPlaceholder>
411+
{`# YAML settings here will be added to the Elasticsearch output section of each policy`}
412+
</CodeEditorPlaceholder>
413+
)}
414+
</CodeEditorContainer>
379415
</EuiFormRow>
380416
</EuiPanel>
381417
</EuiForm>

0 commit comments

Comments
 (0)
Please sign in to comment.