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 pipelines] Edit pipeline page #63522

Merged
Show file tree
Hide file tree
Changes from 8 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 @@ -47,7 +47,7 @@ describe('pipeline_serialization', () => {
},
},
],
onFailure: [
on_failure: [
{
set: {
field: 'error.message',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,10 @@ export function deserializePipelines(pipelinesByName: PipelinesByName): Pipeline
const pipelineNames: string[] = Object.keys(pipelinesByName);

const deserializedPipelines = pipelineNames.map((name: string) => {
const { description, version, processors, on_failure } = pipelinesByName[name];

const pipeline = {
return {
...pipelinesByName[name],
name,
description,
version,
processors,
onFailure: on_failure,
};

return pipeline;
});

return deserializedPipelines;
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/ingest_pipelines/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export interface Pipeline {
description: string;
version?: number;
processors: Processor[];
onFailure?: Processor[];
on_failure?: Processor[];
}

export interface PipelinesByName {
Expand Down
3 changes: 2 additions & 1 deletion x-pack/plugins/ingest_pipelines/public/application/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import React from 'react';
import { HashRouter, Switch, Route } from 'react-router-dom';
import { BASE_PATH } from '../../common/constants';
import { PipelinesList, PipelinesCreate } from './sections';
import { PipelinesList, PipelinesCreate, PipelinesEdit } from './sections';

export const App = () => {
return (
Expand All @@ -21,5 +21,6 @@ export const AppWithoutRouter = () => (
<Switch>
<Route exact path={BASE_PATH} component={PipelinesList} />
<Route exact path={`${BASE_PATH}/create`} component={PipelinesCreate} />
<Route exact path={`${BASE_PATH}/edit/:name`} component={PipelinesEdit} />
</Switch>
);
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@
export { PipelineForm } from './pipeline_form';

export { SectionError } from './section_error';

export { PipelineRequestFlyoutProvider as PipelineRequestFlyout } from './pipeline_request_flyout_provider';
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,15 @@
import React, { useState } from 'react';
import { FormattedMessage } from '@kbn/i18n/react';
import { i18n } from '@kbn/i18n';
import { EuiButton, EuiFlexGroup, EuiFlexItem, EuiSpacer, EuiSwitch, EuiLink } from '@elastic/eui';
import {
EuiButton,
EuiButtonEmpty,
EuiFlexGroup,
EuiFlexItem,
EuiSpacer,
EuiSwitch,
EuiLink,
} from '@elastic/eui';

import {
useForm,
Expand All @@ -20,14 +28,15 @@ import {
} from '../../../shared_imports';
import { Pipeline } from '../../../../common/types';

import { SectionError } from '../section_error';
import { SectionError, PipelineRequestFlyout } from '../';
import { pipelineFormSchema } from './schema';

interface Props {
onSave: (pipeline: Pipeline) => void;
isSaving: boolean;
saveError: any;
defaultValue?: Pipeline;
isEditing?: boolean;
}

const UseField = getUseField({ component: Field });
Expand All @@ -38,17 +47,21 @@ export const PipelineForm: React.FunctionComponent<Props> = ({
name: '',
description: '',
processors: '',
onFailure: '',
on_failure: '',
version: '',
},
onSave,
isSaving,
saveError,
isEditing,
}) => {
const { services } = useKibana();

const [isVersionVisible, setIsVersionVisible] = useState<boolean>(false);
const [isOnFailureEditorVisible, setIsOnFailureEditorVisible] = useState<boolean>(false);
const [isVersionVisible, setIsVersionVisible] = useState<boolean>(Boolean(defaultValue.version));
const [isOnFailureEditorVisible, setIsOnFailureEditorVisible] = useState<boolean>(
Boolean(defaultValue.on_failure)
);
const [isRequestVisible, setIsRequestVisible] = useState<boolean>(false);

const handleSave: FormConfig['onSubmit'] = (formData, isValid) => {
if (isValid) {
Expand All @@ -62,6 +75,23 @@ export const PipelineForm: React.FunctionComponent<Props> = ({
onSubmit: handleSave,
});

const saveButtonLabel = isSaving ? (
<FormattedMessage
id="xpack.ingestPipelines.form.savingButtonLabel"
defaultMessage="Saving..."
/>
) : isEditing ? (
<FormattedMessage
id="xpack.ingestPipelines.form.saveButtonLabel"
defaultMessage="Save pipeline"
/>
) : (
<FormattedMessage
id="xpack.ingestPipelines.form.createButtonLabel"
defaultMessage="Create pipeline"
/>
);

return (
<>
{saveError ? (
Expand Down Expand Up @@ -116,6 +146,7 @@ export const PipelineForm: React.FunctionComponent<Props> = ({
path="name"
componentProps={{
['data-test-subj']: 'nameField',
euiFieldProps: { disabled: Boolean(isEditing) },
}}
/>

Expand Down Expand Up @@ -237,7 +268,7 @@ export const PipelineForm: React.FunctionComponent<Props> = ({
>
{isOnFailureEditorVisible ? (
<UseField
path="onFailure"
path="on_failure"
component={JsonEditorField}
componentProps={{
['data-test-subj']: 'onFailureEditor',
Expand All @@ -264,28 +295,41 @@ export const PipelineForm: React.FunctionComponent<Props> = ({
{/* Form submission */}
<EuiFlexGroup justifyContent="spaceBetween">
<EuiFlexItem grow={false}>
<EuiFlexGroup>
<EuiFlexItem grow={false}>
<EuiButton
fill
color="secondary"
iconType="check"
onClick={form.submit}
data-test-subj="submitButton"
disabled={form.isSubmitted && form.isValid === false}
isLoading={isSaving}
>
{
<FormattedMessage
id="xpack.ingestPipelines.form.createButtonLabel"
defaultMessage="Create pipeline"
/>
}
</EuiButton>
</EuiFlexItem>
</EuiFlexGroup>
<EuiButton
fill
color="secondary"
iconType="check"
onClick={form.submit}
data-test-subj="submitButton"
disabled={form.isSubmitted && form.isValid === false}
isLoading={isSaving}
>
{saveButtonLabel}
</EuiButton>
</EuiFlexItem>
<EuiFlexItem grow={false}>
<EuiButtonEmpty
onClick={() => setIsRequestVisible(prevIsRequestVisible => !prevIsRequestVisible)}
>
{isRequestVisible ? (
<FormattedMessage
id="xpack.ingestPipelines.form.hideRequestButtonLabel"
defaultMessage="Hide request"
/>
) : (
<FormattedMessage
id="xpack.ingestPipelines.form.showRequestButtonLabel"
defaultMessage="Show request"
/>
)}
</EuiButtonEmpty>
</EuiFlexItem>
</EuiFlexGroup>
{isRequestVisible ? (
<PipelineRequestFlyout
closeFlyout={() => setIsRequestVisible(prevIsRequestVisible => !prevIsRequestVisible)}
/>
) : null}
</Form>

<EuiSpacer size="m" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export const pipelineFormSchema: FormSchema = {
},
],
},
onFailure: {
on_failure: {
label: i18n.translate('xpack.ingestPipelines.form.onFailureFieldLabel', {
defaultMessage: 'On-failure processors (optional)',
}),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import React, { useRef } from 'react';
import { FormattedMessage } from '@kbn/i18n/react';

import {
EuiButtonEmpty,
EuiCodeBlock,
EuiFlyout,
EuiFlyoutBody,
EuiFlyoutFooter,
EuiFlyoutHeader,
EuiSpacer,
EuiText,
EuiTitle,
} from '@elastic/eui';

import { Pipeline } from '../../../common/types';

interface Props {
pipeline: Pipeline;
closeFlyout: () => void;
}

export const PipelineRequestFlyout: React.FunctionComponent<Props> = ({
closeFlyout,
pipeline,
}) => {
const { name, ...pipelineBody } = pipeline;
const endpoint = `PUT _ingest/pipeline/${name || '<pipelineName>'}`;
const payload = JSON.stringify(pipelineBody, null, 2);
const request = `${endpoint}\n${payload}`;
// Hack so that copied-to-clipboard value updates as content changes
// Related issue: https://github.com/elastic/eui/issues/3321
const uuid = useRef(0);
uuid.current++;

return (
<EuiFlyout maxWidth={480} onClose={closeFlyout}>
<EuiFlyoutHeader>
<EuiTitle>
<h2>
{name ? (
<FormattedMessage
id="xpack.ingestPipelines.requestFlyout.namedTitle"
defaultMessage="Request for '{name}'"
values={{ name }}
/>
) : (
<FormattedMessage
id="xpack.ingestPipelines.requestFlyout.unnamedTitle"
defaultMessage="Request"
/>
)}
</h2>
</EuiTitle>
</EuiFlyoutHeader>

<EuiFlyoutBody>
<EuiText>
<p>
<FormattedMessage
id="xpack.ingestPipelines.requestFlyout.descriptionText"
defaultMessage="This Elasticsearch request will create or update this pipeline."
/>
</p>
</EuiText>

<EuiSpacer />
<EuiCodeBlock language="json" isCopyable key={uuid.current}>
{request}
</EuiCodeBlock>
</EuiFlyoutBody>

<EuiFlyoutFooter>
<EuiButtonEmpty iconType="cross" onClick={closeFlyout} flush="left">
<FormattedMessage
id="xpack.ingestPipelines.requestFlyout.closeButtonLabel"
defaultMessage="Close"
/>
</EuiButtonEmpty>
</EuiFlyoutFooter>
</EuiFlyout>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import React, { useState, useEffect } from 'react';

import { Pipeline } from '../../../common/types';
import { useFormContext } from '../../shared_imports';
import { PipelineRequestFlyout } from './pipeline_request_flyout';

export const PipelineRequestFlyoutProvider = ({ closeFlyout }: { closeFlyout: () => void }) => {
const form = useFormContext();
const [formData, setFormData] = useState<Pipeline>({} as Pipeline);

useEffect(() => {
const subscription = form.subscribe(async ({ isValid, validate, data }) => {
const isFormValid = isValid ?? (await validate());
if (isFormValid) {
setFormData(data.format() as Pipeline);
}
});

return subscription.unsubscribe;
}, [form]);

return <PipelineRequestFlyout pipeline={formData} closeFlyout={closeFlyout} />;
};
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,6 @@
import { EuiCallOut } from '@elastic/eui';
import React from 'react';

export interface Error {
error: string;
message: string;
statusCode: number;
}

interface Props {
title: React.ReactNode;
error: Error;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@
export { PipelinesList } from './pipelines_list';

export { PipelinesCreate } from './pipelines_create';

export { PipelinesEdit } from './pipelines_edit';
Loading