Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -23,12 +23,15 @@ import {
EuiTitle,
} from '@elastic/eui';
import React, { Fragment, useState } from 'react';
import { HttpStart } from '../../../../../../src/core/public';
import { INTEGRATIONS_BASE } from '../../../../common/constants/shared';

interface IntegrationFlyoutProps {
onClose: () => void;
onCreate: (name: string, dataSource: string) => void;
integrationName: string;
integrationType: string;
http: HttpStart;
}

export const doTypeValidation = (toCheck: any, required: any): boolean => {
Expand Down Expand Up @@ -156,6 +159,17 @@ export function AddIntegrationFlyout(props: IntegrationFlyoutProps) {
},
];

const createDataSourceMappings = async (targetDataSource: string): Promise<any> => {
const data = await fetch(`${INTEGRATIONS_BASE}/repository/${integrationName}/schema`).then(
(response) => {
return response.json();
}
);
Object.keys(data.data.mappings).forEach(function (k) {
createMappings(k, data.data.mappings[k], targetDataSource);
});
};

const onCreateSelectChange = (value: any) => {
setCreateDatasourceOption(value);
};
Expand Down Expand Up @@ -210,6 +224,43 @@ export function AddIntegrationFlyout(props: IntegrationFlyoutProps) {
});
};

const createMappings = async (
componentName: string,
payload: any,
dataSourceName: string
): Promise<{ [key: string]: { properties: any } } | null> => {
if (componentName !== integrationType) {
return fetch(`/api/console/proxy?path=_component_template/${componentName}&method=POST`, {
method: 'POST',
headers: [
['osd-xsrf', 'true'],
['Content-Type', 'application/json'],
],
body: JSON.stringify(payload),
})
.then((response) => response.json())
.catch((err: any) => {
console.error(err);
return null;
});
} else {
payload.index_patterns = [dataSourceName];
return fetch(`/api/console/proxy?path=_index_template/${componentName}&method=POST`, {
method: 'POST',
headers: [
['osd-xsrf', 'true'],
['Content-Type', 'application/json'],
],
body: JSON.stringify(payload),
})
.then((response) => response.json())
.catch((err: any) => {
console.error(err);
return null;
});
}
};

const fetchIntegrationMappings = async (
targetName: string
): Promise<{ [key: string]: { template: { mappings: { properties?: any } } } } | null> => {
Expand Down Expand Up @@ -336,7 +387,9 @@ export function AddIntegrationFlyout(props: IntegrationFlyoutProps) {
append={
<EuiButton
data-test-subj="resetCustomEmbeddablePanelTitle"
onClick={() => {}}
onClick={() => {
createDataSourceMappings(createDataSource);
}}
disabled={createDataSource.length === 0}
>
Create
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ export function Integration(props: AvailableIntegrationProps) {
};

async function addIntegrationRequest(templateName: string, name: string, dataSource: string) {
console.log(name);
http
.post(`${INTEGRATIONS_BASE}/store/${templateName}`, {
body: JSON.stringify({ name, dataSource }),
Expand Down Expand Up @@ -163,6 +162,7 @@ export function Integration(props: AvailableIntegrationProps) {
}}
integrationName={integrationTemplateId}
integrationType={integration.type}
http={http}
/>
)}
</EuiPage>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"index_patterns": [
"sso_logs-*-*"
"ss4o_logs-*-*"
],
"data_stream": {},
"template": {
Expand Down Expand Up @@ -215,8 +215,8 @@
}
},
"composed_of": [
"http_template",
"communication_template"
"communication",
"http"
],
"version": 1,
"_meta": {
Expand Down