Skip to content

Commit 0e5e413

Browse files
[Ingest Node Pipelines] Integrate painless autocomplete (#84554) (#84952)
1 parent de4d81d commit 0e5e413

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

x-pack/plugins/ingest_pipelines/public/application/components/pipeline_processors_editor/components/processor_form/processors/common_fields/common_processor_fields.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import React, { FunctionComponent } from 'react';
88
import { i18n } from '@kbn/i18n';
9+
import { PainlessLang } from '@kbn/monaco';
910

1011
import {
1112
FieldConfig,
@@ -56,14 +57,17 @@ const tagConfig: FieldConfig = {
5657
};
5758

5859
export const CommonProcessorFields: FunctionComponent = () => {
60+
const suggestionProvider = PainlessLang.getSuggestionProvider('processor_conditional');
61+
5962
return (
6063
<section>
6164
<UseField
6265
config={ifConfig}
6366
component={TextEditor}
6467
componentProps={{
6568
editorProps: {
66-
languageId: 'painless',
69+
languageId: PainlessLang.ID,
70+
suggestionProvider,
6771
height: EDITOR_PX_HEIGHT.extraSmall,
6872
options: {
6973
lineNumbers: 'off',

x-pack/plugins/ingest_pipelines/public/application/components/pipeline_processors_editor/components/processor_form/processors/script.tsx

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,19 @@
44
* you may not use this file except in compliance with the Elastic License.
55
*/
66

7-
import React, { useState } from 'react';
7+
import React, { useState, useEffect } from 'react';
88
import { i18n } from '@kbn/i18n';
99
import { FormattedMessage } from '@kbn/i18n/react';
10+
import { PainlessLang } from '@kbn/monaco';
1011
import { EuiCode, EuiSwitch, EuiFormRow } from '@elastic/eui';
1112

12-
import { FIELD_TYPES, fieldValidators, UseField, Field } from '../../../../../../shared_imports';
13+
import {
14+
FIELD_TYPES,
15+
fieldValidators,
16+
UseField,
17+
Field,
18+
useFormData,
19+
} from '../../../../../../shared_imports';
1320

1421
import { XJsonEditor, TextEditor } from '../field_components';
1522

@@ -122,6 +129,17 @@ const fieldsConfig: FieldsConfig = {
122129

123130
export const Script: FormFieldsComponent = ({ initialFieldValues }) => {
124131
const [showId, setShowId] = useState(() => !!initialFieldValues?.id);
132+
const [scriptLanguage, setScriptLanguage] = useState<string>('plaintext');
133+
134+
const [{ fields }] = useFormData({ watch: 'fields.lang' });
135+
136+
const suggestionProvider = PainlessLang.getSuggestionProvider('processor_conditional');
137+
138+
useEffect(() => {
139+
const isPainlessLang = fields?.lang === 'painless' || fields?.lang === ''; // Scripting language defaults to painless if none specified
140+
setScriptLanguage(isPainlessLang ? PainlessLang.ID : 'plaintext');
141+
}, [fields]);
142+
125143
return (
126144
<>
127145
<EuiFormRow>
@@ -147,6 +165,9 @@ export const Script: FormFieldsComponent = ({ initialFieldValues }) => {
147165
component={TextEditor}
148166
componentProps={{
149167
editorProps: {
168+
languageId: scriptLanguage,
169+
suggestionProvider:
170+
scriptLanguage === PainlessLang.ID ? suggestionProvider : undefined,
150171
height: EDITOR_PX_HEIGHT.medium,
151172
'aria-label': i18n.translate(
152173
'xpack.ingestPipelines.pipelineEditor.scriptForm.sourceFieldAriaLabel',

0 commit comments

Comments
 (0)