Skip to content

Commit

Permalink
[Ingest Node Pipelines] Integrate painless autocomplete (elastic#84554)…
Browse files Browse the repository at this point in the history
  • Loading branch information
alisonelizabeth authored Dec 4, 2020
1 parent de4d81d commit 0e5e413
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import React, { FunctionComponent } from 'react';
import { i18n } from '@kbn/i18n';
import { PainlessLang } from '@kbn/monaco';

import {
FieldConfig,
Expand Down Expand Up @@ -56,14 +57,17 @@ const tagConfig: FieldConfig = {
};

export const CommonProcessorFields: FunctionComponent = () => {
const suggestionProvider = PainlessLang.getSuggestionProvider('processor_conditional');

return (
<section>
<UseField
config={ifConfig}
component={TextEditor}
componentProps={{
editorProps: {
languageId: 'painless',
languageId: PainlessLang.ID,
suggestionProvider,
height: EDITOR_PX_HEIGHT.extraSmall,
options: {
lineNumbers: 'off',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,19 @@
* you may not use this file except in compliance with the Elastic License.
*/

import React, { useState } from 'react';
import React, { useState, useEffect } from 'react';
import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n/react';
import { PainlessLang } from '@kbn/monaco';
import { EuiCode, EuiSwitch, EuiFormRow } from '@elastic/eui';

import { FIELD_TYPES, fieldValidators, UseField, Field } from '../../../../../../shared_imports';
import {
FIELD_TYPES,
fieldValidators,
UseField,
Field,
useFormData,
} from '../../../../../../shared_imports';

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

Expand Down Expand Up @@ -122,6 +129,17 @@ const fieldsConfig: FieldsConfig = {

export const Script: FormFieldsComponent = ({ initialFieldValues }) => {
const [showId, setShowId] = useState(() => !!initialFieldValues?.id);
const [scriptLanguage, setScriptLanguage] = useState<string>('plaintext');

const [{ fields }] = useFormData({ watch: 'fields.lang' });

const suggestionProvider = PainlessLang.getSuggestionProvider('processor_conditional');

useEffect(() => {
const isPainlessLang = fields?.lang === 'painless' || fields?.lang === ''; // Scripting language defaults to painless if none specified
setScriptLanguage(isPainlessLang ? PainlessLang.ID : 'plaintext');
}, [fields]);

return (
<>
<EuiFormRow>
Expand All @@ -147,6 +165,9 @@ export const Script: FormFieldsComponent = ({ initialFieldValues }) => {
component={TextEditor}
componentProps={{
editorProps: {
languageId: scriptLanguage,
suggestionProvider:
scriptLanguage === PainlessLang.ID ? suggestionProvider : undefined,
height: EDITOR_PX_HEIGHT.medium,
'aria-label': i18n.translate(
'xpack.ingestPipelines.pipelineEditor.scriptForm.sourceFieldAriaLabel',
Expand Down

0 comments on commit 0e5e413

Please sign in to comment.