-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
debug a pipeline with an index document
- Loading branch information
1 parent
f64aa5b
commit 3936e3b
Showing
10 changed files
with
438 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
174 changes: 174 additions & 0 deletions
174
...essors_editor/components/test_pipeline/test_pipeline_flyout_tabs/import_document_form.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,174 @@ | ||
/* | ||
* 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, FunctionComponent } from 'react'; | ||
import { i18n } from '@kbn/i18n'; | ||
import { | ||
EuiFormRow, | ||
EuiButton, | ||
EuiFlexGroup, | ||
EuiFlexItem, | ||
EuiPanel, | ||
EuiCallOut, | ||
EuiSpacer, | ||
} from '@elastic/eui'; | ||
|
||
import { | ||
getUseField, | ||
Field, | ||
useKibana, | ||
useForm, | ||
Form, | ||
TextField, | ||
fieldValidators, | ||
FieldConfig, | ||
} from '../../../../../../shared_imports'; | ||
|
||
const UseField = getUseField({ component: Field }); | ||
|
||
const { emptyField } = fieldValidators; | ||
|
||
const i18nTexts = { | ||
importDocumentButton: i18n.translate( | ||
'xpack.ingestPipelines.pipelineEditor.loadDocuments.importDocButtonLabel', | ||
{ | ||
defaultMessage: 'Import', | ||
} | ||
), | ||
importDocumentErrorMessage: i18n.translate( | ||
'xpack.ingestPipelines.pipelineEditor.loadDocuments.importDocErrorMessage', | ||
{ | ||
defaultMessage: 'Error importing document', | ||
} | ||
), | ||
indexField: { | ||
fieldLabel: i18n.translate( | ||
'xpack.ingestPipelines.pipelineEditor.loadDocuments.table.indexColumnLabel', | ||
{ | ||
defaultMessage: 'Index', | ||
} | ||
), | ||
validationMessage: i18n.translate( | ||
'ingestPipelines.pipelineEditor.loadDocuments.indexRequiredError', | ||
{ | ||
defaultMessage: 'An index name is required.', | ||
} | ||
), | ||
}, | ||
idField: { | ||
fieldLabel: i18n.translate( | ||
'xpack.ingestPipelines.pipelineEditor.loadDocuments.table.documentIdColumnLabel', | ||
{ | ||
defaultMessage: 'Document ID', | ||
} | ||
), | ||
validationMessage: i18n.translate( | ||
'ingestPipelines.pipelineEditor.loadDocuments.idRequiredError', | ||
{ | ||
defaultMessage: 'A document ID is required.', | ||
} | ||
), | ||
}, | ||
}; | ||
|
||
const fieldsConfig: Record<string, FieldConfig> = { | ||
index: { | ||
label: i18nTexts.indexField.fieldLabel, | ||
validations: [ | ||
{ | ||
validator: emptyField(i18nTexts.indexField.validationMessage), | ||
}, | ||
], | ||
}, | ||
id: { | ||
label: i18nTexts.idField.fieldLabel, | ||
validations: [ | ||
{ | ||
validator: emptyField(i18nTexts.idField.validationMessage), | ||
}, | ||
], | ||
}, | ||
}; | ||
|
||
interface Props { | ||
onAddDocuments: (document: any) => void; | ||
} | ||
|
||
export const ImportDocumentForm: FunctionComponent<Props> = ({ onAddDocuments }) => { | ||
const { services } = useKibana(); | ||
|
||
const [isLoadingDocument, setIsLoadingDocument] = useState<boolean>(false); | ||
const [loadingDocumentError, setLoadingDocumentError] = useState<Error | undefined>(undefined); | ||
|
||
const { form } = useForm({ defaultValue: { index: '', id: '' } }); | ||
|
||
const submitForm = async (e: React.FormEvent) => { | ||
// e.preventDefault(); | ||
|
||
const { isValid, data } = await form.submit(); | ||
|
||
const { id, index } = data; | ||
|
||
if (isValid) { | ||
setIsLoadingDocument(true); | ||
|
||
const { error, data: document } = await services.api.loadDocument(index, id); | ||
|
||
setIsLoadingDocument(false); | ||
|
||
if (error) { | ||
setLoadingDocumentError(error); | ||
return; | ||
} | ||
|
||
onAddDocuments(document); | ||
form.reset(); | ||
} | ||
}; | ||
|
||
return ( | ||
<Form form={form} onSubmit={submitForm}> | ||
{loadingDocumentError && ( | ||
<> | ||
<EuiCallOut | ||
title={i18nTexts.importDocumentErrorMessage} | ||
color="danger" | ||
iconType="alert" | ||
data-test-subj="pipelineExecutionError" | ||
> | ||
<p>{loadingDocumentError.message}</p> | ||
</EuiCallOut> | ||
|
||
<EuiSpacer size="m" /> | ||
</> | ||
)} | ||
|
||
<EuiPanel paddingSize="m"> | ||
<EuiFlexGroup> | ||
<EuiFlexItem> | ||
<UseField path="index" component={TextField} config={fieldsConfig.index} /> | ||
</EuiFlexItem> | ||
|
||
<EuiFlexItem> | ||
<UseField path="id" component={TextField} config={fieldsConfig.id} /> | ||
</EuiFlexItem> | ||
|
||
<EuiFlexItem grow={false}> | ||
<EuiFormRow hasEmptyLabelSpace> | ||
<EuiButton | ||
onClick={submitForm} | ||
data-test-subj="addDocumentButton" | ||
isLoading={isLoadingDocument} | ||
> | ||
{i18nTexts.importDocumentButton} | ||
</EuiButton> | ||
</EuiFormRow> | ||
</EuiFlexItem> | ||
</EuiFlexGroup> | ||
</EuiPanel> | ||
</Form> | ||
); | ||
}; |
54 changes: 54 additions & 0 deletions
54
..._editor/components/test_pipeline/test_pipeline_flyout_tabs/import_documents_accordion.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* 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, { FunctionComponent } from 'react'; | ||
import { i18n } from '@kbn/i18n'; | ||
|
||
import { EuiAccordion, EuiText, EuiSpacer } from '@elastic/eui'; | ||
|
||
import { ImportDocumentForm } from './import_document_form'; | ||
|
||
const i18nTexts = { | ||
addDocumentsButton: i18n.translate( | ||
'xpack.ingestPipelines.pipelineEditor.importDocumentsAccordion.importButtonLabel', | ||
{ | ||
defaultMessage: 'Import existing documents', | ||
} | ||
), | ||
// TODO add link to Discover | ||
contentDescription: i18n.translate( | ||
'xpack.ingestPipelines.pipelineEditor.importDocumentsAccordion.contentDescriptionText', | ||
{ | ||
defaultMessage: | ||
'Provide the index name and document ID of the indexed document to test. To explore your existing data, use Discover.', | ||
} | ||
), | ||
}; | ||
|
||
interface Props { | ||
onAddDocuments: (document: any) => void; | ||
} | ||
|
||
export const ImportDocumentsAccordion: FunctionComponent<Props> = ({ onAddDocuments }) => { | ||
return ( | ||
<EuiAccordion | ||
id="addDocumentsAccordion" | ||
buttonContent={i18nTexts.addDocumentsButton} | ||
paddingSize="s" | ||
data-test-subj="importDocumentsAccordion" | ||
> | ||
<> | ||
<EuiText size="s" color="subdued"> | ||
<p>{i18nTexts.contentDescription}</p> | ||
</EuiText> | ||
|
||
<EuiSpacer size="m" /> | ||
|
||
<ImportDocumentForm onAddDocuments={onAddDocuments} /> | ||
</> | ||
</EuiAccordion> | ||
); | ||
}; |
Oops, something went wrong.