Skip to content

Commit

Permalink
add link to discover using url generator
Browse files Browse the repository at this point in the history
  • Loading branch information
alisonelizabeth committed Sep 21, 2020
1 parent ef10904 commit a32e5c1
Show file tree
Hide file tree
Showing 10 changed files with 83 additions and 28 deletions.
2 changes: 1 addition & 1 deletion x-pack/plugins/ingest_pipelines/kibana.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "8.0.0",
"server": true,
"ui": true,
"requiredPlugins": ["licensing", "management", "features"],
"requiredPlugins": ["licensing", "management", "features", "share"],
"optionalPlugins": ["security", "usageCollection"],
"configPath": ["xpack", "ingest_pipelines"],
"requiredBundles": ["esUiShared", "kibanaReact"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ const appServices = {
notifications: notificationServiceMock.createSetupContract(),
history,
uiSettings: {},
urlGenerators: {
getUrlGenerator: jest.fn().mockReturnValue({
createUrl: jest.fn(),
}),
},
};

const testBedSetup = registerTestBed<TestSubject>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,9 @@ describe('Test pipeline', () => {
const { actions, find, exists } = testBed;

const error = {
status: 400,
error: 'Bad Request',
message:
'"[parse_exception] [_source] required property is missing, with { property_name="_source" }"',
status: 500,
error: 'Internal server error',
message: 'Internal server error',
};

httpRequestsMockHelpers.setSimulatePipelineResponse(undefined, { body: error });
Expand All @@ -153,7 +152,20 @@ describe('Test pipeline', () => {
actions.clickAddDocumentsButton();

// Add invalid sample documents array and run the pipeline
actions.addDocumentsJson(JSON.stringify([{}]));
actions.addDocumentsJson(
JSON.stringify([
{
_index: 'test',
_id: '1',
_version: 1,
_seq_no: 0,
_primary_term: 1,
_source: {
name: 'John Doe',
},
},
])
);
await actions.clickRunPipelineButton();

// Verify error rendered
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
EuiCallOut,
} from '@elastic/eui';

import { Form, FormHook } from '../../../../../shared_imports';
import { FormHook } from '../../../../../shared_imports';
import { Document } from '../../types';

import { Tabs, TestPipelineFlyoutTab, OutputTab, DocumentsTab } from './test_pipeline_flyout_tabs';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const i18nTexts = {
}
),
validationMessage: i18n.translate(
'ingestPipelines.pipelineEditor.loadDocuments.indexRequiredError',
'xpack.ingestPipelines.pipelineEditor.loadDocuments.indexRequiredError',
{
defaultMessage: 'An index name is required.',
}
Expand All @@ -66,7 +66,7 @@ const i18nTexts = {
}
),
validationMessage: i18n.translate(
'ingestPipelines.pipelineEditor.loadDocuments.idRequiredError',
'xpack.ingestPipelines.pipelineEditor.loadDocuments.idRequiredError',
{
defaultMessage: 'A document ID is required.',
}
Expand Down Expand Up @@ -106,8 +106,6 @@ export const ImportDocumentForm: FunctionComponent<Props> = ({ onAddDocuments })
const { form } = useForm({ defaultValue: { index: '', id: '' } });

const submitForm = async (e: React.FormEvent) => {
// e.preventDefault();

const { isValid, data } = await form.submit();

const { id, index } = data;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@
* you may not use this file except in compliance with the Elastic License.
*/

import React, { FunctionComponent } from 'react';
import React, { FunctionComponent, useState, useEffect } from 'react';
import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n/react';

import { EuiAccordion, EuiText, EuiSpacer } from '@elastic/eui';
import { EuiAccordion, EuiText, EuiSpacer, EuiLink } from '@elastic/eui';

import { useKibana } from '../../../../../../shared_imports';

import { ImportDocumentForm } from './import_document_form';

Expand All @@ -18,21 +21,36 @@ const i18nTexts = {
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 }) => {
const { services } = useKibana();
const [discoverLink, setDiscoverLink] = useState('');

useEffect(() => {
let unmounted = false;

const getDiscoverUrl = async (): Promise<void> => {
if (!unmounted) {
const discoverUrlGenerator = services.urlGenerators.getUrlGenerator(
'DISCOVER_APP_URL_GENERATOR'
);
const discoverUrl = await discoverUrlGenerator.createUrl({ indexPatternId: undefined });
setDiscoverLink(discoverUrl);
}
};

getDiscoverUrl();

return () => {
unmounted = true;
};
}, [services.urlGenerators]);

return (
<EuiAccordion
id="addDocumentsAccordion"
Expand All @@ -42,7 +60,19 @@ export const ImportDocumentsAccordion: FunctionComponent<Props> = ({ onAddDocume
>
<>
<EuiText size="s" color="subdued">
<p>{i18nTexts.contentDescription}</p>
<p>
<FormattedMessage
id="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 {discoverLink}."
values={{
discoverLink: (
<EuiLink href={discoverLink} target="_blank" external>
Discover
</EuiLink>
),
}}
/>
</p>
</EuiText>

<EuiSpacer size="m" />
Expand Down
2 changes: 2 additions & 0 deletions x-pack/plugins/ingest_pipelines/public/application/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import React, { ReactNode } from 'react';
import { render, unmountComponentAtNode } from 'react-dom';
import { NotificationsSetup, IUiSettingsClient } from 'kibana/public';
import { ManagementAppMountParams } from 'src/plugins/management/public';
import { SharePluginStart } from 'src/plugins/share/public';
import { KibanaContextProvider } from '../../../../../src/plugins/kibana_react/public';

import { API_BASE_PATH } from '../../common/constants';
Expand All @@ -26,6 +27,7 @@ export interface AppServices {
notifications: NotificationsSetup;
history: ManagementAppMountParams['history'];
uiSettings: IUiSettingsClient;
urlGenerators: SharePluginStart['urlGenerators'];
}

export interface CoreServices {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@
import { CoreSetup } from 'src/core/public';
import { ManagementAppMountParams } from 'src/plugins/management/public';

import { StartDependencies } from '../types';
import { documentationService, uiMetricService, apiService, breadcrumbService } from './services';
import { renderApp } from '.';

export async function mountManagementSection(
{ http, getStartServices, notifications }: CoreSetup,
{ http, getStartServices, notifications }: CoreSetup<StartDependencies>,
params: ManagementAppMountParams
) {
const { element, setBreadcrumbs, history } = params;
const [coreStart] = await getStartServices();
const [coreStart, depsStart] = await getStartServices();
const {
docLinks,
i18n: { Context: I18nContext },
Expand All @@ -31,6 +32,7 @@ export async function mountManagementSection(
notifications,
history,
uiSettings: coreStart.uiSettings,
urlGenerators: depsStart.share.urlGenerators,
};

return renderApp(element, I18nContext, services, { http });
Expand Down
7 changes: 4 additions & 3 deletions x-pack/plugins/ingest_pipelines/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ import { CoreSetup, Plugin } from 'src/core/public';

import { PLUGIN_ID } from '../common/constants';
import { uiMetricService, apiService } from './application/services';
import { Dependencies } from './types';
import { SetupDependencies, StartDependencies } from './types';

export class IngestPipelinesPlugin implements Plugin {
public setup(coreSetup: CoreSetup, plugins: Dependencies): void {
export class IngestPipelinesPlugin
implements Plugin<void, void, SetupDependencies, StartDependencies> {
public setup(coreSetup: CoreSetup<StartDependencies>, plugins: SetupDependencies): void {
const { management, usageCollection } = plugins;
const { http, getStartServices } = coreSetup;

Expand Down
7 changes: 6 additions & 1 deletion x-pack/plugins/ingest_pipelines/public/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,13 @@

import { ManagementSetup } from 'src/plugins/management/public';
import { UsageCollectionSetup } from 'src/plugins/usage_collection/public';
import { SharePluginStart } from 'src/plugins/share/public';

export interface Dependencies {
export interface SetupDependencies {
management: ManagementSetup;
usageCollection: UsageCollectionSetup;
}

export interface StartDependencies {
share: SharePluginStart;
}

0 comments on commit a32e5c1

Please sign in to comment.