Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Ingest Node Pipelines] Integrate painless autocomplete #84554

Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!


const [{ fields }] = useFormData();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

This will make sure we don't re-render unless needed otherwise there is some sluggishness on text inputs.


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